blob: 8fd514dc82a04840c70114a6465b17e7a92a8e57 [file] [log] [blame]
Flavio Castro96646c62015-11-16 15:05:43 -05001"""
2Flow Test
3Test each flow table can set entry, and packet rx correctly.
41) L3UcastRoute
52) QinQ
6"""
7
8import logging
9
10from oftest import config
11import oftest.base_tests as base_tests
12import ofp
13from oftest.testutils import *
14from accton_util import *
15
Flavio Castro6efe1862015-11-18 16:28:06 -050016class L2Flood(base_tests.SimpleDataPlane):
17 def runTest(self):
Flavio Castro96646c62015-11-16 15:05:43 -050018 delete_all_flows(self.controller)
19 delete_all_groups(self.controller)
20
21 if len(config["port_map"]) <2:
22 logging.info("Port count less than 2, can't run this case")
23 return
Flavio Castro6efe1862015-11-18 16:28:06 -050024
Flavio Castro96646c62015-11-16 15:05:43 -050025 vlan_id=1
Flavio Castro6efe1862015-11-18 16:28:06 -050026 mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
Flavio Castro96646c62015-11-16 15:05:43 -050027 for port in config["port_map"].keys():
28 #add l2 interface group
29 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro96646c62015-11-16 15:05:43 -050030 #add vlan flow table
31 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro6efe1862015-11-18 16:28:06 -050032 #add Bridgin table exact match
33 group_id = encode_l2_interface_group_id(vlan_id, port)
34 mac[5]=port
35 add_bridge_flow(self.controller, mac, vlan_id, group_id, True)
Flavio Castro96646c62015-11-16 15:05:43 -050036
Flavio Castro6efe1862015-11-18 16:28:06 -050037 do_barrier(self.controller)
Flavio Castro96646c62015-11-16 15:05:43 -050038
Flavio Castro6efe1862015-11-18 16:28:06 -050039 for outport in config["port_map"].keys():
40 mac[5]=outport
41 dst_mac=':'.join(['%02X' % x for x in mac])
42 for inport in config["port_map"].keys():
43 if inport is not outport:
44 mac[5]=inport
45 src_mac = ':'.join(['%02X' % x for x in mac])
46 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac,
47 eth_src=src_mac, ip_src="192.168.1.1", ip_dst='192.168.1.2')
48 pkt=str(parsed_pkt)
49 self.dataplane.send(inport, pkt)
50 verify_packet(self, pkt, outport)
51 verify_no_other_packets(self)
Flavio Castro96646c62015-11-16 15:05:43 -050052
Flavio Castro6efe1862015-11-18 16:28:06 -050053class L2Unicast(base_tests.SimpleDataPlane):
Flavio Castro8a4665a2015-11-16 18:49:18 -050054 def runTest(self):
Flavio Castro6efe1862015-11-18 16:28:06 -050055 delete_all_flows(self.controller)
56 delete_all_groups(self.controller)
57
58 if len(config["port_map"]) <2:
59 logging.info("Port count less than 2, can't run this case")
60 return
61
62 vlan_id=1
63 mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
64 for port in config["port_map"].keys():
65 #add l2 interface group
66 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
67 #add vlan flow table
68 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
69 #add Bridgin table exact match
70 group_id = encode_l2_interface_group_id(vlan_id, port)
71 mac[5]=port
72 add_bridge_flow(self.controller, mac, vlan_id, group_id, True)
73
74 do_barrier(self.controller)
75
76 for outport in config["port_map"].keys():
77 mac[5]=outport
78 dst_mac=':'.join(['%02X' % x for x in mac])
79 for inport in config["port_map"].keys():
80 if inport is not outport:
81 mac[5]=inport
82 src_mac = ':'.join(['%02X' % x for x in mac])
83 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac,
84 eth_src=src_mac, ip_src="192.168.1.1", ip_dst='192.168.1.2')
85 pkt=str(parsed_pkt)
86 self.dataplane.send(inport, pkt)
87 verify_packet(self, pkt, outport)
88 verify_no_other_packets(self)
89
90
Flavio Castro96646c62015-11-16 15:05:43 -050091
92class qinq(base_tests.SimpleDataPlane):
93 def runTest(self):
94 delete_all_flows(self.controller)
95 delete_all_groups(self.controller)
96
97 in_port = config["port_map"].keys()[0]
98 out_port = config["port_map"].keys()[1]
99 out_vlan=10
100 #add_vlan_table_flow_pvid(self.controller, in_port, None, out_vlan, False)
101 add_vlan_table_flow_pvid(self.controller, in_port, 1,out_vlan, False)
102 group_id, msg=add_one_l2_interface_grouop(self.controller, out_port, out_vlan, True, False)
103 #add acl
104 match = ofp.match()
105 match.oxm_list.append(ofp.oxm.in_port(in_port))
106 request = ofp.message.flow_add(
107 table_id=60,
108 cookie=42,
109 match=match,
110 instructions=[
111 ofp.instruction.write_actions(
112 actions=[
113 ofp.action.group(msg.group_id)])
114 ],
115 buffer_id=ofp.OFP_NO_BUFFER,
116 priority=1000)
117 self.controller.message_send(request)
118
119 #input tag packet
120 parsed_pkt = simple_tcp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=1)
121 pkt = str(parsed_pkt)
122 self.dataplane.send(in_port, pkt)
123
124 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=10,
125 in_dl_vlan_enable=True, in_vlan_vid=1)
126 verify_packet(self, str(parsed_pkt), out_port)
127
Flavio Castro8a4665a2015-11-16 18:49:18 -0500128class VlanFlow(base_tests.SimpleProtocol):
129 def runTest(self):
130 logging.info("Installing ACL rule")
Flavio Castro96646c62015-11-16 15:05:43 -0500131
132class FlowStats(base_tests.SimpleProtocol):
133 """
134 Flow stats multipart transaction
135 Only verifies we get a reply.
136 """
137 def runTest(self):
138 logging.info("Sending flow stats request")
139 stats = get_flow_stats(self, ofp.match())
140 logging.info("Received %d flow stats entries", len(stats))
141 for entry in stats:
142 logging.info(entry.show())
143
144
145class ACLStats(base_tests.SimpleProtocol):
146 """
147 Flow stats multipart transaction
148 Only verifies we get a reply.
149 """
150 def runTest(self):
151 logging.info("Installing ACL rule")
152 #delete_all_flows(self.controller)
153 #delete_all_groups(self.controller)
154
155 in_port = config["port_map"].keys()[0]
156 out_port=config["port_map"].keys()[1]
157 out_vlan=10
158 #add_vlan_table_flow_pvid(self.controller, in_port, None, out_vlan, False)
159 #add_vlan_table_flow_pvid(self.controller, in_port, 1,out_vlan, False)
160 group_id, msg=add_one_l2_interface_grouop(self.controller, out_port, out_vlan, True, False)
161 inst=[ofp.instruction.write_actions(
162 actions=[
163 ofp.action.group(msg.group_id)])
164 ],
165
166 #add acl
167 match = ofp.match()
168 match.oxm_list.append(ofp.oxm.in_port(in_port))
169 request = ofp.message.flow_add(
170 table_id=60,
171 cookie=42,
172 match=match,
173 instructions=inst,
174 buffer_id=ofp.OFP_NO_BUFFER,
175 priority=1000)
176 #self.controller.message_send(request)
177
178 logging.info("Sending flow stats request")
179 stats = get_flow_stats(self, match)
180 logging.info("Received %d flow stats entries", len(stats))
181 verify_flow_stats=[ofp.flow_stats_entry(
182 table_id=60
183 #cookie=42,
184 #match=match,
185 #instructions=inst,
186 #priority=1000
187)]
188 self.assertEquals(stats, verify_flow_stats)
189
Flavio Castro8a4665a2015-11-16 18:49:18 -0500190
191#class LearningPacketIn()git