blob: f9dffe3324829478f5dd4d17acec20860b3603d1 [file] [log] [blame]
Flavio Castro05d20bc2015-11-16 15:06:14 -05001"""
Flavio Castro423df652016-05-17 20:14:08 -04002Check README file
Flavio Castro05d20bc2015-11-16 15:06:14 -05003"""
Flavio Castro1c9b1252016-02-04 18:42:58 -05004import Queue
Flavio Castro05d20bc2015-11-16 15:06:14 -05005
Flavio Castro05d20bc2015-11-16 15:06:14 -05006from oftest import config
Flavio Castro67d8bd52016-02-03 14:22:14 -05007import inspect
Flavio Castro167f5bd2015-12-02 19:33:53 -05008import logging
9import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050010import ofp
11from oftest.testutils import *
12from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050013
Flavio Castro1c9b1252016-02-04 18:42:58 -050014
Flavio Castroa7162bb2016-07-25 17:30:30 -070015class PacketInUDP( base_tests.SimpleDataPlane ):
Flavio Castro6d498522015-12-15 14:05:04 -050016 """
Flavio Castro1c9b1252016-02-04 18:42:58 -050017 Verify a ACL rule that matches on IP_PROTO 2 will not match a UDP packet.
18 Next it verify a rule that matches on IP_PROTO 17 WILL match a UDP packet.
Flavio Castro6d498522015-12-15 14:05:04 -050019 """
20
Flavio Castroa7162bb2016-07-25 17:30:30 -070021 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -070022 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -070023 parsed_vlan_pkt = simple_udp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
24 vlan_pkt = str( parsed_vlan_pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -070025 # create match
Flavio Castroa7162bb2016-07-25 17:30:30 -070026 match = ofp.match( )
27 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
28 match.oxm_list.append( ofp.oxm.ip_proto( 2 ) )
29 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
30 ofp.instruction.apply_actions( actions=[
31 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
32 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
33 logging.info( "Inserting packet in flow to controller" )
34 self.controller.message_send( request )
Flavio Castro1c9b1252016-02-04 18:42:58 -050035
Flavio Castroa7162bb2016-07-25 17:30:30 -070036 for of_port in config[ "port_map" ].keys( ):
37 logging.info( "PacketInMiss test, port %d", of_port )
38 self.dataplane.send( of_port, vlan_pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -050039
Flavio Castroa7162bb2016-07-25 17:30:30 -070040 verify_no_packet_in( self, vlan_pkt, of_port )
41 delete_all_flows( self.controller )
42 do_barrier( self.controller )
Flavio Castro6d498522015-12-15 14:05:04 -050043
Flavio Castroa7162bb2016-07-25 17:30:30 -070044 match = ofp.match( )
45 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
46 match.oxm_list.append( ofp.oxm.ip_proto( 17 ) )
47 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
48 ofp.instruction.apply_actions( actions=[
49 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
50 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
51 logging.info( "Inserting packet in flow to controller" )
52 self.controller.message_send( request )
53 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -050054
Flavio Castroa7162bb2016-07-25 17:30:30 -070055 for of_port in config[ "port_map" ].keys( ):
56 logging.info( "PacketInMiss test, port %d", of_port )
57 self.dataplane.send( of_port, vlan_pkt )
Flavio Castro6d498522015-12-15 14:05:04 -050058
Flavio Castroa7162bb2016-07-25 17:30:30 -070059 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_ACTION )
Flavio Castro6d498522015-12-15 14:05:04 -050060
Flavio Castroa7162bb2016-07-25 17:30:30 -070061 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -070062 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -070063 delete_all_flows( self.controller )
64 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -050065
Flavio Castroaf2b4502016-02-02 17:41:32 -050066
Flavio Castro67d8bd52016-02-03 14:22:14 -050067@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -070068class ArpNL2( base_tests.SimpleDataPlane ):
69 def runTest( self ):
70 delete_all_flows( self.controller )
71 delete_all_groups( self.controller )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050072
Flavio Castroa7162bb2016-07-25 17:30:30 -070073 ports = sorted( config[ "port_map" ].keys( ) )
74 match = ofp.match( )
75 match.oxm_list.append( ofp.oxm.eth_type( 0x0806 ) )
76 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
77 ofp.instruction.apply_actions( actions=[
78 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
79 buffer_id=ofp.OFP_NO_BUFFER, priority=40000 )
80 self.controller.message_send( request )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050081 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -070082 add_one_l2_interface_group( self.controller, port, 1, False, False )
83 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_BOTH )
84 group_id = encode_l2_interface_group_id( 1, port )
85 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], 1, group_id, True )
86 do_barrier( self.controller )
87 parsed_arp_pkt = simple_arp_packet( )
88 arp_pkt = str( parsed_arp_pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050089
90 for out_port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -070091 self.dataplane.send( out_port, arp_pkt )
92 verify_packet_in( self, arp_pkt, out_port, ofp.OFPR_ACTION )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050093 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -050094 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -050095 for in_port in ports:
96 if in_port == out_port:
97 continue
98 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -050099 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700100 parsed_pkt = simple_tcp_packet( eth_dst=mac_dst, eth_src=mac_src )
101 pkt = str( parsed_pkt )
102 self.dataplane.send( in_port, pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500103
104 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700105 if ofport in [ out_port ]:
106 verify_packet( self, pkt, ofport )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500107 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700108 verify_no_packet( self, pkt, ofport )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500109
Flavio Castroa7162bb2016-07-25 17:30:30 -0700110 verify_no_other_packets( self )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500111
Flavio Castroa7162bb2016-07-25 17:30:30 -0700112class PacketInArp( base_tests.SimpleDataPlane ):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500113 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500114 Verify an ACL rule matching on ethertyper 0x806 will result in a packet-in
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500115 """
116
Flavio Castroa7162bb2016-07-25 17:30:30 -0700117 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700118 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700119 parsed_arp_pkt = simple_arp_packet( )
120 arp_pkt = str( parsed_arp_pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700121 # create match
Flavio Castroa7162bb2016-07-25 17:30:30 -0700122 match = ofp.match( )
123 match.oxm_list.append( ofp.oxm.eth_type( 0x0806 ) )
124 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
125 ofp.instruction.apply_actions( actions=[
126 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
127 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500128
Flavio Castroa7162bb2016-07-25 17:30:30 -0700129 logging.info( "Inserting packet in flow to controller" )
130 self.controller.message_send( request )
131 do_barrier( self.controller )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500132
Flavio Castroa7162bb2016-07-25 17:30:30 -0700133 for of_port in config[ "port_map" ].keys( ):
134 logging.info( "PacketInMiss test, port %d", of_port )
135 self.dataplane.send( of_port, arp_pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500136
Flavio Castroa7162bb2016-07-25 17:30:30 -0700137 verify_packet_in( self, arp_pkt, of_port, ofp.OFPR_ACTION )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500138
Flavio Castroa7162bb2016-07-25 17:30:30 -0700139 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700140 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700141 delete_all_flows( self.controller )
142 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500143
Flavio Castroa7162bb2016-07-25 17:30:30 -0700144
145class PacketInIPTable( base_tests.SimpleDataPlane ):
Flavio Castro91d1a552016-05-17 16:59:44 -0700146 """
147 Test packet in function on IPTABLE
148 Send a packet to each dataplane port and verify that a packet
149 in message is received from the controller for each
150 #todo verify you stop receiving after adding rule
151 """
152
Flavio Castroa7162bb2016-07-25 17:30:30 -0700153 def runTest( self ):
154 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700155 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700156 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
157 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
158 dip = 0xc0a80001
159 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro91d1a552016-05-17 16:59:44 -0700160
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700161 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700162 # add l2 interface group
163 vlan_id = port
164 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=True,
165 send_barrier=False )
166 dst_mac[ 5 ] = vlan_id
167 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
168 src_mac=intf_src_mac, dst_mac=dst_mac )
169 # add vlan flow table
170 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
171 # add termination flow
172 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
173 # add unicast routing flow
174 dst_ip = dip + (vlan_id << 8)
175 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id,
176 send_ctrl=True )
177 Groups.put( l3_msg.group_id )
Flavio Castro91d1a552016-05-17 16:59:44 -0700178
Flavio Castroa7162bb2016-07-25 17:30:30 -0700179 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -0700180
Flavio Castroa7162bb2016-07-25 17:30:30 -0700181 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700182 for in_port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700183 mac_src = '00:00:00:22:22:%02X' % in_port
184 ip_src = '192.168.%02d.1' % in_port
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700185 for out_port in ports:
186 if in_port == out_port:
187 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700188 ip_dst = '192.168.%02d.1' % out_port
189 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
190 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
191 pkt = str( parsed_pkt )
192 self.dataplane.send( in_port, pkt )
193 verify_packet_in( self, pkt, in_port, ofp.OFPR_ACTION )
194 # verify_no_other_packets(self)
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700195 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700196 delete_all_flows( self.controller )
197 delete_groups( self.controller, Groups )
198 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -0700199
Flavio Castroa7162bb2016-07-25 17:30:30 -0700200
201class L2FloodQinQ( base_tests.SimpleDataPlane ):
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500202 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500203 Verify a tagged frame can be flooded based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500204 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500205
Flavio Castroa7162bb2016-07-25 17:30:30 -0700206 def runTest( self ):
207 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700208 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700209 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700210 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500211
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700212 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700213 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
214 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
215 Groups.put( L2gid )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500216
Flavio Castroa7162bb2016-07-25 17:30:30 -0700217 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
218 Groups.put( msg.group_id )
219 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
220 do_barrier( self.controller )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500221
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700222 # verify flood
223 for ofport in ports:
224 # change dest based on port number
225 mac_src = '00:12:34:56:78:%02X' % ofport
Flavio Castroa7162bb2016-07-25 17:30:30 -0700226 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
227 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10,
228 eth_dst='00:12:34:56:78:9a', eth_src=mac_src )
229 pkt = str( parsed_pkt )
230 self.dataplane.send( ofport, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700231 # self won't rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700232 verify_no_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700233 # others will rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700234 tmp_ports = list( ports )
235 tmp_ports.remove( ofport )
236 verify_packets( self, pkt, tmp_ports )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500237
Flavio Castroa7162bb2016-07-25 17:30:30 -0700238 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700239 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700240 delete_all_flows( self.controller )
241 delete_groups( self.controller, Groups )
242 delete_all_groups( self.controller )
243
Flavio Castro1c9b1252016-02-04 18:42:58 -0500244
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500245@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -0700246class L2FloodTagged( base_tests.SimpleDataPlane ):
Flavio Castro184cefe2015-11-19 20:52:49 -0500247 """
248 Test L2 flood to a vlan
249 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
Flavio Castro184cefe2015-11-19 20:52:49 -0500250 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500251
Flavio Castroa7162bb2016-07-25 17:30:30 -0700252 def runTest( self ):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500253 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700254 vlan_id = abs( hash( inspect.stack( )[ 0 ][ 3 ] ) ) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500255 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500256
Flavio Castroa7162bb2016-07-25 17:30:30 -0700257 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro34352e72015-12-07 20:01:51 -0500258
Flavio Castroa7162bb2016-07-25 17:30:30 -0700259 delete_all_flows( self.controller )
260 delete_all_groups( self.controller )
Flavio Castro184cefe2015-11-19 20:52:49 -0500261
Flavio Castro184cefe2015-11-19 20:52:49 -0500262 # Installing flows to avoid packet-in
263 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700264 add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
265 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
266 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
267 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
268 do_barrier( self.controller )
Flavio Castro184cefe2015-11-19 20:52:49 -0500269
Flavio Castro1c9b1252016-02-04 18:42:58 -0500270 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500271 for ofport in ports:
272 # change dest based on port number
Flavio Castroa7162bb2016-07-25 17:30:30 -0700273 pkt = str(
274 simple_tcp_packet( dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst='00:12:34:56:78:9a' ) )
275 self.dataplane.send( ofport, pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500276 # self won't rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700277 verify_no_packet( self, pkt, ofport )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500278 # others will rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700279 tmp_ports = list( ports )
280 tmp_ports.remove( ofport )
281 verify_packets( self, pkt, tmp_ports )
282 verify_no_other_packets( self )
Flavio Castroaabb5792015-11-18 19:03:50 -0500283
Flavio Castro1c9b1252016-02-04 18:42:58 -0500284
Flavio Castroa7162bb2016-07-25 17:30:30 -0700285class L2UnicastTagged( base_tests.SimpleDataPlane ):
Flavio Castroaabb5792015-11-18 19:03:50 -0500286 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500287 Verify L2 forwarding works
Flavio Castroaabb5792015-11-18 19:03:50 -0500288 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500289
Flavio Castroa7162bb2016-07-25 17:30:30 -0700290 def runTest( self ):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700291
Flavio Castroa7162bb2016-07-25 17:30:30 -0700292 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700293 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700294 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700295 vlan_id = 1;
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700296 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700297 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
298 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
299 Groups.put( L2gid )
300 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], vlan_id, L2gid,
301 True )
302 do_barrier( self.controller )
Flavio Castro6efe1862015-11-18 16:28:06 -0500303
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700304 for out_port in ports:
305 # change dest based on port number
306 mac_dst = '00:12:34:56:78:%02X' % out_port
307 for in_port in ports:
308 if in_port == out_port:
309 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700310 pkt = str( simple_tcp_packet( dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst=mac_dst ) )
311 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700312 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700313 if ofport in [ out_port ]:
314 verify_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700315 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700316 verify_no_packet( self, pkt, ofport )
317 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700318 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700319 delete_all_flows( self.controller )
320 delete_groups( self.controller, Groups )
321 delete_all_groups( self.controller )
Flavio Castro6efe1862015-11-18 16:28:06 -0500322
Flavio Castroa7162bb2016-07-25 17:30:30 -0700323
324class Mtu1500( base_tests.SimpleDataPlane ):
325 def runTest( self ):
326 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700327 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700328 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700329 vlan_id = 18
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700330 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700331 L2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
332 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
333 Groups.put( L2gid )
334 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], vlan_id, L2gid,
335 True )
336 do_barrier( self.controller )
Flavio Castrob6773032015-11-19 22:49:24 -0500337
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700338 for out_port in ports:
339 # change dest based on port number
340 mac_dst = '00:12:34:56:78:%02X' % out_port
341 for in_port in ports:
342 if in_port == out_port:
343 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700344 pkt = str( simple_tcp_packet( pktlen=1500, dl_vlan_enable=True, vlan_vid=vlan_id,
345 eth_dst=mac_dst ) )
346 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700347 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700348 if ofport in [ out_port ]:
349 verify_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700350 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700351 verify_no_packet( self, pkt, ofport )
352 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700353 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700354 delete_all_flows( self.controller )
355 delete_groups( self.controller, Groups )
356 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500357
Flavio Castroa7162bb2016-07-25 17:30:30 -0700358
359class _32UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500360 """
361 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
362 """
363
Flavio Castroa7162bb2016-07-25 17:30:30 -0700364 def runTest( self ):
365 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700366 try:
367 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -0700368 if len( config[ "port_map" ] ) < 2:
369 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700370 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500371
Flavio Castroa7162bb2016-07-25 17:30:30 -0700372 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
373 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700374 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700375 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700376 for port in ports:
377 # add l2 interface group
378 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -0700379 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
380 is_tagged=True, send_barrier=False )
381 dst_mac[ 5 ] = vlan_id
382 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
383 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700384 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700385 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700386 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700387 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700388 # add unicast routing flow
389 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700390 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
391 Groups.put( l2gid )
392 Groups.put( l3_msg.group_id )
393 do_barrier( self.controller )
Flavio Castrod8f8af22015-12-02 18:19:26 -0500394
Flavio Castroa7162bb2016-07-25 17:30:30 -0700395 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700396 for in_port in ports:
397 mac_src = '00:00:00:22:32:%02X' % (test_id + in_port)
398 ip_src = '192.168.%02d.1' % (test_id + in_port)
399 for out_port in ports:
400 if in_port == out_port:
401 continue
402 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700403 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
404 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
405 ip_src=ip_src, ip_dst=ip_dst )
406 pkt = str( parsed_pkt )
407 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700408 # build expected packet
409 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700410 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
411 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
412 ip_src=ip_src, ip_dst=ip_dst )
413 pkt = str( exp_pkt )
414 verify_packet( self, pkt, out_port )
415 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700416 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700417 delete_all_flows( self.controller )
418 delete_groups( self.controller, Groups )
419 delete_all_groups( self.controller )
Flavio Castro05d20bc2015-11-16 15:06:14 -0500420
Flavio Castroa7162bb2016-07-25 17:30:30 -0700421
422class _32VPN( base_tests.SimpleDataPlane ):
Flavio Castro2262fd42016-02-04 19:03:36 -0500423 """
424 Insert IP packet
425 Receive MPLS packet
426 """
427
Flavio Castroa7162bb2016-07-25 17:30:30 -0700428 def runTest( self ):
429 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700430 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700431 if len( config[ "port_map" ] ) < 2:
432 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700433 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500434
Flavio Castroa7162bb2016-07-25 17:30:30 -0700435 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
436 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700437 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700438 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700439 for port in ports:
440 # add l2 interface group
441 id = port
442 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700443 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
444 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700445 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700446 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
447 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700448 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700449 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
450 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
451 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700452 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castroa7162bb2016-07-25 17:30:30 -0700453 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700454 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700455 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=2,
456 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700457 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700458 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700459 # add routing flow
460 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700461 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, mpls_label_gid, vrf=2 )
462 Groups._put( l2_gid )
463 Groups._put( mpls_gid )
464 Groups._put( mpls_label_gid )
465 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500466
Flavio Castroa7162bb2016-07-25 17:30:30 -0700467 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700468 for in_port in ports:
469 ip_src = '192.168.%02d.1' % (in_port)
470 for out_port in ports:
471 if in_port == out_port:
472 continue
473 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700474 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
475 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
476 pkt = str( parsed_pkt )
477 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700478 # build expect packet
479 mac_dst = '00:00:00:22:22:%02X' % (out_port)
480 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700481 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
482 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
483 label=[ label ] )
484 pkt = str( exp_pkt )
485 verify_packet( self, pkt, out_port )
486 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700487 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700488 delete_all_flows( self.controller )
489 delete_groups( self.controller, Groups )
490 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500491
Flavio Castroa7162bb2016-07-25 17:30:30 -0700492
493class _32EcmpVpn( base_tests.SimpleDataPlane ):
Flavio Castro2262fd42016-02-04 19:03:36 -0500494 """
495 Insert IP packet
496 Receive MPLS packet
497 """
498
Flavio Castroa7162bb2016-07-25 17:30:30 -0700499 def runTest( self ):
500 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700501 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700502 if len( config[ "port_map" ] ) < 2:
503 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700504 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500505
Flavio Castroa7162bb2016-07-25 17:30:30 -0700506 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
507 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700508 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700509 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700510 for port in ports:
511 # add l2 interface group
512 id = port
513 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700514 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
515 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700516 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700517 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
518 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700519 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700520 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
521 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
522 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
523 ecmp_msg = add_l3_ecmp_group( self.controller, vlan_id, [ mpls_label_gid ] )
524 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700525 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700526 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
527 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700528 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700529 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700530 # add routing flow
531 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700532 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, ecmp_msg.group_id )
533 Groups._put( l2_gid )
534 Groups._put( mpls_gid )
535 Groups._put( mpls_label_gid )
536 Groups._put( ecmp_msg.group_id )
537 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500538
Flavio Castroa7162bb2016-07-25 17:30:30 -0700539 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700540 for in_port in ports:
541 ip_src = '192.168.%02d.1' % (in_port)
542 for out_port in ports:
543 if in_port == out_port:
544 continue
545 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700546 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
547 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
548 pkt = str( parsed_pkt )
549 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700550 # build expect packet
551 mac_dst = '00:00:00:22:22:%02X' % (out_port)
552 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700553 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
554 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
555 label=[ label ] )
556 pkt = str( exp_pkt )
557 verify_packet( self, pkt, out_port )
558 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700559 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700560 delete_all_flows( self.controller )
561 delete_groups( self.controller, Groups )
562 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500563
Flavio Castroa7162bb2016-07-25 17:30:30 -0700564
565class _32ECMPL3( base_tests.SimpleDataPlane ):
Flavio Castro2262fd42016-02-04 19:03:36 -0500566 """
Flavio Castrod80fbc32016-07-25 15:54:26 -0700567 Insert IP packet
568 Receive IP packet
Flavio Castro2262fd42016-02-04 19:03:36 -0500569 """
570
Flavio Castroa7162bb2016-07-25 17:30:30 -0700571 def runTest( self ):
572 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700573 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700574 if len( config[ "port_map" ] ) < 2:
575 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700576 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500577
Flavio Castroa7162bb2016-07-25 17:30:30 -0700578 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
579 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700580 dip = 0xc0a80001
581 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700582 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700583 for port in ports:
584 vlan_id = port
585 id = port
586 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700587 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
588 is_tagged=True, send_barrier=False )
589 dst_mac[ 5 ] = vlan_id
590 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
591 src_mac=intf_src_mac, dst_mac=dst_mac )
592 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700593 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700594 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700595 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700596 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700597 # add unicast routing flow
598 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700599 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, ecmp_msg.group_id )
600 Groups._put( l2_gid )
601 Groups._put( l3_msg.group_id )
602 Groups._put( ecmp_msg.group_id )
603 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500604
Flavio Castroa7162bb2016-07-25 17:30:30 -0700605 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700606 for in_port in ports:
607 mac_src = '00:00:00:22:22:%02X' % in_port
608 ip_src = '192.168.%02d.1' % in_port
609 for out_port in ports:
610 if in_port == out_port:
611 continue
612 ip_dst = '192.168.%02d.1' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700613 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
614 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
615 pkt = str( parsed_pkt )
616 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700617 # build expected packet
618 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700619 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
620 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
621 pkt = str( exp_pkt )
622 verify_packet( self, pkt, out_port )
623 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700624 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700625 delete_all_flows( self.controller )
626 delete_groups( self.controller, Groups )
627 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500628
Flavio Castroa7162bb2016-07-25 17:30:30 -0700629
630class _24VPN( base_tests.SimpleDataPlane ):
Flavio Castro2262fd42016-02-04 19:03:36 -0500631 """
632 Insert IP packet
633 Receive MPLS packet
634 """
635
Flavio Castroa7162bb2016-07-25 17:30:30 -0700636 def runTest( self ):
637 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700638 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700639 if len( config[ "port_map" ] ) < 2:
640 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700641 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500642
Flavio Castroa7162bb2016-07-25 17:30:30 -0700643 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
644 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700645 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700646 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700647 for port in ports:
648 # add l2 interface group
649 id = port
650 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700651 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
652 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700653 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700654 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
655 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700656 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700657 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
658 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
659 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700660 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castroa7162bb2016-07-25 17:30:30 -0700661 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700662 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700663 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
664 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700665 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700666 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700667 # add routing flow
668 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700669 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid )
670 Groups._put( l2_gid )
671 Groups._put( mpls_gid )
672 Groups._put( mpls_label_gid )
673 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500674
Flavio Castroa7162bb2016-07-25 17:30:30 -0700675 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700676 for in_port in ports:
677 ip_src = '192.168.%02d.1' % (in_port)
678 for out_port in ports:
679 if in_port == out_port:
680 continue
681 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700682 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
683 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
684 pkt = str( parsed_pkt )
685 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700686 # build expect packet
687 mac_dst = '00:00:00:22:22:%02X' % (out_port)
688 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700689 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
690 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
691 label=[ label ] )
692 pkt = str( exp_pkt )
693 verify_packet( self, pkt, out_port )
694 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700695 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700696 delete_all_flows( self.controller )
697 delete_groups( self.controller, Groups )
698 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500699
Flavio Castroa7162bb2016-07-25 17:30:30 -0700700
701class _24EcmpVpn( base_tests.SimpleDataPlane ):
Flavio Castrod8f8af22015-12-02 18:19:26 -0500702 """
703 Insert IP packet
704 Receive MPLS packet
705 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500706
Flavio Castroa7162bb2016-07-25 17:30:30 -0700707 def runTest( self ):
708 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700709 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700710 if len( config[ "port_map" ] ) < 2:
711 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700712 return
Flavio Castroa7162bb2016-07-25 17:30:30 -0700713 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
714 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700715 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700716 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700717 for port in ports:
718 # add l2 interface group
719 id = port
720 vlan_id = id
Flavio Castroa7162bb2016-07-25 17:30:30 -0700721 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
722 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700723 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700724 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
725 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700726 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700727 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
728 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
729 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
730 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ mpls_label_gid ] )
731 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700732 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700733 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
734 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700735 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700736 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700737 # add routing flow
738 dst_ip = dip + (vlan_id << 8)
739 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700740 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id,
741 vrf=0 )
742 Groups._put( l2_gid )
743 Groups._put( mpls_gid )
744 Groups._put( mpls_label_gid )
745 Groups._put( ecmp_msg.group_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700746
Flavio Castroa7162bb2016-07-25 17:30:30 -0700747 do_barrier( self.controller )
Flavio Castro80730822015-12-11 15:38:47 -0500748
Flavio Castroa7162bb2016-07-25 17:30:30 -0700749 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700750 for in_port in ports:
751 mac_src = '00:00:00:22:22:%02X' % (in_port)
752 ip_src = '192.168.%02d.1' % (in_port)
753 for out_port in ports:
754 if in_port == out_port:
755 continue
756 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700757 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
758 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
759 pkt = str( parsed_pkt )
760 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700761 # build expect packet
762 mac_dst = '00:00:00:22:22:%02X' % out_port
763 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700764 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
765 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
766 label=[ label ] )
767 pkt = str( exp_pkt )
768 verify_packet( self, pkt, out_port )
769 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700770 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700771 delete_all_flows( self.controller )
772 delete_groups( self.controller, Groups )
773 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500774
Flavio Castroa7162bb2016-07-25 17:30:30 -0700775
776class FloodGroupMod( base_tests.SimpleDataPlane ):
777 """
778 Modify referenced group test
779 """
780
781 def runTest( self ):
782 Groups = Queue.LifoQueue( )
783 try:
784 ports = sorted( config[ "port_map" ].keys( ) )
785 vlan_id = 1
786
787 for port in ports:
788 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
789 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
790 Groups.put( L2gid )
791
792 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
793 Groups.put( msg.group_id )
794 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
795 do_barrier( self.controller )
796 # verify flood
797 for ofport in ports:
798 # change dest based on port number
799 mac_src = '00:12:34:56:78:%02X' % ofport
800 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
801 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10,
802 eth_dst='00:12:34:56:78:9a', eth_src=mac_src )
803 pkt = str( parsed_pkt )
804 self.dataplane.send( ofport, pkt )
805 # self won't rx packet
806 verify_no_packet( self, pkt, ofport )
807 # others will rx packet
808 tmp_ports = list( ports )
809 tmp_ports.remove( ofport )
810 verify_packets( self, pkt, tmp_ports )
811 verify_no_other_packets( self )
812 msg = mod_l2_flood_group( self.controller, [ ports[ 0 ] ], vlan_id, vlan_id )
813 mac_src = '00:12:34:56:78:%02X' % ports[ 1 ]
814 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
815 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a',
816 eth_src=mac_src )
817 pkt = str( parsed_pkt )
818 self.dataplane.send( ports[ 1 ], pkt )
819 verify_packets( self, pkt, [ ports[ 0 ] ] )
820 finally:
821 delete_all_flows( self.controller )
822 delete_groups( self.controller, Groups )
823 delete_all_groups( self.controller )
824
825
826class _24ECMPL3( base_tests.SimpleDataPlane ):
Flavio Castro80730822015-12-11 15:38:47 -0500827 """
Flavio Castrod80fbc32016-07-25 15:54:26 -0700828 Insert IP packet
829 Receive IP packet
Flavio Castro80730822015-12-11 15:38:47 -0500830 """
Flavio Castro80730822015-12-11 15:38:47 -0500831
Flavio Castroa7162bb2016-07-25 17:30:30 -0700832 def runTest( self ):
833 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700834 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700835 if len( config[ "port_map" ] ) < 2:
836 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700837 return
Flavio Castro80730822015-12-11 15:38:47 -0500838
Flavio Castroa7162bb2016-07-25 17:30:30 -0700839 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
840 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700841 dip = 0xc0a80001
842 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700843 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700844 for port in ports:
845 vlan_id = port
846 id = port
847 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700848 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
849 is_tagged=True, send_barrier=False )
850 dst_mac[ 5 ] = vlan_id
851 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
852 src_mac=intf_src_mac, dst_mac=dst_mac )
853 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700854 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700855 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700856 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700857 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700858 # add unicast routing flow
859 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700860 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
861 Groups._put( l2_gid )
862 Groups._put( l3_msg.group_id )
863 Groups._put( ecmp_msg.group_id )
864 do_barrier( self.controller )
Flavio Castro72a45d52015-12-02 16:37:05 -0500865
Flavio Castroa7162bb2016-07-25 17:30:30 -0700866 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700867 for in_port in ports:
868 mac_src = '00:00:00:22:22:%02X' % in_port
869 ip_src = '192.168.%02d.1' % in_port
870 for out_port in ports:
871 if in_port == out_port:
872 continue
873 ip_dst = '192.168.%02d.1' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700874 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
875 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
876 pkt = str( parsed_pkt )
877 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700878 # build expected packet
879 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700880 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
881 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
882 pkt = str( exp_pkt )
883 verify_packet( self, pkt, out_port )
884 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700885 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700886 delete_all_flows( self.controller )
887 delete_groups( self.controller, Groups )
888 delete_all_groups( self.controller )
889
Flavio Castro1c9b1252016-02-04 18:42:58 -0500890
Flavio Castroaba28ff2016-02-03 16:47:48 -0500891@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -0700892class MPLSBUG( base_tests.SimpleDataPlane ):
893 def runTest( self ):
894 if len( config[ "port_map" ] ) < 2:
895 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro80730822015-12-11 15:38:47 -0500896 return
Flavio Castroa7162bb2016-07-25 17:30:30 -0700897 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
898 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro1c9b1252016-02-04 18:42:58 -0500899 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700900 Groups = Queue.LifoQueue( )
901 ports = config[ "port_map" ].keys( )
Flavio Castro80730822015-12-11 15:38:47 -0500902 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500903 # add l2 interface group
904 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700905 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
906 dst_mac[ 5 ] = vlan_id
Flavio Castro1c9b1252016-02-04 18:42:58 -0500907 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700908 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
909 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500910 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700911 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500912 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700913 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500914 # add mpls flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700915 add_mpls_flow( self.controller, l3_msg.group_id, port )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500916 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700917 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500918 # add unicast routing flow
919 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700920 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
921 Groups._put( l2_gid )
922 Groups._put( l3_msg.group_id )
923 do_barrier( self.controller )
Flavio Castro80730822015-12-11 15:38:47 -0500924
Flavio Castroa7162bb2016-07-25 17:30:30 -0700925 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro80730822015-12-11 15:38:47 -0500926 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500927 mac_src = '00:00:00:22:22:%02X' % in_port
928 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -0500929 for out_port in ports:
930 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500931 continue
932 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500933 switch_mac = "00:00:00:cc:cc:cc"
934 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700935 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
936 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[ label ] )
937 pkt = str( parsed_pkt )
938 self.dataplane.send( in_port, pkt )
Flavio Castro80730822015-12-11 15:38:47 -0500939
Flavio Castro1c9b1252016-02-04 18:42:58 -0500940 # build expect packet
941 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700942 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
943 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
944 pkt = str( exp_pkt )
945 verify_packet( self, pkt, out_port )
946 verify_no_other_packets( self )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500947
Flavio Castroa7162bb2016-07-25 17:30:30 -0700948 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
949 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
950 pkt = str( parsed_pkt )
951 self.dataplane.send( in_port, pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500952 # build expected packet
953 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700954 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
955 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
956 pkt = str( exp_pkt )
957 verify_packet( self, pkt, out_port )
958 verify_no_other_packets( self )
959 delete_all_flows( self.controller )
960 delete_groups( self.controller, Groups )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500961
Flavio Castroa7162bb2016-07-25 17:30:30 -0700962
963class L3McastToL2( base_tests.SimpleDataPlane ):
castroflaviocc403a92015-12-15 14:04:19 -0500964 """
Flavio Castro12296312015-12-15 17:48:26 -0500965 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -0500966 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500967
Flavio Castroa7162bb2016-07-25 17:30:30 -0700968 def runTest( self ):
castroflaviocc403a92015-12-15 14:04:19 -0500969 """
970 port1 (vlan 300)-> All Ports (vlan 300)
971 """
Flavio Castroa7162bb2016-07-25 17:30:30 -0700972 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700973 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700974 if len( config[ "port_map" ] ) < 3:
975 logging.info( "Port count less than 3, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700976 assert (False)
977 return
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700978 vlan_id = 300
Flavio Castroa7162bb2016-07-25 17:30:30 -0700979 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
980 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
981 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
982 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
983 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
984 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700985 src_ip = 0xc0a80101
986 src_ip_str = "192.168.1.1"
987 dst_ip = 0xe0010101
988 dst_ip_str = "224.1.1.1"
castroflaviocc403a92015-12-15 14:04:19 -0500989
Flavio Castroa7162bb2016-07-25 17:30:30 -0700990 port1 = config[ "port_map" ].keys( )[ 0 ]
991 port2 = config[ "port_map" ].keys( )[ 1 ]
castroflaviocc403a92015-12-15 14:04:19 -0500992
Flavio Castroa7162bb2016-07-25 17:30:30 -0700993 switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ]
castroflaviocc403a92015-12-15 14:04:19 -0500994
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700995 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700996 l2_intf_group_list = [ ]
997 for port in config[ "port_map" ].keys( ):
998 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700999 if port == port2:
1000 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -07001001 l2_intf_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1002 is_tagged=True, send_barrier=False )
1003 l2_intf_group_list.append( l2_intf_gid )
1004 Groups.put( l2_intf_gid )
castroflaviocc403a92015-12-15 14:04:19 -05001005
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001006 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001007 add_termination_flow( self.controller, port1, 0x0800, switch_mac, vlan_id )
castroflaviocc403a92015-12-15 14:04:19 -05001008
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001009 # add l3 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001010 mcat_group_msg = add_l3_mcast_group( self.controller, vlan_id, 2, l2_intf_group_list )
1011 add_mcast4_routing_flow( self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id )
1012 Groups._put( mcat_group_msg.group_id )
castroflaviocc403a92015-12-15 14:04:19 -05001013
Flavio Castroa7162bb2016-07-25 17:30:30 -07001014 parsed_pkt = simple_udp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=vlan_id,
1015 eth_dst=dst_mac_str, eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str,
1016 ip_dst=dst_ip_str )
1017 pkt = str( parsed_pkt )
1018 self.dataplane.send( port1, pkt )
1019 for port in config[ "port_map" ].keys( ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001020 if port == port2 or port == port1:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001021 verify_no_packet( self, pkt, port )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001022 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -07001023 verify_packet( self, pkt, port )
1024 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001025 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001026 delete_all_flows( self.controller )
1027 delete_groups( self.controller, Groups )
1028 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001029
Flavio Castroa7162bb2016-07-25 17:30:30 -07001030
1031class L3McastToL3( base_tests.SimpleDataPlane ):
Flavio Castro12296312015-12-15 17:48:26 -05001032 """
1033 Mcast routing
1034 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001035
Flavio Castroa7162bb2016-07-25 17:30:30 -07001036 def runTest( self ):
Flavio Castro12296312015-12-15 17:48:26 -05001037 """
1038 port1 (vlan 1)-> port 2 (vlan 2)
1039 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001040 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001041 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001042 if len( config[ "port_map" ] ) < 3:
1043 logging.info( "Port count less than 3, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001044 assert (False)
1045 return
Flavio Castro12296312015-12-15 17:48:26 -05001046
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001047 vlan_id = 1
1048 port2_out_vlan = 2
1049 port3_out_vlan = 3
1050 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
Flavio Castroa7162bb2016-07-25 17:30:30 -07001051 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1052 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1053 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
1054 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
1055 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
1056 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001057 src_ip = 0xc0a80101
1058 src_ip_str = "192.168.1.1"
1059 dst_ip = 0xe0010101
1060 dst_ip_str = "224.1.1.1"
Flavio Castro12296312015-12-15 17:48:26 -05001061
Flavio Castroa7162bb2016-07-25 17:30:30 -07001062 port1 = config[ "port_map" ].keys( )[ 0 ]
1063 port2 = config[ "port_map" ].keys( )[ 1 ]
1064 port3 = config[ "port_map" ].keys( )[ 2 ]
Flavio Castro12296312015-12-15 17:48:26 -05001065
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001066 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001067 for port in config[ "port_map" ].keys( ):
1068 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1069 is_tagged=False, send_barrier=False )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001070 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001071 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001072 vlan_id += 1
Flavio Castroa7162bb2016-07-25 17:30:30 -07001073 Groups._put( l2gid )
Flavio Castro12296312015-12-15 17:48:26 -05001074
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001075 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001076 add_termination_flow( self.controller, port1, 0x0800, [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ],
1077 vlan_id )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001078
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001079 # add l3 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001080 port2_ucast_msg = add_l3_interface_group( self.controller, port2, port2_out_vlan, 2,
1081 intf_src_mac )
1082 port3_ucast_msg = add_l3_interface_group( self.controller, port3, port3_out_vlan, 3,
1083 intf_src_mac )
1084 mcat_group_msg = add_l3_mcast_group( self.controller, in_vlan, 2,
1085 [ port2_ucast_msg.group_id, port3_ucast_msg.group_id ] )
1086 add_mcast4_routing_flow( self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id )
1087 Groups._put( port2_ucast_msg.group_id )
1088 Groups._put( port3_ucast_msg.group_id )
1089 Groups._put( mcat_group_msg.group_id )
1090 parsed_pkt = simple_udp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac_str,
1091 eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str, ip_dst=dst_ip_str )
1092 pkt = str( parsed_pkt )
1093 self.dataplane.send( port1, pkt )
1094 parsed_pkt = simple_udp_packet( pktlen=96, eth_dst=dst_mac_str, eth_src=intf_src_mac_str,
1095 ip_ttl=63, ip_src=src_ip_str, ip_dst=dst_ip_str )
1096 pkt = str( parsed_pkt )
1097 verify_packet( self, pkt, port2 )
1098 verify_packet( self, pkt, port3 )
1099 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001100 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001101 delete_all_flows( self.controller )
1102 delete_groups( self.controller, Groups )
1103 delete_all_groups( self.controller )
1104
1105
Flavio Castrod80fbc32016-07-25 15:54:26 -07001106@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -07001107class _MplsFwd( base_tests.SimpleDataPlane ):
Flavio Castro12296312015-12-15 17:48:26 -05001108 """
Flavio Castrod80fbc32016-07-25 15:54:26 -07001109 Insert MPLS packet
Flavio Castro54947942016-02-03 16:05:20 -05001110 Receive MPLS packet
castroflavio30c6cc52016-01-07 15:19:42 -08001111 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001112
1113 def runTest( self ):
1114 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001115 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001116 if len( config[ "port_map" ] ) < 2:
1117 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001118 return
1119 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001120 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1121 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001122 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001123 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001124 for port in ports:
1125 # add l2 interface group
1126 id = port
1127 vlan_id = id
Flavio Castroa7162bb2016-07-25 17:30:30 -07001128 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
1129 dst_mac[ 5 ] = vlan_id
1130 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1131 vlan_id, id )
1132 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
1133 subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL, index=id, ref_gid=mpls_gid,
1134 push_mpls_header=False, set_mpls_label=port, set_bos=1 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001135 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001136 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001137 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001138 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
1139 add_mpls_flow( self.controller, mpls_label_gid, port, goto_table=29 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001140 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001141 Groups._put( l2_gid )
1142 Groups._put( mpls_gid )
1143 Groups._put( mpls_label_gid )
1144 do_barrier( self.controller )
castroflavio30c6cc52016-01-07 15:19:42 -08001145
Flavio Castroa7162bb2016-07-25 17:30:30 -07001146 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001147 for in_port in ports:
1148 ip_src = '192.168.%02d.1' % (in_port)
1149 for out_port in ports:
1150 if in_port == out_port:
1151 continue
1152 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castro54947942016-02-03 16:05:20 -05001153
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001154 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001155 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port),
1156 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1157 pkt = str( parsed_pkt )
1158 self.dataplane.send( in_port, pkt )
Flavio Castro54947942016-02-03 16:05:20 -05001159
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001160 # build expect packet
1161 mac_dst = '00:00:00:22:22:%02X' % (out_port)
1162 label = (out_port, 0, 1, 31)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001163 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port),
1164 ip_src=ip_src, ip_dst=ip_dst, eth_src=switch_mac, eth_dst=mac_dst,
1165 label=[ label ] )
1166 pkt = str( exp_pkt )
1167 verify_packet( self, pkt, out_port )
1168 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001169 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001170 delete_all_flows( self.controller )
1171 delete_groups( self.controller, Groups )
1172 delete_all_groups( self.controller )
Flavio Castrob702a2f2016-04-10 22:01:48 -04001173
Flavio Castroa7162bb2016-07-25 17:30:30 -07001174
1175class _MplsTermination( base_tests.SimpleDataPlane ):
Flavio Castrob702a2f2016-04-10 22:01:48 -04001176 """
Flavio Castrod80fbc32016-07-25 15:54:26 -07001177 Insert MPLS packet
1178 Receive IP packet
Flavio Castrob702a2f2016-04-10 22:01:48 -04001179 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001180
1181 def runTest( self ):
1182 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001183 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001184 if len( config[ "port_map" ] ) < 2:
1185 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001186 return
1187 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001188 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1189 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001190 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001191 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001192 for port in ports:
1193 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001194 vlan_id, id, dst_mac[ 5 ] = port, port, port
1195 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001196 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001197 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1198 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001199 # add L3 ecmp group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001200 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001201 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001202 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001203 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001204 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
1205 # add_mpls_flow(self.controller, ecmp_msg.group_id, port)
1206 add_mpls_flow( self.controller, label=port )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001207 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001208 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id, 1 )
1209 Groups._put( l2_gid )
1210 Groups._put( l3_msg.group_id )
1211 Groups._put( ecmp_msg.group_id )
1212 do_barrier( self.controller )
Flavio Castrob702a2f2016-04-10 22:01:48 -04001213
Flavio Castroa7162bb2016-07-25 17:30:30 -07001214 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001215 for in_port in ports:
1216 ip_src = '192.168.%02d.1' % (in_port)
1217 for out_port in ports:
1218 if in_port == out_port:
1219 continue
1220 ip_dst = '192.168.%02d.1' % (out_port)
1221 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001222 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port),
1223 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1224 pkt = str( parsed_pkt )
1225 self.dataplane.send( in_port, pkt )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001226 # build expect packet
1227 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001228 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port),
1229 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
1230 pkt = str( exp_pkt )
1231 verify_packet( self, pkt, out_port )
1232 verify_no_other_packets( self )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001233 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001234 delete_all_flows( self.controller )
1235 delete_groups( self.controller, Groups )
1236 delete_all_groups( self.controller )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001237
Flavio Castroa7162bb2016-07-25 17:30:30 -07001238
1239class _MplsVpnFwd( base_tests.SimpleDataPlane ):
Flavio Castrod80fbc32016-07-25 15:54:26 -07001240 """
1241 Insert MPLS packet
1242 Receive IP packet
1243 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001244
1245 def runTest( self ):
1246 Groups = Queue.LifoQueue( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001247 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001248 if len( config[ "port_map" ] ) < 2:
1249 logging.info( "Port count less than 2, can't run this case" )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001250 return
1251 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001252 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1253 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castrod80fbc32016-07-25 15:54:26 -07001254 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001255 ports = config[ "port_map" ].keys( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001256 for port in ports:
1257 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001258 vlan_id, id, dst_mac[ 5 ] = port, port, port
1259 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001260 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001261 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1262 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001263 # add L3 ecmp group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001264 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001265 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001266 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001267 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001268 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
1269 add_mpls_flow( self.controller, ecmp_msg.group_id, port )
1270 # add_mpls_flow(self.controller, label=port)
Flavio Castrod80fbc32016-07-25 15:54:26 -07001271 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001272 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
Flavio Castrod80fbc32016-07-25 15:54:26 -07001273 # ecmp_msg.group_id, 1)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001274 Groups._put( l2_gid )
1275 Groups._put( l3_msg.group_id )
1276 Groups._put( ecmp_msg.group_id )
1277 do_barrier( self.controller )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001278
Flavio Castroa7162bb2016-07-25 17:30:30 -07001279 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001280 for in_port in ports:
1281 ip_src = '192.168.%02d.1' % (in_port)
1282 for out_port in ports:
1283 if in_port == out_port:
1284 continue
1285 ip_dst = '192.168.%02d.1' % (out_port)
1286 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001287 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port),
1288 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1289 pkt = str( parsed_pkt )
1290 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001291 # build expect packet
1292 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001293 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port),
1294 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
1295 pkt = str( exp_pkt )
1296 verify_packet( self, pkt, out_port )
1297 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001298 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001299 delete_all_flows( self.controller )
1300 delete_groups( self.controller, Groups )
1301 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001302
Flavio Castroa7162bb2016-07-25 17:30:30 -07001303
1304class _24UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro1c9b1252016-02-04 18:42:58 -05001305 """
1306 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
1307 """
1308
Flavio Castroa7162bb2016-07-25 17:30:30 -07001309 def runTest( self ):
1310 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001311 try:
1312 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -07001313 if len( config[ "port_map" ] ) < 2:
1314 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001315 return
Flavio Castroa7162bb2016-07-25 17:30:30 -07001316 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1317 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001318 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001319 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001320 for port in ports:
1321 # add l2 interface group
1322 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -07001323 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1324 is_tagged=True, send_barrier=False )
1325 dst_mac[ 5 ] = vlan_id
1326 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
1327 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001328 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001329 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001330 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001331 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001332 # add unicast routing flow
1333 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001334 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id )
1335 Groups.put( l2gid )
1336 Groups.put( l3_msg.group_id )
1337 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001338
Flavio Castroa7162bb2016-07-25 17:30:30 -07001339 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001340 for in_port in ports:
1341 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1342 ip_src = '192.168.%02d.1' % (test_id + in_port)
1343 for out_port in ports:
1344 if in_port == out_port:
1345 continue
1346 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001347 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1348 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
1349 ip_src=ip_src, ip_dst=ip_dst )
1350 pkt = str( parsed_pkt )
1351 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001352 # build expected packet
1353 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001354 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1355 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
1356 ip_src=ip_src, ip_dst=ip_dst )
1357 pkt = str( exp_pkt )
1358 verify_packet( self, pkt, out_port )
1359 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001360 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001361 delete_all_flows( self.controller )
1362 delete_groups( self.controller, Groups )
1363 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001364
Flavio Castroa7162bb2016-07-25 17:30:30 -07001365
1366class _0Ucast( base_tests.SimpleDataPlane ):
Flavio Castro91d1a552016-05-17 16:59:44 -07001367 """
1368 Verify a IP forwarding works for a /0 rule to L3 Unicast Interface
1369 """
1370
Flavio Castroa7162bb2016-07-25 17:30:30 -07001371 def runTest( self ):
1372 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001373 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001374 if len( config[ "port_map" ] ) < 2:
1375 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001376 return
Flavio Castro91d1a552016-05-17 16:59:44 -07001377
Flavio Castroa7162bb2016-07-25 17:30:30 -07001378 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1379 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001380 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001381 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001382 for port in ports:
1383 # add l2 interface group
1384 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001385 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id + 1,
1386 is_tagged=True, send_barrier=False )
1387 dst_mac[ 5 ] = vlan_id
1388 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id + 1, id=vlan_id,
1389 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001390 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001391 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001392 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001393 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001394 # add unicast routing flow
1395 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001396 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
1397 Groups.put( l2gid )
1398 Groups.put( l3_msg.group_id )
1399 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001400 dst_ip = 0x0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001401 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0x0, l3_gid )
1402 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001403
Flavio Castroa7162bb2016-07-25 17:30:30 -07001404 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001405 for in_port in ports:
1406 mac_src = '00:00:00:22:22:%02X' % (in_port)
1407 ip_src = '192.168.%02d.1' % (in_port)
1408 for out_port in ports:
1409 if in_port == out_port:
1410 continue
1411 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001412 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
1413 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1414 pkt = str( parsed_pkt )
1415 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001416 # build expected packet
1417 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001418 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port + 1),
1419 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
1420 pkt = str( exp_pkt )
1421 verify_packet( self, pkt, out_port )
1422 verify_no_other_packets( self )
1423 ip_dst = '1.168.%02d.1' % ports[ 0 ]
1424 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1425 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1426 pkt = str( parsed_pkt )
1427 self.dataplane.send( in_port, pkt )
1428 # build expect packet
1429 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1430 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ] + 1,
1431 ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac )
1432 pkt = str( exp_pkt )
1433 verify_packet( self, pkt, ports[ 0 ] )
1434 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001435 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001436 delete_all_flows( self.controller )
1437 delete_groups( self.controller, Groups )
1438 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001439
Flavio Castroa7162bb2016-07-25 17:30:30 -07001440
1441class Unfiltered( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001442 """
1443 Testing addition of unfiltered groups
1444 """
Flavio Castro91d1a552016-05-17 16:59:44 -07001445
Flavio Castroa7162bb2016-07-25 17:30:30 -07001446 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001447 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001448 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001449 vlan_id = 1;
1450 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001451 add_l2_unfiltered_group( self.controller, [ port ], False )
1452 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001453 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001454 delete_all_flows( self.controller )
1455 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001456
Flavio Castroa7162bb2016-07-25 17:30:30 -07001457
1458class L3McastToVPN( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001459 """
1460 Mcast routing
1461 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001462
1463 def runTest( self ):
Flavio Castro423df652016-05-17 20:14:08 -04001464 """
1465 port1 (vlan 1)-> port 2 (vlan 2)
1466 """
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001467 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001468 delete_all_flows( self.controller )
1469 delete_all_groups( self.controller )
Flavio Castro423df652016-05-17 20:14:08 -04001470
Flavio Castroa7162bb2016-07-25 17:30:30 -07001471 if len( config[ "port_map" ] ) < 3:
1472 logging.info( "Port count less than 3, can't run this case" )
1473 assert (False)
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001474 return
Flavio Castro423df652016-05-17 20:14:08 -04001475
Flavio Castroa7162bb2016-07-25 17:30:30 -07001476 vlan_id = 1
1477 port2_out_vlan = 2
1478 port3_out_vlan = 3
1479 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
1480 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1481 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1482 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
1483 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
1484 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
1485 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
1486 src_ip = 0xc0a80101
1487 src_ip_str = "192.168.1.1"
1488 dst_ip = 0xe0010101
1489 dst_ip_str = "224.1.1.1"
Flavio Castro423df652016-05-17 20:14:08 -04001490
Flavio Castroa7162bb2016-07-25 17:30:30 -07001491 port1 = config[ "port_map" ].keys( )[ 0 ]
1492 port2 = config[ "port_map" ].keys( )[ 1 ]
1493 # port3=config["port_map"].keys()[2]
Flavio Castro423df652016-05-17 20:14:08 -04001494
Flavio Castroa7162bb2016-07-25 17:30:30 -07001495 # add l2 interface group
1496 for port in config[ "port_map" ].keys( ):
1497 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=False,
1498 send_barrier=False )
1499 # add vlan flow table
1500 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1501 vlan_id += 1
Flavio Castro423df652016-05-17 20:14:08 -04001502
Flavio Castroa7162bb2016-07-25 17:30:30 -07001503 # add termination flow
1504 add_termination_flow( self.controller, port1, 0x0800, [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ],
1505 vlan_id )
Flavio Castro423df652016-05-17 20:14:08 -04001506
Flavio Castroa7162bb2016-07-25 17:30:30 -07001507 # add MPLS interface group
1508 l2_gid = encode_l2_interface_group_id( port2_out_vlan, port2 )
1509 mpls_gid2, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1510 port2_out_vlan, port2 )
1511 # l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
1512 # mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
1513 # add L3VPN groups
1514 mpls_label_gid2, mpls_label_msg = add_mpls_label_group( self.controller,
1515 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=(0x20000 + port2), ref_gid=mpls_gid2,
1516 push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True )
1517 # mpls_label_gid3, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001518 # index=(0x10000+port3), ref_gid= mpls_gid3, push_mpls_header=True, set_mpls_label=port3, set_bos=1, cpy_ttl_outward=True)
Flavio Castro423df652016-05-17 20:14:08 -04001519
Flavio Castroa7162bb2016-07-25 17:30:30 -07001520 mcat_group_msg = add_l3_mcast_group( self.controller, in_vlan, 2, [ mpls_label_gid2 ] )
1521 add_mcast4_routing_flow( self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id )
Flavio Castro423df652016-05-17 20:14:08 -04001522
Flavio Castroa7162bb2016-07-25 17:30:30 -07001523 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac_str,
1524 eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str, ip_dst=dst_ip_str )
1525 pkt = str( parsed_pkt )
1526 self.dataplane.send( port1, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001527 label = (12, 0, 1, 63)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001528 exp_pkt = mpls_packet( pktlen=100, eth_dst=dst_mac_str, eth_src=intf_src_mac_str, ip_ttl=64,
1529 ip_src=src_ip_str, label=[ label ], ip_dst=dst_ip_str )
1530 pkt = str( exp_pkt )
1531 verify_packet( self, pkt, port2 )
1532 # verify_packet(self, pkt, port3)
1533 verify_no_other_packets( self )
1534 delete_all_groups( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001535 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001536 delete_all_flows( self.controller )
1537 delete_all_groups( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001538
Flavio Castro423df652016-05-17 20:14:08 -04001539
Flavio Castroa7162bb2016-07-25 17:30:30 -07001540class PacketInSrcMacMiss( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001541 """
1542 Test packet in function on a src-mac miss
1543 Send a packet to each dataplane port and verify that a packet
1544 in message is received from the controller for each
1545 #todo verify you stop receiving after adding rule
1546 """
1547
Flavio Castroa7162bb2016-07-25 17:30:30 -07001548 def runTest( self ):
1549 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001550 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001551 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro423df652016-05-17 20:14:08 -04001552
Flavio Castroa7162bb2016-07-25 17:30:30 -07001553 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001554 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001555 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, 1, True, False )
1556 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1557 Groups.put( L2gid )
1558 parsed_vlan_pkt = simple_tcp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
1559 vlan_pkt = str( parsed_vlan_pkt )
1560 for of_port in config[ "port_map" ].keys( ):
1561 logging.info( "PacketInMiss test, port %d", of_port )
1562 self.dataplane.send( of_port, vlan_pkt )
1563 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH )
1564 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001565 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001566 delete_all_flows( self.controller )
1567 delete_all_groups( self.controller )
1568
1569
1570class EcmpGroupMod( base_tests.SimpleDataPlane ):
1571 """
1572 Insert IP packet
1573 Receive IP packet
1574 """
1575
1576 def runTest( self ):
1577 Groups = Queue.LifoQueue( )
1578 try:
1579 if len( config[ "port_map" ] ) < 2:
1580 logging.info( "Port count less than 2, can't run this case" )
1581 return
1582
1583 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1584 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
1585 dip = 0xc0a80001
1586 # Hashes Test Name and uses it as id for installing unique groups
1587 ports = config[ "port_map" ].keys( )
1588 ecmp=[]
1589 for port in ports:
1590 vlan_id = port
1591 id = port
1592 # add l2 interface group
1593 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1594 is_tagged=True, send_barrier=False )
1595 dst_mac[ 5 ] = vlan_id
1596 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1597 src_mac=intf_src_mac, dst_mac=dst_mac )
1598 ecmp +=[l3_msg.group_id]
1599 Groups._put( l2_gid )
1600 Groups._put( l3_msg.group_id )
1601 ecmp_msg = add_l3_ecmp_group( self.controller, ports[0], [l3_msg.group_id])
1602 #ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
1603 # add vlan flow table
1604 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1605 # add termination flow
1606 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
1607 # add unicast routing flow
1608 dst_ip = dip + (vlan_id << 8)
1609 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
1610 Groups._put( ecmp_msg.group_id )
1611 mod_l3_ecmp_group( self.controller, ports[0], ecmp)
1612
1613 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1614 parsed_pkt=exp_pkt=0
1615 for out_port in ports:
1616 mac_src = '00:00:00:22:22:%02X' % ports[0]
1617 ip_src = '192.168.%02d.%02d' % (ports[0], 1)
1618 ip_dst = '192.168.%02d.%02d' % ( ports[1], 1)
1619 tcp= out_port if out_port==24 else 25
1620 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[0],
1621 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1622 tcp_dport=tcp)
1623 pkt = str( parsed_pkt )
1624 self.dataplane.send( ports[0], pkt )
1625 # build expected packet
1626 mac_dst = '00:00:00:22:22:%02X' % out_port
1627 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
1628 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst, tcp_dport=tcp )
1629 pkt = str( exp_pkt )
1630 verify_packet( self, pkt, out_port )
1631 verify_no_other_packets( self )
1632 l3_gid = encode_l3_unicast_group_id(ports[0])
1633 mod_l3_ecmp_group( self.controller, ports[0], [l3_gid])
1634 for port in ports:
1635 mac_src = '00:00:00:22:22:%02X' % ports[0]
1636 ip_src = '192.168.%02d.%02d' % ( ports[0], 1 )
1637 ip_dst = '192.168.%02d.%02d' % ( ports[1], 1 )
1638 tcp= port if port==24 else 25
1639 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[0],
1640 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1641 tcp_dport=tcp)
1642 pkt = str( parsed_pkt )
1643 self.dataplane.send( ports[0], pkt )
1644 # build expected packet
1645 mac_dst = '00:00:00:22:22:%02X' % ports[0]
1646 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[0],
1647 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst, tcp_dport=tcp )
1648 pkt = str( exp_pkt )
1649 verify_packet( self, pkt, ports[0] )
1650 verify_no_other_packets( self )
1651 mod_l3_ecmp_group( self.controller, ports[0], [] )
1652 for port in ports:
1653 mac_src = '00:00:00:22:22:%02X' % ports[0]
1654 ip_src = '192.168.%02d.%02d' % ( ports[0], 1 )
1655 ip_dst = '192.168.%02d.%02d' % ( ports[1], 1 )
1656 tcp= port if port==24 else 25
1657 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[0],
1658 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1659 tcp_dport=tcp)
1660 pkt = str( parsed_pkt )
1661 self.dataplane.send( ports[0], pkt )
1662 verify_no_other_packets( self )
1663 finally:
1664 delete_all_flows( self.controller )
1665 delete_groups( self.controller, Groups )
1666 delete_all_groups( self.controller )
1667