Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 17 | """
|
| 18 | Flow Test
|
| 19 |
|
| 20 | Test each flow table can set entry, and packet rx correctly.
|
| 21 | """
|
| 22 |
|
| 23 | import logging
|
| 24 |
|
| 25 | from oftest import config
|
| 26 | import oftest.base_tests as base_tests
|
| 27 | import ofp
|
| 28 | from oftest.testutils import *
|
| 29 | from accton_util import *
|
| 30 |
|
| 31 | class L2McastFlow(base_tests.SimpleDataPlane):
|
| 32 | """
|
| 33 | Test output function for an exact-match flow
|
| 34 |
|
| 35 | Add some multicast flows
|
| 36 | Then, for all ports, verifies that sending a matching packet
|
| 37 | to a multicast match results in an output to all ports.
|
| 38 | """
|
| 39 | def runTest(self):
|
| 40 | ports = sorted(config["port_map"].keys())
|
| 41 |
|
| 42 | delete_all_flows(self.controller)
|
| 43 | delete_all_groups(self.controller)
|
| 44 |
|
| 45 | # table 10: vlan
|
| 46 | # send to table 20
|
| 47 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 48 |
|
| 49 | # group table
|
| 50 | # set up untag groups for each port
|
| 51 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
|
| 52 |
|
| 53 | # set up multicast group
|
| 54 | add_l2_mcast_group(self.controller, config["port_map"].keys(), 1, 1)
|
| 55 |
|
macauley | 53e64c4 | 2015-07-30 14:07:45 +0800 | [diff] [blame] | 56 | test_macs = [[0x01, 0x00, 0x5e, 0x0f, 0xff, 0xff]]
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 57 |
|
| 58 | for test_mac in test_macs:
|
| 59 | group_id = encode_l2_mcast_group_id(1, 1)
|
| 60 | add_bridge_flow(self.controller, test_mac, 1, group_id, True)
|
| 61 |
|
| 62 | for test_mac in test_macs:
|
| 63 | mactest = ':'.join(['%02X' % x for x in test_mac])
|
| 64 |
|
| 65 | for in_port in ports:
|
| 66 | # change dest based on port number
|
| 67 | parsed_pkt = simple_tcp_packet(eth_dst=mactest)
|
| 68 | pkt = str(parsed_pkt)
|
| 69 | logging.info("OutputExact test, from port %d to mac %s", in_port, mactest)
|
| 70 | self.dataplane.send(in_port, pkt)
|
| 71 |
|
| 72 | for ofport in ports:
|
| 73 | if ofport == in_port: #tx port won't rx packet, unless L3 mcast routing
|
| 74 | continue
|
| 75 | verify_packet(self, pkt, ofport)
|
| 76 | verify_no_other_packets(self)
|
| 77 |
|
| 78 | class L2UnicastFlow(base_tests.SimpleDataPlane):
|
| 79 | """
|
| 80 | Test output function for an exact-match flow
|
| 81 |
|
| 82 | For each port A, adds a flow directing matching packets to that port.
|
| 83 | Then, for all other ports B != A, verifies that sending a matching packet
|
| 84 | to B results in an output to A.
|
| 85 | """
|
| 86 | def runTest(self):
|
| 87 | ports = sorted(config["port_map"].keys())
|
| 88 |
|
| 89 | delete_all_flows(self.controller)
|
| 90 | delete_all_groups(self.controller)
|
| 91 | # table 10: vlan
|
| 92 | # send to table 20
|
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 93 | #add_vlan_table_flow(self.controller, config["port_map"].keys(),1)
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 94 |
|
| 95 | # group table
|
Flavio Castro | 77625dd | 2015-11-18 17:04:14 -0500 | [diff] [blame] | 96 | # set up tag groups for each port
|
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 97 | add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1)
|
Flavio Castro | 77625dd | 2015-11-18 17:04:14 -0500 | [diff] [blame] | 98 |
|
| 99 | for port in ports:
|
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 100 | add_one_vlan_table_flow(self.controller, port, 1)
|
Flavio Castro | 77625dd | 2015-11-18 17:04:14 -0500 | [diff] [blame] | 101 | group_id = encode_l2_interface_group_id(1, port)
|
| 102 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
|
| 103 | do_barrier(self.controller)
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 104 |
|
| 105 | for out_port in ports:
|
Flavio Castro | 77625dd | 2015-11-18 17:04:14 -0500 | [diff] [blame] | 106 | # change dest based on port number
|
| 107 | mac_dst= '00:12:34:56:78:%02X' % out_port
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 108 |
|
| 109 | for in_port in ports:
|
| 110 | if in_port == out_port:
|
| 111 | continue
|
Flavio Castro | 77625dd | 2015-11-18 17:04:14 -0500 | [diff] [blame] | 112 | # change source based on port number to avoid packet-ins from learning
|
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 113 | mac_src= '00:12:34:56:79:%02X' % in_port
|
Flavio Castro | 77625dd | 2015-11-18 17:04:14 -0500 | [diff] [blame] | 114 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 115 | pkt = str(parsed_pkt)
|
| 116 | logging.info("OutputExact test, ports %d to %d", in_port, out_port)
|
| 117 | self.dataplane.send(in_port, pkt)
|
| 118 |
|
| 119 | for ofport in ports:
|
| 120 | if ofport in [out_port]:
|
| 121 | verify_packet(self, pkt, ofport)
|
| 122 | else:
|
| 123 | verify_no_packet(self, pkt, ofport)
|
| 124 |
|
| 125 | verify_no_other_packets(self)
|
| 126 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 127 | class L2Flood(base_tests.SimpleDataPlane):
|
| 128 | """
|
| 129 | Test L2 unknown unicast flooding and broadcast flood
|
| 130 | """
|
| 131 | def runTest(self):
|
| 132 | ports = sorted(config["port_map"].keys())
|
| 133 |
|
| 134 | delete_all_flows(self.controller)
|
| 135 | delete_all_groups(self.controller)
|
| 136 | # table 10: vlan
|
| 137 | # send to table 20
|
| 138 | add_vlan_table_flow(self.controller, ports, 1)
|
| 139 |
|
| 140 | # group table
|
| 141 | # set up untag groups for each port
|
| 142 | add_l2_interface_grouop(self.controller, ports, 1, False, 1)
|
| 143 |
|
| 144 | input_port = ports.pop()
|
| 145 | flood_ports= ports
|
macauley | 53e64c4 | 2015-07-30 14:07:45 +0800 | [diff] [blame] | 146 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 147 | #no fllod group create, veriy all drop
|
| 148 | parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
|
| 149 | pkt = str(parsed_pkt)
|
| 150 | self.dataplane.send(input_port, pkt)
|
| 151 | verify_no_other_packets(self)
|
| 152 | parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
|
| 153 | pkt = str(parsed_pkt)
|
| 154 | self.dataplane.send(input_port, pkt)
|
| 155 | verify_no_other_packets(self)
|
| 156 | #add flood groupo
|
| 157 | msg=add_l2_flood_group(self.controller, flood_ports, 1, 1)
|
| 158 | add_bridge_flow(self.controller, None, 1, msg.group_id, True)
|
| 159 | #verify flood
|
| 160 | parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
|
| 161 | pkt = str(parsed_pkt)
|
| 162 | self.dataplane.send(input_port, pkt)
|
| 163 | for ofport in flood_ports:
|
| 164 | verify_packet(self, pkt, ofport)
|
| 165 |
|
| 166 | verify_no_other_packets(self)
|
| 167 |
|
| 168 | for ofport in flood_ports:
|
| 169 | self.dataplane.send(ofport, pkt)
|
macauley | 53e64c4 | 2015-07-30 14:07:45 +0800 | [diff] [blame] | 170 | #self won't rx packet
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 171 | verify_no_packet(self, pkt, ofport)
|
macauley | 53e64c4 | 2015-07-30 14:07:45 +0800 | [diff] [blame] | 172 | #others will rx packet
|
| 173 | tmp_ports=[]
|
| 174 | for tmp in flood_ports:
|
| 175 | if tmp != ofport:
|
| 176 | tmp_ports.append(tmp)
|
| 177 | verify_packets(self, pkt, tmp_ports)
|
| 178 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 179 | verify_no_other_packets(self)
|
| 180 |
|
| 181 | parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
|
| 182 | pkt = str(parsed_pkt)
|
| 183 | self.dataplane.send(input_port, pkt)
|
| 184 | for ofport in flood_ports:
|
| 185 | verify_packet(self, pkt, ofport)
|
| 186 |
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 187 | class PacketInMiss(base_tests.SimpleDataPlane):
|
| 188 | """
|
| 189 | Test packet in function for a table-miss flow
|
| 190 |
|
| 191 | Send a packet to each dataplane port and verify that a packet
|
| 192 | in message is received from the controller for each
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 193 |
|
| 194 | NOTE: Verify This case the oft option shall not use --switch-ip
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 195 | """
|
| 196 |
|
| 197 | def runTest(self):
|
| 198 | delete_all_flows(self.controller)
|
| 199 | delete_all_groups(self.controller)
|
| 200 |
|
| 201 | parsed_pkt = simple_tcp_packet(pktlen=100)
|
| 202 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
|
| 203 | vlan_vid=0x1001, dl_vlan_enable=True)
|
| 204 | pkt = str(parsed_pkt)
|
| 205 | vlan_pkt = str(parsed_vlan_pkt)
|
| 206 | # table 10: vlan
|
| 207 | # send to table 20
|
| 208 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 209 |
|
| 210 | # group table
|
| 211 | # set up untag groups for each port
|
| 212 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
|
| 213 |
|
| 214 | # create match
|
| 215 | match = ofp.match()
|
| 216 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1001))
|
| 217 | request = ofp.message.flow_add(
|
| 218 | table_id=60,
|
| 219 | cookie=42,
|
| 220 | match=match,
|
| 221 | instructions=[
|
| 222 | ofp.instruction.apply_actions(
|
| 223 | actions=[
|
| 224 | ofp.action.output(
|
| 225 | port=ofp.OFPP_CONTROLLER,
|
| 226 | max_len=ofp.OFPCML_NO_BUFFER)]),
|
| 227 | ],
|
| 228 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 229 | priority=1)
|
| 230 |
|
| 231 | logging.info("Inserting packet in flow to controller")
|
| 232 | self.controller.message_send(request)
|
| 233 | do_barrier(self.controller)
|
| 234 |
|
| 235 | for of_port in config["port_map"].keys():
|
| 236 | logging.info("PacketInMiss test, port %d", of_port)
|
| 237 | self.dataplane.send(of_port, pkt)
|
| 238 |
|
| 239 | #AOS current packet in will not have vlan tag
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 240 | if config["cicada_poject"]:
|
| 241 | verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
|
| 242 | else:
|
| 243 | verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
|
| 244 |
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 245 | verify_no_other_packets(self)
|
| 246 |
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 247 | class PacketOut(base_tests.SimpleDataPlane):
|
| 248 | """
|
| 249 | Verify action Flood, ALL, in port
|
| 250 | """
|
| 251 |
|
| 252 | def runTest(self):
|
| 253 | if config["cicada_poject"]:
|
| 254 | pass
|
| 255 |
|
| 256 | delete_all_flows(self.controller)
|
| 257 | delete_all_groups(self.controller)
|
| 258 |
|
| 259 | parsed_pkt = simple_tcp_packet(pktlen=100)
|
| 260 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
|
| 261 | vlan_vid=0x1002, dl_vlan_enable=True)
|
| 262 |
|
| 263 | pkt = str(parsed_pkt)
|
| 264 | vlan_pkt = str(parsed_vlan_pkt)
|
| 265 |
|
| 266 |
|
| 267 | #packet out flood, untag packet
|
| 268 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 269 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 270 | actions=[ofp.action.output(
|
| 271 | port=ofp.OFPP_FLOOD)],
|
| 272 | data=pkt))
|
| 273 |
|
| 274 | for of_port in config["port_map"].keys():
|
| 275 | verify_packet(self, pkt, of_port)
|
| 276 |
|
| 277 | verify_no_other_packets(self)
|
| 278 |
|
| 279 | #packet out flood, tag packet, because it can't identify vlan has which port
|
| 280 | #so we do as all action.
|
| 281 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 282 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 283 | actions=[ofp.action.output(
|
| 284 | port=ofp.OFPP_FLOOD)],
|
| 285 | data=vlan_pkt))
|
| 286 |
|
| 287 | for of_port in config["port_map"].keys():
|
| 288 | verify_packet(self, vlan_pkt, of_port)
|
| 289 |
|
| 290 | verify_no_other_packets(self)
|
| 291 |
|
| 292 | #packet out all
|
| 293 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 294 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 295 | actions=[ofp.action.output(
|
| 296 | port=ofp.OFPP_FLOOD)],
|
| 297 | data=pkt))
|
| 298 |
|
| 299 | for of_port in config["port_map"].keys():
|
| 300 | verify_packet(self, pkt, of_port)
|
| 301 |
|
| 302 | verify_no_other_packets(self)
|
| 303 |
|
| 304 | #packet out to in port
|
| 305 | in_port = config["port_map"].keys()[0]
|
| 306 | self.controller.message_send(ofp.message.packet_out(in_port=in_port,
|
| 307 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 308 | actions=[ofp.action.output(
|
| 309 | port=in_port)],
|
| 310 | data=pkt))
|
| 311 |
|
| 312 | verify_packet(self, pkt, in_port)
|
| 313 | verify_no_other_packets(self)
|
| 314 |
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 315 | class L3UcastRoute(base_tests.SimpleDataPlane):
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 316 | """
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 317 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 318 | Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 319 | """
|
| 320 | def runTest(self):
|
| 321 | delete_all_flows(self.controller)
|
| 322 | delete_all_groups(self.controller)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 323 |
|
| 324 | if len(config["port_map"]) <2:
|
| 325 | logging.info("Port count less than 2, can't run this case")
|
| 326 | return
|
| 327 |
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 328 | vlan_id=1
|
| 329 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 330 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
|
| 331 | dip=0xc0a80001
|
| 332 | for port in config["port_map"].keys():
|
| 333 | #add l2 interface group
|
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 334 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 335 | dst_mac[5]=vlan_id
|
| 336 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
|
| 337 | #add vlan flow table
|
| 338 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 339 | #add termination flow
|
| 340 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
|
| 341 | #add unicast routing flow
|
| 342 | dst_ip = dip + (vlan_id<<8)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 343 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 344 | vlan_id += 1
|
| 345 |
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 346 | do_barrier(self.controller)
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 347 |
|
| 348 | port1=config["port_map"].keys()[0]
|
| 349 | port2=config["port_map"].keys()[1]
|
| 350 | #port 1 to port 2
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 351 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 352 | dst_mac[5]=1
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 353 | port1_mac=':'.join(['%02X' % x for x in dst_mac])
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 354 |
|
| 355 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 356 | eth_dst=switch_mac,
|
| 357 | eth_src=port1_mac,
|
| 358 | ip_ttl=64,
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 359 | ip_src="192.168.1.1",
|
| 360 | ip_dst='192.168.2.1')
|
| 361 | pkt=str(parsed_pkt)
|
| 362 | self.dataplane.send(port1, pkt)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 363 | #build expect packet
|
| 364 | dst_mac[5]=2
|
| 365 | port2_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 366 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 367 | eth_dst=port2_mac,
|
| 368 | eth_src=switch_mac,
|
| 369 | ip_ttl=63,
|
| 370 | ip_src="192.168.1.1",
|
| 371 | ip_dst='192.168.2.1')
|
| 372 | pkt=str(exp_pkt)
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 373 | verify_packet(self, pkt, port2)
|
| 374 | verify_no_other_packets(self)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 375 |
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 376 | #port 2 to port 1
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 377 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 378 | dst_mac[5]=2
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 379 | port2_mac=':'.join(['%02X' % x for x in dst_mac])
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 380 |
|
| 381 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 382 | eth_dst=switch_mac,
|
| 383 | eth_src=port2_mac,
|
| 384 | ip_ttl=64,
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 385 | ip_src="192.168.2.1",
|
| 386 | ip_dst='192.168.1.1')
|
| 387 | pkt=str(parsed_pkt)
|
| 388 | self.dataplane.send(port2, pkt)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 389 | #build expect packet
|
| 390 | dst_mac[5]=1
|
| 391 | port1_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 392 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 393 | eth_dst=port1_mac,
|
| 394 | eth_src=switch_mac,
|
| 395 | ip_ttl=63,
|
| 396 | ip_src="192.168.2.1",
|
| 397 | ip_dst='192.168.1.1')
|
| 398 | pkt=str(exp_pkt)
|
| 399 | verify_packet(self, pkt, port1)
|
| 400 | verify_no_other_packets(self)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 401 |
|
macauley | 9a53bf9 | 2015-08-03 13:36:00 +0800 | [diff] [blame] | 402 | class L3UcastRouteOnSamVLANSamPort(base_tests.SimpleDataPlane):
|
| 403 | """
|
| 404 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 405 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
| 406 | """
|
| 407 | def runTest(self):
|
| 408 | delete_all_flows(self.controller)
|
| 409 | delete_all_groups(self.controller)
|
| 410 | port = config["port_map"].keys()[0]
|
| 411 |
|
| 412 | vlan_id=1
|
| 413 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 414 | port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
|
| 415 | port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
|
| 416 | port_ip1=0xc0a80101
|
| 417 | port_ip1_str=convertIP4toStr(port_ip1)
|
| 418 | port_ip2=0xc0a80201
|
| 419 | port_ip2_str=convertIP4toStr(port_ip2)
|
| 420 | #add l2 interface group
|
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 421 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
macauley | 9a53bf9 | 2015-08-03 13:36:00 +0800 | [diff] [blame] | 422 | #add vlan flow table
|
| 423 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 424 | #add termination flow
|
| 425 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
|
| 426 |
|
| 427 | """192.168.1.1->192.168.2.1"""
|
| 428 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
|
| 429 | add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id)
|
| 430 | """192.168.1.1->192.168.2.1"""
|
| 431 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=2, src_mac=intf_src_mac, dst_mac=port_mac1)
|
| 432 | add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id)
|
| 433 |
|
| 434 | do_barrier(self.controller)
|
| 435 |
|
| 436 | """send packet to verify"""
|
| 437 | """192.168.1.1->192.168.2.1"""
|
| 438 | switch_mac_str = convertMACtoStr(intf_src_mac)
|
| 439 | port_mac1_str = convertMACtoStr(port_mac1)
|
| 440 | port_mac2_str = convertMACtoStr(port_mac2)
|
| 441 | ttl=64
|
| 442 | #send packet
|
| 443 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 444 | eth_dst=switch_mac_str,
|
| 445 | eth_src=port_mac1_str,
|
| 446 | ip_ttl=ttl,
|
| 447 | ip_src=port_ip1_str,
|
| 448 | ip_dst=port_ip2_str)
|
| 449 | pkt=str(parsed_pkt)
|
| 450 | self.dataplane.send(port, pkt)
|
| 451 | #build expect packet
|
| 452 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 453 | eth_dst=port_mac2_str,
|
| 454 | eth_src=switch_mac_str,
|
| 455 | ip_ttl=(ttl-1),
|
| 456 | ip_src=port_ip1_str,
|
| 457 | ip_dst=port_ip2_str)
|
| 458 | pkt=str(exp_pkt)
|
| 459 | verify_packet(self, pkt, port)
|
| 460 | verify_no_other_packets(self)
|
| 461 |
|
| 462 | """192.168.2.1->192.168.1.1"""
|
| 463 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 464 | eth_dst=switch_mac_str,
|
| 465 | eth_src=port_mac2_str,
|
| 466 | ip_ttl=ttl,
|
| 467 | ip_src=port_ip2_str,
|
| 468 | ip_dst=port_ip1_str)
|
| 469 | pkt=str(parsed_pkt)
|
| 470 | self.dataplane.send(port, pkt)
|
| 471 | #build expect packet
|
| 472 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 473 | eth_dst=port_mac1_str,
|
| 474 | eth_src=switch_mac_str,
|
| 475 | ip_ttl=(ttl-1),
|
| 476 | ip_src=port_ip2_str,
|
| 477 | ip_dst=port_ip1_str)
|
| 478 | pkt=str(exp_pkt)
|
| 479 | verify_packet(self, pkt, port)
|
| 480 | verify_no_other_packets(self)
|
| 481 |
|
| 482 | class L3UcastRouteOnDiffVLANSamPort(base_tests.SimpleDataPlane):
|
| 483 | """
|
| 484 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 485 | Port1(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
| 486 | """
|
| 487 | def runTest(self):
|
| 488 | delete_all_flows(self.controller)
|
| 489 | delete_all_groups(self.controller)
|
| 490 | port = config["port_map"].keys()[0]
|
| 491 |
|
| 492 | port_vlan_id1=1
|
| 493 | port_vlan_id2=2
|
| 494 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 495 | port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
|
| 496 | port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
|
| 497 | port_ip1=0xc0a80101
|
| 498 | port_ip1_str=convertIP4toStr(port_ip1)
|
| 499 | port_ip2=0xc0a80201
|
| 500 | port_ip2_str=convertIP4toStr(port_ip2)
|
| 501 | #add l2 interface group
|
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 502 | add_one_l2_interface_group(self.controller, port, vlan_id=port_vlan_id1, is_tagged=True, send_barrier=False)
|
| 503 | add_one_l2_interface_group(self.controller, port, vlan_id=port_vlan_id2, is_tagged=True, send_barrier=False)
|
macauley | 9a53bf9 | 2015-08-03 13:36:00 +0800 | [diff] [blame] | 504 | #add vlan flow table
|
| 505 | add_one_vlan_table_flow(self.controller, port, port_vlan_id1, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 506 | add_one_vlan_table_flow(self.controller, port, port_vlan_id2, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 507 | #add termination flow
|
| 508 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, port_vlan_id1)
|
| 509 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, port_vlan_id2)
|
| 510 |
|
| 511 | """192.168.1.1->192.168.2.1"""
|
| 512 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=port_vlan_id2, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
|
| 513 | add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id)
|
| 514 | """192.168.1.1->192.168.2.1"""
|
| 515 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=port_vlan_id1, id=2, src_mac=intf_src_mac, dst_mac=port_mac1)
|
| 516 | add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id)
|
| 517 |
|
| 518 | do_barrier(self.controller)
|
| 519 |
|
| 520 | """send packet to verify"""
|
| 521 | """192.168.1.1->192.168.2.1"""
|
| 522 | switch_mac_str =convertMACtoStr(intf_src_mac)
|
| 523 | port_mac1_str= convertMACtoStr(port_mac1)
|
| 524 | port_mac2_str= convertMACtoStr(port_mac2)
|
| 525 | ttl=64
|
| 526 | #send packet
|
| 527 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 528 | eth_dst=switch_mac_str,
|
| 529 | eth_src=port_mac1_str,
|
| 530 | dl_vlan_enable=True,
|
| 531 | vlan_vid=port_vlan_id1,
|
| 532 | ip_ttl=ttl,
|
| 533 | ip_src=port_ip1_str,
|
| 534 | ip_dst=port_ip2_str)
|
| 535 | pkt=str(parsed_pkt)
|
| 536 | self.dataplane.send(port, pkt)
|
| 537 | #build expect packet
|
| 538 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 539 | eth_dst=port_mac2_str,
|
| 540 | eth_src=switch_mac_str,
|
| 541 | dl_vlan_enable=True,
|
| 542 | vlan_vid=port_vlan_id2,
|
| 543 | ip_ttl=(ttl-1),
|
| 544 | ip_src=port_ip1_str,
|
| 545 | ip_dst=port_ip2_str)
|
| 546 | pkt=str(exp_pkt)
|
| 547 | verify_packet(self, pkt, port)
|
| 548 | verify_no_other_packets(self)
|
| 549 |
|
| 550 | """192.168.2.1->192.168.1.1"""
|
| 551 | switch_mac = convertMACtoStr(intf_src_mac)
|
| 552 | port_mac2_str=convertMACtoStr(port_mac2)
|
| 553 |
|
| 554 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 555 | eth_dst=switch_mac_str,
|
| 556 | eth_src=port_mac2_str,
|
| 557 | dl_vlan_enable=True,
|
| 558 | vlan_vid=port_vlan_id2,
|
| 559 | ip_ttl=ttl,
|
| 560 | ip_src=port_ip2_str,
|
| 561 | ip_dst=port_ip1_str)
|
| 562 | pkt=str(parsed_pkt)
|
| 563 | self.dataplane.send(port, pkt)
|
| 564 | #build expect packet
|
| 565 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 566 | eth_dst=port_mac1_str,
|
| 567 | eth_src=switch_mac_str,
|
| 568 | dl_vlan_enable=True,
|
| 569 | vlan_vid=port_vlan_id1,
|
| 570 | ip_ttl=(ttl-1),
|
| 571 | ip_src=port_ip2_str,
|
| 572 | ip_dst=port_ip1_str)
|
| 573 | pkt=str(exp_pkt)
|
| 574 | verify_packet(self, pkt, port)
|
| 575 | verify_no_other_packets(self)
|
| 576 |
|
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 577 | class L3UcastVrfRouteOnSamVLANSamPort(base_tests.SimpleDataPlane):
|
| 578 | """
|
| 579 | Port1(vlan1, VRF1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 580 | Port1(vlan1, VRF1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
| 581 | Port1(vlan2, VRF2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 582 | Port1(vlan2, VRF2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
| 583 |
|
| 584 | """
|
| 585 | def runTest(self):
|
| 586 | delete_all_flows(self.controller)
|
| 587 | delete_all_groups(self.controller)
|
| 588 | port = config["port_map"].keys()[0]
|
| 589 |
|
| 590 | vrf1=1
|
| 591 | vrf2=2
|
| 592 | vrf1_vlan_id=1
|
| 593 | vrf2_vlan_id=2
|
| 594 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 595 | port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
|
| 596 | port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
|
| 597 | port_ip1=0xc0a80101
|
| 598 | port_ip1_str=convertIP4toStr(port_ip1)
|
| 599 | port_ip2=0xc0a80201
|
| 600 | port_ip2_str=convertIP4toStr(port_ip2)
|
| 601 | #add l2 interface group
|
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 602 | add_one_l2_interface_group(self.controller, port, vlan_id=vrf1_vlan_id, is_tagged=True, send_barrier=False)
|
| 603 | add_one_l2_interface_group(self.controller, port, vlan_id=vrf2_vlan_id, is_tagged=True, send_barrier=False)
|
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 604 | #add vlan flow table
|
| 605 | add_one_vlan_table_flow(self.controller, port, vrf1_vlan_id, vrf=vrf1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
|
| 606 | add_one_vlan_table_flow(self.controller, port, vrf2_vlan_id, vrf=vrf2, flag=VLAN_TABLE_FLAG_ONLY_TAG)
|
| 607 |
|
| 608 | #add termination flow
|
| 609 | add_termination_flow(self.controller, 0, 0x0800, intf_src_mac, vrf1_vlan_id)
|
| 610 | add_termination_flow(self.controller, 0, 0x0800, intf_src_mac, vrf2_vlan_id)
|
| 611 |
|
| 612 | """192.168.1.1->192.168.2.1"""
|
| 613 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf1_vlan_id, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
|
| 614 | add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id, vrf1)
|
| 615 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf2_vlan_id, id=2, src_mac=intf_src_mac, dst_mac=port_mac2)
|
| 616 | add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id, vrf2)
|
| 617 |
|
| 618 | """192.168.1.1->192.168.2.1"""
|
| 619 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf1_vlan_id, id=3, src_mac=intf_src_mac, dst_mac=port_mac1)
|
| 620 | add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id, vrf1)
|
| 621 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf2_vlan_id, id=4, src_mac=intf_src_mac, dst_mac=port_mac1)
|
| 622 | add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id, vrf2)
|
| 623 |
|
| 624 | do_barrier(self.controller)
|
| 625 |
|
| 626 | """send packet to verify on VRF vrf1"""
|
| 627 | """192.168.1.1->192.168.2.1"""
|
| 628 | switch_mac_str = convertMACtoStr(intf_src_mac)
|
| 629 | port_mac1_str = convertMACtoStr(port_mac1)
|
| 630 | port_mac2_str = convertMACtoStr(port_mac2)
|
| 631 | ttl=64
|
| 632 | #send packet
|
| 633 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 634 | eth_dst=switch_mac_str,
|
| 635 | eth_src=port_mac1_str,
|
| 636 | dl_vlan_enable=True,
|
| 637 | vlan_vid=vrf1_vlan_id,
|
| 638 | ip_ttl=ttl,
|
| 639 | ip_src=port_ip1_str,
|
| 640 | ip_dst=port_ip2_str)
|
| 641 | pkt=str(parsed_pkt)
|
| 642 | self.dataplane.send(port, pkt)
|
| 643 | #build expect packet
|
| 644 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 645 | eth_dst=port_mac2_str,
|
| 646 | eth_src=switch_mac_str,
|
| 647 | dl_vlan_enable=True,
|
| 648 | vlan_vid=vrf1_vlan_id,
|
| 649 | ip_ttl=(ttl-1),
|
| 650 | ip_src=port_ip1_str,
|
| 651 | ip_dst=port_ip2_str)
|
| 652 | pkt=str(exp_pkt)
|
| 653 | verify_packet(self, pkt, port)
|
| 654 | verify_no_other_packets(self)
|
| 655 |
|
| 656 | """192.168.2.1->192.168.1.1"""
|
| 657 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 658 | eth_dst=switch_mac_str,
|
| 659 | eth_src=port_mac2_str,
|
| 660 | dl_vlan_enable=True,
|
| 661 | vlan_vid=vrf1_vlan_id,
|
| 662 | ip_ttl=ttl,
|
| 663 | ip_src=port_ip2_str,
|
| 664 | ip_dst=port_ip1_str)
|
| 665 | pkt=str(parsed_pkt)
|
| 666 | self.dataplane.send(port, pkt)
|
| 667 | #build expect packet
|
| 668 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 669 | eth_dst=port_mac1_str,
|
| 670 | eth_src=switch_mac_str,
|
| 671 | dl_vlan_enable=True,
|
| 672 | vlan_vid=vrf1_vlan_id,
|
| 673 | ip_ttl=(ttl-1),
|
| 674 | ip_src=port_ip2_str,
|
| 675 | ip_dst=port_ip1_str)
|
| 676 | pkt=str(exp_pkt)
|
| 677 | verify_packet(self, pkt, port)
|
| 678 | verify_no_other_packets(self)
|
| 679 |
|
| 680 |
|
| 681 | """send packet to verify on VRF vrf2"""
|
| 682 | """192.168.1.1->192.168.2.1"""
|
| 683 | switch_mac_str = convertMACtoStr(intf_src_mac)
|
| 684 | port_mac1_str = convertMACtoStr(port_mac1)
|
| 685 | port_mac2_str = convertMACtoStr(port_mac2)
|
| 686 | ttl=64
|
| 687 | #send packet
|
| 688 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 689 | eth_dst=switch_mac_str,
|
| 690 | eth_src=port_mac1_str,
|
| 691 | dl_vlan_enable=True,
|
| 692 | vlan_vid=vrf2_vlan_id,
|
| 693 | ip_ttl=ttl,
|
| 694 | ip_src=port_ip1_str,
|
| 695 | ip_dst=port_ip2_str)
|
| 696 | pkt=str(parsed_pkt)
|
| 697 | self.dataplane.send(port, pkt)
|
| 698 | #build expect packet
|
| 699 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 700 | eth_dst=port_mac2_str,
|
| 701 | eth_src=switch_mac_str,
|
| 702 | dl_vlan_enable=True,
|
| 703 | vlan_vid=vrf2_vlan_id,
|
| 704 | ip_ttl=(ttl-1),
|
| 705 | ip_src=port_ip1_str,
|
| 706 | ip_dst=port_ip2_str)
|
| 707 | pkt=str(exp_pkt)
|
| 708 | verify_packet(self, pkt, port)
|
| 709 | verify_no_other_packets(self)
|
| 710 |
|
| 711 | """192.168.2.1->192.168.1.1"""
|
| 712 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 713 | eth_dst=switch_mac_str,
|
| 714 | eth_src=port_mac2_str,
|
| 715 | dl_vlan_enable=True,
|
| 716 | vlan_vid=vrf2_vlan_id,
|
| 717 | ip_ttl=ttl,
|
| 718 | ip_src=port_ip2_str,
|
| 719 | ip_dst=port_ip1_str)
|
| 720 | pkt=str(parsed_pkt)
|
| 721 | self.dataplane.send(port, pkt)
|
| 722 | #build expect packet
|
| 723 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 724 | eth_dst=port_mac1_str,
|
| 725 | eth_src=switch_mac_str,
|
| 726 | dl_vlan_enable=True,
|
| 727 | vlan_vid=vrf2_vlan_id,
|
| 728 | ip_ttl=(ttl-1),
|
| 729 | ip_src=port_ip2_str,
|
| 730 | ip_dst=port_ip1_str)
|
| 731 | pkt=str(exp_pkt)
|
| 732 | verify_packet(self, pkt, port)
|
| 733 | verify_no_other_packets(self)
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 738 | class L3UcastECMP(base_tests.SimpleDataPlane):
|
| 739 | """
|
| 740 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 741 | Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
| 742 | """
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 743 | def runTest(self):
|
| 744 | delete_all_flows(self.controller)
|
| 745 | delete_all_groups(self.controller)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 746 |
|
| 747 | if len(config["port_map"]) <2:
|
| 748 | logging.info("Port count less than 2, can't run this case")
|
| 749 | return
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 750 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 751 | vlan_id=1
|
| 752 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 753 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
|
| 754 | dip=0xc0a80001
|
| 755 | for port in config["port_map"].keys():
|
| 756 | #add l2 interface group
|
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 757 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 758 | dst_mac[5]=vlan_id
|
| 759 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
|
| 760 | ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [l3_msg.group_id])
|
| 761 | #add vlan flow table
|
| 762 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 763 | #add termination flow
|
| 764 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
|
| 765 | #add unicast routing flow
|
| 766 | dst_ip = dip + (vlan_id<<8)
|
| 767 | #ECMP shall have prefix not 32
|
| 768 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
|
| 769 | vlan_id += 1
|
| 770 |
|
| 771 | do_barrier(self.controller)
|
| 772 |
|
| 773 | port1=config["port_map"].keys()[0]
|
| 774 | port2=config["port_map"].keys()[1]
|
| 775 | #port 1 to port 2
|
| 776 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
| 777 | dst_mac[5]=1
|
| 778 | port1_mac=':'.join(['%02X' % x for x in dst_mac])
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 779 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 780 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 781 | eth_dst=switch_mac,
|
| 782 | eth_src=port1_mac,
|
| 783 | ip_ttl=64,
|
| 784 | ip_src="192.168.1.1",
|
| 785 | ip_dst='192.168.2.1')
|
| 786 | pkt=str(parsed_pkt)
|
| 787 | self.dataplane.send(port1, pkt)
|
| 788 | #build expect packet
|
| 789 | dst_mac[5]=2
|
| 790 | port2_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 791 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 792 | eth_dst=port2_mac,
|
| 793 | eth_src=switch_mac,
|
| 794 | ip_ttl=63,
|
| 795 | ip_src="192.168.1.1",
|
| 796 | ip_dst='192.168.2.1')
|
| 797 | pkt=str(exp_pkt)
|
| 798 | verify_packet(self, pkt, port2)
|
| 799 | verify_no_other_packets(self)
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 800 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 801 | #port 2 to port 1
|
| 802 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
| 803 | dst_mac[5]=2
|
| 804 | port2_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 805 |
|
| 806 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 807 | eth_dst=switch_mac,
|
| 808 | eth_src=port2_mac,
|
| 809 | ip_ttl=64,
|
| 810 | ip_src="192.168.2.1",
|
| 811 | ip_dst='192.168.1.1')
|
| 812 | pkt=str(parsed_pkt)
|
| 813 | self.dataplane.send(port2, pkt)
|
| 814 | #build expect packet
|
| 815 | dst_mac[5]=1
|
| 816 | port1_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 817 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 818 | eth_dst=port1_mac,
|
| 819 | eth_src=switch_mac,
|
| 820 | ip_ttl=63,
|
| 821 | ip_src="192.168.2.1",
|
| 822 | ip_dst='192.168.1.1')
|
| 823 | pkt=str(exp_pkt)
|
| 824 | verify_packet(self, pkt, port1)
|
| 825 | verify_no_other_packets(self)
|
macauley_cheng | 1db6a36 | 2015-09-01 13:39:40 +0800 | [diff] [blame] | 826 |
|
| 827 |
|
| 828 | class L3UcastECMP2(base_tests.SimpleDataPlane):
|
| 829 | """
|
| 830 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 831 | Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
| 832 | Portn(vlann, 0x00, 0x00, 0x00, 0x22, 0x22, 0x0n, 19.168.n.1)
|
| 833 | """
|
| 834 |
|
| 835 | def runTest(self):
|
| 836 | delete_all_flows(self.controller)
|
| 837 | delete_all_groups(self.controller)
|
| 838 |
|
| 839 | if len(config["port_map"]) <3:
|
| 840 | logging.info("Port count less than 3, can't run this case")
|
| 841 | return
|
| 842 |
|
| 843 | vlan_id=1
|
| 844 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 845 | same_dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x22]
|
| 846 |
|
| 847 | l3_ucast_gips=[]
|
| 848 | tx_port = config["port_map"].keys()[0]
|
| 849 | for port in config["port_map"].keys():
|
| 850 | #add l2 interface group
|
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 851 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
macauley_cheng | 1db6a36 | 2015-09-01 13:39:40 +0800 | [diff] [blame] | 852 | if tx_port != port:
|
| 853 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=same_dst_mac)
|
| 854 | l3_ucast_gips.append(l3_msg.group_id)
|
| 855 | #add vlan flow table
|
| 856 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 857 | #add termination flow
|
| 858 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
|
| 859 | vlan_id += 1
|
| 860 |
|
| 861 | tx_dip=0x0a0a0a0a
|
| 862 | tx_sip=0x0b0a0a0a
|
| 863 | ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, l3_ucast_gips)
|
| 864 | #ECMP shall have prefix not 32
|
| 865 | add_unicast_routing_flow(self.controller, 0x0800, tx_dip, 0xffffff00, ecmp_msg.group_id)
|
| 866 |
|
| 867 | do_barrier(self.controller)
|
| 868 |
|
| 869 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
| 870 | packet_src_mac="00:00:33:44:55:66"
|
| 871 | #from unknown src ip to unknown dst ip, to verify ecmp
|
| 872 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 873 | eth_dst=switch_mac,
|
| 874 | eth_src=packet_src_mac,
|
| 875 | ip_ttl=64,
|
| 876 | ip_src=convertIP4toStr(tx_sip),
|
| 877 | ip_dst=convertIP4toStr(tx_dip))
|
| 878 | self.dataplane.send(tx_port, str(parsed_pkt))
|
| 879 | #build expect packet
|
| 880 | dst_mac=':'.join(['%02X' % x for x in same_dst_mac])
|
| 881 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 882 | eth_dst=dst_mac,
|
| 883 | eth_src=switch_mac,
|
| 884 | ip_ttl=63,
|
| 885 | ip_src=convertIP4toStr(tx_sip),
|
| 886 | ip_dst=convertIP4toStr(tx_dip))
|
| 887 |
|
| 888 | verify_packet(self, exp_pkt, config["port_map"].keys()[2])
|
| 889 | verify_no_other_packets(self)
|
| 890 | tx_sip=tx_sip+0x01000000
|
| 891 | #from unknown scr ip to unknown dst ip, to verify ecmp
|
| 892 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 893 | eth_dst=switch_mac,
|
| 894 | eth_src=packet_src_mac,
|
| 895 | ip_ttl=64,
|
| 896 | ip_src=convertIP4toStr(tx_sip),
|
| 897 | ip_dst=convertIP4toStr(tx_dip))
|
| 898 | self.dataplane.send(tx_port, str(parsed_pkt))
|
| 899 | #build expect packet
|
| 900 | dst_mac=':'.join(['%02X' % x for x in same_dst_mac])
|
| 901 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 902 | eth_dst=dst_mac,
|
| 903 | eth_src=switch_mac,
|
| 904 | ip_ttl=63,
|
| 905 | ip_src=convertIP4toStr(tx_sip),
|
| 906 | ip_dst=convertIP4toStr(tx_dip))
|
| 907 |
|
| 908 | verify_packet(self, exp_pkt, config["port_map"].keys()[1])
|
| 909 | verify_no_other_packets(self)
|
| 910 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 911 | class L3McastRoute1(base_tests.SimpleDataPlane):
|
| 912 | """
|
| 913 | Mcast routing, From VLAN 1 to VLAN 2
|
| 914 | """
|
| 915 | def runTest(self):
|
| 916 | """
|
| 917 | port1 (vlan 1)-> port 2 (vlan 2)
|
| 918 | """
|
| 919 | delete_all_flows(self.controller)
|
| 920 | delete_all_groups(self.controller)
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 921 |
|
| 922 | if len(config["port_map"]) <3:
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 923 | logging.info("Port count less than 2, can't run this case")
|
| 924 | return
|
| 925 |
|
| 926 | vlan_id =1
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 927 | port2_out_vlan=2
|
| 928 | port3_out_vlan=3
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 929 | in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
|
| 930 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 931 | intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
|
| 932 | dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
|
| 933 | dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
|
| 934 | port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
|
| 935 | port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
|
| 936 | src_ip=0xc0a80101
|
| 937 | src_ip_str="192.168.1.1"
|
| 938 | dst_ip=0xe0010101
|
| 939 | dst_ip_str="224.1.1.1"
|
| 940 |
|
| 941 | port1=config["port_map"].keys()[0]
|
| 942 | port2=config["port_map"].keys()[1]
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 943 | port3=config["port_map"].keys()[2]
|
| 944 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 945 | #add l2 interface group
|
| 946 | for port in config["port_map"].keys():
|
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 947 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 948 | #add vlan flow table
|
| 949 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 950 | vlan_id +=1
|
| 951 |
|
| 952 | #add termination flow
|
| 953 | add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
|
| 954 |
|
| 955 | #add l3 interface group
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 956 | port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
|
| 957 | port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
|
| 958 | mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id])
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 959 | add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
|
| 960 |
|
| 961 | parsed_pkt = simple_udp_packet(pktlen=100,
|
| 962 | eth_dst=dst_mac_str,
|
| 963 | eth_src=port1_mac_str,
|
| 964 | ip_ttl=64,
|
| 965 | ip_src=src_ip_str,
|
| 966 | ip_dst=dst_ip_str)
|
| 967 | pkt=str(parsed_pkt)
|
| 968 | self.dataplane.send(port1, pkt)
|
| 969 | parsed_pkt = simple_udp_packet(pktlen=100,
|
| 970 | eth_dst=dst_mac_str,
|
| 971 | eth_src=intf_src_mac_str,
|
| 972 | ip_ttl=63,
|
| 973 | ip_src=src_ip_str,
|
| 974 | ip_dst=dst_ip_str)
|
| 975 | pkt=str(parsed_pkt)
|
| 976 | verify_packet(self, pkt, port2)
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 977 | verify_packet(self, pkt, port3)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 978 | verify_no_other_packets(self)
|
| 979 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 980 | class L3McastRoute2(base_tests.SimpleDataPlane):
|
| 981 | """
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 982 | Mcast routing, but on same vlan (l2mcast)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 983 | """
|
| 984 | def runTest(self):
|
| 985 | """
|
| 986 | port1 (vlan 1)-> port 2 (vlan 1)
|
| 987 | """
|
| 988 | delete_all_flows(self.controller)
|
| 989 | delete_all_groups(self.controller)
|
| 990 |
|
| 991 | if len(config["port_map"]) <2:
|
| 992 | logging.info("Port count less than 2, can't run this case")
|
| 993 | return
|
| 994 |
|
| 995 | vlan_id =1
|
| 996 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 997 | intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
|
| 998 | dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
|
| 999 | dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
|
| 1000 | port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
|
| 1001 | port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
|
| 1002 | src_ip=0xc0a80101
|
| 1003 | src_ip_str="192.168.1.1"
|
| 1004 | dst_ip=0xe0010101
|
| 1005 | dst_ip_str="224.1.1.1"
|
| 1006 |
|
| 1007 | port1=config["port_map"].keys()[0]
|
| 1008 | port2=config["port_map"].keys()[1]
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 1009 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 1010 |
|
| 1011 | #add l2 interface group
|
| 1012 | l2_intf_group_list=[]
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 1013 | for port in config["port_map"].keys():
|
| 1014 | if port != port1 and port !=port2:
|
| 1015 | continue
|
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 1016 | l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 1017 | l2_intf_group_list.append(l2_intf_gid)
|
| 1018 | #add vlan flow table
|
| 1019 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 1020 |
|
| 1021 | #add termination flow
|
| 1022 | add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
|
| 1023 |
|
| 1024 | #add l3 interface group
|
| 1025 | mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
|
| 1026 | add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
|
| 1027 |
|
| 1028 | parsed_pkt = simple_udp_packet(pktlen=100,
|
| 1029 | eth_dst=dst_mac_str,
|
| 1030 | eth_src=port1_mac_str,
|
| 1031 | ip_ttl=64,
|
| 1032 | ip_src=src_ip_str,
|
| 1033 | ip_dst=dst_ip_str)
|
| 1034 | pkt=str(parsed_pkt)
|
| 1035 | self.dataplane.send(port1, pkt)
|
| 1036 | verify_packet(self, pkt, port2)
|
| 1037 | verify_no_other_packets(self)
|
| 1038 |
|
| 1039 |
|
Flavio Castro | 77625dd | 2015-11-18 17:04:14 -0500 | [diff] [blame] | 1040 |
|