blob: 851036d9f1908c190ab620904c87743d611cf292 [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 Castro76c5b262016-07-27 19:53:00 -070017 Verify ACL rule for IP_PROTO=2 wont match a UDP packet and a rule for IP_PROTO=17 WILL match a UDP packet.
Flavio Castro6d498522015-12-15 14:05:04 -050018 """
19
Flavio Castroa7162bb2016-07-25 17:30:30 -070020 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -070021 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -070022 parsed_vlan_pkt = simple_udp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
23 vlan_pkt = str( parsed_vlan_pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -070024 # create match
Flavio Castroa7162bb2016-07-25 17:30:30 -070025 match = ofp.match( )
26 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
27 match.oxm_list.append( ofp.oxm.ip_proto( 2 ) )
28 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
29 ofp.instruction.apply_actions( actions=[
30 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
31 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
32 logging.info( "Inserting packet in flow to controller" )
33 self.controller.message_send( request )
Flavio Castro1c9b1252016-02-04 18:42:58 -050034
Flavio Castroa7162bb2016-07-25 17:30:30 -070035 for of_port in config[ "port_map" ].keys( ):
36 logging.info( "PacketInMiss test, port %d", of_port )
37 self.dataplane.send( of_port, vlan_pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -050038
Flavio Castroa7162bb2016-07-25 17:30:30 -070039 verify_no_packet_in( self, vlan_pkt, of_port )
40 delete_all_flows( self.controller )
41 do_barrier( self.controller )
Flavio Castro6d498522015-12-15 14:05:04 -050042
Flavio Castroa7162bb2016-07-25 17:30:30 -070043 match = ofp.match( )
44 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
45 match.oxm_list.append( ofp.oxm.ip_proto( 17 ) )
46 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
47 ofp.instruction.apply_actions( actions=[
48 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
49 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
50 logging.info( "Inserting packet in flow to controller" )
51 self.controller.message_send( request )
52 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -050053
Flavio Castroa7162bb2016-07-25 17:30:30 -070054 for of_port in config[ "port_map" ].keys( ):
55 logging.info( "PacketInMiss test, port %d", of_port )
56 self.dataplane.send( of_port, vlan_pkt )
Flavio Castro6d498522015-12-15 14:05:04 -050057
Flavio Castroa7162bb2016-07-25 17:30:30 -070058 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_ACTION )
Flavio Castro6d498522015-12-15 14:05:04 -050059
Flavio Castroa7162bb2016-07-25 17:30:30 -070060 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -070061 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -070062 delete_all_flows( self.controller )
63 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -050064
Flavio Castroaf2b4502016-02-02 17:41:32 -050065
Flavio Castro67d8bd52016-02-03 14:22:14 -050066@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -070067class ArpNL2( base_tests.SimpleDataPlane ):
68 def runTest( self ):
69 delete_all_flows( self.controller )
70 delete_all_groups( self.controller )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050071
Flavio Castroa7162bb2016-07-25 17:30:30 -070072 ports = sorted( config[ "port_map" ].keys( ) )
73 match = ofp.match( )
74 match.oxm_list.append( ofp.oxm.eth_type( 0x0806 ) )
75 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
76 ofp.instruction.apply_actions( actions=[
77 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
78 buffer_id=ofp.OFP_NO_BUFFER, priority=40000 )
79 self.controller.message_send( request )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050080 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -070081 add_one_l2_interface_group( self.controller, port, 1, False, False )
82 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_BOTH )
83 group_id = encode_l2_interface_group_id( 1, port )
84 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], 1, group_id, True )
85 do_barrier( self.controller )
86 parsed_arp_pkt = simple_arp_packet( )
87 arp_pkt = str( parsed_arp_pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050088
89 for out_port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -070090 self.dataplane.send( out_port, arp_pkt )
91 verify_packet_in( self, arp_pkt, out_port, ofp.OFPR_ACTION )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050092 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -050093 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -050094 for in_port in ports:
95 if in_port == out_port:
96 continue
97 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -050098 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castroa7162bb2016-07-25 17:30:30 -070099 parsed_pkt = simple_tcp_packet( eth_dst=mac_dst, eth_src=mac_src )
100 pkt = str( parsed_pkt )
101 self.dataplane.send( in_port, pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500102
103 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700104 if ofport in [ out_port ]:
105 verify_packet( self, pkt, ofport )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500106 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700107 verify_no_packet( self, pkt, ofport )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500108
Flavio Castroa7162bb2016-07-25 17:30:30 -0700109 verify_no_other_packets( self )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500110
Flavio Castroa7162bb2016-07-25 17:30:30 -0700111class PacketInArp( base_tests.SimpleDataPlane ):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500112 """
Flavio Castro76c5b262016-07-27 19:53:00 -0700113 Verify Packet-in message from eth_type 0x806 on ACL table
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500114 """
115
Flavio Castroa7162bb2016-07-25 17:30:30 -0700116 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700117 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700118 parsed_arp_pkt = simple_arp_packet( )
119 arp_pkt = str( parsed_arp_pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700120 # create match
Flavio Castroa7162bb2016-07-25 17:30:30 -0700121 match = ofp.match( )
122 match.oxm_list.append( ofp.oxm.eth_type( 0x0806 ) )
123 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
124 ofp.instruction.apply_actions( actions=[
125 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
126 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500127
Flavio Castroa7162bb2016-07-25 17:30:30 -0700128 logging.info( "Inserting packet in flow to controller" )
129 self.controller.message_send( request )
130 do_barrier( self.controller )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500131
Flavio Castroa7162bb2016-07-25 17:30:30 -0700132 for of_port in config[ "port_map" ].keys( ):
133 logging.info( "PacketInMiss test, port %d", of_port )
134 self.dataplane.send( of_port, arp_pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500135
Flavio Castroa7162bb2016-07-25 17:30:30 -0700136 verify_packet_in( self, arp_pkt, of_port, ofp.OFPR_ACTION )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500137
Flavio Castroa7162bb2016-07-25 17:30:30 -0700138 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700139 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700140 delete_all_flows( self.controller )
141 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500142
Flavio Castroa7162bb2016-07-25 17:30:30 -0700143
144class PacketInIPTable( base_tests.SimpleDataPlane ):
Flavio Castro91d1a552016-05-17 16:59:44 -0700145 """
Flavio Castro76c5b262016-07-27 19:53:00 -0700146 Verify Packet-in message from IP table when controller action is used
Flavio Castro91d1a552016-05-17 16:59:44 -0700147 Send a packet to each dataplane port and verify that a packet
148 in message is received from the controller for each
149 #todo verify you stop receiving after adding rule
150 """
151
Flavio Castroa7162bb2016-07-25 17:30:30 -0700152 def runTest( self ):
153 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700154 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700155 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
156 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
157 dip = 0xc0a80001
158 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro91d1a552016-05-17 16:59:44 -0700159
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700160 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700161 # add l2 interface group
162 vlan_id = port
163 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=True,
164 send_barrier=False )
165 dst_mac[ 5 ] = vlan_id
166 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
167 src_mac=intf_src_mac, dst_mac=dst_mac )
168 # add vlan flow table
169 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
170 # add termination flow
171 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
172 # add unicast routing flow
173 dst_ip = dip + (vlan_id << 8)
174 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id,
175 send_ctrl=True )
176 Groups.put( l3_msg.group_id )
Flavio Castro91d1a552016-05-17 16:59:44 -0700177
Flavio Castroa7162bb2016-07-25 17:30:30 -0700178 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -0700179
Flavio Castroa7162bb2016-07-25 17:30:30 -0700180 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700181 for in_port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700182 mac_src = '00:00:00:22:22:%02X' % in_port
183 ip_src = '192.168.%02d.1' % in_port
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700184 for out_port in ports:
185 if in_port == out_port:
186 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700187 ip_dst = '192.168.%02d.1' % out_port
188 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
189 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
190 pkt = str( parsed_pkt )
191 self.dataplane.send( in_port, pkt )
192 verify_packet_in( self, pkt, in_port, ofp.OFPR_ACTION )
193 # verify_no_other_packets(self)
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700194 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700195 delete_all_flows( self.controller )
196 delete_groups( self.controller, Groups )
197 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -0700198
Flavio Castroa7162bb2016-07-25 17:30:30 -0700199
200class L2FloodQinQ( base_tests.SimpleDataPlane ):
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500201 """
Flavio Castro76c5b262016-07-27 19:53:00 -0700202 Verify Vlan based flooding of QinQ based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500203 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500204
Flavio Castroa7162bb2016-07-25 17:30:30 -0700205 def runTest( self ):
206 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700207 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700208 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700209 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500210
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700211 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700212 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
213 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
214 Groups.put( L2gid )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500215
Flavio Castroa7162bb2016-07-25 17:30:30 -0700216 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
217 Groups.put( msg.group_id )
218 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
219 do_barrier( self.controller )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500220
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700221 # verify flood
222 for ofport in ports:
223 # change dest based on port number
224 mac_src = '00:12:34:56:78:%02X' % ofport
Flavio Castroa7162bb2016-07-25 17:30:30 -0700225 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
226 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10,
227 eth_dst='00:12:34:56:78:9a', eth_src=mac_src )
228 pkt = str( parsed_pkt )
229 self.dataplane.send( ofport, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700230 # self won't rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700231 verify_no_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700232 # others will rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700233 tmp_ports = list( ports )
234 tmp_ports.remove( ofport )
235 verify_packets( self, pkt, tmp_ports )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500236
Flavio Castroa7162bb2016-07-25 17:30:30 -0700237 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700238 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700239 delete_all_flows( self.controller )
240 delete_groups( self.controller, Groups )
241 delete_all_groups( self.controller )
242
Flavio Castro1c9b1252016-02-04 18:42:58 -0500243
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500244@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -0700245class L2FloodTagged( base_tests.SimpleDataPlane ):
Flavio Castro184cefe2015-11-19 20:52:49 -0500246 """
247 Test L2 flood to a vlan
248 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 -0500249 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500250
Flavio Castroa7162bb2016-07-25 17:30:30 -0700251 def runTest( self ):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500252 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700253 vlan_id = abs( hash( inspect.stack( )[ 0 ][ 3 ] ) ) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500254 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500255
Flavio Castroa7162bb2016-07-25 17:30:30 -0700256 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro34352e72015-12-07 20:01:51 -0500257
Flavio Castroa7162bb2016-07-25 17:30:30 -0700258 delete_all_flows( self.controller )
259 delete_all_groups( self.controller )
Flavio Castro184cefe2015-11-19 20:52:49 -0500260
Flavio Castro184cefe2015-11-19 20:52:49 -0500261 # Installing flows to avoid packet-in
262 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700263 add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
264 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
265 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
266 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
267 do_barrier( self.controller )
Flavio Castro184cefe2015-11-19 20:52:49 -0500268
Flavio Castro1c9b1252016-02-04 18:42:58 -0500269 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500270 for ofport in ports:
271 # change dest based on port number
Flavio Castroa7162bb2016-07-25 17:30:30 -0700272 pkt = str(
273 simple_tcp_packet( dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst='00:12:34:56:78:9a' ) )
274 self.dataplane.send( ofport, pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500275 # self won't rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700276 verify_no_packet( self, pkt, ofport )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500277 # others will rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700278 tmp_ports = list( ports )
279 tmp_ports.remove( ofport )
280 verify_packets( self, pkt, tmp_ports )
281 verify_no_other_packets( self )
Flavio Castroaabb5792015-11-18 19:03:50 -0500282
Flavio Castro1c9b1252016-02-04 18:42:58 -0500283
Flavio Castroa7162bb2016-07-25 17:30:30 -0700284class L2UnicastTagged( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700285 """ Verify Bridging works: match(VID, DST_MAC)> fwd(port) """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500286
Flavio Castroa7162bb2016-07-25 17:30:30 -0700287 def runTest( self ):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700288
Flavio Castroa7162bb2016-07-25 17:30:30 -0700289 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700290 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700291 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700292 vlan_id = 1;
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700293 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700294 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
295 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
296 Groups.put( L2gid )
297 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], vlan_id, L2gid,
298 True )
299 do_barrier( self.controller )
Flavio Castro6efe1862015-11-18 16:28:06 -0500300
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700301 for out_port in ports:
302 # change dest based on port number
303 mac_dst = '00:12:34:56:78:%02X' % out_port
304 for in_port in ports:
305 if in_port == out_port:
306 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700307 pkt = str( simple_tcp_packet( dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst=mac_dst ) )
308 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700309 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700310 if ofport in [ out_port ]:
311 verify_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700312 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700313 verify_no_packet( self, pkt, ofport )
314 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700315 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700316 delete_all_flows( self.controller )
317 delete_groups( self.controller, Groups )
318 delete_all_groups( self.controller )
Flavio Castro6efe1862015-11-18 16:28:06 -0500319
Flavio Castroa7162bb2016-07-25 17:30:30 -0700320
321class Mtu1500( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700322 """V erifies basic mtu limits"""
Flavio Castroa7162bb2016-07-25 17:30:30 -0700323 def runTest( self ):
324 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700325 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700326 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700327 vlan_id = 18
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700328 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700329 L2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
330 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
331 Groups.put( L2gid )
332 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], vlan_id, L2gid,
333 True )
334 do_barrier( self.controller )
Flavio Castrob6773032015-11-19 22:49:24 -0500335
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700336 for out_port in ports:
337 # change dest based on port number
338 mac_dst = '00:12:34:56:78:%02X' % out_port
339 for in_port in ports:
340 if in_port == out_port:
341 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700342 pkt = str( simple_tcp_packet( pktlen=1500, dl_vlan_enable=True, vlan_vid=vlan_id,
343 eth_dst=mac_dst ) )
344 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700345 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700346 if ofport in [ out_port ]:
347 verify_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700348 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700349 verify_no_packet( self, pkt, ofport )
350 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700351 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700352 delete_all_flows( self.controller )
353 delete_groups( self.controller, Groups )
354 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500355
Flavio Castroa7162bb2016-07-25 17:30:30 -0700356
357class _32UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700358 """ Verify /32 IP forwarding to L3 Interface"""
Flavio Castro1c9b1252016-02-04 18:42:58 -0500359
Flavio Castroa7162bb2016-07-25 17:30:30 -0700360 def runTest( self ):
361 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700362 try:
363 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -0700364 if len( config[ "port_map" ] ) < 2:
365 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700366 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500367
Flavio Castroa7162bb2016-07-25 17:30:30 -0700368 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
369 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700370 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700371 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700372 for port in ports:
373 # add l2 interface group
374 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -0700375 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
376 is_tagged=True, send_barrier=False )
377 dst_mac[ 5 ] = vlan_id
378 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
379 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700380 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700381 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700382 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700383 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700384 # add unicast routing flow
385 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700386 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
387 Groups.put( l2gid )
388 Groups.put( l3_msg.group_id )
389 do_barrier( self.controller )
Flavio Castrod8f8af22015-12-02 18:19:26 -0500390
Flavio Castroa7162bb2016-07-25 17:30:30 -0700391 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700392 for in_port in ports:
393 mac_src = '00:00:00:22:32:%02X' % (test_id + in_port)
394 ip_src = '192.168.%02d.1' % (test_id + in_port)
395 for out_port in ports:
396 if in_port == out_port:
397 continue
398 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700399 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
400 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
401 ip_src=ip_src, ip_dst=ip_dst )
402 pkt = str( parsed_pkt )
403 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700404 # build expected packet
405 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700406 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
407 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
408 ip_src=ip_src, ip_dst=ip_dst )
409 pkt = str( exp_pkt )
410 verify_packet( self, pkt, out_port )
411 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700412 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700413 delete_all_flows( self.controller )
414 delete_groups( self.controller, Groups )
415 delete_all_groups( self.controller )
Flavio Castro05d20bc2015-11-16 15:06:14 -0500416
Flavio Castroa7162bb2016-07-25 17:30:30 -0700417
418class _32VPN( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700419 """ Verify MPLS IP VPN Initiation from /32 rule """
Flavio Castro2262fd42016-02-04 19:03:36 -0500420
Flavio Castroa7162bb2016-07-25 17:30:30 -0700421 def runTest( self ):
422 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700423 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700424 if len( config[ "port_map" ] ) < 2:
425 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700426 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500427
Flavio Castroa7162bb2016-07-25 17:30:30 -0700428 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
429 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700430 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700431 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700432 for port in ports:
433 # add l2 interface group
434 id = port
435 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700436 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
437 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700438 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700439 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
440 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700441 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700442 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
443 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
444 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700445 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castroa7162bb2016-07-25 17:30:30 -0700446 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700447 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700448 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=2,
449 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700450 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700451 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700452 # add routing flow
453 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700454 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, mpls_label_gid, vrf=2 )
455 Groups._put( l2_gid )
456 Groups._put( mpls_gid )
457 Groups._put( mpls_label_gid )
458 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500459
Flavio Castroa7162bb2016-07-25 17:30:30 -0700460 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700461 for in_port in ports:
462 ip_src = '192.168.%02d.1' % (in_port)
463 for out_port in ports:
464 if in_port == out_port:
465 continue
466 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700467 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
468 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
469 pkt = str( parsed_pkt )
470 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700471 # build expect packet
472 mac_dst = '00:00:00:22:22:%02X' % (out_port)
473 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700474 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
475 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
476 label=[ label ] )
477 pkt = str( exp_pkt )
478 verify_packet( self, pkt, out_port )
479 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700480 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700481 delete_all_flows( self.controller )
482 delete_groups( self.controller, Groups )
483 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500484
Flavio Castroa7162bb2016-07-25 17:30:30 -0700485
486class _32EcmpVpn( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700487 """ Verify MPLS IP VPN Initiation from /32 rule using ECMP """
Flavio Castro2262fd42016-02-04 19:03:36 -0500488
Flavio Castroa7162bb2016-07-25 17:30:30 -0700489 def runTest( self ):
490 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700491 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700492 if len( config[ "port_map" ] ) < 2:
493 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700494 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500495
Flavio Castroa7162bb2016-07-25 17:30:30 -0700496 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
497 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700498 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700499 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700500 for port in ports:
501 # add l2 interface group
502 id = port
503 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700504 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
505 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700506 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700507 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
508 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700509 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700510 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
511 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
512 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
513 ecmp_msg = add_l3_ecmp_group( self.controller, vlan_id, [ mpls_label_gid ] )
514 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700515 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700516 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
517 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700518 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700519 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700520 # add routing flow
521 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700522 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, ecmp_msg.group_id )
523 Groups._put( l2_gid )
524 Groups._put( mpls_gid )
525 Groups._put( mpls_label_gid )
526 Groups._put( ecmp_msg.group_id )
527 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500528
Flavio Castroa7162bb2016-07-25 17:30:30 -0700529 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700530 for in_port in ports:
531 ip_src = '192.168.%02d.1' % (in_port)
532 for out_port in ports:
533 if in_port == out_port:
534 continue
535 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700536 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
537 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
538 pkt = str( parsed_pkt )
539 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700540 # build expect packet
541 mac_dst = '00:00:00:22:22:%02X' % (out_port)
542 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700543 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
544 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
545 label=[ label ] )
546 pkt = str( exp_pkt )
547 verify_packet( self, pkt, out_port )
548 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700549 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700550 delete_all_flows( self.controller )
551 delete_groups( self.controller, Groups )
552 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500553
Flavio Castroa7162bb2016-07-25 17:30:30 -0700554
555class _32ECMPL3( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700556 """ Verifies /32 IP routing and ECMP """
Flavio Castro2262fd42016-02-04 19:03:36 -0500557
Flavio Castroa7162bb2016-07-25 17:30:30 -0700558 def runTest( self ):
559 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700560 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700561 if len( config[ "port_map" ] ) < 2:
562 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700563 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500564
Flavio Castroa7162bb2016-07-25 17:30:30 -0700565 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
566 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700567 dip = 0xc0a80001
568 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700569 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700570 for port in ports:
571 vlan_id = port
572 id = port
573 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700574 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
575 is_tagged=True, send_barrier=False )
576 dst_mac[ 5 ] = vlan_id
577 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
578 src_mac=intf_src_mac, dst_mac=dst_mac )
579 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700580 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700581 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700582 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700583 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700584 # add unicast routing flow
585 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700586 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, ecmp_msg.group_id )
587 Groups._put( l2_gid )
588 Groups._put( l3_msg.group_id )
589 Groups._put( ecmp_msg.group_id )
590 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500591
Flavio Castroa7162bb2016-07-25 17:30:30 -0700592 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700593 for in_port in ports:
594 mac_src = '00:00:00:22:22:%02X' % in_port
595 ip_src = '192.168.%02d.1' % in_port
596 for out_port in ports:
597 if in_port == out_port:
598 continue
599 ip_dst = '192.168.%02d.1' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700600 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
601 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
602 pkt = str( parsed_pkt )
603 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700604 # build expected packet
605 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700606 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
607 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
608 pkt = str( exp_pkt )
609 verify_packet( self, pkt, out_port )
610 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700611 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700612 delete_all_flows( self.controller )
613 delete_groups( self.controller, Groups )
614 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500615
Flavio Castroa7162bb2016-07-25 17:30:30 -0700616
617class _24VPN( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700618 """ Verify MPLS IP VPN Initiation from /32 rule using ECMP """
Flavio Castro2262fd42016-02-04 19:03:36 -0500619
Flavio Castroa7162bb2016-07-25 17:30:30 -0700620 def runTest( self ):
621 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700622 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700623 if len( config[ "port_map" ] ) < 2:
624 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700625 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500626
Flavio Castroa7162bb2016-07-25 17:30:30 -0700627 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
628 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700629 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700630 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700631 for port in ports:
632 # add l2 interface group
633 id = port
634 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700635 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
636 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700637 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700638 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
639 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700640 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700641 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
642 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
643 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700644 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castroa7162bb2016-07-25 17:30:30 -0700645 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700646 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700647 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
648 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700649 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700650 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700651 # add routing flow
652 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700653 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid )
654 Groups._put( l2_gid )
655 Groups._put( mpls_gid )
656 Groups._put( mpls_label_gid )
657 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500658
Flavio Castroa7162bb2016-07-25 17:30:30 -0700659 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700660 for in_port in ports:
661 ip_src = '192.168.%02d.1' % (in_port)
662 for out_port in ports:
663 if in_port == out_port:
664 continue
665 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700666 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
667 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
668 pkt = str( parsed_pkt )
669 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700670 # build expect packet
671 mac_dst = '00:00:00:22:22:%02X' % (out_port)
672 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700673 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
674 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
675 label=[ label ] )
676 pkt = str( exp_pkt )
677 verify_packet( self, pkt, out_port )
678 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700679 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700680 delete_all_flows( self.controller )
681 delete_groups( self.controller, Groups )
682 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500683
Flavio Castroa7162bb2016-07-25 17:30:30 -0700684
685class _24EcmpVpn( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700686 """ Verify MPLS IP VPN Initiation from /24 rule using ECMP """
Flavio Castro72a45d52015-12-02 16:37:05 -0500687
Flavio Castroa7162bb2016-07-25 17:30:30 -0700688 def runTest( self ):
689 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700690 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700691 if len( config[ "port_map" ] ) < 2:
692 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700693 return
Flavio Castroa7162bb2016-07-25 17:30:30 -0700694 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
695 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700696 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700697 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700698 for port in ports:
699 # add l2 interface group
700 id = port
701 vlan_id = id
Flavio Castroa7162bb2016-07-25 17:30:30 -0700702 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
703 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700704 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700705 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
706 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700707 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700708 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
709 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
710 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
711 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ mpls_label_gid ] )
712 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700713 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700714 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
715 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700716 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700717 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700718 # add routing flow
719 dst_ip = dip + (vlan_id << 8)
720 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700721 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id,
722 vrf=0 )
723 Groups._put( l2_gid )
724 Groups._put( mpls_gid )
725 Groups._put( mpls_label_gid )
726 Groups._put( ecmp_msg.group_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700727
Flavio Castroa7162bb2016-07-25 17:30:30 -0700728 do_barrier( self.controller )
Flavio Castro80730822015-12-11 15:38:47 -0500729
Flavio Castroa7162bb2016-07-25 17:30:30 -0700730 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700731 for in_port in ports:
732 mac_src = '00:00:00:22:22:%02X' % (in_port)
733 ip_src = '192.168.%02d.1' % (in_port)
734 for out_port in ports:
735 if in_port == out_port:
736 continue
737 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700738 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
739 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
740 pkt = str( parsed_pkt )
741 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700742 # build expect packet
743 mac_dst = '00:00:00:22:22:%02X' % out_port
744 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700745 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
746 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
747 label=[ label ] )
748 pkt = str( exp_pkt )
749 verify_packet( self, pkt, out_port )
750 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700751 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700752 delete_all_flows( self.controller )
753 delete_groups( self.controller, Groups )
754 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500755
Flavio Castroa7162bb2016-07-25 17:30:30 -0700756
757class FloodGroupMod( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700758 """ Modify referenced group test """
Flavio Castroa7162bb2016-07-25 17:30:30 -0700759
760 def runTest( self ):
761 Groups = Queue.LifoQueue( )
762 try:
763 ports = sorted( config[ "port_map" ].keys( ) )
764 vlan_id = 1
765
766 for port in ports:
767 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
768 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
769 Groups.put( L2gid )
770
771 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
772 Groups.put( msg.group_id )
773 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
774 do_barrier( self.controller )
775 # verify flood
776 for ofport in ports:
777 # change dest based on port number
778 mac_src = '00:12:34:56:78:%02X' % ofport
779 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
780 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10,
781 eth_dst='00:12:34:56:78:9a', eth_src=mac_src )
782 pkt = str( parsed_pkt )
783 self.dataplane.send( ofport, pkt )
784 # self won't rx packet
785 verify_no_packet( self, pkt, ofport )
786 # others will rx packet
787 tmp_ports = list( ports )
788 tmp_ports.remove( ofport )
789 verify_packets( self, pkt, tmp_ports )
790 verify_no_other_packets( self )
791 msg = mod_l2_flood_group( self.controller, [ ports[ 0 ] ], vlan_id, vlan_id )
792 mac_src = '00:12:34:56:78:%02X' % ports[ 1 ]
793 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
794 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a',
795 eth_src=mac_src )
796 pkt = str( parsed_pkt )
797 self.dataplane.send( ports[ 1 ], pkt )
798 verify_packets( self, pkt, [ ports[ 0 ] ] )
799 finally:
800 delete_all_flows( self.controller )
801 delete_groups( self.controller, Groups )
802 delete_all_groups( self.controller )
803
804
805class _24ECMPL3( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700806 """ Verifies /24 IP routing using ECMP """
Flavio Castro80730822015-12-11 15:38:47 -0500807
Flavio Castroa7162bb2016-07-25 17:30:30 -0700808 def runTest( self ):
809 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700810 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700811 if len( config[ "port_map" ] ) < 2:
812 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700813 return
Flavio Castro80730822015-12-11 15:38:47 -0500814
Flavio Castroa7162bb2016-07-25 17:30:30 -0700815 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
816 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700817 dip = 0xc0a80001
818 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700819 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700820 for port in ports:
821 vlan_id = port
822 id = port
823 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700824 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
825 is_tagged=True, send_barrier=False )
826 dst_mac[ 5 ] = vlan_id
827 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
828 src_mac=intf_src_mac, dst_mac=dst_mac )
829 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700830 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700831 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700832 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700833 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700834 # add unicast routing flow
835 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700836 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
837 Groups._put( l2_gid )
838 Groups._put( l3_msg.group_id )
839 Groups._put( ecmp_msg.group_id )
840 do_barrier( self.controller )
Flavio Castro72a45d52015-12-02 16:37:05 -0500841
Flavio Castroa7162bb2016-07-25 17:30:30 -0700842 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700843 for in_port in ports:
844 mac_src = '00:00:00:22:22:%02X' % in_port
845 ip_src = '192.168.%02d.1' % in_port
846 for out_port in ports:
847 if in_port == out_port:
848 continue
849 ip_dst = '192.168.%02d.1' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700850 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
851 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
852 pkt = str( parsed_pkt )
853 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700854 # build expected packet
855 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700856 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
857 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
858 pkt = str( exp_pkt )
859 verify_packet( self, pkt, out_port )
860 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700861 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700862 delete_all_flows( self.controller )
863 delete_groups( self.controller, Groups )
864 delete_all_groups( self.controller )
865
Flavio Castro1c9b1252016-02-04 18:42:58 -0500866
Flavio Castroaba28ff2016-02-03 16:47:48 -0500867@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -0700868class MPLSBUG( base_tests.SimpleDataPlane ):
869 def runTest( self ):
870 if len( config[ "port_map" ] ) < 2:
871 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro80730822015-12-11 15:38:47 -0500872 return
Flavio Castroa7162bb2016-07-25 17:30:30 -0700873 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
874 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro1c9b1252016-02-04 18:42:58 -0500875 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700876 Groups = Queue.LifoQueue( )
877 ports = config[ "port_map" ].keys( )
Flavio Castro80730822015-12-11 15:38:47 -0500878 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500879 # add l2 interface group
880 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700881 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
882 dst_mac[ 5 ] = vlan_id
Flavio Castro1c9b1252016-02-04 18:42:58 -0500883 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700884 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
885 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500886 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700887 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500888 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700889 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500890 # add mpls flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700891 add_mpls_flow( self.controller, l3_msg.group_id, port )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500892 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700893 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500894 # add unicast routing flow
895 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700896 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
897 Groups._put( l2_gid )
898 Groups._put( l3_msg.group_id )
899 do_barrier( self.controller )
Flavio Castro80730822015-12-11 15:38:47 -0500900
Flavio Castroa7162bb2016-07-25 17:30:30 -0700901 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro80730822015-12-11 15:38:47 -0500902 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500903 mac_src = '00:00:00:22:22:%02X' % in_port
904 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -0500905 for out_port in ports:
906 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500907 continue
908 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500909 switch_mac = "00:00:00:cc:cc:cc"
910 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700911 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
912 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[ label ] )
913 pkt = str( parsed_pkt )
914 self.dataplane.send( in_port, pkt )
Flavio Castro80730822015-12-11 15:38:47 -0500915
Flavio Castro1c9b1252016-02-04 18:42:58 -0500916 # build expect packet
917 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700918 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
919 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
920 pkt = str( exp_pkt )
921 verify_packet( self, pkt, out_port )
922 verify_no_other_packets( self )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500923
Flavio Castroa7162bb2016-07-25 17:30:30 -0700924 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
925 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
926 pkt = str( parsed_pkt )
927 self.dataplane.send( in_port, pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500928 # build expected packet
929 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700930 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
931 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
932 pkt = str( exp_pkt )
933 verify_packet( self, pkt, out_port )
934 verify_no_other_packets( self )
935 delete_all_flows( self.controller )
936 delete_groups( self.controller, Groups )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500937
Flavio Castroa7162bb2016-07-25 17:30:30 -0700938
939class L3McastToL2( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700940 """ Mcast routing in the same vlan """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500941
Flavio Castroa7162bb2016-07-25 17:30:30 -0700942 def runTest( self ):
castroflaviocc403a92015-12-15 14:04:19 -0500943 """
944 port1 (vlan 300)-> All Ports (vlan 300)
945 """
Flavio Castroa7162bb2016-07-25 17:30:30 -0700946 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700947 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700948 if len( config[ "port_map" ] ) < 3:
949 logging.info( "Port count less than 3, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700950 assert (False)
951 return
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700952 vlan_id = 300
Flavio Castroa7162bb2016-07-25 17:30:30 -0700953 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
954 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
955 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
956 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
957 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
958 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700959 src_ip = 0xc0a80101
960 src_ip_str = "192.168.1.1"
961 dst_ip = 0xe0010101
962 dst_ip_str = "224.1.1.1"
castroflaviocc403a92015-12-15 14:04:19 -0500963
Flavio Castroa7162bb2016-07-25 17:30:30 -0700964 port1 = config[ "port_map" ].keys( )[ 0 ]
965 port2 = config[ "port_map" ].keys( )[ 1 ]
castroflaviocc403a92015-12-15 14:04:19 -0500966
Flavio Castroa7162bb2016-07-25 17:30:30 -0700967 switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ]
castroflaviocc403a92015-12-15 14:04:19 -0500968
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700969 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700970 l2_intf_group_list = [ ]
971 for port in config[ "port_map" ].keys( ):
972 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700973 if port == port2:
974 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700975 l2_intf_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
976 is_tagged=True, send_barrier=False )
977 l2_intf_group_list.append( l2_intf_gid )
978 Groups.put( l2_intf_gid )
castroflaviocc403a92015-12-15 14:04:19 -0500979
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700980 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700981 add_termination_flow( self.controller, port1, 0x0800, switch_mac, vlan_id )
castroflaviocc403a92015-12-15 14:04:19 -0500982
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700983 # add l3 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700984 mcat_group_msg = add_l3_mcast_group( self.controller, vlan_id, 2, l2_intf_group_list )
985 add_mcast4_routing_flow( self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id )
986 Groups._put( mcat_group_msg.group_id )
castroflaviocc403a92015-12-15 14:04:19 -0500987
Flavio Castroa7162bb2016-07-25 17:30:30 -0700988 parsed_pkt = simple_udp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=vlan_id,
989 eth_dst=dst_mac_str, eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str,
990 ip_dst=dst_ip_str )
991 pkt = str( parsed_pkt )
992 self.dataplane.send( port1, pkt )
993 for port in config[ "port_map" ].keys( ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700994 if port == port2 or port == port1:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700995 verify_no_packet( self, pkt, port )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700996 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700997 verify_packet( self, pkt, port )
998 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700999 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001000 delete_all_flows( self.controller )
1001 delete_groups( self.controller, Groups )
1002 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001003
Flavio Castroa7162bb2016-07-25 17:30:30 -07001004
1005class L3McastToL3( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001006 """ Mcast routing on different vlans"""
Flavio Castro1c9b1252016-02-04 18:42:58 -05001007
Flavio Castroa7162bb2016-07-25 17:30:30 -07001008 def runTest( self ):
Flavio Castro12296312015-12-15 17:48:26 -05001009 """
1010 port1 (vlan 1)-> port 2 (vlan 2)
1011 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001012 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001013 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001014 if len( config[ "port_map" ] ) < 3:
1015 logging.info( "Port count less than 3, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001016 assert (False)
1017 return
Flavio Castro12296312015-12-15 17:48:26 -05001018
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001019 vlan_id = 1
1020 port2_out_vlan = 2
1021 port3_out_vlan = 3
1022 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
Flavio Castroa7162bb2016-07-25 17:30:30 -07001023 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1024 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1025 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
1026 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
1027 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
1028 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001029 src_ip = 0xc0a80101
1030 src_ip_str = "192.168.1.1"
1031 dst_ip = 0xe0010101
1032 dst_ip_str = "224.1.1.1"
Flavio Castro12296312015-12-15 17:48:26 -05001033
Flavio Castroa7162bb2016-07-25 17:30:30 -07001034 port1 = config[ "port_map" ].keys( )[ 0 ]
1035 port2 = config[ "port_map" ].keys( )[ 1 ]
1036 port3 = config[ "port_map" ].keys( )[ 2 ]
Flavio Castro12296312015-12-15 17:48:26 -05001037
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001038 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001039 for port in config[ "port_map" ].keys( ):
1040 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1041 is_tagged=False, send_barrier=False )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001042 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001043 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001044 vlan_id += 1
Flavio Castroa7162bb2016-07-25 17:30:30 -07001045 Groups._put( l2gid )
Flavio Castro12296312015-12-15 17:48:26 -05001046
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001047 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001048 add_termination_flow( self.controller, port1, 0x0800, [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ],
1049 vlan_id )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001050
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001051 # add l3 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001052 port2_ucast_msg = add_l3_interface_group( self.controller, port2, port2_out_vlan, 2,
1053 intf_src_mac )
1054 port3_ucast_msg = add_l3_interface_group( self.controller, port3, port3_out_vlan, 3,
1055 intf_src_mac )
1056 mcat_group_msg = add_l3_mcast_group( self.controller, in_vlan, 2,
1057 [ port2_ucast_msg.group_id, port3_ucast_msg.group_id ] )
1058 add_mcast4_routing_flow( self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id )
1059 Groups._put( port2_ucast_msg.group_id )
1060 Groups._put( port3_ucast_msg.group_id )
1061 Groups._put( mcat_group_msg.group_id )
1062 parsed_pkt = simple_udp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac_str,
1063 eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str, ip_dst=dst_ip_str )
1064 pkt = str( parsed_pkt )
1065 self.dataplane.send( port1, pkt )
1066 parsed_pkt = simple_udp_packet( pktlen=96, eth_dst=dst_mac_str, eth_src=intf_src_mac_str,
1067 ip_ttl=63, ip_src=src_ip_str, ip_dst=dst_ip_str )
1068 pkt = str( parsed_pkt )
1069 verify_packet( self, pkt, port2 )
1070 verify_packet( self, pkt, port3 )
1071 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001072 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001073 delete_all_flows( self.controller )
1074 delete_groups( self.controller, Groups )
1075 delete_all_groups( self.controller )
1076
Flavio Castroa7162bb2016-07-25 17:30:30 -07001077class _MplsFwd( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001078 """ Verify basic MPLS forwarding: Label switch router """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001079
1080 def runTest( self ):
1081 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001082 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001083 if len( config[ "port_map" ] ) < 2:
1084 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001085 return
1086 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001087 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1088 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001089 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001090 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001091 for port in ports:
Charles Chan53cac542016-08-22 16:03:26 -07001092 # Shift MPLS label and VLAN ID by 16 to avoid reserved values
1093 vlan_id = port + 16
1094 mpls_label = port + 16
1095
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001096 # add l2 interface group
1097 id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001098 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Charles Chan53cac542016-08-22 16:03:26 -07001099 dst_mac[ 5 ] = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001100 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1101 vlan_id, id )
1102 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
1103 subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL, index=id, ref_gid=mpls_gid,
Charles Chan53cac542016-08-22 16:03:26 -07001104 push_mpls_header=False, set_mpls_label=mpls_label, set_bos=1 )
Pierf3504f82016-08-19 15:32:53 -07001105 ecmp_gid, ecmp_msg = add_mpls_forwarding_group( self.controller,
1106 subtype=OFDPA_MPLS_GROUP_SUBTYPE_ECMP, index=id, ref_gids=[mpls_label_gid] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001107 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001108 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001109 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001110 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001111 #add_mpls_flow( self.controller, ecmp_gid, port, goto_table=29 )
Charles Chan53cac542016-08-22 16:03:26 -07001112 add_mpls_flow( self.controller, mpls_label_gid, mpls_label, goto_table=29 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001113 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001114 Groups._put( l2_gid )
1115 Groups._put( mpls_gid )
1116 Groups._put( mpls_label_gid )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001117 Groups._put( ecmp_gid )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001118 do_barrier( self.controller )
castroflavio30c6cc52016-01-07 15:19:42 -08001119
Flavio Castroa7162bb2016-07-25 17:30:30 -07001120 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001121 for in_port in ports:
1122 ip_src = '192.168.%02d.1' % (in_port)
1123 for out_port in ports:
1124 if in_port == out_port:
1125 continue
Flavio Castro54947942016-02-03 16:05:20 -05001126
Charles Chan53cac542016-08-22 16:03:26 -07001127 # Shift MPLS label and VLAN ID by 16 to avoid reserved values
1128 out_mpls_label = out_port + 16
1129 in_vlan_vid = in_port + 16
1130 out_vlan_vid = out_port + 16
1131
1132 ip_dst = '192.168.%02d.1' % (out_port)
1133 label = (out_mpls_label, 0, 1, 32)
1134 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_vlan_vid),
Flavio Castroa7162bb2016-07-25 17:30:30 -07001135 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1136 pkt = str( parsed_pkt )
1137 self.dataplane.send( in_port, pkt )
Flavio Castro54947942016-02-03 16:05:20 -05001138
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001139 # build expect packet
1140 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Charles Chan53cac542016-08-22 16:03:26 -07001141 label = (out_mpls_label, 0, 1, 31)
1142 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_vlan_vid),
Flavio Castroa7162bb2016-07-25 17:30:30 -07001143 ip_src=ip_src, ip_dst=ip_dst, eth_src=switch_mac, eth_dst=mac_dst,
1144 label=[ label ] )
1145 pkt = str( exp_pkt )
1146 verify_packet( self, pkt, out_port )
1147 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001148 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001149 delete_all_flows( self.controller )
1150 delete_groups( self.controller, Groups )
1151 delete_all_groups( self.controller )
Flavio Castrob702a2f2016-04-10 22:01:48 -04001152
Flavio Castroa7162bb2016-07-25 17:30:30 -07001153
1154class _MplsTermination( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001155 """ Verify MPLS VPN Termination at penultimate hop """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001156
1157 def runTest( self ):
1158 Groups = Queue.LifoQueue( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001159 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001160 if len( config[ "port_map" ] ) < 2:
1161 logging.info( "Port count less than 2, can't run this case" )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001162 return
1163 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001164 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1165 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castrod80fbc32016-07-25 15:54:26 -07001166 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001167 ports = config[ "port_map" ].keys( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001168 for port in ports:
Charles Chan53cac542016-08-22 16:03:26 -07001169 # Shift MPLS label and VLAN ID by 16 to avoid reserved values
1170 vlan_id = port + 16
1171 mpls_label = port + 16
1172
Flavio Castrod80fbc32016-07-25 15:54:26 -07001173 # add l2 interface group
Charles Chan53cac542016-08-22 16:03:26 -07001174 id, dst_mac[ 5 ] = port, port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001175 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001176 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001177 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1178 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001179 # add L3 ecmp group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001180 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001181 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001182 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001183 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001184 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Charles Chan53cac542016-08-22 16:03:26 -07001185 add_mpls_flow( self.controller, ecmp_msg.group_id, mpls_label )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001186 # add_mpls_flow(self.controller, label=port)
Flavio Castrod80fbc32016-07-25 15:54:26 -07001187 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001188 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
Flavio Castrod80fbc32016-07-25 15:54:26 -07001189 # ecmp_msg.group_id, 1)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001190 Groups._put( l2_gid )
1191 Groups._put( l3_msg.group_id )
1192 Groups._put( ecmp_msg.group_id )
1193 do_barrier( self.controller )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001194
Flavio Castroa7162bb2016-07-25 17:30:30 -07001195 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001196 for in_port in ports:
1197 ip_src = '192.168.%02d.1' % (in_port)
1198 for out_port in ports:
1199 if in_port == out_port:
1200 continue
Charles Chan53cac542016-08-22 16:03:26 -07001201
1202 # Shift MPLS label and VLAN ID by 16 to avoid reserved values
1203 out_mpls_label = out_port + 16
1204 in_vlan_vid = in_port + 16
1205 out_vlan_vid = out_port + 16
1206
Flavio Castrod80fbc32016-07-25 15:54:26 -07001207 ip_dst = '192.168.%02d.1' % (out_port)
Charles Chan53cac542016-08-22 16:03:26 -07001208 label = (out_mpls_label, 0, 1, 32)
1209 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_vlan_vid),
Flavio Castroa7162bb2016-07-25 17:30:30 -07001210 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1211 pkt = str( parsed_pkt )
1212 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001213 # build expect packet
1214 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Charles Chan53cac542016-08-22 16:03:26 -07001215 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_vlan_vid),
Flavio Castroa7162bb2016-07-25 17:30:30 -07001216 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
1217 pkt = str( exp_pkt )
1218 verify_packet( self, pkt, out_port )
1219 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001220 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001221 delete_all_flows( self.controller )
1222 delete_groups( self.controller, Groups )
1223 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001224
Flavio Castroa7162bb2016-07-25 17:30:30 -07001225
1226class _24UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001227 """ Verify /24 IP forwarding to L3 Interface """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001228
Flavio Castroa7162bb2016-07-25 17:30:30 -07001229 def runTest( self ):
1230 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001231 try:
1232 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -07001233 if len( config[ "port_map" ] ) < 2:
1234 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001235 return
Flavio Castroa7162bb2016-07-25 17:30:30 -07001236 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1237 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001238 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001239 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001240 for port in ports:
1241 # add l2 interface group
1242 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -07001243 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1244 is_tagged=True, send_barrier=False )
1245 dst_mac[ 5 ] = vlan_id
1246 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
1247 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001248 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001249 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001250 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001251 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001252 # add unicast routing flow
1253 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001254 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id )
1255 Groups.put( l2gid )
1256 Groups.put( l3_msg.group_id )
1257 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001258
Flavio Castroa7162bb2016-07-25 17:30:30 -07001259 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001260 for in_port in ports:
1261 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1262 ip_src = '192.168.%02d.1' % (test_id + in_port)
1263 for out_port in ports:
1264 if in_port == out_port:
1265 continue
1266 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001267 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1268 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
1269 ip_src=ip_src, ip_dst=ip_dst )
1270 pkt = str( parsed_pkt )
1271 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001272 # build expected packet
1273 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001274 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1275 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
1276 ip_src=ip_src, ip_dst=ip_dst )
1277 pkt = str( exp_pkt )
1278 verify_packet( self, pkt, out_port )
1279 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001280 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001281 delete_all_flows( self.controller )
1282 delete_groups( self.controller, Groups )
1283 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001284
Flavio Castroa7162bb2016-07-25 17:30:30 -07001285
1286class _0Ucast( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001287 """ Verify default gateway IP forwarding to L3 Interface ( /0 rule ) """
Flavio Castro91d1a552016-05-17 16:59:44 -07001288
Flavio Castroa7162bb2016-07-25 17:30:30 -07001289 def runTest( self ):
1290 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001291 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001292 if len( config[ "port_map" ] ) < 2:
1293 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001294 return
Flavio Castro91d1a552016-05-17 16:59:44 -07001295
Flavio Castroa7162bb2016-07-25 17:30:30 -07001296 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1297 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001298 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001299 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001300 for port in ports:
1301 # add l2 interface group
1302 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001303 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id + 1,
1304 is_tagged=True, send_barrier=False )
1305 dst_mac[ 5 ] = vlan_id
1306 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id + 1, id=vlan_id,
1307 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001308 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001309 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001310 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001311 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001312 # add unicast routing flow
1313 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001314 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
1315 Groups.put( l2gid )
1316 Groups.put( l3_msg.group_id )
1317 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001318 dst_ip = 0x0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001319 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0x0, l3_gid )
1320 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001321
Flavio Castroa7162bb2016-07-25 17:30:30 -07001322 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001323 for in_port in ports:
1324 mac_src = '00:00:00:22:22:%02X' % (in_port)
1325 ip_src = '192.168.%02d.1' % (in_port)
1326 for out_port in ports:
1327 if in_port == out_port:
1328 continue
1329 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001330 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
1331 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1332 pkt = str( parsed_pkt )
1333 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001334 # build expected packet
1335 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001336 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port + 1),
1337 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
1338 pkt = str( exp_pkt )
1339 verify_packet( self, pkt, out_port )
1340 verify_no_other_packets( self )
1341 ip_dst = '1.168.%02d.1' % ports[ 0 ]
1342 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1343 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1344 pkt = str( parsed_pkt )
1345 self.dataplane.send( in_port, pkt )
1346 # build expect packet
1347 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1348 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ] + 1,
1349 ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac )
1350 pkt = str( exp_pkt )
1351 verify_packet( self, pkt, ports[ 0 ] )
1352 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001353 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001354 delete_all_flows( self.controller )
1355 delete_groups( self.controller, Groups )
1356 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001357
Flavio Castroa7162bb2016-07-25 17:30:30 -07001358
1359class Unfiltered( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001360 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001361 Attempt to add an unfiltered group: [ATTENTION] this doesn't verify addition
Flavio Castro423df652016-05-17 20:14:08 -04001362 """
Flavio Castro91d1a552016-05-17 16:59:44 -07001363
Flavio Castroa7162bb2016-07-25 17:30:30 -07001364 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001365 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001366 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001367 vlan_id = 1;
1368 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001369 add_l2_unfiltered_group( self.controller, [ port ], False )
1370 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001371 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001372 delete_all_flows( self.controller )
1373 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001374
Flavio Castroa7162bb2016-07-25 17:30:30 -07001375
1376class L3McastToVPN( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001377 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001378 Mcast routing and VPN initiation
Flavio Castro423df652016-05-17 20:14:08 -04001379 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001380
1381 def runTest( self ):
Flavio Castro423df652016-05-17 20:14:08 -04001382 """
1383 port1 (vlan 1)-> port 2 (vlan 2)
1384 """
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001385 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001386 delete_all_flows( self.controller )
1387 delete_all_groups( self.controller )
Flavio Castro423df652016-05-17 20:14:08 -04001388
Flavio Castroa7162bb2016-07-25 17:30:30 -07001389 if len( config[ "port_map" ] ) < 3:
1390 logging.info( "Port count less than 3, can't run this case" )
1391 assert (False)
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001392 return
Flavio Castro423df652016-05-17 20:14:08 -04001393
Flavio Castroa7162bb2016-07-25 17:30:30 -07001394 vlan_id = 1
1395 port2_out_vlan = 2
1396 port3_out_vlan = 3
1397 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
1398 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1399 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1400 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
1401 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
1402 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
1403 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
1404 src_ip = 0xc0a80101
1405 src_ip_str = "192.168.1.1"
1406 dst_ip = 0xe0010101
1407 dst_ip_str = "224.1.1.1"
Flavio Castro423df652016-05-17 20:14:08 -04001408
Flavio Castroa7162bb2016-07-25 17:30:30 -07001409 port1 = config[ "port_map" ].keys( )[ 0 ]
1410 port2 = config[ "port_map" ].keys( )[ 1 ]
1411 # port3=config["port_map"].keys()[2]
Flavio Castro423df652016-05-17 20:14:08 -04001412
Flavio Castroa7162bb2016-07-25 17:30:30 -07001413 # add l2 interface group
1414 for port in config[ "port_map" ].keys( ):
1415 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=False,
1416 send_barrier=False )
1417 # add vlan flow table
1418 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1419 vlan_id += 1
Flavio Castro423df652016-05-17 20:14:08 -04001420
Flavio Castroa7162bb2016-07-25 17:30:30 -07001421 # add termination flow
1422 add_termination_flow( self.controller, port1, 0x0800, [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ],
1423 vlan_id )
Flavio Castro423df652016-05-17 20:14:08 -04001424
Flavio Castroa7162bb2016-07-25 17:30:30 -07001425 # add MPLS interface group
1426 l2_gid = encode_l2_interface_group_id( port2_out_vlan, port2 )
1427 mpls_gid2, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1428 port2_out_vlan, port2 )
1429 # l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
1430 # mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
1431 # add L3VPN groups
1432 mpls_label_gid2, mpls_label_msg = add_mpls_label_group( self.controller,
1433 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=(0x20000 + port2), ref_gid=mpls_gid2,
1434 push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True )
1435 # 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 -07001436 # 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 -04001437
Flavio Castroa7162bb2016-07-25 17:30:30 -07001438 mcat_group_msg = add_l3_mcast_group( self.controller, in_vlan, 2, [ mpls_label_gid2 ] )
1439 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 -04001440
Flavio Castroa7162bb2016-07-25 17:30:30 -07001441 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac_str,
1442 eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str, ip_dst=dst_ip_str )
1443 pkt = str( parsed_pkt )
1444 self.dataplane.send( port1, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001445 label = (12, 0, 1, 63)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001446 exp_pkt = mpls_packet( pktlen=100, eth_dst=dst_mac_str, eth_src=intf_src_mac_str, ip_ttl=64,
1447 ip_src=src_ip_str, label=[ label ], ip_dst=dst_ip_str )
1448 pkt = str( exp_pkt )
1449 verify_packet( self, pkt, port2 )
1450 # verify_packet(self, pkt, port3)
1451 verify_no_other_packets( self )
1452 delete_all_groups( 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 Castro8c37e1c2016-07-19 18:26:33 -07001456
Flavio Castro423df652016-05-17 20:14:08 -04001457
Flavio Castroa7162bb2016-07-25 17:30:30 -07001458class PacketInSrcMacMiss( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001459 """
1460 Test packet in function on a src-mac miss
1461 Send a packet to each dataplane port and verify that a packet
1462 in message is received from the controller for each
1463 #todo verify you stop receiving after adding rule
1464 """
1465
Flavio Castroa7162bb2016-07-25 17:30:30 -07001466 def runTest( self ):
1467 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001468 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001469 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro423df652016-05-17 20:14:08 -04001470
Flavio Castroa7162bb2016-07-25 17:30:30 -07001471 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001472 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001473 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, 1, True, False )
1474 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1475 Groups.put( L2gid )
1476 parsed_vlan_pkt = simple_tcp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
1477 vlan_pkt = str( parsed_vlan_pkt )
1478 for of_port in config[ "port_map" ].keys( ):
1479 logging.info( "PacketInMiss test, port %d", of_port )
1480 self.dataplane.send( of_port, vlan_pkt )
1481 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH )
1482 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001483 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001484 delete_all_flows( self.controller )
1485 delete_all_groups( self.controller )
1486
1487
1488class EcmpGroupMod( base_tests.SimpleDataPlane ):
1489 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001490 Verify referenced group can be modified adding or removing buckets
1491 Attention the hashing behavior may vary according to your porting assigment
1492 Current values are hardcoded for our topology
Flavio Castroa7162bb2016-07-25 17:30:30 -07001493 """
1494
1495 def runTest( self ):
1496 Groups = Queue.LifoQueue( )
1497 try:
1498 if len( config[ "port_map" ] ) < 2:
1499 logging.info( "Port count less than 2, can't run this case" )
1500 return
1501
1502 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1503 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
1504 dip = 0xc0a80001
1505 # Hashes Test Name and uses it as id for installing unique groups
1506 ports = config[ "port_map" ].keys( )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001507 ecmp = [ ]
Flavio Castroa7162bb2016-07-25 17:30:30 -07001508 for port in ports:
1509 vlan_id = port
1510 id = port
1511 # add l2 interface group
1512 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1513 is_tagged=True, send_barrier=False )
1514 dst_mac[ 5 ] = vlan_id
1515 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1516 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001517 ecmp += [ l3_msg.group_id ]
Flavio Castroa7162bb2016-07-25 17:30:30 -07001518 Groups._put( l2_gid )
1519 Groups._put( l3_msg.group_id )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001520 ecmp_msg = add_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_msg.group_id ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001521 # add vlan flow table
1522 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1523 # add termination flow
1524 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
1525 # add unicast routing flow
1526 dst_ip = dip + (vlan_id << 8)
1527 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
1528 Groups._put( ecmp_msg.group_id )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001529 mod_l3_ecmp_group( self.controller, ports[ 0 ], ecmp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001530
1531 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001532 parsed_pkt = exp_pkt = 0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001533 for out_port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001534 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1535 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1536 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1537 tcp = out_port if out_port == 24 else 25
1538 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1539 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1540 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001541 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001542 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001543 # build expected packet
1544 mac_dst = '00:00:00:22:22:%02X' % out_port
1545 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castro9debaaa2016-07-26 19:37:50 -07001546 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst,
1547 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001548 pkt = str( exp_pkt )
1549 verify_packet( self, pkt, out_port )
1550 verify_no_other_packets( self )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001551 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
1552 mod_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_gid ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001553 for port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001554 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1555 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1556 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1557 tcp = port if port == 24 else 25
1558 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1559 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1560 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001561 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001562 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001563 # build expected packet
Flavio Castro9debaaa2016-07-26 19:37:50 -07001564 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1565 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1566 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst,
1567 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001568 pkt = str( exp_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001569 verify_packet( self, pkt, ports[ 0 ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001570 verify_no_other_packets( self )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001571 mod_l3_ecmp_group( self.controller, ports[ 0 ], [ ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001572 for port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001573 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1574 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1575 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1576 tcp = port if port == 24 else 25
1577 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1578 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1579 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001580 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001581 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001582 verify_no_other_packets( self )
1583 finally:
1584 delete_all_flows( self.controller )
1585 delete_groups( self.controller, Groups )
1586 delete_all_groups( self.controller )
Pier8b223022016-08-19 22:47:49 -07001587
1588class Untagged( base_tests.SimpleDataPlane ):
1589 """
1590 Verify VLAN filtering table does not require OFPVID_PRESENT bit to be 0.
1591 This should be fixed in OFDPA 2.0 GA and above, the test fails with
1592 previous versions of the OFDPA.
1593
1594 Two rules are necessary in VLAN table (10):
1595 1) Assignment: match 0x0000/(no mask), set_vlan_vid 0x100A, goto 20
1596 2) Filtering: match 0x100A/0x1FFF, goto 20
1597
1598 In this test case vlan_id = (MAX_INTERNAL_VLAN - port_no).
1599 The remaining part of the test is based on the use of the bridging table
1600 """
1601
1602 MAX_INTERNAL_VLAN = 4094
1603
1604 def runTest( self ):
1605 groups = Queue.LifoQueue( )
1606 try:
1607 if len( config[ "port_map" ] ) < 2:
1608 logging.info( "Port count less than 2, can't run this case" )
1609 return
1610
1611 ports = sorted( config[ "port_map" ].keys( ) )
1612 for port in ports:
1613 vlan_id = Untagged.MAX_INTERNAL_VLAN - port
1614 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1615 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_UNTAG )
1616 for other_port in ports:
1617 if other_port == port:
1618 continue
1619 L2gid, l2msg = add_one_l2_interface_group( self.controller, other_port, vlan_id, False, False )
1620 groups.put( L2gid )
1621 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, other_port ], vlan_id, L2gid, True )
1622
1623 do_barrier( self.controller )
1624
1625 for out_port in ports:
1626 # change dest based on port number
1627 mac_dst = '00:12:34:56:78:%02X' % out_port
1628 for in_port in ports:
1629 if in_port == out_port:
1630 continue
1631 pkt = str( simple_tcp_packet( eth_dst=mac_dst ) )
1632 self.dataplane.send( in_port, pkt )
1633 for ofport in ports:
1634 if ofport in [ out_port ]:
1635 verify_packet( self, pkt, ofport )
1636 else:
1637 verify_no_packet( self, pkt, ofport )
1638 verify_no_other_packets( self )
1639 finally:
1640 delete_all_flows( self.controller )
1641 delete_groups( self.controller, Groups )
1642 delete_all_groups( self.controller )
1643