blob: 02ec223fce5f2ad65f4807c75f0f4941cd569418 [file] [log] [blame]
Rich Lane284dc4d2014-01-06 15:24:07 -08001# Distributed under the OpenFlow Software License (see LICENSE)
2# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
3"""
4BSN gentable extension test cases
5"""
6
7import logging
8
9from oftest import config
10import oftest.base_tests as base_tests
11import ofp
12
13from oftest.testutils import *
14
15# Hardcoded in the switch to ease testing
16TABLE_ID = 0
17
18class BaseGenTableTest(base_tests.SimpleProtocol):
19 def setUp(self):
20 base_tests.SimpleProtocol.setUp(self)
21 self.clear()
22
23 def tearDown(self):
24 self.clear()
25 base_tests.SimpleProtocol.tearDown(self)
26
27 def clear(self):
28 request = ofp.message.bsn_gentable_clear_request(table_id=TABLE_ID)
29 response, _ = self.controller.transact(request)
30 self.assertIsInstance(response, ofp.message.bsn_gentable_clear_reply)
31 self.assertEquals(response.error_count, 0)
32
33 def do_add(self, vlan_vid, ipv4, mac, idle_notification=False):
34 msg = ofp.message.bsn_gentable_entry_add(
35 table_id=TABLE_ID,
36 key=[
37 ofp.bsn_tlv.vlan_vid(vlan_vid),
38 ofp.bsn_tlv.ipv4(ipv4)],
39 value=[
40 ofp.bsn_tlv.mac(mac)],
41 checksum=0)
42 if idle_notification:
43 msg.value.append(ofp.bsn_tlv.idle_notification())
44 self.controller.message_send(msg)
45
46 def do_delete(self, vlan_vid, ipv4):
47 msg = ofp.message.bsn_gentable_entry_delete(
48 table_id=TABLE_ID,
49 key=[
50 ofp.bsn_tlv.vlan_vid(vlan_vid),
51 ofp.bsn_tlv.ipv4(ipv4)])
52 self.controller.message_send(msg)
53
54class ClearAll(BaseGenTableTest):
55 """
56 Test clearing entire table
57 """
58 def runTest(self):
59 # Add a few entries
60 for i in range(0, 3):
61 self.do_add(vlan_vid=i, ipv4=0x12345678, mac=(0, 1, 2, 3, 4, i))
62
63 do_barrier(self.controller)
64 verify_no_errors(self.controller)
65
66 # Delete all entries
67 request = ofp.message.bsn_gentable_clear_request(table_id=TABLE_ID)
68 response, _ = self.controller.transact(request)
69 self.assertIsInstance(response, ofp.message.bsn_gentable_clear_reply)
70 self.assertEquals(response.error_count, 0)
71 self.assertEquals(response.deleted_count, 3)
72
73class AddDelete(BaseGenTableTest):
74 """
75 Test adding and deleting entries
76 """
77 def runTest(self):
78 # Add a few entries
79 for i in range(0, 3):
80 self.do_add(vlan_vid=i, ipv4=0x12345678, mac=(0, 1, 2, 3, 4, i))
81
82 do_barrier(self.controller)
83 verify_no_errors(self.controller)
84
85 # Delete each entry
86 for i in range(0, 3):
87 self.do_delete(vlan_vid=i, ipv4=0x12345678)
88
89 do_barrier(self.controller)
90 verify_no_errors(self.controller)
91
92 # Clear table, but expect it to have already been empty
93 request = ofp.message.bsn_gentable_clear_request(table_id=TABLE_ID)
94 response, _ = self.controller.transact(request)
95 self.assertIsInstance(response, ofp.message.bsn_gentable_clear_reply)
96 self.assertEquals(response.error_count, 0)
97 self.assertEquals(response.deleted_count, 0)