blob: 675b2849fe79b4f88a78ffb317336e20624c6cc7 [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 *
Pierbbdf3782016-08-22 17:58:26 -070013from utils import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050014
Flavio Castro1c9b1252016-02-04 18:42:58 -050015
Flavio Castroa7162bb2016-07-25 17:30:30 -070016class PacketInUDP( base_tests.SimpleDataPlane ):
Flavio Castro6d498522015-12-15 14:05:04 -050017 """
Flavio Castro76c5b262016-07-27 19:53:00 -070018 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 -050019 """
20
Flavio Castroa7162bb2016-07-25 17:30:30 -070021 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -070022 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -070023 parsed_vlan_pkt = simple_udp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
24 vlan_pkt = str( parsed_vlan_pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -070025 # create match
Flavio Castroa7162bb2016-07-25 17:30:30 -070026 match = ofp.match( )
27 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
28 match.oxm_list.append( ofp.oxm.ip_proto( 2 ) )
29 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
30 ofp.instruction.apply_actions( actions=[
31 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
32 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
33 logging.info( "Inserting packet in flow to controller" )
34 self.controller.message_send( request )
Flavio Castro1c9b1252016-02-04 18:42:58 -050035
Flavio Castroa7162bb2016-07-25 17:30:30 -070036 for of_port in config[ "port_map" ].keys( ):
37 logging.info( "PacketInMiss test, port %d", of_port )
38 self.dataplane.send( of_port, vlan_pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -050039
Flavio Castroa7162bb2016-07-25 17:30:30 -070040 verify_no_packet_in( self, vlan_pkt, of_port )
41 delete_all_flows( self.controller )
42 do_barrier( self.controller )
Flavio Castro6d498522015-12-15 14:05:04 -050043
Flavio Castroa7162bb2016-07-25 17:30:30 -070044 match = ofp.match( )
45 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
46 match.oxm_list.append( ofp.oxm.ip_proto( 17 ) )
47 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
48 ofp.instruction.apply_actions( actions=[
49 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
50 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
51 logging.info( "Inserting packet in flow to controller" )
52 self.controller.message_send( request )
53 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -050054
Flavio Castroa7162bb2016-07-25 17:30:30 -070055 for of_port in config[ "port_map" ].keys( ):
56 logging.info( "PacketInMiss test, port %d", of_port )
57 self.dataplane.send( of_port, vlan_pkt )
Flavio Castro6d498522015-12-15 14:05:04 -050058
Flavio Castroa7162bb2016-07-25 17:30:30 -070059 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_ACTION )
Flavio Castro6d498522015-12-15 14:05:04 -050060
Flavio Castroa7162bb2016-07-25 17:30:30 -070061 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -070062 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -070063 delete_all_flows( self.controller )
64 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -050065
Flavio Castroaf2b4502016-02-02 17:41:32 -050066
Flavio Castro67d8bd52016-02-03 14:22:14 -050067@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -070068class ArpNL2( base_tests.SimpleDataPlane ):
69 def runTest( self ):
70 delete_all_flows( self.controller )
71 delete_all_groups( self.controller )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050072
Flavio Castroa7162bb2016-07-25 17:30:30 -070073 ports = sorted( config[ "port_map" ].keys( ) )
74 match = ofp.match( )
75 match.oxm_list.append( ofp.oxm.eth_type( 0x0806 ) )
76 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
77 ofp.instruction.apply_actions( actions=[
78 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
79 buffer_id=ofp.OFP_NO_BUFFER, priority=40000 )
80 self.controller.message_send( request )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050081 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -070082 add_one_l2_interface_group( self.controller, port, 1, False, False )
83 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_BOTH )
84 group_id = encode_l2_interface_group_id( 1, port )
85 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], 1, group_id, True )
86 do_barrier( self.controller )
87 parsed_arp_pkt = simple_arp_packet( )
88 arp_pkt = str( parsed_arp_pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050089
90 for out_port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -070091 self.dataplane.send( out_port, arp_pkt )
92 verify_packet_in( self, arp_pkt, out_port, ofp.OFPR_ACTION )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050093 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -050094 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -050095 for in_port in ports:
96 if in_port == out_port:
97 continue
98 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -050099 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700100 parsed_pkt = simple_tcp_packet( eth_dst=mac_dst, eth_src=mac_src )
101 pkt = str( parsed_pkt )
102 self.dataplane.send( in_port, pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500103
104 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700105 if ofport in [ out_port ]:
106 verify_packet( self, pkt, ofport )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500107 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700108 verify_no_packet( self, pkt, ofport )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500109
Flavio Castroa7162bb2016-07-25 17:30:30 -0700110 verify_no_other_packets( self )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500111
Flavio Castroa7162bb2016-07-25 17:30:30 -0700112class PacketInArp( base_tests.SimpleDataPlane ):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500113 """
Flavio Castro76c5b262016-07-27 19:53:00 -0700114 Verify Packet-in message from eth_type 0x806 on ACL table
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500115 """
116
Flavio Castroa7162bb2016-07-25 17:30:30 -0700117 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700118 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700119 parsed_arp_pkt = simple_arp_packet( )
120 arp_pkt = str( parsed_arp_pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700121 # create match
Flavio Castroa7162bb2016-07-25 17:30:30 -0700122 match = ofp.match( )
123 match.oxm_list.append( ofp.oxm.eth_type( 0x0806 ) )
124 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
125 ofp.instruction.apply_actions( actions=[
126 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
127 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500128
Flavio Castroa7162bb2016-07-25 17:30:30 -0700129 logging.info( "Inserting packet in flow to controller" )
130 self.controller.message_send( request )
131 do_barrier( self.controller )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500132
Flavio Castroa7162bb2016-07-25 17:30:30 -0700133 for of_port in config[ "port_map" ].keys( ):
134 logging.info( "PacketInMiss test, port %d", of_port )
135 self.dataplane.send( of_port, arp_pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500136
Flavio Castroa7162bb2016-07-25 17:30:30 -0700137 verify_packet_in( self, arp_pkt, of_port, ofp.OFPR_ACTION )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500138
Flavio Castroa7162bb2016-07-25 17:30:30 -0700139 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700140 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700141 delete_all_flows( self.controller )
142 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500143
Flavio Castroa7162bb2016-07-25 17:30:30 -0700144
145class PacketInIPTable( base_tests.SimpleDataPlane ):
Flavio Castro91d1a552016-05-17 16:59:44 -0700146 """
Flavio Castro76c5b262016-07-27 19:53:00 -0700147 Verify Packet-in message from IP table when controller action is used
Flavio Castro91d1a552016-05-17 16:59:44 -0700148 Send a packet to each dataplane port and verify that a packet
149 in message is received from the controller for each
150 #todo verify you stop receiving after adding rule
151 """
152
Flavio Castroa7162bb2016-07-25 17:30:30 -0700153 def runTest( self ):
154 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700155 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700156 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
157 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
158 dip = 0xc0a80001
159 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro91d1a552016-05-17 16:59:44 -0700160
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700161 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700162 # add l2 interface group
163 vlan_id = port
164 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=True,
165 send_barrier=False )
166 dst_mac[ 5 ] = vlan_id
167 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
168 src_mac=intf_src_mac, dst_mac=dst_mac )
169 # add vlan flow table
170 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
171 # add termination flow
172 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
173 # add unicast routing flow
174 dst_ip = dip + (vlan_id << 8)
175 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id,
176 send_ctrl=True )
177 Groups.put( l3_msg.group_id )
Flavio Castro91d1a552016-05-17 16:59:44 -0700178
Flavio Castroa7162bb2016-07-25 17:30:30 -0700179 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -0700180
Flavio Castroa7162bb2016-07-25 17:30:30 -0700181 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700182 for in_port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700183 mac_src = '00:00:00:22:22:%02X' % in_port
184 ip_src = '192.168.%02d.1' % in_port
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700185 for out_port in ports:
186 if in_port == out_port:
187 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700188 ip_dst = '192.168.%02d.1' % out_port
189 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
190 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
191 pkt = str( parsed_pkt )
192 self.dataplane.send( in_port, pkt )
193 verify_packet_in( self, pkt, in_port, ofp.OFPR_ACTION )
194 # verify_no_other_packets(self)
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700195 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700196 delete_all_flows( self.controller )
197 delete_groups( self.controller, Groups )
198 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -0700199
Flavio Castroa7162bb2016-07-25 17:30:30 -0700200
201class L2FloodQinQ( base_tests.SimpleDataPlane ):
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500202 """
Flavio Castro76c5b262016-07-27 19:53:00 -0700203 Verify Vlan based flooding of QinQ based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500204 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500205
Flavio Castroa7162bb2016-07-25 17:30:30 -0700206 def runTest( self ):
207 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700208 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700209 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700210 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500211
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700212 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700213 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
214 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
215 Groups.put( L2gid )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500216
Flavio Castroa7162bb2016-07-25 17:30:30 -0700217 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
218 Groups.put( msg.group_id )
219 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
220 do_barrier( self.controller )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500221
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700222 # verify flood
223 for ofport in ports:
224 # change dest based on port number
225 mac_src = '00:12:34:56:78:%02X' % ofport
Flavio Castroa7162bb2016-07-25 17:30:30 -0700226 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
227 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10,
228 eth_dst='00:12:34:56:78:9a', eth_src=mac_src )
229 pkt = str( parsed_pkt )
230 self.dataplane.send( ofport, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700231 # self won't rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700232 verify_no_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700233 # others will rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700234 tmp_ports = list( ports )
235 tmp_ports.remove( ofport )
236 verify_packets( self, pkt, tmp_ports )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500237
Flavio Castroa7162bb2016-07-25 17:30:30 -0700238 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700239 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700240 delete_all_flows( self.controller )
241 delete_groups( self.controller, Groups )
242 delete_all_groups( self.controller )
243
Flavio Castro1c9b1252016-02-04 18:42:58 -0500244
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500245@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -0700246class L2FloodTagged( base_tests.SimpleDataPlane ):
Flavio Castro184cefe2015-11-19 20:52:49 -0500247 """
248 Test L2 flood to a vlan
249 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
Flavio Castro184cefe2015-11-19 20:52:49 -0500250 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500251
Flavio Castroa7162bb2016-07-25 17:30:30 -0700252 def runTest( self ):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500253 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700254 vlan_id = abs( hash( inspect.stack( )[ 0 ][ 3 ] ) ) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500255 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500256
Flavio Castroa7162bb2016-07-25 17:30:30 -0700257 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro34352e72015-12-07 20:01:51 -0500258
Flavio Castroa7162bb2016-07-25 17:30:30 -0700259 delete_all_flows( self.controller )
260 delete_all_groups( self.controller )
Flavio Castro184cefe2015-11-19 20:52:49 -0500261
Flavio Castro184cefe2015-11-19 20:52:49 -0500262 # Installing flows to avoid packet-in
263 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700264 add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
265 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
266 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
267 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
268 do_barrier( self.controller )
Flavio Castro184cefe2015-11-19 20:52:49 -0500269
Flavio Castro1c9b1252016-02-04 18:42:58 -0500270 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500271 for ofport in ports:
272 # change dest based on port number
Flavio Castroa7162bb2016-07-25 17:30:30 -0700273 pkt = str(
274 simple_tcp_packet( dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst='00:12:34:56:78:9a' ) )
275 self.dataplane.send( ofport, pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500276 # self won't rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700277 verify_no_packet( self, pkt, ofport )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500278 # others will rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700279 tmp_ports = list( ports )
280 tmp_ports.remove( ofport )
281 verify_packets( self, pkt, tmp_ports )
282 verify_no_other_packets( self )
Flavio Castroaabb5792015-11-18 19:03:50 -0500283
Flavio Castro1c9b1252016-02-04 18:42:58 -0500284
Flavio Castroa7162bb2016-07-25 17:30:30 -0700285class L2UnicastTagged( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700286 """ Verify Bridging works: match(VID, DST_MAC)> fwd(port) """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500287
Flavio Castroa7162bb2016-07-25 17:30:30 -0700288 def runTest( self ):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700289
Flavio Castroa7162bb2016-07-25 17:30:30 -0700290 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700291 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700292 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700293 vlan_id = 1;
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700294 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700295 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
296 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
297 Groups.put( L2gid )
298 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], vlan_id, L2gid,
299 True )
300 do_barrier( self.controller )
Flavio Castro6efe1862015-11-18 16:28:06 -0500301
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700302 for out_port in ports:
303 # change dest based on port number
304 mac_dst = '00:12:34:56:78:%02X' % out_port
305 for in_port in ports:
306 if in_port == out_port:
307 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700308 pkt = str( simple_tcp_packet( dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst=mac_dst ) )
309 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700310 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700311 if ofport in [ out_port ]:
312 verify_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700313 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700314 verify_no_packet( self, pkt, ofport )
315 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700316 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700317 delete_all_flows( self.controller )
318 delete_groups( self.controller, Groups )
319 delete_all_groups( self.controller )
Flavio Castro6efe1862015-11-18 16:28:06 -0500320
Flavio Castroa7162bb2016-07-25 17:30:30 -0700321
322class Mtu1500( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700323 """V erifies basic mtu limits"""
Flavio Castroa7162bb2016-07-25 17:30:30 -0700324 def runTest( self ):
325 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700326 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700327 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700328 vlan_id = 18
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700329 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700330 L2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
331 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
332 Groups.put( L2gid )
333 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], vlan_id, L2gid,
334 True )
335 do_barrier( self.controller )
Flavio Castrob6773032015-11-19 22:49:24 -0500336
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700337 for out_port in ports:
338 # change dest based on port number
339 mac_dst = '00:12:34:56:78:%02X' % out_port
340 for in_port in ports:
341 if in_port == out_port:
342 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700343 pkt = str( simple_tcp_packet( pktlen=1500, dl_vlan_enable=True, vlan_vid=vlan_id,
344 eth_dst=mac_dst ) )
345 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700346 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700347 if ofport in [ out_port ]:
348 verify_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700349 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700350 verify_no_packet( self, pkt, ofport )
351 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700352 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700353 delete_all_flows( self.controller )
354 delete_groups( self.controller, Groups )
355 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500356
Flavio Castroa7162bb2016-07-25 17:30:30 -0700357
358class _32UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700359 """ Verify /32 IP forwarding to L3 Interface"""
Flavio Castro1c9b1252016-02-04 18:42:58 -0500360
Flavio Castroa7162bb2016-07-25 17:30:30 -0700361 def runTest( self ):
362 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700363 try:
364 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -0700365 if len( config[ "port_map" ] ) < 2:
366 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700367 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500368
Flavio Castroa7162bb2016-07-25 17:30:30 -0700369 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
370 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700371 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700372 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700373 for port in ports:
374 # add l2 interface group
375 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -0700376 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
377 is_tagged=True, send_barrier=False )
378 dst_mac[ 5 ] = vlan_id
379 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
380 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700381 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700382 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700383 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700384 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700385 # add unicast routing flow
386 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700387 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
388 Groups.put( l2gid )
389 Groups.put( l3_msg.group_id )
390 do_barrier( self.controller )
Flavio Castrod8f8af22015-12-02 18:19:26 -0500391
Flavio Castroa7162bb2016-07-25 17:30:30 -0700392 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700393 for in_port in ports:
394 mac_src = '00:00:00:22:32:%02X' % (test_id + in_port)
395 ip_src = '192.168.%02d.1' % (test_id + in_port)
396 for out_port in ports:
397 if in_port == out_port:
398 continue
399 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700400 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
401 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
402 ip_src=ip_src, ip_dst=ip_dst )
403 pkt = str( parsed_pkt )
404 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700405 # build expected packet
406 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700407 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
408 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
409 ip_src=ip_src, ip_dst=ip_dst )
410 pkt = str( exp_pkt )
411 verify_packet( self, pkt, out_port )
412 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700413 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700414 delete_all_flows( self.controller )
415 delete_groups( self.controller, Groups )
416 delete_all_groups( self.controller )
Flavio Castro05d20bc2015-11-16 15:06:14 -0500417
Flavio Castroa7162bb2016-07-25 17:30:30 -0700418
419class _32VPN( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700420 """ Verify MPLS IP VPN Initiation from /32 rule """
Flavio Castro2262fd42016-02-04 19:03:36 -0500421
Flavio Castroa7162bb2016-07-25 17:30:30 -0700422 def runTest( self ):
423 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700424 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700425 if len( config[ "port_map" ] ) < 2:
426 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700427 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500428
Flavio Castroa7162bb2016-07-25 17:30:30 -0700429 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
430 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700431 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700432 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700433 for port in ports:
434 # add l2 interface group
435 id = port
436 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700437 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
438 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700439 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700440 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
441 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700442 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700443 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
444 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
445 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700446 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castroa7162bb2016-07-25 17:30:30 -0700447 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700448 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700449 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=2,
450 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700451 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700452 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700453 # add routing flow
454 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700455 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, mpls_label_gid, vrf=2 )
456 Groups._put( l2_gid )
457 Groups._put( mpls_gid )
458 Groups._put( mpls_label_gid )
459 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500460
Flavio Castroa7162bb2016-07-25 17:30:30 -0700461 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700462 for in_port in ports:
463 ip_src = '192.168.%02d.1' % (in_port)
464 for out_port in ports:
465 if in_port == out_port:
466 continue
467 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700468 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
469 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
470 pkt = str( parsed_pkt )
471 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700472 # build expect packet
473 mac_dst = '00:00:00:22:22:%02X' % (out_port)
474 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700475 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
476 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
477 label=[ label ] )
478 pkt = str( exp_pkt )
479 verify_packet( self, pkt, out_port )
480 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700481 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700482 delete_all_flows( self.controller )
483 delete_groups( self.controller, Groups )
484 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500485
Flavio Castroa7162bb2016-07-25 17:30:30 -0700486
487class _32EcmpVpn( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700488 """ Verify MPLS IP VPN Initiation from /32 rule using ECMP """
Flavio Castro2262fd42016-02-04 19:03:36 -0500489
Flavio Castroa7162bb2016-07-25 17:30:30 -0700490 def runTest( self ):
491 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700492 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700493 if len( config[ "port_map" ] ) < 2:
494 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700495 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500496
Flavio Castroa7162bb2016-07-25 17:30:30 -0700497 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
498 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700499 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700500 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700501 for port in ports:
502 # add l2 interface group
503 id = port
504 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700505 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
506 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700507 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700508 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
509 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700510 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700511 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
512 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
513 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
514 ecmp_msg = add_l3_ecmp_group( self.controller, vlan_id, [ mpls_label_gid ] )
515 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700516 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700517 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
518 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700519 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700520 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700521 # add routing flow
522 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700523 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, ecmp_msg.group_id )
524 Groups._put( l2_gid )
525 Groups._put( mpls_gid )
526 Groups._put( mpls_label_gid )
527 Groups._put( ecmp_msg.group_id )
528 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500529
Flavio Castroa7162bb2016-07-25 17:30:30 -0700530 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700531 for in_port in ports:
532 ip_src = '192.168.%02d.1' % (in_port)
533 for out_port in ports:
534 if in_port == out_port:
535 continue
536 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700537 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
538 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
539 pkt = str( parsed_pkt )
540 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700541 # build expect packet
542 mac_dst = '00:00:00:22:22:%02X' % (out_port)
543 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700544 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
545 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
546 label=[ label ] )
547 pkt = str( exp_pkt )
548 verify_packet( self, pkt, out_port )
549 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700550 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700551 delete_all_flows( self.controller )
552 delete_groups( self.controller, Groups )
553 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500554
Flavio Castroa7162bb2016-07-25 17:30:30 -0700555
556class _32ECMPL3( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700557 """ Verifies /32 IP routing and ECMP """
Flavio Castro2262fd42016-02-04 19:03:36 -0500558
Flavio Castroa7162bb2016-07-25 17:30:30 -0700559 def runTest( self ):
560 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700561 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700562 if len( config[ "port_map" ] ) < 2:
563 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700564 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500565
Flavio Castroa7162bb2016-07-25 17:30:30 -0700566 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
567 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700568 dip = 0xc0a80001
569 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700570 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700571 for port in ports:
572 vlan_id = port
573 id = port
574 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700575 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
576 is_tagged=True, send_barrier=False )
577 dst_mac[ 5 ] = vlan_id
578 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
579 src_mac=intf_src_mac, dst_mac=dst_mac )
580 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700581 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700582 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700583 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700584 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700585 # add unicast routing flow
586 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700587 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, ecmp_msg.group_id )
588 Groups._put( l2_gid )
589 Groups._put( l3_msg.group_id )
590 Groups._put( ecmp_msg.group_id )
591 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500592
Flavio Castroa7162bb2016-07-25 17:30:30 -0700593 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700594 for in_port in ports:
595 mac_src = '00:00:00:22:22:%02X' % in_port
596 ip_src = '192.168.%02d.1' % in_port
597 for out_port in ports:
598 if in_port == out_port:
599 continue
600 ip_dst = '192.168.%02d.1' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700601 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
602 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
603 pkt = str( parsed_pkt )
604 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700605 # build expected packet
606 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700607 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
608 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
609 pkt = str( exp_pkt )
610 verify_packet( self, pkt, out_port )
611 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700612 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700613 delete_all_flows( self.controller )
614 delete_groups( self.controller, Groups )
615 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500616
Flavio Castroa7162bb2016-07-25 17:30:30 -0700617
618class _24VPN( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700619 """ Verify MPLS IP VPN Initiation from /32 rule using ECMP """
Flavio Castro2262fd42016-02-04 19:03:36 -0500620
Flavio Castroa7162bb2016-07-25 17:30:30 -0700621 def runTest( self ):
622 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700623 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700624 if len( config[ "port_map" ] ) < 2:
625 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700626 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500627
Flavio Castroa7162bb2016-07-25 17:30:30 -0700628 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
629 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700630 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700631 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700632 for port in ports:
633 # add l2 interface group
634 id = port
635 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700636 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
637 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700638 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700639 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
640 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700641 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700642 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
643 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
644 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700645 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castroa7162bb2016-07-25 17:30:30 -0700646 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700647 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700648 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
649 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700650 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700651 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700652 # add routing flow
653 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700654 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid )
655 Groups._put( l2_gid )
656 Groups._put( mpls_gid )
657 Groups._put( mpls_label_gid )
658 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500659
Flavio Castroa7162bb2016-07-25 17:30:30 -0700660 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700661 for in_port in ports:
662 ip_src = '192.168.%02d.1' % (in_port)
663 for out_port in ports:
664 if in_port == out_port:
665 continue
666 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700667 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
668 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
669 pkt = str( parsed_pkt )
670 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700671 # build expect packet
672 mac_dst = '00:00:00:22:22:%02X' % (out_port)
673 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700674 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
675 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
676 label=[ label ] )
677 pkt = str( exp_pkt )
678 verify_packet( self, pkt, out_port )
679 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700680 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700681 delete_all_flows( self.controller )
682 delete_groups( self.controller, Groups )
683 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500684
Flavio Castroa7162bb2016-07-25 17:30:30 -0700685
686class _24EcmpVpn( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700687 """ Verify MPLS IP VPN Initiation from /24 rule using ECMP """
Flavio Castro72a45d52015-12-02 16:37:05 -0500688
Flavio Castroa7162bb2016-07-25 17:30:30 -0700689 def runTest( self ):
690 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700691 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700692 if len( config[ "port_map" ] ) < 2:
693 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700694 return
Flavio Castroa7162bb2016-07-25 17:30:30 -0700695 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
696 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700697 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700698 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700699 for port in ports:
700 # add l2 interface group
701 id = port
702 vlan_id = id
Flavio Castroa7162bb2016-07-25 17:30:30 -0700703 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
704 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700705 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700706 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
707 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700708 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700709 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
710 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
711 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
712 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ mpls_label_gid ] )
713 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700714 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700715 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
716 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700717 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700718 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700719 # add routing flow
720 dst_ip = dip + (vlan_id << 8)
721 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700722 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id,
723 vrf=0 )
724 Groups._put( l2_gid )
725 Groups._put( mpls_gid )
726 Groups._put( mpls_label_gid )
727 Groups._put( ecmp_msg.group_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700728
Flavio Castroa7162bb2016-07-25 17:30:30 -0700729 do_barrier( self.controller )
Flavio Castro80730822015-12-11 15:38:47 -0500730
Flavio Castroa7162bb2016-07-25 17:30:30 -0700731 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700732 for in_port in ports:
733 mac_src = '00:00:00:22:22:%02X' % (in_port)
734 ip_src = '192.168.%02d.1' % (in_port)
735 for out_port in ports:
736 if in_port == out_port:
737 continue
738 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700739 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
740 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
741 pkt = str( parsed_pkt )
742 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700743 # build expect packet
744 mac_dst = '00:00:00:22:22:%02X' % out_port
745 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700746 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
747 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
748 label=[ label ] )
749 pkt = str( exp_pkt )
750 verify_packet( self, pkt, out_port )
751 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700752 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700753 delete_all_flows( self.controller )
754 delete_groups( self.controller, Groups )
755 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500756
Flavio Castroa7162bb2016-07-25 17:30:30 -0700757
758class FloodGroupMod( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700759 """ Modify referenced group test """
Flavio Castroa7162bb2016-07-25 17:30:30 -0700760
761 def runTest( self ):
762 Groups = Queue.LifoQueue( )
763 try:
764 ports = sorted( config[ "port_map" ].keys( ) )
765 vlan_id = 1
766
767 for port in ports:
768 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
769 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
770 Groups.put( L2gid )
771
772 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
773 Groups.put( msg.group_id )
774 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
775 do_barrier( self.controller )
776 # verify flood
777 for ofport in ports:
778 # change dest based on port number
779 mac_src = '00:12:34:56:78:%02X' % ofport
780 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
781 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10,
782 eth_dst='00:12:34:56:78:9a', eth_src=mac_src )
783 pkt = str( parsed_pkt )
784 self.dataplane.send( ofport, pkt )
785 # self won't rx packet
786 verify_no_packet( self, pkt, ofport )
787 # others will rx packet
788 tmp_ports = list( ports )
789 tmp_ports.remove( ofport )
790 verify_packets( self, pkt, tmp_ports )
791 verify_no_other_packets( self )
792 msg = mod_l2_flood_group( self.controller, [ ports[ 0 ] ], vlan_id, vlan_id )
793 mac_src = '00:12:34:56:78:%02X' % ports[ 1 ]
794 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
795 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a',
796 eth_src=mac_src )
797 pkt = str( parsed_pkt )
798 self.dataplane.send( ports[ 1 ], pkt )
799 verify_packets( self, pkt, [ ports[ 0 ] ] )
800 finally:
801 delete_all_flows( self.controller )
802 delete_groups( self.controller, Groups )
803 delete_all_groups( self.controller )
804
805
806class _24ECMPL3( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -0700807 """ Verifies /24 IP routing using ECMP """
Flavio Castro80730822015-12-11 15:38:47 -0500808
Flavio Castroa7162bb2016-07-25 17:30:30 -0700809 def runTest( self ):
810 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700811 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700812 if len( config[ "port_map" ] ) < 2:
813 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700814 return
Flavio Castro80730822015-12-11 15:38:47 -0500815
Flavio Castroa7162bb2016-07-25 17:30:30 -0700816 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
817 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700818 dip = 0xc0a80001
819 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700820 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700821 for port in ports:
822 vlan_id = port
823 id = port
824 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700825 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
826 is_tagged=True, send_barrier=False )
827 dst_mac[ 5 ] = vlan_id
828 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
829 src_mac=intf_src_mac, dst_mac=dst_mac )
830 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700831 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700832 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700833 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700834 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700835 # add unicast routing flow
836 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700837 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
838 Groups._put( l2_gid )
839 Groups._put( l3_msg.group_id )
840 Groups._put( ecmp_msg.group_id )
841 do_barrier( self.controller )
Flavio Castro72a45d52015-12-02 16:37:05 -0500842
Flavio Castroa7162bb2016-07-25 17:30:30 -0700843 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700844 for in_port in ports:
845 mac_src = '00:00:00:22:22:%02X' % in_port
846 ip_src = '192.168.%02d.1' % in_port
847 for out_port in ports:
848 if in_port == out_port:
849 continue
850 ip_dst = '192.168.%02d.1' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700851 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
852 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
853 pkt = str( parsed_pkt )
854 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700855 # build expected packet
856 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700857 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
858 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
859 pkt = str( exp_pkt )
860 verify_packet( self, pkt, out_port )
861 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700862 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700863 delete_all_flows( self.controller )
864 delete_groups( self.controller, Groups )
865 delete_all_groups( self.controller )
866
Flavio Castro1c9b1252016-02-04 18:42:58 -0500867
Flavio Castroaba28ff2016-02-03 16:47:48 -0500868@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -0700869class MPLSBUG( base_tests.SimpleDataPlane ):
870 def runTest( self ):
871 if len( config[ "port_map" ] ) < 2:
872 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro80730822015-12-11 15:38:47 -0500873 return
Flavio Castroa7162bb2016-07-25 17:30:30 -0700874 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
875 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro1c9b1252016-02-04 18:42:58 -0500876 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700877 Groups = Queue.LifoQueue( )
878 ports = config[ "port_map" ].keys( )
Flavio Castro80730822015-12-11 15:38:47 -0500879 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500880 # add l2 interface group
881 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700882 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
883 dst_mac[ 5 ] = vlan_id
Flavio Castro1c9b1252016-02-04 18:42:58 -0500884 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700885 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
886 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500887 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700888 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500889 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700890 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500891 # add mpls flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700892 add_mpls_flow( self.controller, l3_msg.group_id, port )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500893 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700894 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500895 # add unicast routing flow
896 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700897 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
898 Groups._put( l2_gid )
899 Groups._put( l3_msg.group_id )
900 do_barrier( self.controller )
Flavio Castro80730822015-12-11 15:38:47 -0500901
Flavio Castroa7162bb2016-07-25 17:30:30 -0700902 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro80730822015-12-11 15:38:47 -0500903 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500904 mac_src = '00:00:00:22:22:%02X' % in_port
905 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -0500906 for out_port in ports:
907 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500908 continue
909 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500910 switch_mac = "00:00:00:cc:cc:cc"
911 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700912 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
913 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[ label ] )
914 pkt = str( parsed_pkt )
915 self.dataplane.send( in_port, pkt )
Flavio Castro80730822015-12-11 15:38:47 -0500916
Flavio Castro1c9b1252016-02-04 18:42:58 -0500917 # build expect packet
918 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700919 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
920 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
921 pkt = str( exp_pkt )
922 verify_packet( self, pkt, out_port )
923 verify_no_other_packets( self )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500924
Flavio Castroa7162bb2016-07-25 17:30:30 -0700925 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
926 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
927 pkt = str( parsed_pkt )
928 self.dataplane.send( in_port, pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500929 # build expected packet
930 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700931 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
932 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
933 pkt = str( exp_pkt )
934 verify_packet( self, pkt, out_port )
935 verify_no_other_packets( self )
936 delete_all_flows( self.controller )
937 delete_groups( self.controller, Groups )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500938
Flavio Castroa7162bb2016-07-25 17:30:30 -0700939class L3McastToL3( base_tests.SimpleDataPlane ):
Pierbbdf3782016-08-22 17:58:26 -0700940 """
941 Mcast routing, in this test case the traffic comes in tagged.
942 port+1 is used as ingress vlan_id. The packet goes out tagged on
943 different ports. 4094-port is used as egress vlan_id.
944 """
Flavio Castroa7162bb2016-07-25 17:30:30 -0700945 def runTest( self ):
Pier7b031af2016-08-25 15:00:22 -0700946 """
947 port1 (vlan 300)-> All Ports (vlan 300)
948 """
Flavio Castroa7162bb2016-07-25 17:30:30 -0700949 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700950 try:
Pierbbdf3782016-08-22 17:58:26 -0700951 # We can forward on the in_port but egress_vlan has to be different from ingress_vlan
952 if len( config[ "port_map" ] ) < 1:
953 logging.info( "Port count less than 1, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700954 assert (False)
955 return
Pierbbdf3782016-08-22 17:58:26 -0700956 ports = config[ "port_map" ].keys( )
957 dst_ip_str = "224.0.0.1"
958 (
959 port_to_in_vlan,
960 port_to_out_vlan,
961 port_to_src_mac_str,
962 port_to_dst_mac_str,
963 port_to_src_ip_str,
964 port_to_intf_src_mac_str,
965 Groups) = fill_mcast_pipeline_L3toL3(
966 self.controller,
967 logging,
968 ports,
969 is_ingress_tagged = True,
970 is_egress_tagged = True,
971 is_vlan_translated = True,
972 is_max_vlan = False
973 )
Flavio Castro12296312015-12-15 17:48:26 -0500974
Pierbbdf3782016-08-22 17:58:26 -0700975 for in_port in ports:
Flavio Castro12296312015-12-15 17:48:26 -0500976
Pierbbdf3782016-08-22 17:58:26 -0700977 parsed_pkt = simple_udp_packet(
978 pktlen = 100,
979 dl_vlan_enable = True,
980 vlan_vid = port_to_in_vlan[in_port],
981 eth_dst = port_to_dst_mac_str[in_port],
982 eth_src = port_to_src_mac_str[in_port],
983 ip_ttl = 64,
984 ip_src = port_to_src_ip_str[in_port],
985 ip_dst = dst_ip_str
986 )
987 pkt = str( parsed_pkt )
988 self.dataplane.send( in_port, pkt )
Flavio Castro12296312015-12-15 17:48:26 -0500989
Pierbbdf3782016-08-22 17:58:26 -0700990 for out_port in ports:
Flavio Castro12296312015-12-15 17:48:26 -0500991
Pierbbdf3782016-08-22 17:58:26 -0700992 parsed_pkt = simple_udp_packet(
993 pktlen = 100,
994 dl_vlan_enable = True,
995 vlan_vid = port_to_out_vlan[out_port],
996 eth_dst = port_to_dst_mac_str[in_port],
997 eth_src = port_to_intf_src_mac_str[out_port],
998 ip_ttl = 63,
999 ip_src = port_to_src_ip_str[in_port],
1000 ip_dst = dst_ip_str
1001 )
1002 pkt = str( parsed_pkt )
1003 verify_packet( self, pkt, out_port )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001004
Pierbbdf3782016-08-22 17:58:26 -07001005 verify_no_other_packets( self )
1006
Pier7b031af2016-08-25 15:00:22 -07001007 parsed_pkt = simple_udp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=vlan_id,
1008 eth_dst=dst_mac_str, eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str,
1009 ip_dst=dst_ip_str )
1010 pkt = str( parsed_pkt )
1011 self.dataplane.send( port1, pkt )
1012 for port in config[ "port_map" ].keys( ):
1013 if port == port2 or port == port1:
1014 verify_no_packet( self, pkt, port )
1015 continue
1016 verify_packet( self, pkt, port )
1017 verify_no_other_packets( self )
1018 finally:
1019 delete_all_flows( self.controller )
1020 delete_groups( self.controller, Groups )
1021 delete_all_groups( self.controller )
1022
1023class L3McastToL2UntagToUntag( base_tests.SimpleDataPlane ):
1024 """
1025 Mcast routing, in this test case the traffic is untagged.
1026 4094 is used as internal vlan_id. The packet goes out
1027 untagged.
1028 """
1029 def runTest( self ):
1030 Groups = Queue.LifoQueue( )
1031 try:
1032 if len( config[ "port_map" ] ) < 2:
1033 logging.info( "Port count less than 2, can't run this case" )
1034 assert (False)
1035 return
1036 ports = config[ "port_map" ].keys( )
1037 dst_ip_str = "224.0.0.1"
1038 (
1039 port_to_in_vlan,
1040 port_to_out_vlan,
1041 port_to_src_mac_str,
1042 port_to_dst_mac_str,
1043 port_to_src_ip_str,
1044 Groups) = fill_mcast_pipeline_L3toL2(
1045 self.controller,
1046 logging,
1047 ports,
1048 is_ingress_tagged = False,
1049 is_egress_tagged = False,
1050 is_vlan_translated = False,
1051 is_max_vlan = True
1052 )
1053
1054 for in_port in ports:
1055
1056 parsed_pkt = simple_udp_packet(
1057 pktlen = 96,
1058 eth_dst = port_to_dst_mac_str[in_port],
1059 eth_src = port_to_src_mac_str[in_port],
1060 ip_ttl = 64,
1061 ip_src = port_to_src_ip_str[in_port],
1062 ip_dst = dst_ip_str
1063 )
1064 pkt = str( parsed_pkt )
1065 self.dataplane.send( in_port, pkt )
1066
1067 for out_port in ports:
1068
1069 parsed_pkt = simple_udp_packet(
1070 pktlen = 96,
1071 eth_dst = port_to_dst_mac_str[in_port],
1072 eth_src = port_to_src_mac_str[in_port],
1073 ip_ttl = 64,
1074 ip_src = port_to_src_ip_str[in_port],
1075 ip_dst = dst_ip_str
1076 )
1077 pkt = str( parsed_pkt )
1078 if out_port == in_port:
1079 verify_no_packet( self, pkt, in_port )
1080 continue
1081 verify_packet( self, pkt, out_port )
1082 verify_no_other_packets( self )
1083 finally:
1084 delete_all_flows( self.controller )
1085 delete_groups( self.controller, Groups )
1086 delete_all_groups( self.controller )
1087
1088class L3McastToL2UntagToTag( base_tests.SimpleDataPlane ):
1089 """
1090 Mcast routing, in this test case the traffic is untagged.
1091 300 is used as vlan_id. The packet goes out
1092 tagged.
1093 """
1094 def runTest( self ):
1095 Groups = Queue.LifoQueue( )
1096 try:
1097 if len( config[ "port_map" ] ) < 2:
1098 logging.info( "Port count less than 2, can't run this case" )
1099 assert (False)
1100 return
1101 ports = config[ "port_map" ].keys( )
1102 dst_ip_str = "224.0.0.1"
1103 (
1104 port_to_in_vlan,
1105 port_to_out_vlan,
1106 port_to_src_mac_str,
1107 port_to_dst_mac_str,
1108 port_to_src_ip_str,
1109 Groups) = fill_mcast_pipeline_L3toL2(
1110 self.controller,
1111 logging,
1112 ports,
1113 is_ingress_tagged = False,
1114 is_egress_tagged = True,
1115 is_vlan_translated = False,
1116 is_max_vlan = False
1117 )
1118
1119 for in_port in ports:
1120
1121 parsed_pkt = simple_udp_packet(
1122 pktlen = 96,
1123 eth_dst = port_to_dst_mac_str[in_port],
1124 eth_src = port_to_src_mac_str[in_port],
1125 ip_ttl = 64,
1126 ip_src = port_to_src_ip_str[in_port],
1127 ip_dst = dst_ip_str
1128 )
1129 pkt = str( parsed_pkt )
1130 self.dataplane.send( in_port, pkt )
1131
1132 for out_port in ports:
1133
1134 parsed_pkt = simple_udp_packet(
1135 pktlen = 100,
1136 dl_vlan_enable = True,
1137 vlan_vid = port_to_out_vlan[in_port],
1138 eth_dst = port_to_dst_mac_str[in_port],
1139 eth_src = port_to_src_mac_str[in_port],
1140 ip_ttl = 64,
1141 ip_src = port_to_src_ip_str[in_port],
1142 ip_dst = dst_ip_str
1143 )
1144 pkt = str( parsed_pkt )
1145 if out_port == in_port:
1146 verify_no_packet( self, pkt, in_port )
1147 continue
1148 verify_packet( self, pkt, out_port )
1149 verify_no_other_packets( self )
1150 finally:
1151 delete_all_flows( self.controller )
1152 delete_groups( self.controller, Groups )
1153 delete_all_groups( self.controller )
1154
1155
1156class L3McastToL2TagToUntag( base_tests.SimpleDataPlane ):
1157 """
1158 Mcast routing, in this test case the traffic is tagged.
1159 300 is used as vlan_id. The packet goes out
1160 untagged.
1161 """
1162 def runTest( self ):
1163 Groups = Queue.LifoQueue( )
1164 try:
1165 if len( config[ "port_map" ] ) < 2:
1166 logging.info( "Port count less than 2, can't run this case" )
1167 assert (False)
1168 return
1169 ports = config[ "port_map" ].keys( )
1170 dst_ip_str = "224.0.0.1"
1171 (
1172 port_to_in_vlan,
1173 port_to_out_vlan,
1174 port_to_src_mac_str,
1175 port_to_dst_mac_str,
1176 port_to_src_ip_str,
1177 Groups) = fill_mcast_pipeline_L3toL2(
1178 self.controller,
1179 logging,
1180 ports,
1181 is_ingress_tagged = True,
1182 is_egress_tagged = False,
1183 is_vlan_translated = False,
1184 is_max_vlan = False
1185 )
1186
1187 for in_port in ports:
1188
1189 parsed_pkt = simple_udp_packet(
1190 pktlen = 100,
1191 dl_vlan_enable = True,
1192 vlan_vid = port_to_in_vlan[in_port],
1193 eth_dst = port_to_dst_mac_str[in_port],
1194 eth_src = port_to_src_mac_str[in_port],
1195 ip_ttl = 64,
1196 ip_src = port_to_src_ip_str[in_port],
1197 ip_dst = dst_ip_str
1198 )
1199 pkt = str( parsed_pkt )
1200 self.dataplane.send( in_port, pkt )
1201
1202 for out_port in ports:
1203
1204 parsed_pkt = simple_udp_packet(
1205 pktlen = 96,
1206 eth_dst = port_to_dst_mac_str[in_port],
1207 eth_src = port_to_src_mac_str[in_port],
1208 ip_ttl = 64,
1209 ip_src = port_to_src_ip_str[in_port],
1210 ip_dst = dst_ip_str
1211 )
1212 pkt = str( parsed_pkt )
1213 if out_port == in_port:
1214 verify_no_packet( self, pkt, in_port )
1215 continue
1216 verify_packet( self, pkt, out_port )
1217 verify_no_other_packets( self )
1218 finally:
1219 delete_all_flows( self.controller )
1220 delete_groups( self.controller, Groups )
1221 delete_all_groups( self.controller )
1222
1223class L3McastToL2TagToTag( base_tests.SimpleDataPlane ):
1224 """
1225 Mcast routing, in this test case the traffic is tagged.
1226 300 is used as vlan_id. The packet goes out tagged.
1227 """
1228 def runTest( self ):
1229 Groups = Queue.LifoQueue( )
1230 try:
1231 if len( config[ "port_map" ] ) < 2:
1232 logging.info( "Port count less than 2, can't run this case" )
1233 assert (False)
1234 return
1235 ports = config[ "port_map" ].keys( )
1236 dst_ip_str = "224.0.0.1"
1237 (
1238 port_to_in_vlan,
1239 port_to_out_vlan,
1240 port_to_src_mac_str,
1241 port_to_dst_mac_str,
1242 port_to_src_ip_str,
1243 Groups) = fill_mcast_pipeline_L3toL2(
1244 self.controller,
1245 logging,
1246 ports,
1247 is_ingress_tagged = True,
1248 is_egress_tagged = True,
1249 is_vlan_translated = False,
1250 is_max_vlan = False
1251 )
1252
1253 for in_port in ports:
1254
1255 parsed_pkt = simple_udp_packet(
1256 pktlen = 100,
1257 dl_vlan_enable = True,
1258 vlan_vid = port_to_in_vlan[in_port],
1259 eth_dst = port_to_dst_mac_str[in_port],
1260 eth_src = port_to_src_mac_str[in_port],
1261 ip_ttl = 64,
1262 ip_src = port_to_src_ip_str[in_port],
1263 ip_dst = dst_ip_str
1264 )
1265 pkt = str( parsed_pkt )
1266 self.dataplane.send( in_port, pkt )
1267
1268 for out_port in ports:
1269
1270 parsed_pkt = simple_udp_packet(
1271 pktlen = 100,
1272 dl_vlan_enable = True,
1273 vlan_vid = port_to_in_vlan[in_port],
1274 eth_dst = port_to_dst_mac_str[in_port],
1275 eth_src = port_to_src_mac_str[in_port],
1276 ip_ttl = 64,
1277 ip_src = port_to_src_ip_str[in_port],
1278 ip_dst = dst_ip_str
1279 )
1280 pkt = str( parsed_pkt )
1281 if out_port == in_port:
1282 verify_no_packet( self, pkt, in_port )
1283 continue
1284 verify_packet( self, pkt, out_port )
1285 verify_no_other_packets( self )
1286 finally:
1287 delete_all_flows( self.controller )
1288 delete_groups( self.controller, Groups )
1289 delete_all_groups( self.controller )
1290
1291class L3McastToL2TagToTagTranslated( base_tests.SimpleDataPlane ):
1292 """
1293 Mcast routing, in this test case the traffic is tagged.
1294 port+1 is used as ingress vlan_id. The packet goes out
1295 tagged. 4094-port is used as egress vlan_id
1296 """
1297 def runTest( self ):
1298 Groups = Queue.LifoQueue( )
1299 try:
1300 if len( config[ "port_map" ] ) < 2:
1301 logging.info( "Port count less than 2, can't run this case" )
1302 assert (False)
1303 return
1304 ports = config[ "port_map" ].keys( )
1305 dst_ip_str = "224.0.0.1"
1306 (
1307 port_to_in_vlan,
1308 port_to_out_vlan,
1309 port_to_src_mac_str,
1310 port_to_dst_mac_str,
1311 port_to_src_ip_str,
1312 Groups) = fill_mcast_pipeline_L3toL2(
1313 self.controller,
1314 logging,
1315 ports,
1316 is_ingress_tagged = True,
1317 is_egress_tagged = True,
1318 is_vlan_translated = True,
1319 is_max_vlan = False
1320 )
1321
1322 for in_port in ports:
1323
1324 parsed_pkt = simple_udp_packet(
1325 pktlen = 100,
1326 dl_vlan_enable = True,
1327 vlan_vid = port_to_in_vlan[in_port],
1328 eth_dst = port_to_dst_mac_str[in_port],
1329 eth_src = port_to_src_mac_str[in_port],
1330 ip_ttl = 64,
1331 ip_src = port_to_src_ip_str[in_port],
1332 ip_dst = dst_ip_str
1333 )
1334 pkt = str( parsed_pkt )
1335 self.dataplane.send( in_port, pkt )
1336
1337 for out_port in ports:
1338
1339 parsed_pkt = simple_udp_packet(
1340 pktlen = 100,
1341 dl_vlan_enable = True,
1342 vlan_vid = port_to_out_vlan[in_port],
1343 eth_dst = port_to_dst_mac_str[in_port],
1344 eth_src = port_to_src_mac_str[in_port],
1345 ip_ttl = 64,
1346 ip_src = port_to_src_ip_str[in_port],
1347 ip_dst = dst_ip_str
1348 )
1349 pkt = str( parsed_pkt )
1350 if out_port == in_port:
1351 verify_no_packet( self, pkt, in_port )
1352 continue
1353 verify_packet( self, pkt, out_port )
1354 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001355 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001356 delete_all_flows( self.controller )
1357 delete_groups( self.controller, Groups )
1358 delete_all_groups( self.controller )
1359
Pierbbdf3782016-08-22 17:58:26 -07001360
Flavio Castroa7162bb2016-07-25 17:30:30 -07001361class _MplsFwd( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001362 """ Verify basic MPLS forwarding: Label switch router """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001363
1364 def runTest( self ):
1365 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001366 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001367 if len( config[ "port_map" ] ) < 2:
1368 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001369 return
1370 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001371 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1372 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001373 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001374 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001375 for port in ports:
Charles Chan53cac542016-08-22 16:03:26 -07001376 # Shift MPLS label and VLAN ID by 16 to avoid reserved values
1377 vlan_id = port + 16
1378 mpls_label = port + 16
1379
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001380 # add l2 interface group
1381 id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001382 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Charles Chan53cac542016-08-22 16:03:26 -07001383 dst_mac[ 5 ] = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001384 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1385 vlan_id, id )
1386 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
1387 subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL, index=id, ref_gid=mpls_gid,
Charles Chan53cac542016-08-22 16:03:26 -07001388 push_mpls_header=False, set_mpls_label=mpls_label, set_bos=1 )
Pierf3504f82016-08-19 15:32:53 -07001389 ecmp_gid, ecmp_msg = add_mpls_forwarding_group( self.controller,
1390 subtype=OFDPA_MPLS_GROUP_SUBTYPE_ECMP, index=id, ref_gids=[mpls_label_gid] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001391 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001392 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001393 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001394 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001395 #add_mpls_flow( self.controller, ecmp_gid, port, goto_table=29 )
Charles Chan53cac542016-08-22 16:03:26 -07001396 add_mpls_flow( self.controller, mpls_label_gid, mpls_label, goto_table=29 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001397 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001398 Groups._put( l2_gid )
1399 Groups._put( mpls_gid )
1400 Groups._put( mpls_label_gid )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001401 Groups._put( ecmp_gid )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001402 do_barrier( self.controller )
castroflavio30c6cc52016-01-07 15:19:42 -08001403
Flavio Castroa7162bb2016-07-25 17:30:30 -07001404 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001405 for in_port in ports:
1406 ip_src = '192.168.%02d.1' % (in_port)
1407 for out_port in ports:
1408 if in_port == out_port:
1409 continue
Flavio Castro54947942016-02-03 16:05:20 -05001410
Charles Chan53cac542016-08-22 16:03:26 -07001411 # Shift MPLS label and VLAN ID by 16 to avoid reserved values
1412 out_mpls_label = out_port + 16
1413 in_vlan_vid = in_port + 16
1414 out_vlan_vid = out_port + 16
1415
1416 ip_dst = '192.168.%02d.1' % (out_port)
1417 label = (out_mpls_label, 0, 1, 32)
1418 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_vlan_vid),
Flavio Castroa7162bb2016-07-25 17:30:30 -07001419 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1420 pkt = str( parsed_pkt )
1421 self.dataplane.send( in_port, pkt )
Flavio Castro54947942016-02-03 16:05:20 -05001422
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001423 # build expect packet
1424 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Charles Chan53cac542016-08-22 16:03:26 -07001425 label = (out_mpls_label, 0, 1, 31)
1426 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_vlan_vid),
Flavio Castroa7162bb2016-07-25 17:30:30 -07001427 ip_src=ip_src, ip_dst=ip_dst, eth_src=switch_mac, eth_dst=mac_dst,
1428 label=[ label ] )
1429 pkt = str( exp_pkt )
1430 verify_packet( self, pkt, out_port )
1431 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001432 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001433 delete_all_flows( self.controller )
1434 delete_groups( self.controller, Groups )
1435 delete_all_groups( self.controller )
Flavio Castrob702a2f2016-04-10 22:01:48 -04001436
Flavio Castroa7162bb2016-07-25 17:30:30 -07001437
1438class _MplsTermination( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001439 """ Verify MPLS VPN Termination at penultimate hop """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001440
1441 def runTest( self ):
1442 Groups = Queue.LifoQueue( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001443 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001444 if len( config[ "port_map" ] ) < 2:
1445 logging.info( "Port count less than 2, can't run this case" )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001446 return
1447 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001448 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1449 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castrod80fbc32016-07-25 15:54:26 -07001450 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001451 ports = config[ "port_map" ].keys( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001452 for port in ports:
Charles Chan53cac542016-08-22 16:03:26 -07001453 # Shift MPLS label and VLAN ID by 16 to avoid reserved values
1454 vlan_id = port + 16
1455 mpls_label = port + 16
1456
Flavio Castrod80fbc32016-07-25 15:54:26 -07001457 # add l2 interface group
Charles Chan53cac542016-08-22 16:03:26 -07001458 id, dst_mac[ 5 ] = port, port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001459 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001460 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001461 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1462 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001463 # add L3 ecmp group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001464 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001465 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001466 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001467 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001468 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Charles Chan53cac542016-08-22 16:03:26 -07001469 add_mpls_flow( self.controller, ecmp_msg.group_id, mpls_label )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001470 # add_mpls_flow(self.controller, label=port)
Flavio Castrod80fbc32016-07-25 15:54:26 -07001471 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001472 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
Flavio Castrod80fbc32016-07-25 15:54:26 -07001473 # ecmp_msg.group_id, 1)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001474 Groups._put( l2_gid )
1475 Groups._put( l3_msg.group_id )
1476 Groups._put( ecmp_msg.group_id )
1477 do_barrier( self.controller )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001478
Flavio Castroa7162bb2016-07-25 17:30:30 -07001479 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001480 for in_port in ports:
1481 ip_src = '192.168.%02d.1' % (in_port)
1482 for out_port in ports:
1483 if in_port == out_port:
1484 continue
Charles Chan53cac542016-08-22 16:03:26 -07001485
1486 # Shift MPLS label and VLAN ID by 16 to avoid reserved values
1487 out_mpls_label = out_port + 16
1488 in_vlan_vid = in_port + 16
1489 out_vlan_vid = out_port + 16
1490
Flavio Castrod80fbc32016-07-25 15:54:26 -07001491 ip_dst = '192.168.%02d.1' % (out_port)
Charles Chan53cac542016-08-22 16:03:26 -07001492 label = (out_mpls_label, 0, 1, 32)
1493 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_vlan_vid),
Flavio Castroa7162bb2016-07-25 17:30:30 -07001494 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1495 pkt = str( parsed_pkt )
1496 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001497 # build expect packet
1498 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Charles Chan53cac542016-08-22 16:03:26 -07001499 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_vlan_vid),
Flavio Castroa7162bb2016-07-25 17:30:30 -07001500 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
1501 pkt = str( exp_pkt )
1502 verify_packet( self, pkt, out_port )
1503 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001504 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001505 delete_all_flows( self.controller )
1506 delete_groups( self.controller, Groups )
1507 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001508
Flavio Castroa7162bb2016-07-25 17:30:30 -07001509
1510class _24UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001511 """ Verify /24 IP forwarding to L3 Interface """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001512
Flavio Castroa7162bb2016-07-25 17:30:30 -07001513 def runTest( self ):
1514 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001515 try:
1516 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -07001517 if len( config[ "port_map" ] ) < 2:
1518 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001519 return
Flavio Castroa7162bb2016-07-25 17:30:30 -07001520 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1521 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001522 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001523 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001524 for port in ports:
1525 # add l2 interface group
1526 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -07001527 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1528 is_tagged=True, send_barrier=False )
1529 dst_mac[ 5 ] = vlan_id
1530 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
1531 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001532 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001533 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001534 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001535 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001536 # add unicast routing flow
1537 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001538 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id )
1539 Groups.put( l2gid )
1540 Groups.put( l3_msg.group_id )
1541 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001542
Flavio Castroa7162bb2016-07-25 17:30:30 -07001543 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001544 for in_port in ports:
1545 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1546 ip_src = '192.168.%02d.1' % (test_id + in_port)
1547 for out_port in ports:
1548 if in_port == out_port:
1549 continue
1550 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001551 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1552 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
1553 ip_src=ip_src, ip_dst=ip_dst )
1554 pkt = str( parsed_pkt )
1555 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001556 # build expected packet
1557 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001558 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1559 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
1560 ip_src=ip_src, ip_dst=ip_dst )
1561 pkt = str( exp_pkt )
1562 verify_packet( self, pkt, out_port )
1563 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001564 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001565 delete_all_flows( self.controller )
1566 delete_groups( self.controller, Groups )
1567 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001568
Flavio Castroa7162bb2016-07-25 17:30:30 -07001569
1570class _0Ucast( base_tests.SimpleDataPlane ):
Flavio Castro76c5b262016-07-27 19:53:00 -07001571 """ Verify default gateway IP forwarding to L3 Interface ( /0 rule ) """
Flavio Castro91d1a552016-05-17 16:59:44 -07001572
Flavio Castroa7162bb2016-07-25 17:30:30 -07001573 def runTest( self ):
1574 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001575 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001576 if len( config[ "port_map" ] ) < 2:
1577 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001578 return
Flavio Castro91d1a552016-05-17 16:59:44 -07001579
Flavio Castroa7162bb2016-07-25 17:30:30 -07001580 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1581 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001582 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001583 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001584 for port in ports:
1585 # add l2 interface group
1586 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001587 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id + 1,
1588 is_tagged=True, send_barrier=False )
1589 dst_mac[ 5 ] = vlan_id
1590 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id + 1, id=vlan_id,
1591 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001592 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001593 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001594 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001595 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001596 # add unicast routing flow
1597 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001598 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
1599 Groups.put( l2gid )
1600 Groups.put( l3_msg.group_id )
1601 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001602 dst_ip = 0x0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001603 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0x0, l3_gid )
1604 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001605
Flavio Castroa7162bb2016-07-25 17:30:30 -07001606 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001607 for in_port in ports:
1608 mac_src = '00:00:00:22:22:%02X' % (in_port)
1609 ip_src = '192.168.%02d.1' % (in_port)
1610 for out_port in ports:
1611 if in_port == out_port:
1612 continue
1613 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001614 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
1615 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1616 pkt = str( parsed_pkt )
1617 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001618 # build expected packet
1619 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001620 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port + 1),
1621 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
1622 pkt = str( exp_pkt )
1623 verify_packet( self, pkt, out_port )
1624 verify_no_other_packets( self )
1625 ip_dst = '1.168.%02d.1' % ports[ 0 ]
1626 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1627 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1628 pkt = str( parsed_pkt )
1629 self.dataplane.send( in_port, pkt )
1630 # build expect packet
1631 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1632 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ] + 1,
1633 ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac )
1634 pkt = str( exp_pkt )
1635 verify_packet( self, pkt, ports[ 0 ] )
1636 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001637 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001638 delete_all_flows( self.controller )
1639 delete_groups( self.controller, Groups )
1640 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001641
Flavio Castroa7162bb2016-07-25 17:30:30 -07001642
1643class Unfiltered( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001644 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001645 Attempt to add an unfiltered group: [ATTENTION] this doesn't verify addition
Flavio Castro423df652016-05-17 20:14:08 -04001646 """
Flavio Castro91d1a552016-05-17 16:59:44 -07001647
Flavio Castroa7162bb2016-07-25 17:30:30 -07001648 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001649 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001650 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001651 vlan_id = 1;
1652 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001653 add_l2_unfiltered_group( self.controller, [ port ], False )
1654 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001655 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001656 delete_all_flows( self.controller )
1657 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001658
Flavio Castroa7162bb2016-07-25 17:30:30 -07001659
1660class L3McastToVPN( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001661 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001662 Mcast routing and VPN initiation
Flavio Castro423df652016-05-17 20:14:08 -04001663 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001664
1665 def runTest( self ):
Flavio Castro423df652016-05-17 20:14:08 -04001666 """
1667 port1 (vlan 1)-> port 2 (vlan 2)
1668 """
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001669 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001670 delete_all_flows( self.controller )
1671 delete_all_groups( self.controller )
Flavio Castro423df652016-05-17 20:14:08 -04001672
Flavio Castroa7162bb2016-07-25 17:30:30 -07001673 if len( config[ "port_map" ] ) < 3:
1674 logging.info( "Port count less than 3, can't run this case" )
1675 assert (False)
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001676 return
Flavio Castro423df652016-05-17 20:14:08 -04001677
Flavio Castroa7162bb2016-07-25 17:30:30 -07001678 vlan_id = 1
1679 port2_out_vlan = 2
1680 port3_out_vlan = 3
1681 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
1682 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1683 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1684 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
1685 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
1686 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
1687 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
1688 src_ip = 0xc0a80101
1689 src_ip_str = "192.168.1.1"
1690 dst_ip = 0xe0010101
1691 dst_ip_str = "224.1.1.1"
Flavio Castro423df652016-05-17 20:14:08 -04001692
Flavio Castroa7162bb2016-07-25 17:30:30 -07001693 port1 = config[ "port_map" ].keys( )[ 0 ]
1694 port2 = config[ "port_map" ].keys( )[ 1 ]
1695 # port3=config["port_map"].keys()[2]
Flavio Castro423df652016-05-17 20:14:08 -04001696
Flavio Castroa7162bb2016-07-25 17:30:30 -07001697 # add l2 interface group
1698 for port in config[ "port_map" ].keys( ):
1699 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=False,
1700 send_barrier=False )
1701 # add vlan flow table
1702 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1703 vlan_id += 1
Flavio Castro423df652016-05-17 20:14:08 -04001704
Flavio Castroa7162bb2016-07-25 17:30:30 -07001705 # add termination flow
1706 add_termination_flow( self.controller, port1, 0x0800, [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ],
1707 vlan_id )
Flavio Castro423df652016-05-17 20:14:08 -04001708
Flavio Castroa7162bb2016-07-25 17:30:30 -07001709 # add MPLS interface group
1710 l2_gid = encode_l2_interface_group_id( port2_out_vlan, port2 )
1711 mpls_gid2, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1712 port2_out_vlan, port2 )
1713 # l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
1714 # mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
1715 # add L3VPN groups
1716 mpls_label_gid2, mpls_label_msg = add_mpls_label_group( self.controller,
1717 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=(0x20000 + port2), ref_gid=mpls_gid2,
1718 push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True )
1719 # 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 -07001720 # 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 -04001721
Flavio Castroa7162bb2016-07-25 17:30:30 -07001722 mcat_group_msg = add_l3_mcast_group( self.controller, in_vlan, 2, [ mpls_label_gid2 ] )
1723 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 -04001724
Flavio Castroa7162bb2016-07-25 17:30:30 -07001725 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac_str,
1726 eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str, ip_dst=dst_ip_str )
1727 pkt = str( parsed_pkt )
1728 self.dataplane.send( port1, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001729 label = (12, 0, 1, 63)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001730 exp_pkt = mpls_packet( pktlen=100, eth_dst=dst_mac_str, eth_src=intf_src_mac_str, ip_ttl=64,
1731 ip_src=src_ip_str, label=[ label ], ip_dst=dst_ip_str )
1732 pkt = str( exp_pkt )
1733 verify_packet( self, pkt, port2 )
1734 # verify_packet(self, pkt, port3)
1735 verify_no_other_packets( self )
1736 delete_all_groups( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001737 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001738 delete_all_flows( self.controller )
1739 delete_all_groups( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001740
Flavio Castro423df652016-05-17 20:14:08 -04001741
Flavio Castroa7162bb2016-07-25 17:30:30 -07001742class PacketInSrcMacMiss( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001743 """
1744 Test packet in function on a src-mac miss
1745 Send a packet to each dataplane port and verify that a packet
1746 in message is received from the controller for each
1747 #todo verify you stop receiving after adding rule
1748 """
1749
Flavio Castroa7162bb2016-07-25 17:30:30 -07001750 def runTest( self ):
1751 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001752 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001753 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro423df652016-05-17 20:14:08 -04001754
Flavio Castroa7162bb2016-07-25 17:30:30 -07001755 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001756 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001757 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, 1, True, False )
1758 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1759 Groups.put( L2gid )
1760 parsed_vlan_pkt = simple_tcp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
1761 vlan_pkt = str( parsed_vlan_pkt )
1762 for of_port in config[ "port_map" ].keys( ):
1763 logging.info( "PacketInMiss test, port %d", of_port )
1764 self.dataplane.send( of_port, vlan_pkt )
1765 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH )
1766 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001767 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001768 delete_all_flows( self.controller )
1769 delete_all_groups( self.controller )
1770
1771
1772class EcmpGroupMod( base_tests.SimpleDataPlane ):
1773 """
Flavio Castro76c5b262016-07-27 19:53:00 -07001774 Verify referenced group can be modified adding or removing buckets
1775 Attention the hashing behavior may vary according to your porting assigment
1776 Current values are hardcoded for our topology
Flavio Castroa7162bb2016-07-25 17:30:30 -07001777 """
1778
1779 def runTest( self ):
1780 Groups = Queue.LifoQueue( )
1781 try:
1782 if len( config[ "port_map" ] ) < 2:
1783 logging.info( "Port count less than 2, can't run this case" )
1784 return
1785
1786 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1787 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
1788 dip = 0xc0a80001
1789 # Hashes Test Name and uses it as id for installing unique groups
1790 ports = config[ "port_map" ].keys( )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001791 ecmp = [ ]
Flavio Castroa7162bb2016-07-25 17:30:30 -07001792 for port in ports:
1793 vlan_id = port
1794 id = port
1795 # add l2 interface group
1796 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1797 is_tagged=True, send_barrier=False )
1798 dst_mac[ 5 ] = vlan_id
1799 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1800 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001801 ecmp += [ l3_msg.group_id ]
Flavio Castroa7162bb2016-07-25 17:30:30 -07001802 Groups._put( l2_gid )
1803 Groups._put( l3_msg.group_id )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001804 ecmp_msg = add_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_msg.group_id ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001805 # add vlan flow table
1806 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1807 # add termination flow
1808 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
1809 # add unicast routing flow
1810 dst_ip = dip + (vlan_id << 8)
1811 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
1812 Groups._put( ecmp_msg.group_id )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001813 mod_l3_ecmp_group( self.controller, ports[ 0 ], ecmp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001814
1815 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001816 parsed_pkt = exp_pkt = 0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001817 for out_port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001818 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1819 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1820 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1821 tcp = out_port if out_port == 24 else 25
1822 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1823 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1824 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001825 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001826 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001827 # build expected packet
1828 mac_dst = '00:00:00:22:22:%02X' % out_port
1829 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castro9debaaa2016-07-26 19:37:50 -07001830 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst,
1831 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001832 pkt = str( exp_pkt )
1833 verify_packet( self, pkt, out_port )
1834 verify_no_other_packets( self )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001835 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
1836 mod_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_gid ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001837 for port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001838 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1839 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1840 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1841 tcp = port if port == 24 else 25
1842 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1843 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1844 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001845 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001846 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001847 # build expected packet
Flavio Castro9debaaa2016-07-26 19:37:50 -07001848 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1849 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1850 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst,
1851 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001852 pkt = str( exp_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001853 verify_packet( self, pkt, ports[ 0 ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001854 verify_no_other_packets( self )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001855 mod_l3_ecmp_group( self.controller, ports[ 0 ], [ ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001856 for port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001857 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1858 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1859 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1860 tcp = port if port == 24 else 25
1861 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1862 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1863 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001864 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001865 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001866 verify_no_other_packets( self )
1867 finally:
1868 delete_all_flows( self.controller )
1869 delete_groups( self.controller, Groups )
1870 delete_all_groups( self.controller )
Pier8b223022016-08-19 22:47:49 -07001871
1872class Untagged( base_tests.SimpleDataPlane ):
1873 """
1874 Verify VLAN filtering table does not require OFPVID_PRESENT bit to be 0.
1875 This should be fixed in OFDPA 2.0 GA and above, the test fails with
1876 previous versions of the OFDPA.
1877
1878 Two rules are necessary in VLAN table (10):
1879 1) Assignment: match 0x0000/(no mask), set_vlan_vid 0x100A, goto 20
1880 2) Filtering: match 0x100A/0x1FFF, goto 20
1881
1882 In this test case vlan_id = (MAX_INTERNAL_VLAN - port_no).
1883 The remaining part of the test is based on the use of the bridging table
1884 """
1885
1886 MAX_INTERNAL_VLAN = 4094
1887
1888 def runTest( self ):
1889 groups = Queue.LifoQueue( )
1890 try:
1891 if len( config[ "port_map" ] ) < 2:
1892 logging.info( "Port count less than 2, can't run this case" )
1893 return
1894
1895 ports = sorted( config[ "port_map" ].keys( ) )
1896 for port in ports:
1897 vlan_id = Untagged.MAX_INTERNAL_VLAN - port
1898 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1899 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_UNTAG )
1900 for other_port in ports:
1901 if other_port == port:
1902 continue
1903 L2gid, l2msg = add_one_l2_interface_group( self.controller, other_port, vlan_id, False, False )
1904 groups.put( L2gid )
1905 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, other_port ], vlan_id, L2gid, True )
1906
1907 do_barrier( self.controller )
1908
1909 for out_port in ports:
1910 # change dest based on port number
1911 mac_dst = '00:12:34:56:78:%02X' % out_port
1912 for in_port in ports:
1913 if in_port == out_port:
1914 continue
1915 pkt = str( simple_tcp_packet( eth_dst=mac_dst ) )
1916 self.dataplane.send( in_port, pkt )
1917 for ofport in ports:
1918 if ofport in [ out_port ]:
1919 verify_packet( self, pkt, ofport )
1920 else:
1921 verify_no_packet( self, pkt, ofport )
1922 verify_no_other_packets( self )
1923 finally:
1924 delete_all_flows( self.controller )
Pierf49f79b2016-08-25 15:12:04 -07001925 delete_groups( self.controller, groups )
Pier8b223022016-08-19 22:47:49 -07001926 delete_all_groups( self.controller )
1927