blob: 96bec1ebbaa034bb0e5f16c8c97908865a21cc18 [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:
1092 # add l2 interface group
1093 id = port
1094 vlan_id = id
Flavio Castroa7162bb2016-07-25 17:30:30 -07001095 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
1096 dst_mac[ 5 ] = vlan_id
1097 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1098 vlan_id, id )
1099 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
1100 subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL, index=id, ref_gid=mpls_gid,
1101 push_mpls_header=False, set_mpls_label=port, set_bos=1 )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001102 #ecmp_gid, ecmp_msg = add_mpls_forwarding_group( self.controller,
1103 # subtype=OFDPA_MPLS_GROUP_SUBTYPE_ECMP, index=id, ref_gids=[mpls_label_gid] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001104 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001105 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001106 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001107 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001108 #add_mpls_flow( self.controller, ecmp_gid, port, goto_table=29 )
1109 add_mpls_flow( self.controller, mpls_label_gid, port, goto_table=29 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001110 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001111 Groups._put( l2_gid )
1112 Groups._put( mpls_gid )
1113 Groups._put( mpls_label_gid )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001114 Groups._put( ecmp_gid )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001115 do_barrier( self.controller )
castroflavio30c6cc52016-01-07 15:19:42 -08001116
Flavio Castroa7162bb2016-07-25 17:30:30 -07001117 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001118 for in_port in ports:
1119 ip_src = '192.168.%02d.1' % (in_port)
1120 for out_port in ports:
1121 if in_port == out_port:
1122 continue
1123 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castro54947942016-02-03 16:05:20 -05001124
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001125 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001126 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port),
1127 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1128 pkt = str( parsed_pkt )
1129 self.dataplane.send( in_port, pkt )
Flavio Castro54947942016-02-03 16:05:20 -05001130
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001131 # build expect packet
1132 mac_dst = '00:00:00:22:22:%02X' % (out_port)
1133 label = (out_port, 0, 1, 31)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001134 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port),
1135 ip_src=ip_src, ip_dst=ip_dst, eth_src=switch_mac, eth_dst=mac_dst,
1136 label=[ label ] )
1137 pkt = str( exp_pkt )
1138 verify_packet( self, pkt, out_port )
1139 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001140 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001141 delete_all_flows( self.controller )
1142 delete_groups( self.controller, Groups )
1143 delete_all_groups( self.controller )
Flavio Castrob702a2f2016-04-10 22:01:48 -04001144
Flavio Castroa7162bb2016-07-25 17:30:30 -07001145
1146class _MplsTermination( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001147 """ Verify MPLS VPN Termination at penultimate hop """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001148
1149 def runTest( self ):
1150 Groups = Queue.LifoQueue( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001151 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001152 if len( config[ "port_map" ] ) < 2:
1153 logging.info( "Port count less than 2, can't run this case" )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001154 return
1155 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001156 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1157 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castrod80fbc32016-07-25 15:54:26 -07001158 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001159 ports = config[ "port_map" ].keys( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001160 for port in ports:
1161 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001162 vlan_id, id, dst_mac[ 5 ] = port, port, port
1163 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001164 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001165 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1166 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001167 # add L3 ecmp group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001168 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001169 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001170 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001171 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001172 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
1173 add_mpls_flow( self.controller, ecmp_msg.group_id, port )
1174 # add_mpls_flow(self.controller, label=port)
Flavio Castrod80fbc32016-07-25 15:54:26 -07001175 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001176 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
Flavio Castrod80fbc32016-07-25 15:54:26 -07001177 # ecmp_msg.group_id, 1)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001178 Groups._put( l2_gid )
1179 Groups._put( l3_msg.group_id )
1180 Groups._put( ecmp_msg.group_id )
1181 do_barrier( self.controller )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001182
Flavio Castroa7162bb2016-07-25 17:30:30 -07001183 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001184 for in_port in ports:
1185 ip_src = '192.168.%02d.1' % (in_port)
1186 for out_port in ports:
1187 if in_port == out_port:
1188 continue
1189 ip_dst = '192.168.%02d.1' % (out_port)
1190 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001191 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port),
1192 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1193 pkt = str( parsed_pkt )
1194 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001195 # build expect packet
1196 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001197 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port),
1198 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
1199 pkt = str( exp_pkt )
1200 verify_packet( self, pkt, out_port )
1201 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001202 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001203 delete_all_flows( self.controller )
1204 delete_groups( self.controller, Groups )
1205 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001206
Flavio Castroa7162bb2016-07-25 17:30:30 -07001207
1208class _24UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001209 """ Verify /24 IP forwarding to L3 Interface """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001210
Flavio Castroa7162bb2016-07-25 17:30:30 -07001211 def runTest( self ):
1212 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001213 try:
1214 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -07001215 if len( config[ "port_map" ] ) < 2:
1216 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001217 return
Flavio Castroa7162bb2016-07-25 17:30:30 -07001218 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1219 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001220 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001221 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001222 for port in ports:
1223 # add l2 interface group
1224 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -07001225 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1226 is_tagged=True, send_barrier=False )
1227 dst_mac[ 5 ] = vlan_id
1228 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
1229 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001230 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001231 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001232 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001233 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001234 # add unicast routing flow
1235 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001236 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id )
1237 Groups.put( l2gid )
1238 Groups.put( l3_msg.group_id )
1239 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001240
Flavio Castroa7162bb2016-07-25 17:30:30 -07001241 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001242 for in_port in ports:
1243 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1244 ip_src = '192.168.%02d.1' % (test_id + in_port)
1245 for out_port in ports:
1246 if in_port == out_port:
1247 continue
1248 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001249 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1250 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
1251 ip_src=ip_src, ip_dst=ip_dst )
1252 pkt = str( parsed_pkt )
1253 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001254 # build expected packet
1255 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001256 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1257 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
1258 ip_src=ip_src, ip_dst=ip_dst )
1259 pkt = str( exp_pkt )
1260 verify_packet( self, pkt, out_port )
1261 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001262 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001263 delete_all_flows( self.controller )
1264 delete_groups( self.controller, Groups )
1265 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001266
Flavio Castroa7162bb2016-07-25 17:30:30 -07001267
1268class _0Ucast( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001269 """ Verify default gateway IP forwarding to L3 Interface ( /0 rule ) """
Flavio Castro91d1a552016-05-17 16:59:44 -07001270
Flavio Castroa7162bb2016-07-25 17:30:30 -07001271 def runTest( self ):
1272 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001273 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001274 if len( config[ "port_map" ] ) < 2:
1275 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001276 return
Flavio Castro91d1a552016-05-17 16:59:44 -07001277
Flavio Castroa7162bb2016-07-25 17:30:30 -07001278 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1279 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001280 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001281 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001282 for port in ports:
1283 # add l2 interface group
1284 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001285 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id + 1,
1286 is_tagged=True, send_barrier=False )
1287 dst_mac[ 5 ] = vlan_id
1288 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id + 1, id=vlan_id,
1289 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001290 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001291 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001292 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001293 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001294 # add unicast routing flow
1295 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001296 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
1297 Groups.put( l2gid )
1298 Groups.put( l3_msg.group_id )
1299 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001300 dst_ip = 0x0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001301 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0x0, l3_gid )
1302 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001303
Flavio Castroa7162bb2016-07-25 17:30:30 -07001304 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001305 for in_port in ports:
1306 mac_src = '00:00:00:22:22:%02X' % (in_port)
1307 ip_src = '192.168.%02d.1' % (in_port)
1308 for out_port in ports:
1309 if in_port == out_port:
1310 continue
1311 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001312 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
1313 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1314 pkt = str( parsed_pkt )
1315 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001316 # build expected packet
1317 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001318 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port + 1),
1319 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
1320 pkt = str( exp_pkt )
1321 verify_packet( self, pkt, out_port )
1322 verify_no_other_packets( self )
1323 ip_dst = '1.168.%02d.1' % ports[ 0 ]
1324 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1325 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1326 pkt = str( parsed_pkt )
1327 self.dataplane.send( in_port, pkt )
1328 # build expect packet
1329 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1330 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ] + 1,
1331 ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac )
1332 pkt = str( exp_pkt )
1333 verify_packet( self, pkt, ports[ 0 ] )
1334 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001335 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001336 delete_all_flows( self.controller )
1337 delete_groups( self.controller, Groups )
1338 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001339
Flavio Castroa7162bb2016-07-25 17:30:30 -07001340
1341class Unfiltered( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001342 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001343 Attempt to add an unfiltered group: [ATTENTION] this doesn't verify addition
Flavio Castro423df652016-05-17 20:14:08 -04001344 """
Flavio Castro91d1a552016-05-17 16:59:44 -07001345
Flavio Castroa7162bb2016-07-25 17:30:30 -07001346 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001347 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001348 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001349 vlan_id = 1;
1350 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001351 add_l2_unfiltered_group( self.controller, [ port ], False )
1352 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001353 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001354 delete_all_flows( self.controller )
1355 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001356
Flavio Castroa7162bb2016-07-25 17:30:30 -07001357
1358class L3McastToVPN( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001359 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001360 Mcast routing and VPN initiation
Flavio Castro423df652016-05-17 20:14:08 -04001361 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001362
1363 def runTest( self ):
Flavio Castro423df652016-05-17 20:14:08 -04001364 """
1365 port1 (vlan 1)-> port 2 (vlan 2)
1366 """
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001367 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001368 delete_all_flows( self.controller )
1369 delete_all_groups( self.controller )
Flavio Castro423df652016-05-17 20:14:08 -04001370
Flavio Castroa7162bb2016-07-25 17:30:30 -07001371 if len( config[ "port_map" ] ) < 3:
1372 logging.info( "Port count less than 3, can't run this case" )
1373 assert (False)
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001374 return
Flavio Castro423df652016-05-17 20:14:08 -04001375
Flavio Castroa7162bb2016-07-25 17:30:30 -07001376 vlan_id = 1
1377 port2_out_vlan = 2
1378 port3_out_vlan = 3
1379 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
1380 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1381 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1382 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
1383 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
1384 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
1385 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
1386 src_ip = 0xc0a80101
1387 src_ip_str = "192.168.1.1"
1388 dst_ip = 0xe0010101
1389 dst_ip_str = "224.1.1.1"
Flavio Castro423df652016-05-17 20:14:08 -04001390
Flavio Castroa7162bb2016-07-25 17:30:30 -07001391 port1 = config[ "port_map" ].keys( )[ 0 ]
1392 port2 = config[ "port_map" ].keys( )[ 1 ]
1393 # port3=config["port_map"].keys()[2]
Flavio Castro423df652016-05-17 20:14:08 -04001394
Flavio Castroa7162bb2016-07-25 17:30:30 -07001395 # add l2 interface group
1396 for port in config[ "port_map" ].keys( ):
1397 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=False,
1398 send_barrier=False )
1399 # add vlan flow table
1400 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1401 vlan_id += 1
Flavio Castro423df652016-05-17 20:14:08 -04001402
Flavio Castroa7162bb2016-07-25 17:30:30 -07001403 # add termination flow
1404 add_termination_flow( self.controller, port1, 0x0800, [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ],
1405 vlan_id )
Flavio Castro423df652016-05-17 20:14:08 -04001406
Flavio Castroa7162bb2016-07-25 17:30:30 -07001407 # add MPLS interface group
1408 l2_gid = encode_l2_interface_group_id( port2_out_vlan, port2 )
1409 mpls_gid2, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1410 port2_out_vlan, port2 )
1411 # l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
1412 # mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
1413 # add L3VPN groups
1414 mpls_label_gid2, mpls_label_msg = add_mpls_label_group( self.controller,
1415 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=(0x20000 + port2), ref_gid=mpls_gid2,
1416 push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True )
1417 # 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 -07001418 # 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 -04001419
Flavio Castroa7162bb2016-07-25 17:30:30 -07001420 mcat_group_msg = add_l3_mcast_group( self.controller, in_vlan, 2, [ mpls_label_gid2 ] )
1421 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 -04001422
Flavio Castroa7162bb2016-07-25 17:30:30 -07001423 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac_str,
1424 eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str, ip_dst=dst_ip_str )
1425 pkt = str( parsed_pkt )
1426 self.dataplane.send( port1, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001427 label = (12, 0, 1, 63)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001428 exp_pkt = mpls_packet( pktlen=100, eth_dst=dst_mac_str, eth_src=intf_src_mac_str, ip_ttl=64,
1429 ip_src=src_ip_str, label=[ label ], ip_dst=dst_ip_str )
1430 pkt = str( exp_pkt )
1431 verify_packet( self, pkt, port2 )
1432 # verify_packet(self, pkt, port3)
1433 verify_no_other_packets( self )
1434 delete_all_groups( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001435 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001436 delete_all_flows( self.controller )
1437 delete_all_groups( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001438
Flavio Castro423df652016-05-17 20:14:08 -04001439
Flavio Castroa7162bb2016-07-25 17:30:30 -07001440class PacketInSrcMacMiss( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001441 """
1442 Test packet in function on a src-mac miss
1443 Send a packet to each dataplane port and verify that a packet
1444 in message is received from the controller for each
1445 #todo verify you stop receiving after adding rule
1446 """
1447
Flavio Castroa7162bb2016-07-25 17:30:30 -07001448 def runTest( self ):
1449 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001450 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001451 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro423df652016-05-17 20:14:08 -04001452
Flavio Castroa7162bb2016-07-25 17:30:30 -07001453 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001454 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001455 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, 1, True, False )
1456 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1457 Groups.put( L2gid )
1458 parsed_vlan_pkt = simple_tcp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
1459 vlan_pkt = str( parsed_vlan_pkt )
1460 for of_port in config[ "port_map" ].keys( ):
1461 logging.info( "PacketInMiss test, port %d", of_port )
1462 self.dataplane.send( of_port, vlan_pkt )
1463 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH )
1464 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001465 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001466 delete_all_flows( self.controller )
1467 delete_all_groups( self.controller )
1468
1469
1470class EcmpGroupMod( base_tests.SimpleDataPlane ):
1471 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001472 Verify referenced group can be modified adding or removing buckets
1473 Attention the hashing behavior may vary according to your porting assigment
1474 Current values are hardcoded for our topology
Flavio Castroa7162bb2016-07-25 17:30:30 -07001475 """
1476
1477 def runTest( self ):
1478 Groups = Queue.LifoQueue( )
1479 try:
1480 if len( config[ "port_map" ] ) < 2:
1481 logging.info( "Port count less than 2, can't run this case" )
1482 return
1483
1484 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1485 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
1486 dip = 0xc0a80001
1487 # Hashes Test Name and uses it as id for installing unique groups
1488 ports = config[ "port_map" ].keys( )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001489 ecmp = [ ]
Flavio Castroa7162bb2016-07-25 17:30:30 -07001490 for port in ports:
1491 vlan_id = port
1492 id = port
1493 # add l2 interface group
1494 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1495 is_tagged=True, send_barrier=False )
1496 dst_mac[ 5 ] = vlan_id
1497 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1498 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001499 ecmp += [ l3_msg.group_id ]
Flavio Castroa7162bb2016-07-25 17:30:30 -07001500 Groups._put( l2_gid )
1501 Groups._put( l3_msg.group_id )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001502 ecmp_msg = add_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_msg.group_id ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001503 # add vlan flow table
1504 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1505 # add termination flow
1506 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
1507 # add unicast routing flow
1508 dst_ip = dip + (vlan_id << 8)
1509 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
1510 Groups._put( ecmp_msg.group_id )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001511 mod_l3_ecmp_group( self.controller, ports[ 0 ], ecmp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001512
1513 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001514 parsed_pkt = exp_pkt = 0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001515 for out_port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001516 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1517 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1518 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1519 tcp = out_port if out_port == 24 else 25
1520 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1521 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1522 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001523 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001524 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001525 # build expected packet
1526 mac_dst = '00:00:00:22:22:%02X' % out_port
1527 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castro9debaaa2016-07-26 19:37:50 -07001528 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst,
1529 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001530 pkt = str( exp_pkt )
1531 verify_packet( self, pkt, out_port )
1532 verify_no_other_packets( self )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001533 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
1534 mod_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_gid ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001535 for port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001536 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1537 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1538 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1539 tcp = port if port == 24 else 25
1540 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1541 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1542 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001543 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001544 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001545 # build expected packet
Flavio Castro9debaaa2016-07-26 19:37:50 -07001546 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1547 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1548 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst,
1549 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001550 pkt = str( exp_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001551 verify_packet( self, pkt, ports[ 0 ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001552 verify_no_other_packets( self )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001553 mod_l3_ecmp_group( self.controller, ports[ 0 ], [ ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001554 for port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001555 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1556 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1557 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1558 tcp = port if port == 24 else 25
1559 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1560 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1561 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001562 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001563 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001564 verify_no_other_packets( self )
1565 finally:
1566 delete_all_flows( self.controller )
1567 delete_groups( self.controller, Groups )
1568 delete_all_groups( self.controller )