blob: ef5c598ec5c031402787bc3dd3a4fbdb4cd2e007 [file] [log] [blame]
Flavio Castro05d20bc2015-11-16 15:06:14 -05001"""
Flavio Castro423df652016-05-17 20:14:08 -04002Check README file
Flavio Castro05d20bc2015-11-16 15:06:14 -05003"""
Flavio Castro1c9b1252016-02-04 18:42:58 -05004import Queue
Flavio Castro05d20bc2015-11-16 15:06:14 -05005
Flavio Castro05d20bc2015-11-16 15:06:14 -05006from oftest import config
Flavio Castro67d8bd52016-02-03 14:22:14 -05007import inspect
Flavio Castro167f5bd2015-12-02 19:33:53 -05008import logging
9import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050010import ofp
11from oftest.testutils import *
12from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050013
Flavio Castro1c9b1252016-02-04 18:42:58 -050014
Flavio Castroa7162bb2016-07-25 17:30:30 -070015class PacketInUDP( base_tests.SimpleDataPlane ):
Flavio Castro6d498522015-12-15 14:05:04 -050016 """
Flavio Castro1c9b1252016-02-04 18:42:58 -050017 Verify a ACL rule that matches on IP_PROTO 2 will not match a UDP packet.
18 Next it verify a rule that matches on IP_PROTO 17 WILL match a UDP packet.
Flavio Castro6d498522015-12-15 14:05:04 -050019 """
20
Flavio Castroa7162bb2016-07-25 17:30:30 -070021 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -070022 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -070023 parsed_vlan_pkt = simple_udp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
24 vlan_pkt = str( parsed_vlan_pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -070025 # create match
Flavio Castroa7162bb2016-07-25 17:30:30 -070026 match = ofp.match( )
27 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
28 match.oxm_list.append( ofp.oxm.ip_proto( 2 ) )
29 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
30 ofp.instruction.apply_actions( actions=[
31 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
32 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
33 logging.info( "Inserting packet in flow to controller" )
34 self.controller.message_send( request )
Flavio Castro1c9b1252016-02-04 18:42:58 -050035
Flavio Castroa7162bb2016-07-25 17:30:30 -070036 for of_port in config[ "port_map" ].keys( ):
37 logging.info( "PacketInMiss test, port %d", of_port )
38 self.dataplane.send( of_port, vlan_pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -050039
Flavio Castroa7162bb2016-07-25 17:30:30 -070040 verify_no_packet_in( self, vlan_pkt, of_port )
41 delete_all_flows( self.controller )
42 do_barrier( self.controller )
Flavio Castro6d498522015-12-15 14:05:04 -050043
Flavio Castroa7162bb2016-07-25 17:30:30 -070044 match = ofp.match( )
45 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
46 match.oxm_list.append( ofp.oxm.ip_proto( 17 ) )
47 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
48 ofp.instruction.apply_actions( actions=[
49 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
50 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
51 logging.info( "Inserting packet in flow to controller" )
52 self.controller.message_send( request )
53 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -050054
Flavio Castroa7162bb2016-07-25 17:30:30 -070055 for of_port in config[ "port_map" ].keys( ):
56 logging.info( "PacketInMiss test, port %d", of_port )
57 self.dataplane.send( of_port, vlan_pkt )
Flavio Castro6d498522015-12-15 14:05:04 -050058
Flavio Castroa7162bb2016-07-25 17:30:30 -070059 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_ACTION )
Flavio Castro6d498522015-12-15 14:05:04 -050060
Flavio Castroa7162bb2016-07-25 17:30:30 -070061 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -070062 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -070063 delete_all_flows( self.controller )
64 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -050065
Flavio Castroaf2b4502016-02-02 17:41:32 -050066
Flavio Castro67d8bd52016-02-03 14:22:14 -050067@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -070068class ArpNL2( base_tests.SimpleDataPlane ):
69 def runTest( self ):
70 delete_all_flows( self.controller )
71 delete_all_groups( self.controller )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050072
Flavio Castroa7162bb2016-07-25 17:30:30 -070073 ports = sorted( config[ "port_map" ].keys( ) )
74 match = ofp.match( )
75 match.oxm_list.append( ofp.oxm.eth_type( 0x0806 ) )
76 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
77 ofp.instruction.apply_actions( actions=[
78 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
79 buffer_id=ofp.OFP_NO_BUFFER, priority=40000 )
80 self.controller.message_send( request )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050081 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -070082 add_one_l2_interface_group( self.controller, port, 1, False, False )
83 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_BOTH )
84 group_id = encode_l2_interface_group_id( 1, port )
85 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], 1, group_id, True )
86 do_barrier( self.controller )
87 parsed_arp_pkt = simple_arp_packet( )
88 arp_pkt = str( parsed_arp_pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050089
90 for out_port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -070091 self.dataplane.send( out_port, arp_pkt )
92 verify_packet_in( self, arp_pkt, out_port, ofp.OFPR_ACTION )
Flavio Castro7fb6ca92015-12-16 15:50:14 -050093 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -050094 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -050095 for in_port in ports:
96 if in_port == out_port:
97 continue
98 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -050099 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700100 parsed_pkt = simple_tcp_packet( eth_dst=mac_dst, eth_src=mac_src )
101 pkt = str( parsed_pkt )
102 self.dataplane.send( in_port, pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500103
104 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700105 if ofport in [ out_port ]:
106 verify_packet( self, pkt, ofport )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500107 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700108 verify_no_packet( self, pkt, ofport )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500109
Flavio Castroa7162bb2016-07-25 17:30:30 -0700110 verify_no_other_packets( self )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500111
Flavio Castroa7162bb2016-07-25 17:30:30 -0700112class PacketInArp( base_tests.SimpleDataPlane ):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500113 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500114 Verify an ACL rule matching on ethertyper 0x806 will result in a packet-in
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500115 """
116
Flavio Castroa7162bb2016-07-25 17:30:30 -0700117 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700118 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700119 parsed_arp_pkt = simple_arp_packet( )
120 arp_pkt = str( parsed_arp_pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700121 # create match
Flavio Castroa7162bb2016-07-25 17:30:30 -0700122 match = ofp.match( )
123 match.oxm_list.append( ofp.oxm.eth_type( 0x0806 ) )
124 request = ofp.message.flow_add( table_id=60, cookie=42, match=match, instructions=[
125 ofp.instruction.apply_actions( actions=[
126 ofp.action.output( port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER ) ] ), ],
127 buffer_id=ofp.OFP_NO_BUFFER, priority=1 )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500128
Flavio Castroa7162bb2016-07-25 17:30:30 -0700129 logging.info( "Inserting packet in flow to controller" )
130 self.controller.message_send( request )
131 do_barrier( self.controller )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500132
Flavio Castroa7162bb2016-07-25 17:30:30 -0700133 for of_port in config[ "port_map" ].keys( ):
134 logging.info( "PacketInMiss test, port %d", of_port )
135 self.dataplane.send( of_port, arp_pkt )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500136
Flavio Castroa7162bb2016-07-25 17:30:30 -0700137 verify_packet_in( self, arp_pkt, of_port, ofp.OFPR_ACTION )
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500138
Flavio Castroa7162bb2016-07-25 17:30:30 -0700139 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700140 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700141 delete_all_flows( self.controller )
142 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500143
Flavio Castroa7162bb2016-07-25 17:30:30 -0700144
145class PacketInIPTable( base_tests.SimpleDataPlane ):
Flavio Castro91d1a552016-05-17 16:59:44 -0700146 """
147 Test packet in function on IPTABLE
148 Send a packet to each dataplane port and verify that a packet
149 in message is received from the controller for each
150 #todo verify you stop receiving after adding rule
151 """
152
Flavio Castroa7162bb2016-07-25 17:30:30 -0700153 def runTest( self ):
154 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700155 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700156 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
157 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
158 dip = 0xc0a80001
159 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro91d1a552016-05-17 16:59:44 -0700160
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700161 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700162 # add l2 interface group
163 vlan_id = port
164 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=True,
165 send_barrier=False )
166 dst_mac[ 5 ] = vlan_id
167 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
168 src_mac=intf_src_mac, dst_mac=dst_mac )
169 # add vlan flow table
170 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
171 # add termination flow
172 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
173 # add unicast routing flow
174 dst_ip = dip + (vlan_id << 8)
175 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id,
176 send_ctrl=True )
177 Groups.put( l3_msg.group_id )
Flavio Castro91d1a552016-05-17 16:59:44 -0700178
Flavio Castroa7162bb2016-07-25 17:30:30 -0700179 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -0700180
Flavio Castroa7162bb2016-07-25 17:30:30 -0700181 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700182 for in_port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700183 mac_src = '00:00:00:22:22:%02X' % in_port
184 ip_src = '192.168.%02d.1' % in_port
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700185 for out_port in ports:
186 if in_port == out_port:
187 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700188 ip_dst = '192.168.%02d.1' % out_port
189 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
190 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
191 pkt = str( parsed_pkt )
192 self.dataplane.send( in_port, pkt )
193 verify_packet_in( self, pkt, in_port, ofp.OFPR_ACTION )
194 # verify_no_other_packets(self)
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700195 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700196 delete_all_flows( self.controller )
197 delete_groups( self.controller, Groups )
198 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -0700199
Flavio Castroa7162bb2016-07-25 17:30:30 -0700200
201class L2FloodQinQ( base_tests.SimpleDataPlane ):
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500202 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500203 Verify a tagged frame can be flooded based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500204 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500205
Flavio Castroa7162bb2016-07-25 17:30:30 -0700206 def runTest( self ):
207 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700208 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700209 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700210 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500211
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700212 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700213 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
214 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
215 Groups.put( L2gid )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500216
Flavio Castroa7162bb2016-07-25 17:30:30 -0700217 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
218 Groups.put( msg.group_id )
219 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
220 do_barrier( self.controller )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500221
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700222 # verify flood
223 for ofport in ports:
224 # change dest based on port number
225 mac_src = '00:12:34:56:78:%02X' % ofport
Flavio Castroa7162bb2016-07-25 17:30:30 -0700226 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
227 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10,
228 eth_dst='00:12:34:56:78:9a', eth_src=mac_src )
229 pkt = str( parsed_pkt )
230 self.dataplane.send( ofport, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700231 # self won't rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700232 verify_no_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700233 # others will rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700234 tmp_ports = list( ports )
235 tmp_ports.remove( ofport )
236 verify_packets( self, pkt, tmp_ports )
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500237
Flavio Castroa7162bb2016-07-25 17:30:30 -0700238 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700239 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700240 delete_all_flows( self.controller )
241 delete_groups( self.controller, Groups )
242 delete_all_groups( self.controller )
243
Flavio Castro1c9b1252016-02-04 18:42:58 -0500244
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500245@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -0700246class L2FloodTagged( base_tests.SimpleDataPlane ):
Flavio Castro184cefe2015-11-19 20:52:49 -0500247 """
248 Test L2 flood to a vlan
249 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
Flavio Castro184cefe2015-11-19 20:52:49 -0500250 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500251
Flavio Castroa7162bb2016-07-25 17:30:30 -0700252 def runTest( self ):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500253 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700254 vlan_id = abs( hash( inspect.stack( )[ 0 ][ 3 ] ) ) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500255 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500256
Flavio Castroa7162bb2016-07-25 17:30:30 -0700257 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro34352e72015-12-07 20:01:51 -0500258
Flavio Castroa7162bb2016-07-25 17:30:30 -0700259 delete_all_flows( self.controller )
260 delete_all_groups( self.controller )
Flavio Castro184cefe2015-11-19 20:52:49 -0500261
Flavio Castro184cefe2015-11-19 20:52:49 -0500262 # Installing flows to avoid packet-in
263 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700264 add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
265 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
266 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
267 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
268 do_barrier( self.controller )
Flavio Castro184cefe2015-11-19 20:52:49 -0500269
Flavio Castro1c9b1252016-02-04 18:42:58 -0500270 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500271 for ofport in ports:
272 # change dest based on port number
Flavio Castroa7162bb2016-07-25 17:30:30 -0700273 pkt = str(
274 simple_tcp_packet( dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst='00:12:34:56:78:9a' ) )
275 self.dataplane.send( ofport, pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500276 # self won't rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700277 verify_no_packet( self, pkt, ofport )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500278 # others will rx packet
Flavio Castroa7162bb2016-07-25 17:30:30 -0700279 tmp_ports = list( ports )
280 tmp_ports.remove( ofport )
281 verify_packets( self, pkt, tmp_ports )
282 verify_no_other_packets( self )
Flavio Castroaabb5792015-11-18 19:03:50 -0500283
Flavio Castro1c9b1252016-02-04 18:42:58 -0500284
Flavio Castroa7162bb2016-07-25 17:30:30 -0700285class L2UnicastTagged( base_tests.SimpleDataPlane ):
Flavio Castroaabb5792015-11-18 19:03:50 -0500286 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500287 Verify L2 forwarding works
Flavio Castroaabb5792015-11-18 19:03:50 -0500288 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500289
Flavio Castroa7162bb2016-07-25 17:30:30 -0700290 def runTest( self ):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700291
Flavio Castroa7162bb2016-07-25 17:30:30 -0700292 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700293 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700294 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700295 vlan_id = 1;
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700296 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700297 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
298 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
299 Groups.put( L2gid )
300 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], vlan_id, L2gid,
301 True )
302 do_barrier( self.controller )
Flavio Castro6efe1862015-11-18 16:28:06 -0500303
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700304 for out_port in ports:
305 # change dest based on port number
306 mac_dst = '00:12:34:56:78:%02X' % out_port
307 for in_port in ports:
308 if in_port == out_port:
309 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700310 pkt = str( simple_tcp_packet( dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst=mac_dst ) )
311 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700312 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700313 if ofport in [ out_port ]:
314 verify_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700315 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700316 verify_no_packet( self, pkt, ofport )
317 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700318 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700319 delete_all_flows( self.controller )
320 delete_groups( self.controller, Groups )
321 delete_all_groups( self.controller )
Flavio Castro6efe1862015-11-18 16:28:06 -0500322
Flavio Castroa7162bb2016-07-25 17:30:30 -0700323
324class Mtu1500( base_tests.SimpleDataPlane ):
325 def runTest( self ):
326 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700327 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700328 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700329 vlan_id = 18
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700330 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700331 L2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
332 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
333 Groups.put( L2gid )
334 add_bridge_flow( self.controller, [ 0x00, 0x12, 0x34, 0x56, 0x78, port ], vlan_id, L2gid,
335 True )
336 do_barrier( self.controller )
Flavio Castrob6773032015-11-19 22:49:24 -0500337
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700338 for out_port in ports:
339 # change dest based on port number
340 mac_dst = '00:12:34:56:78:%02X' % out_port
341 for in_port in ports:
342 if in_port == out_port:
343 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -0700344 pkt = str( simple_tcp_packet( pktlen=1500, dl_vlan_enable=True, vlan_vid=vlan_id,
345 eth_dst=mac_dst ) )
346 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700347 for ofport in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700348 if ofport in [ out_port ]:
349 verify_packet( self, pkt, ofport )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700350 else:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700351 verify_no_packet( self, pkt, ofport )
352 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700353 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700354 delete_all_flows( self.controller )
355 delete_groups( self.controller, Groups )
356 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500357
Flavio Castroa7162bb2016-07-25 17:30:30 -0700358
359class _32UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500360 """
361 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
362 """
363
Flavio Castroa7162bb2016-07-25 17:30:30 -0700364 def runTest( self ):
365 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700366 try:
367 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -0700368 if len( config[ "port_map" ] ) < 2:
369 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700370 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500371
Flavio Castroa7162bb2016-07-25 17:30:30 -0700372 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
373 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700374 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700375 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700376 for port in ports:
377 # add l2 interface group
378 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -0700379 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
380 is_tagged=True, send_barrier=False )
381 dst_mac[ 5 ] = vlan_id
382 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
383 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700384 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700385 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700386 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700387 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700388 # add unicast routing flow
389 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700390 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
391 Groups.put( l2gid )
392 Groups.put( l3_msg.group_id )
393 do_barrier( self.controller )
Flavio Castrod8f8af22015-12-02 18:19:26 -0500394
Flavio Castroa7162bb2016-07-25 17:30:30 -0700395 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700396 for in_port in ports:
397 mac_src = '00:00:00:22:32:%02X' % (test_id + in_port)
398 ip_src = '192.168.%02d.1' % (test_id + in_port)
399 for out_port in ports:
400 if in_port == out_port:
401 continue
402 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700403 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
404 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
405 ip_src=ip_src, ip_dst=ip_dst )
406 pkt = str( parsed_pkt )
407 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700408 # build expected packet
409 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700410 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
411 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
412 ip_src=ip_src, ip_dst=ip_dst )
413 pkt = str( exp_pkt )
414 verify_packet( self, pkt, out_port )
415 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700416 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700417 delete_all_flows( self.controller )
418 delete_groups( self.controller, Groups )
419 delete_all_groups( self.controller )
Flavio Castro05d20bc2015-11-16 15:06:14 -0500420
Flavio Castroa7162bb2016-07-25 17:30:30 -0700421
422class _32VPN( base_tests.SimpleDataPlane ):
Flavio Castro2262fd42016-02-04 19:03:36 -0500423 """
424 Insert IP packet
425 Receive MPLS packet
426 """
427
Flavio Castroa7162bb2016-07-25 17:30:30 -0700428 def runTest( self ):
429 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700430 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700431 if len( config[ "port_map" ] ) < 2:
432 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700433 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500434
Flavio Castroa7162bb2016-07-25 17:30:30 -0700435 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
436 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700437 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700438 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700439 for port in ports:
440 # add l2 interface group
441 id = port
442 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700443 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
444 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700445 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700446 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
447 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700448 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700449 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
450 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
451 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700452 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castroa7162bb2016-07-25 17:30:30 -0700453 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700454 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700455 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=2,
456 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700457 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700458 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700459 # add routing flow
460 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700461 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, mpls_label_gid, vrf=2 )
462 Groups._put( l2_gid )
463 Groups._put( mpls_gid )
464 Groups._put( mpls_label_gid )
465 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500466
Flavio Castroa7162bb2016-07-25 17:30:30 -0700467 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700468 for in_port in ports:
469 ip_src = '192.168.%02d.1' % (in_port)
470 for out_port in ports:
471 if in_port == out_port:
472 continue
473 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700474 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
475 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
476 pkt = str( parsed_pkt )
477 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700478 # build expect packet
479 mac_dst = '00:00:00:22:22:%02X' % (out_port)
480 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700481 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
482 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
483 label=[ label ] )
484 pkt = str( exp_pkt )
485 verify_packet( self, pkt, out_port )
486 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700487 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700488 delete_all_flows( self.controller )
489 delete_groups( self.controller, Groups )
490 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500491
Flavio Castroa7162bb2016-07-25 17:30:30 -0700492
493class _32EcmpVpn( base_tests.SimpleDataPlane ):
Flavio Castro2262fd42016-02-04 19:03:36 -0500494 """
495 Insert IP packet
496 Receive MPLS packet
497 """
498
Flavio Castroa7162bb2016-07-25 17:30:30 -0700499 def runTest( self ):
500 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700501 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700502 if len( config[ "port_map" ] ) < 2:
503 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700504 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500505
Flavio Castroa7162bb2016-07-25 17:30:30 -0700506 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
507 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700508 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700509 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700510 for port in ports:
511 # add l2 interface group
512 id = port
513 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700514 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
515 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700516 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700517 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
518 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700519 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700520 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
521 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
522 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
523 ecmp_msg = add_l3_ecmp_group( self.controller, vlan_id, [ mpls_label_gid ] )
524 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700525 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700526 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
527 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700528 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700529 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700530 # add routing flow
531 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700532 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, ecmp_msg.group_id )
533 Groups._put( l2_gid )
534 Groups._put( mpls_gid )
535 Groups._put( mpls_label_gid )
536 Groups._put( ecmp_msg.group_id )
537 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500538
Flavio Castroa7162bb2016-07-25 17:30:30 -0700539 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700540 for in_port in ports:
541 ip_src = '192.168.%02d.1' % (in_port)
542 for out_port in ports:
543 if in_port == out_port:
544 continue
545 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700546 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
547 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
548 pkt = str( parsed_pkt )
549 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700550 # build expect packet
551 mac_dst = '00:00:00:22:22:%02X' % (out_port)
552 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700553 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
554 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
555 label=[ label ] )
556 pkt = str( exp_pkt )
557 verify_packet( self, pkt, out_port )
558 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700559 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700560 delete_all_flows( self.controller )
561 delete_groups( self.controller, Groups )
562 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500563
Flavio Castroa7162bb2016-07-25 17:30:30 -0700564
565class _32ECMPL3( base_tests.SimpleDataPlane ):
Flavio Castro2262fd42016-02-04 19:03:36 -0500566 """
Flavio Castrod80fbc32016-07-25 15:54:26 -0700567 Insert IP packet
568 Receive IP packet
Flavio Castro2262fd42016-02-04 19:03:36 -0500569 """
570
Flavio Castroa7162bb2016-07-25 17:30:30 -0700571 def runTest( self ):
572 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700573 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700574 if len( config[ "port_map" ] ) < 2:
575 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700576 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500577
Flavio Castroa7162bb2016-07-25 17:30:30 -0700578 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
579 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700580 dip = 0xc0a80001
581 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700582 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700583 for port in ports:
584 vlan_id = port
585 id = port
586 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700587 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
588 is_tagged=True, send_barrier=False )
589 dst_mac[ 5 ] = vlan_id
590 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
591 src_mac=intf_src_mac, dst_mac=dst_mac )
592 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700593 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700594 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700595 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700596 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700597 # add unicast routing flow
598 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700599 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, ecmp_msg.group_id )
600 Groups._put( l2_gid )
601 Groups._put( l3_msg.group_id )
602 Groups._put( ecmp_msg.group_id )
603 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500604
Flavio Castroa7162bb2016-07-25 17:30:30 -0700605 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700606 for in_port in ports:
607 mac_src = '00:00:00:22:22:%02X' % in_port
608 ip_src = '192.168.%02d.1' % in_port
609 for out_port in ports:
610 if in_port == out_port:
611 continue
612 ip_dst = '192.168.%02d.1' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700613 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
614 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
615 pkt = str( parsed_pkt )
616 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700617 # build expected packet
618 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700619 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
620 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
621 pkt = str( exp_pkt )
622 verify_packet( self, pkt, out_port )
623 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700624 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700625 delete_all_flows( self.controller )
626 delete_groups( self.controller, Groups )
627 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500628
Flavio Castroa7162bb2016-07-25 17:30:30 -0700629
630class _24VPN( base_tests.SimpleDataPlane ):
Flavio Castro2262fd42016-02-04 19:03:36 -0500631 """
632 Insert IP packet
633 Receive MPLS packet
634 """
635
Flavio Castroa7162bb2016-07-25 17:30:30 -0700636 def runTest( self ):
637 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700638 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700639 if len( config[ "port_map" ] ) < 2:
640 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700641 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500642
Flavio Castroa7162bb2016-07-25 17:30:30 -0700643 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
644 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700645 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700646 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700647 for port in ports:
648 # add l2 interface group
649 id = port
650 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700651 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
652 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700653 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700654 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
655 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700656 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700657 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
658 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
659 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700660 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castroa7162bb2016-07-25 17:30:30 -0700661 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700662 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700663 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
664 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700665 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700666 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700667 # add routing flow
668 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700669 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid )
670 Groups._put( l2_gid )
671 Groups._put( mpls_gid )
672 Groups._put( mpls_label_gid )
673 do_barrier( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500674
Flavio Castroa7162bb2016-07-25 17:30:30 -0700675 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700676 for in_port in ports:
677 ip_src = '192.168.%02d.1' % (in_port)
678 for out_port in ports:
679 if in_port == out_port:
680 continue
681 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700682 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
683 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
684 pkt = str( parsed_pkt )
685 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700686 # build expect packet
687 mac_dst = '00:00:00:22:22:%02X' % (out_port)
688 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700689 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
690 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
691 label=[ label ] )
692 pkt = str( exp_pkt )
693 verify_packet( self, pkt, out_port )
694 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700695 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700696 delete_all_flows( self.controller )
697 delete_groups( self.controller, Groups )
698 delete_all_groups( self.controller )
Flavio Castro2262fd42016-02-04 19:03:36 -0500699
Flavio Castroa7162bb2016-07-25 17:30:30 -0700700
701class _24EcmpVpn( base_tests.SimpleDataPlane ):
Flavio Castrod8f8af22015-12-02 18:19:26 -0500702 """
703 Insert IP packet
704 Receive MPLS packet
705 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500706
Flavio Castroa7162bb2016-07-25 17:30:30 -0700707 def runTest( self ):
708 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700709 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700710 if len( config[ "port_map" ] ) < 2:
711 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700712 return
Flavio Castroa7162bb2016-07-25 17:30:30 -0700713 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
714 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700715 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700716 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700717 for port in ports:
718 # add l2 interface group
719 id = port
720 vlan_id = id
Flavio Castroa7162bb2016-07-25 17:30:30 -0700721 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, True )
722 dst_mac[ 5 ] = vlan_id
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700723 # add MPLS interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700724 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
725 vlan_id, id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700726 # add MPLS L3 VPN group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700727 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
728 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=id, ref_gid=mpls_gid,
729 push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32 )
730 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ mpls_label_gid ] )
731 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700732 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700733 add_one_vlan_table_flow( self.controller, port, vlan_id, vrf=0,
734 flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700735 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700736 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700737 # add routing flow
738 dst_ip = dip + (vlan_id << 8)
739 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700740 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id,
741 vrf=0 )
742 Groups._put( l2_gid )
743 Groups._put( mpls_gid )
744 Groups._put( mpls_label_gid )
745 Groups._put( ecmp_msg.group_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700746
Flavio Castroa7162bb2016-07-25 17:30:30 -0700747 do_barrier( self.controller )
Flavio Castro80730822015-12-11 15:38:47 -0500748
Flavio Castroa7162bb2016-07-25 17:30:30 -0700749 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700750 for in_port in ports:
751 mac_src = '00:00:00:22:22:%02X' % (in_port)
752 ip_src = '192.168.%02d.1' % (in_port)
753 for out_port in ports:
754 if in_port == out_port:
755 continue
756 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700757 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
758 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
759 pkt = str( parsed_pkt )
760 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700761 # build expect packet
762 mac_dst = '00:00:00:22:22:%02X' % out_port
763 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700764 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port), ip_ttl=63,
765 ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac,
766 label=[ label ] )
767 pkt = str( exp_pkt )
768 verify_packet( self, pkt, out_port )
769 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700770 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700771 delete_all_flows( self.controller )
772 delete_groups( self.controller, Groups )
773 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500774
Flavio Castroa7162bb2016-07-25 17:30:30 -0700775
776class FloodGroupMod( base_tests.SimpleDataPlane ):
777 """
778 Modify referenced group test
779 """
780
781 def runTest( self ):
782 Groups = Queue.LifoQueue( )
783 try:
784 ports = sorted( config[ "port_map" ].keys( ) )
785 vlan_id = 1
786
787 for port in ports:
788 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
789 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
790 Groups.put( L2gid )
791
792 msg = add_l2_flood_group( self.controller, ports, vlan_id, vlan_id )
793 Groups.put( msg.group_id )
794 add_bridge_flow( self.controller, None, vlan_id, msg.group_id, True )
795 do_barrier( self.controller )
796 # verify flood
797 for ofport in ports:
798 # change dest based on port number
799 mac_src = '00:12:34:56:78:%02X' % ofport
800 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
801 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10,
802 eth_dst='00:12:34:56:78:9a', eth_src=mac_src )
803 pkt = str( parsed_pkt )
804 self.dataplane.send( ofport, pkt )
805 # self won't rx packet
806 verify_no_packet( self, pkt, ofport )
807 # others will rx packet
808 tmp_ports = list( ports )
809 tmp_ports.remove( ofport )
810 verify_packets( self, pkt, tmp_ports )
811 verify_no_other_packets( self )
812 msg = mod_l2_flood_group( self.controller, [ ports[ 0 ] ], vlan_id, vlan_id )
813 mac_src = '00:12:34:56:78:%02X' % ports[ 1 ]
814 parsed_pkt = simple_tcp_packet_two_vlan( pktlen=108, out_dl_vlan_enable=True,
815 out_vlan_vid=vlan_id, in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a',
816 eth_src=mac_src )
817 pkt = str( parsed_pkt )
818 self.dataplane.send( ports[ 1 ], pkt )
819 verify_packets( self, pkt, [ ports[ 0 ] ] )
820 finally:
821 delete_all_flows( self.controller )
822 delete_groups( self.controller, Groups )
823 delete_all_groups( self.controller )
824
825
826class _24ECMPL3( base_tests.SimpleDataPlane ):
Flavio Castro80730822015-12-11 15:38:47 -0500827 """
Flavio Castrod80fbc32016-07-25 15:54:26 -0700828 Insert IP packet
829 Receive IP packet
Flavio Castro80730822015-12-11 15:38:47 -0500830 """
Flavio Castro80730822015-12-11 15:38:47 -0500831
Flavio Castroa7162bb2016-07-25 17:30:30 -0700832 def runTest( self ):
833 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700834 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700835 if len( config[ "port_map" ] ) < 2:
836 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700837 return
Flavio Castro80730822015-12-11 15:38:47 -0500838
Flavio Castroa7162bb2016-07-25 17:30:30 -0700839 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
840 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700841 dip = 0xc0a80001
842 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castroa7162bb2016-07-25 17:30:30 -0700843 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700844 for port in ports:
845 vlan_id = port
846 id = port
847 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700848 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
849 is_tagged=True, send_barrier=False )
850 dst_mac[ 5 ] = vlan_id
851 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
852 src_mac=intf_src_mac, dst_mac=dst_mac )
853 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700854 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700855 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700856 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700857 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700858 # add unicast routing flow
859 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700860 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
861 Groups._put( l2_gid )
862 Groups._put( l3_msg.group_id )
863 Groups._put( ecmp_msg.group_id )
864 do_barrier( self.controller )
Flavio Castro72a45d52015-12-02 16:37:05 -0500865
Flavio Castroa7162bb2016-07-25 17:30:30 -0700866 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700867 for in_port in ports:
868 mac_src = '00:00:00:22:22:%02X' % in_port
869 ip_src = '192.168.%02d.1' % in_port
870 for out_port in ports:
871 if in_port == out_port:
872 continue
873 ip_dst = '192.168.%02d.1' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700874 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
875 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
876 pkt = str( parsed_pkt )
877 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700878 # build expected packet
879 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700880 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
881 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
882 pkt = str( exp_pkt )
883 verify_packet( self, pkt, out_port )
884 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700885 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700886 delete_all_flows( self.controller )
887 delete_groups( self.controller, Groups )
888 delete_all_groups( self.controller )
889
Flavio Castro1c9b1252016-02-04 18:42:58 -0500890
Flavio Castroaba28ff2016-02-03 16:47:48 -0500891@disabled
Flavio Castroa7162bb2016-07-25 17:30:30 -0700892class MPLSBUG( base_tests.SimpleDataPlane ):
893 def runTest( self ):
894 if len( config[ "port_map" ] ) < 2:
895 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro80730822015-12-11 15:38:47 -0500896 return
Flavio Castroa7162bb2016-07-25 17:30:30 -0700897 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
898 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro1c9b1252016-02-04 18:42:58 -0500899 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -0700900 Groups = Queue.LifoQueue( )
901 ports = config[ "port_map" ].keys( )
Flavio Castro80730822015-12-11 15:38:47 -0500902 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500903 # add l2 interface group
904 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700905 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
906 dst_mac[ 5 ] = vlan_id
Flavio Castro1c9b1252016-02-04 18:42:58 -0500907 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700908 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
909 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500910 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -0700911 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500912 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700913 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500914 # add mpls flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700915 add_mpls_flow( self.controller, l3_msg.group_id, port )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500916 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -0700917 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500918 # add unicast routing flow
919 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700920 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
921 Groups._put( l2_gid )
922 Groups._put( l3_msg.group_id )
923 do_barrier( self.controller )
Flavio Castro80730822015-12-11 15:38:47 -0500924
Flavio Castroa7162bb2016-07-25 17:30:30 -0700925 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro80730822015-12-11 15:38:47 -0500926 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500927 mac_src = '00:00:00:22:22:%02X' % in_port
928 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -0500929 for out_port in ports:
930 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500931 continue
932 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500933 switch_mac = "00:00:00:cc:cc:cc"
934 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -0700935 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
936 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[ label ] )
937 pkt = str( parsed_pkt )
938 self.dataplane.send( in_port, pkt )
Flavio Castro80730822015-12-11 15:38:47 -0500939
Flavio Castro1c9b1252016-02-04 18:42:58 -0500940 # build expect packet
941 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700942 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
943 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
944 pkt = str( exp_pkt )
945 verify_packet( self, pkt, out_port )
946 verify_no_other_packets( self )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500947
Flavio Castroa7162bb2016-07-25 17:30:30 -0700948 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
949 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
950 pkt = str( parsed_pkt )
951 self.dataplane.send( in_port, pkt )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500952 # build expected packet
953 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castroa7162bb2016-07-25 17:30:30 -0700954 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
955 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
956 pkt = str( exp_pkt )
957 verify_packet( self, pkt, out_port )
958 verify_no_other_packets( self )
959 delete_all_flows( self.controller )
960 delete_groups( self.controller, Groups )
Flavio Castro1c9b1252016-02-04 18:42:58 -0500961
Flavio Castroa7162bb2016-07-25 17:30:30 -0700962
963class L3McastToL2( base_tests.SimpleDataPlane ):
castroflaviocc403a92015-12-15 14:04:19 -0500964 """
Flavio Castro12296312015-12-15 17:48:26 -0500965 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -0500966 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500967
Flavio Castroa7162bb2016-07-25 17:30:30 -0700968 def runTest( self ):
castroflaviocc403a92015-12-15 14:04:19 -0500969 """
970 port1 (vlan 300)-> All Ports (vlan 300)
971 """
Flavio Castroa7162bb2016-07-25 17:30:30 -0700972 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700973 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -0700974 if len( config[ "port_map" ] ) < 3:
975 logging.info( "Port count less than 3, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700976 assert (False)
977 return
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700978 vlan_id = 300
Flavio Castroa7162bb2016-07-25 17:30:30 -0700979 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
980 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
981 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
982 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
983 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
984 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700985 src_ip = 0xc0a80101
986 src_ip_str = "192.168.1.1"
987 dst_ip = 0xe0010101
988 dst_ip_str = "224.1.1.1"
castroflaviocc403a92015-12-15 14:04:19 -0500989
Flavio Castroa7162bb2016-07-25 17:30:30 -0700990 port1 = config[ "port_map" ].keys( )[ 0 ]
991 port2 = config[ "port_map" ].keys( )[ 1 ]
castroflaviocc403a92015-12-15 14:04:19 -0500992
Flavio Castroa7162bb2016-07-25 17:30:30 -0700993 switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ]
castroflaviocc403a92015-12-15 14:04:19 -0500994
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700995 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -0700996 l2_intf_group_list = [ ]
997 for port in config[ "port_map" ].keys( ):
998 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700999 if port == port2:
1000 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -07001001 l2_intf_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1002 is_tagged=True, send_barrier=False )
1003 l2_intf_group_list.append( l2_intf_gid )
1004 Groups.put( l2_intf_gid )
castroflaviocc403a92015-12-15 14:04:19 -05001005
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001006 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001007 add_termination_flow( self.controller, port1, 0x0800, switch_mac, vlan_id )
castroflaviocc403a92015-12-15 14:04:19 -05001008
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001009 # add l3 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001010 mcat_group_msg = add_l3_mcast_group( self.controller, vlan_id, 2, l2_intf_group_list )
1011 add_mcast4_routing_flow( self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id )
1012 Groups._put( mcat_group_msg.group_id )
castroflaviocc403a92015-12-15 14:04:19 -05001013
Flavio Castroa7162bb2016-07-25 17:30:30 -07001014 parsed_pkt = simple_udp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=vlan_id,
1015 eth_dst=dst_mac_str, eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str,
1016 ip_dst=dst_ip_str )
1017 pkt = str( parsed_pkt )
1018 self.dataplane.send( port1, pkt )
1019 for port in config[ "port_map" ].keys( ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001020 if port == port2 or port == port1:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001021 verify_no_packet( self, pkt, port )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001022 continue
Flavio Castroa7162bb2016-07-25 17:30:30 -07001023 verify_packet( self, pkt, port )
1024 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001025 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001026 delete_all_flows( self.controller )
1027 delete_groups( self.controller, Groups )
1028 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001029
Flavio Castroa7162bb2016-07-25 17:30:30 -07001030
1031class L3McastToL3( base_tests.SimpleDataPlane ):
Flavio Castro12296312015-12-15 17:48:26 -05001032 """
1033 Mcast routing
1034 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001035
Flavio Castroa7162bb2016-07-25 17:30:30 -07001036 def runTest( self ):
Flavio Castro12296312015-12-15 17:48:26 -05001037 """
1038 port1 (vlan 1)-> port 2 (vlan 2)
1039 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001040 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001041 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001042 if len( config[ "port_map" ] ) < 3:
1043 logging.info( "Port count less than 3, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001044 assert (False)
1045 return
Flavio Castro12296312015-12-15 17:48:26 -05001046
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001047 vlan_id = 1
1048 port2_out_vlan = 2
1049 port3_out_vlan = 3
1050 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
Flavio Castroa7162bb2016-07-25 17:30:30 -07001051 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1052 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1053 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
1054 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
1055 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
1056 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001057 src_ip = 0xc0a80101
1058 src_ip_str = "192.168.1.1"
1059 dst_ip = 0xe0010101
1060 dst_ip_str = "224.1.1.1"
Flavio Castro12296312015-12-15 17:48:26 -05001061
Flavio Castroa7162bb2016-07-25 17:30:30 -07001062 port1 = config[ "port_map" ].keys( )[ 0 ]
1063 port2 = config[ "port_map" ].keys( )[ 1 ]
1064 port3 = config[ "port_map" ].keys( )[ 2 ]
Flavio Castro12296312015-12-15 17:48:26 -05001065
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001066 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001067 for port in config[ "port_map" ].keys( ):
1068 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1069 is_tagged=False, send_barrier=False )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001070 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001071 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001072 vlan_id += 1
Flavio Castroa7162bb2016-07-25 17:30:30 -07001073 Groups._put( l2gid )
Flavio Castro12296312015-12-15 17:48:26 -05001074
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001075 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001076 add_termination_flow( self.controller, port1, 0x0800, [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ],
1077 vlan_id )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001078
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001079 # add l3 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001080 port2_ucast_msg = add_l3_interface_group( self.controller, port2, port2_out_vlan, 2,
1081 intf_src_mac )
1082 port3_ucast_msg = add_l3_interface_group( self.controller, port3, port3_out_vlan, 3,
1083 intf_src_mac )
1084 mcat_group_msg = add_l3_mcast_group( self.controller, in_vlan, 2,
1085 [ port2_ucast_msg.group_id, port3_ucast_msg.group_id ] )
1086 add_mcast4_routing_flow( self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id )
1087 Groups._put( port2_ucast_msg.group_id )
1088 Groups._put( port3_ucast_msg.group_id )
1089 Groups._put( mcat_group_msg.group_id )
1090 parsed_pkt = simple_udp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac_str,
1091 eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str, ip_dst=dst_ip_str )
1092 pkt = str( parsed_pkt )
1093 self.dataplane.send( port1, pkt )
1094 parsed_pkt = simple_udp_packet( pktlen=96, eth_dst=dst_mac_str, eth_src=intf_src_mac_str,
1095 ip_ttl=63, ip_src=src_ip_str, ip_dst=dst_ip_str )
1096 pkt = str( parsed_pkt )
1097 verify_packet( self, pkt, port2 )
1098 verify_packet( self, pkt, port3 )
1099 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001100 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001101 delete_all_flows( self.controller )
1102 delete_groups( self.controller, Groups )
1103 delete_all_groups( self.controller )
1104
Flavio Castroa7162bb2016-07-25 17:30:30 -07001105class _MplsFwd( base_tests.SimpleDataPlane ):
Flavio Castro12296312015-12-15 17:48:26 -05001106 """
Flavio Castrod80fbc32016-07-25 15:54:26 -07001107 Insert MPLS packet
Flavio Castro54947942016-02-03 16:05:20 -05001108 Receive MPLS packet
castroflavio30c6cc52016-01-07 15:19:42 -08001109 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001110
1111 def runTest( self ):
1112 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001113 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001114 if len( config[ "port_map" ] ) < 2:
1115 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001116 return
1117 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001118 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1119 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001120 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001121 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001122 for port in ports:
1123 # add l2 interface group
1124 id = port
1125 vlan_id = id
Flavio Castroa7162bb2016-07-25 17:30:30 -07001126 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
1127 dst_mac[ 5 ] = vlan_id
1128 mpls_gid, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1129 vlan_id, id )
1130 mpls_label_gid, mpls_label_msg = add_mpls_label_group( self.controller,
1131 subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL, index=id, ref_gid=mpls_gid,
1132 push_mpls_header=False, set_mpls_label=port, set_bos=1 )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001133 #ecmp_gid, ecmp_msg = add_mpls_forwarding_group( self.controller,
1134 # subtype=OFDPA_MPLS_GROUP_SUBTYPE_ECMP, index=id, ref_gids=[mpls_label_gid] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001135 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001136 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001137 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001138 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001139 #add_mpls_flow( self.controller, ecmp_gid, port, goto_table=29 )
1140 add_mpls_flow( self.controller, mpls_label_gid, port, goto_table=29 )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001141 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001142 Groups._put( l2_gid )
1143 Groups._put( mpls_gid )
1144 Groups._put( mpls_label_gid )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001145 Groups._put( ecmp_gid )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001146 do_barrier( self.controller )
castroflavio30c6cc52016-01-07 15:19:42 -08001147
Flavio Castroa7162bb2016-07-25 17:30:30 -07001148 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001149 for in_port in ports:
1150 ip_src = '192.168.%02d.1' % (in_port)
1151 for out_port in ports:
1152 if in_port == out_port:
1153 continue
1154 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castro54947942016-02-03 16:05:20 -05001155
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001156 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001157 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port),
1158 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1159 pkt = str( parsed_pkt )
1160 self.dataplane.send( in_port, pkt )
Flavio Castro54947942016-02-03 16:05:20 -05001161
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001162 # build expect packet
1163 mac_dst = '00:00:00:22:22:%02X' % (out_port)
1164 label = (out_port, 0, 1, 31)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001165 exp_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port),
1166 ip_src=ip_src, ip_dst=ip_dst, eth_src=switch_mac, eth_dst=mac_dst,
1167 label=[ label ] )
1168 pkt = str( exp_pkt )
1169 verify_packet( self, pkt, out_port )
1170 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001171 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001172 delete_all_flows( self.controller )
1173 delete_groups( self.controller, Groups )
1174 delete_all_groups( self.controller )
Flavio Castrob702a2f2016-04-10 22:01:48 -04001175
Flavio Castroa7162bb2016-07-25 17:30:30 -07001176
1177class _MplsTermination( base_tests.SimpleDataPlane ):
Flavio Castrob702a2f2016-04-10 22:01:48 -04001178 """
Flavio Castrod80fbc32016-07-25 15:54:26 -07001179 Insert MPLS packet
1180 Receive IP packet
Flavio Castrob702a2f2016-04-10 22:01:48 -04001181 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001182
1183 def runTest( self ):
1184 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001185 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001186 if len( config[ "port_map" ] ) < 2:
1187 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001188 return
1189 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001190 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1191 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001192 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001193 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001194 for port in ports:
1195 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001196 vlan_id, id, dst_mac[ 5 ] = port, port, port
1197 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001198 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001199 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1200 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001201 # add L3 ecmp group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001202 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001203 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001204 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001205 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001206 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
1207 # add_mpls_flow(self.controller, ecmp_msg.group_id, port)
1208 add_mpls_flow( self.controller, label=port )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001209 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001210 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id, 1 )
1211 Groups._put( l2_gid )
1212 Groups._put( l3_msg.group_id )
1213 Groups._put( ecmp_msg.group_id )
1214 do_barrier( self.controller )
Flavio Castrob702a2f2016-04-10 22:01:48 -04001215
Flavio Castroa7162bb2016-07-25 17:30:30 -07001216 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001217 for in_port in ports:
1218 ip_src = '192.168.%02d.1' % (in_port)
1219 for out_port in ports:
1220 if in_port == out_port:
1221 continue
1222 ip_dst = '192.168.%02d.1' % (out_port)
1223 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001224 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port),
1225 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1226 pkt = str( parsed_pkt )
1227 self.dataplane.send( in_port, pkt )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001228 # build expect packet
1229 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001230 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port),
1231 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
1232 pkt = str( exp_pkt )
1233 verify_packet( self, pkt, out_port )
1234 verify_no_other_packets( self )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001235 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001236 delete_all_flows( self.controller )
1237 delete_groups( self.controller, Groups )
1238 delete_all_groups( self.controller )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001239
Flavio Castroa7162bb2016-07-25 17:30:30 -07001240
1241class _MplsVpnFwd( base_tests.SimpleDataPlane ):
Flavio Castrod80fbc32016-07-25 15:54:26 -07001242 """
1243 Insert MPLS packet
1244 Receive IP packet
1245 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001246
1247 def runTest( self ):
1248 Groups = Queue.LifoQueue( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001249 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001250 if len( config[ "port_map" ] ) < 2:
1251 logging.info( "Port count less than 2, can't run this case" )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001252 return
1253 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001254 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1255 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castrod80fbc32016-07-25 15:54:26 -07001256 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
Flavio Castroa7162bb2016-07-25 17:30:30 -07001257 ports = config[ "port_map" ].keys( )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001258 for port in ports:
1259 # add l2 interface group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001260 vlan_id, id, dst_mac[ 5 ] = port, port, port
1261 l2_gid, l2_msg = add_one_l2_interface_group( self.controller, port, vlan_id, True, False )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001262 # add L3 Unicast group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001263 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1264 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001265 # add L3 ecmp group
Flavio Castroa7162bb2016-07-25 17:30:30 -07001266 ecmp_msg = add_l3_ecmp_group( self.controller, id, [ l3_msg.group_id ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001267 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001268 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001269 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001270 add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
1271 add_mpls_flow( self.controller, ecmp_msg.group_id, port )
1272 # add_mpls_flow(self.controller, label=port)
Flavio Castrod80fbc32016-07-25 15:54:26 -07001273 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001274 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
Flavio Castrod80fbc32016-07-25 15:54:26 -07001275 # ecmp_msg.group_id, 1)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001276 Groups._put( l2_gid )
1277 Groups._put( l3_msg.group_id )
1278 Groups._put( ecmp_msg.group_id )
1279 do_barrier( self.controller )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001280
Flavio Castroa7162bb2016-07-25 17:30:30 -07001281 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castrod80fbc32016-07-25 15:54:26 -07001282 for in_port in ports:
1283 ip_src = '192.168.%02d.1' % (in_port)
1284 for out_port in ports:
1285 if in_port == out_port:
1286 continue
1287 ip_dst = '192.168.%02d.1' % (out_port)
1288 label = (out_port, 0, 1, 32)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001289 parsed_pkt = mpls_packet( pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port),
1290 ip_src=ip_src, ip_dst=ip_dst, eth_dst=switch_mac, label=[ label ] )
1291 pkt = str( parsed_pkt )
1292 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001293 # build expect packet
1294 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001295 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port),
1296 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
1297 pkt = str( exp_pkt )
1298 verify_packet( self, pkt, out_port )
1299 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001300 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001301 delete_all_flows( self.controller )
1302 delete_groups( self.controller, Groups )
1303 delete_all_groups( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001304
Flavio Castroa7162bb2016-07-25 17:30:30 -07001305
1306class _24UcastTagged( base_tests.SimpleDataPlane ):
Flavio Castro1c9b1252016-02-04 18:42:58 -05001307 """
1308 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
1309 """
1310
Flavio Castroa7162bb2016-07-25 17:30:30 -07001311 def runTest( self ):
1312 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001313 try:
1314 test_id = 26
Flavio Castroa7162bb2016-07-25 17:30:30 -07001315 if len( config[ "port_map" ] ) < 2:
1316 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001317 return
Flavio Castroa7162bb2016-07-25 17:30:30 -07001318 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1319 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001320 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001321 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001322 for port in ports:
1323 # add l2 interface group
1324 vlan_id = port + test_id
Flavio Castroa7162bb2016-07-25 17:30:30 -07001325 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1326 is_tagged=True, send_barrier=False )
1327 dst_mac[ 5 ] = vlan_id
1328 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=vlan_id,
1329 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001330 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001331 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001332 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001333 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001334 # add unicast routing flow
1335 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001336 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id )
1337 Groups.put( l2gid )
1338 Groups.put( l3_msg.group_id )
1339 do_barrier( self.controller )
Flavio Castro1c9b1252016-02-04 18:42:58 -05001340
Flavio Castroa7162bb2016-07-25 17:30:30 -07001341 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001342 for in_port in ports:
1343 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1344 ip_src = '192.168.%02d.1' % (test_id + in_port)
1345 for out_port in ports:
1346 if in_port == out_port:
1347 continue
1348 ip_dst = '192.168.%02d.1' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001349 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1350 vlan_vid=(test_id + in_port), eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64,
1351 ip_src=ip_src, ip_dst=ip_dst )
1352 pkt = str( parsed_pkt )
1353 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001354 # build expected packet
1355 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001356 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True,
1357 vlan_vid=(test_id + out_port), eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
1358 ip_src=ip_src, ip_dst=ip_dst )
1359 pkt = str( exp_pkt )
1360 verify_packet( self, pkt, out_port )
1361 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001362 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001363 delete_all_flows( self.controller )
1364 delete_groups( self.controller, Groups )
1365 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001366
Flavio Castroa7162bb2016-07-25 17:30:30 -07001367
1368class _0Ucast( base_tests.SimpleDataPlane ):
Flavio Castro91d1a552016-05-17 16:59:44 -07001369 """
1370 Verify a IP forwarding works for a /0 rule to L3 Unicast Interface
1371 """
1372
Flavio Castroa7162bb2016-07-25 17:30:30 -07001373 def runTest( self ):
1374 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001375 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001376 if len( config[ "port_map" ] ) < 2:
1377 logging.info( "Port count less than 2, can't run this case" )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001378 return
Flavio Castro91d1a552016-05-17 16:59:44 -07001379
Flavio Castroa7162bb2016-07-25 17:30:30 -07001380 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1381 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001382 dip = 0xc0a80001
Flavio Castroa7162bb2016-07-25 17:30:30 -07001383 ports = config[ "port_map" ].keys( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001384 for port in ports:
1385 # add l2 interface group
1386 vlan_id = port
Flavio Castroa7162bb2016-07-25 17:30:30 -07001387 l2gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id + 1,
1388 is_tagged=True, send_barrier=False )
1389 dst_mac[ 5 ] = vlan_id
1390 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id + 1, id=vlan_id,
1391 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001392 # add vlan flow table
Flavio Castroa7162bb2016-07-25 17:30:30 -07001393 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001394 # add termination flow
Flavio Castroa7162bb2016-07-25 17:30:30 -07001395 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001396 # add unicast routing flow
1397 dst_ip = dip + (vlan_id << 8)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001398 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
1399 Groups.put( l2gid )
1400 Groups.put( l3_msg.group_id )
1401 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001402 dst_ip = 0x0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001403 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0x0, l3_gid )
1404 do_barrier( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001405
Flavio Castroa7162bb2016-07-25 17:30:30 -07001406 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001407 for in_port in ports:
1408 mac_src = '00:00:00:22:22:%02X' % (in_port)
1409 ip_src = '192.168.%02d.1' % (in_port)
1410 for out_port in ports:
1411 if in_port == out_port:
1412 continue
1413 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001414 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(in_port),
1415 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1416 pkt = str( parsed_pkt )
1417 self.dataplane.send( in_port, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001418 # build expected packet
1419 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001420 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_port + 1),
1421 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst )
1422 pkt = str( exp_pkt )
1423 verify_packet( self, pkt, out_port )
1424 verify_no_other_packets( self )
1425 ip_dst = '1.168.%02d.1' % ports[ 0 ]
1426 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1427 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst )
1428 pkt = str( parsed_pkt )
1429 self.dataplane.send( in_port, pkt )
1430 # build expect packet
1431 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1432 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ] + 1,
1433 ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac )
1434 pkt = str( exp_pkt )
1435 verify_packet( self, pkt, ports[ 0 ] )
1436 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001437 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001438 delete_all_flows( self.controller )
1439 delete_groups( self.controller, Groups )
1440 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001441
Flavio Castroa7162bb2016-07-25 17:30:30 -07001442
1443class Unfiltered( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001444 """
1445 Testing addition of unfiltered groups
1446 """
Flavio Castro91d1a552016-05-17 16:59:44 -07001447
Flavio Castroa7162bb2016-07-25 17:30:30 -07001448 def runTest( self ):
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001449 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001450 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001451 vlan_id = 1;
1452 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001453 add_l2_unfiltered_group( self.controller, [ port ], False )
1454 do_barrier( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001455 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001456 delete_all_flows( self.controller )
1457 delete_all_groups( self.controller )
Flavio Castro91d1a552016-05-17 16:59:44 -07001458
Flavio Castroa7162bb2016-07-25 17:30:30 -07001459
1460class L3McastToVPN( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001461 """
1462 Mcast routing
1463 """
Flavio Castroa7162bb2016-07-25 17:30:30 -07001464
1465 def runTest( self ):
Flavio Castro423df652016-05-17 20:14:08 -04001466 """
1467 port1 (vlan 1)-> port 2 (vlan 2)
1468 """
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001469 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001470 delete_all_flows( self.controller )
1471 delete_all_groups( self.controller )
Flavio Castro423df652016-05-17 20:14:08 -04001472
Flavio Castroa7162bb2016-07-25 17:30:30 -07001473 if len( config[ "port_map" ] ) < 3:
1474 logging.info( "Port count less than 3, can't run this case" )
1475 assert (False)
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001476 return
Flavio Castro423df652016-05-17 20:14:08 -04001477
Flavio Castroa7162bb2016-07-25 17:30:30 -07001478 vlan_id = 1
1479 port2_out_vlan = 2
1480 port3_out_vlan = 3
1481 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
1482 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1483 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
1484 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, 0x01 ]
1485 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
1486 port1_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, 0x11 ]
1487 port1_mac_str = ':'.join( [ '%02X' % x for x in port1_mac ] )
1488 src_ip = 0xc0a80101
1489 src_ip_str = "192.168.1.1"
1490 dst_ip = 0xe0010101
1491 dst_ip_str = "224.1.1.1"
Flavio Castro423df652016-05-17 20:14:08 -04001492
Flavio Castroa7162bb2016-07-25 17:30:30 -07001493 port1 = config[ "port_map" ].keys( )[ 0 ]
1494 port2 = config[ "port_map" ].keys( )[ 1 ]
1495 # port3=config["port_map"].keys()[2]
Flavio Castro423df652016-05-17 20:14:08 -04001496
Flavio Castroa7162bb2016-07-25 17:30:30 -07001497 # add l2 interface group
1498 for port in config[ "port_map" ].keys( ):
1499 add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id, is_tagged=False,
1500 send_barrier=False )
1501 # add vlan flow table
1502 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1503 vlan_id += 1
Flavio Castro423df652016-05-17 20:14:08 -04001504
Flavio Castroa7162bb2016-07-25 17:30:30 -07001505 # add termination flow
1506 add_termination_flow( self.controller, port1, 0x0800, [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ],
1507 vlan_id )
Flavio Castro423df652016-05-17 20:14:08 -04001508
Flavio Castroa7162bb2016-07-25 17:30:30 -07001509 # add MPLS interface group
1510 l2_gid = encode_l2_interface_group_id( port2_out_vlan, port2 )
1511 mpls_gid2, mpls_msg = add_mpls_intf_group( self.controller, l2_gid, dst_mac, intf_src_mac,
1512 port2_out_vlan, port2 )
1513 # l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
1514 # mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
1515 # add L3VPN groups
1516 mpls_label_gid2, mpls_label_msg = add_mpls_label_group( self.controller,
1517 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=(0x20000 + port2), ref_gid=mpls_gid2,
1518 push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True )
1519 # 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 -07001520 # 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 -04001521
Flavio Castroa7162bb2016-07-25 17:30:30 -07001522 mcat_group_msg = add_l3_mcast_group( self.controller, in_vlan, 2, [ mpls_label_gid2 ] )
1523 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 -04001524
Flavio Castroa7162bb2016-07-25 17:30:30 -07001525 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac_str,
1526 eth_src=port1_mac_str, ip_ttl=64, ip_src=src_ip_str, ip_dst=dst_ip_str )
1527 pkt = str( parsed_pkt )
1528 self.dataplane.send( port1, pkt )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001529 label = (12, 0, 1, 63)
Flavio Castroa7162bb2016-07-25 17:30:30 -07001530 exp_pkt = mpls_packet( pktlen=100, eth_dst=dst_mac_str, eth_src=intf_src_mac_str, ip_ttl=64,
1531 ip_src=src_ip_str, label=[ label ], ip_dst=dst_ip_str )
1532 pkt = str( exp_pkt )
1533 verify_packet( self, pkt, port2 )
1534 # verify_packet(self, pkt, port3)
1535 verify_no_other_packets( self )
1536 delete_all_groups( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001537 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001538 delete_all_flows( self.controller )
1539 delete_all_groups( self.controller )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001540
Flavio Castro423df652016-05-17 20:14:08 -04001541
Flavio Castroa7162bb2016-07-25 17:30:30 -07001542class PacketInSrcMacMiss( base_tests.SimpleDataPlane ):
Flavio Castro423df652016-05-17 20:14:08 -04001543 """
1544 Test packet in function on a src-mac miss
1545 Send a packet to each dataplane port and verify that a packet
1546 in message is received from the controller for each
1547 #todo verify you stop receiving after adding rule
1548 """
1549
Flavio Castroa7162bb2016-07-25 17:30:30 -07001550 def runTest( self ):
1551 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001552 try:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001553 ports = sorted( config[ "port_map" ].keys( ) )
Flavio Castro423df652016-05-17 20:14:08 -04001554
Flavio Castroa7162bb2016-07-25 17:30:30 -07001555 Groups = Queue.LifoQueue( )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001556 for port in ports:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001557 L2gid, l2msg = add_one_l2_interface_group( self.controller, port, 1, True, False )
1558 add_one_vlan_table_flow( self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1559 Groups.put( L2gid )
1560 parsed_vlan_pkt = simple_tcp_packet( pktlen=104, vlan_vid=0x1001, dl_vlan_enable=True )
1561 vlan_pkt = str( parsed_vlan_pkt )
1562 for of_port in config[ "port_map" ].keys( ):
1563 logging.info( "PacketInMiss test, port %d", of_port )
1564 self.dataplane.send( of_port, vlan_pkt )
1565 verify_packet_in( self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH )
1566 verify_no_other_packets( self )
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001567 finally:
Flavio Castroa7162bb2016-07-25 17:30:30 -07001568 delete_all_flows( self.controller )
1569 delete_all_groups( self.controller )
1570
1571
1572class EcmpGroupMod( base_tests.SimpleDataPlane ):
1573 """
1574 Insert IP packet
1575 Receive IP packet
1576 """
1577
1578 def runTest( self ):
1579 Groups = Queue.LifoQueue( )
1580 try:
1581 if len( config[ "port_map" ] ) < 2:
1582 logging.info( "Port count less than 2, can't run this case" )
1583 return
1584
1585 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc ]
1586 dst_mac = [ 0x00, 0x00, 0x00, 0x22, 0x22, 0x00 ]
1587 dip = 0xc0a80001
1588 # Hashes Test Name and uses it as id for installing unique groups
1589 ports = config[ "port_map" ].keys( )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001590 ecmp = [ ]
Flavio Castroa7162bb2016-07-25 17:30:30 -07001591 for port in ports:
1592 vlan_id = port
1593 id = port
1594 # add l2 interface group
1595 l2_gid, msg = add_one_l2_interface_group( self.controller, port, vlan_id=vlan_id,
1596 is_tagged=True, send_barrier=False )
1597 dst_mac[ 5 ] = vlan_id
1598 l3_msg = add_l3_unicast_group( self.controller, port, vlanid=vlan_id, id=id,
1599 src_mac=intf_src_mac, dst_mac=dst_mac )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001600 ecmp += [ l3_msg.group_id ]
Flavio Castroa7162bb2016-07-25 17:30:30 -07001601 Groups._put( l2_gid )
1602 Groups._put( l3_msg.group_id )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001603 ecmp_msg = add_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_msg.group_id ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001604 # add vlan flow table
1605 add_one_vlan_table_flow( self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG )
1606 # add termination flow
1607 add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
1608 # add unicast routing flow
1609 dst_ip = dip + (vlan_id << 8)
1610 add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id )
1611 Groups._put( ecmp_msg.group_id )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001612 mod_l3_ecmp_group( self.controller, ports[ 0 ], ecmp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001613
1614 switch_mac = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001615 parsed_pkt = exp_pkt = 0
Flavio Castroa7162bb2016-07-25 17:30:30 -07001616 for out_port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001617 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1618 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1619 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1620 tcp = out_port if out_port == 24 else 25
1621 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1622 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1623 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001624 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001625 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001626 # build expected packet
1627 mac_dst = '00:00:00:22:22:%02X' % out_port
1628 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castro9debaaa2016-07-26 19:37:50 -07001629 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst,
1630 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001631 pkt = str( exp_pkt )
1632 verify_packet( self, pkt, out_port )
1633 verify_no_other_packets( self )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001634 l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
1635 mod_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_gid ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001636 for port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001637 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1638 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1639 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1640 tcp = port if port == 24 else 25
1641 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1642 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1643 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001644 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001645 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001646 # build expected packet
Flavio Castro9debaaa2016-07-26 19:37:50 -07001647 mac_dst = '00:00:00:22:22:%02X' % ports[ 0 ]
1648 exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1649 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src, ip_dst=ip_dst,
1650 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001651 pkt = str( exp_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001652 verify_packet( self, pkt, ports[ 0 ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001653 verify_no_other_packets( self )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001654 mod_l3_ecmp_group( self.controller, ports[ 0 ], [ ] )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001655 for port in ports:
Flavio Castro9debaaa2016-07-26 19:37:50 -07001656 mac_src = '00:00:00:22:22:%02X' % ports[ 0 ]
1657 ip_src = '192.168.%02d.%02d' % (ports[ 0 ], 1)
1658 ip_dst = '192.168.%02d.%02d' % (ports[ 1 ], 1)
1659 tcp = port if port == 24 else 25
1660 parsed_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
1661 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst,
1662 tcp_dport=tcp )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001663 pkt = str( parsed_pkt )
Flavio Castro9debaaa2016-07-26 19:37:50 -07001664 self.dataplane.send( ports[ 0 ], pkt )
Flavio Castroa7162bb2016-07-25 17:30:30 -07001665 verify_no_other_packets( self )
1666 finally:
1667 delete_all_flows( self.controller )
1668 delete_groups( self.controller, Groups )
1669 delete_all_groups( self.controller )