macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 1 | """
|
| 2 | Flow Test
|
| 3 |
|
| 4 | Test each flow table can set entry, and packet rx correctly.
|
| 5 | """
|
| 6 |
|
| 7 | import logging
|
| 8 |
|
| 9 | from oftest import config
|
| 10 | import oftest.base_tests as base_tests
|
| 11 | import ofp
|
| 12 | from oftest.testutils import *
|
| 13 | from accton_util import *
|
| 14 |
|
| 15 | class L2McastFlow(base_tests.SimpleDataPlane):
|
| 16 | """
|
| 17 | Test output function for an exact-match flow
|
| 18 |
|
| 19 | Add some multicast flows
|
| 20 | Then, for all ports, verifies that sending a matching packet
|
| 21 | to a multicast match results in an output to all ports.
|
| 22 | """
|
| 23 | def runTest(self):
|
| 24 | ports = sorted(config["port_map"].keys())
|
| 25 |
|
| 26 | delete_all_flows(self.controller)
|
| 27 | delete_all_groups(self.controller)
|
| 28 |
|
| 29 | # table 10: vlan
|
| 30 | # send to table 20
|
| 31 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 32 |
|
| 33 | # group table
|
| 34 | # set up untag groups for each port
|
| 35 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
|
| 36 |
|
| 37 | # set up multicast group
|
| 38 | add_l2_mcast_group(self.controller, config["port_map"].keys(), 1, 1)
|
| 39 |
|
macauley | 53e64c4 | 2015-07-30 14:07:45 +0800 | [diff] [blame] | 40 | test_macs = [[0x01, 0x00, 0x5e, 0x0f, 0xff, 0xff]]
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 41 |
|
| 42 | for test_mac in test_macs:
|
| 43 | group_id = encode_l2_mcast_group_id(1, 1)
|
| 44 | add_bridge_flow(self.controller, test_mac, 1, group_id, True)
|
| 45 |
|
| 46 | for test_mac in test_macs:
|
| 47 | mactest = ':'.join(['%02X' % x for x in test_mac])
|
| 48 |
|
| 49 | for in_port in ports:
|
| 50 | # change dest based on port number
|
| 51 | parsed_pkt = simple_tcp_packet(eth_dst=mactest)
|
| 52 | pkt = str(parsed_pkt)
|
| 53 | logging.info("OutputExact test, from port %d to mac %s", in_port, mactest)
|
| 54 | self.dataplane.send(in_port, pkt)
|
| 55 |
|
| 56 | for ofport in ports:
|
| 57 | if ofport == in_port: #tx port won't rx packet, unless L3 mcast routing
|
| 58 | continue
|
| 59 | verify_packet(self, pkt, ofport)
|
| 60 | verify_no_other_packets(self)
|
| 61 |
|
| 62 | class L2UnicastFlow(base_tests.SimpleDataPlane):
|
| 63 | """
|
| 64 | Test output function for an exact-match flow
|
| 65 |
|
| 66 | For each port A, adds a flow directing matching packets to that port.
|
| 67 | Then, for all other ports B != A, verifies that sending a matching packet
|
| 68 | to B results in an output to A.
|
| 69 | """
|
| 70 | def runTest(self):
|
| 71 | ports = sorted(config["port_map"].keys())
|
| 72 |
|
| 73 | delete_all_flows(self.controller)
|
| 74 | delete_all_groups(self.controller)
|
| 75 | # table 10: vlan
|
| 76 | # send to table 20
|
| 77 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 78 |
|
| 79 | # group table
|
| 80 | # set up untag groups for each port
|
| 81 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
|
| 82 |
|
| 83 | for out_port in ports:
|
| 84 | group_id = encode_l2_interface_group_id(1, out_port)
|
| 85 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, out_port], 1, group_id, True)
|
| 86 |
|
| 87 | for in_port in ports:
|
| 88 | if in_port == out_port:
|
| 89 | continue
|
| 90 | # change dest based on port number
|
| 91 | parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:%02X' % out_port)
|
| 92 | pkt = str(parsed_pkt)
|
| 93 | logging.info("OutputExact test, ports %d to %d", in_port, out_port)
|
| 94 | self.dataplane.send(in_port, pkt)
|
| 95 |
|
| 96 | for ofport in ports:
|
| 97 | if ofport in [out_port]:
|
| 98 | verify_packet(self, pkt, ofport)
|
| 99 | else:
|
| 100 | verify_no_packet(self, pkt, ofport)
|
| 101 |
|
| 102 | verify_no_other_packets(self)
|
| 103 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 104 | class L2Flood(base_tests.SimpleDataPlane):
|
| 105 | """
|
| 106 | Test L2 unknown unicast flooding and broadcast flood
|
| 107 | """
|
| 108 | def runTest(self):
|
| 109 | ports = sorted(config["port_map"].keys())
|
| 110 |
|
| 111 | delete_all_flows(self.controller)
|
| 112 | delete_all_groups(self.controller)
|
| 113 | # table 10: vlan
|
| 114 | # send to table 20
|
| 115 | add_vlan_table_flow(self.controller, ports, 1)
|
| 116 |
|
| 117 | # group table
|
| 118 | # set up untag groups for each port
|
| 119 | add_l2_interface_grouop(self.controller, ports, 1, False, 1)
|
| 120 |
|
| 121 | input_port = ports.pop()
|
| 122 | flood_ports= ports
|
macauley | 53e64c4 | 2015-07-30 14:07:45 +0800 | [diff] [blame] | 123 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 124 | #no fllod group create, veriy all drop
|
| 125 | parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
|
| 126 | pkt = str(parsed_pkt)
|
| 127 | self.dataplane.send(input_port, pkt)
|
| 128 | verify_no_other_packets(self)
|
| 129 | parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
|
| 130 | pkt = str(parsed_pkt)
|
| 131 | self.dataplane.send(input_port, pkt)
|
| 132 | verify_no_other_packets(self)
|
| 133 | #add flood groupo
|
| 134 | msg=add_l2_flood_group(self.controller, flood_ports, 1, 1)
|
| 135 | add_bridge_flow(self.controller, None, 1, msg.group_id, True)
|
| 136 | #verify flood
|
| 137 | parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
|
| 138 | pkt = str(parsed_pkt)
|
| 139 | self.dataplane.send(input_port, pkt)
|
| 140 | for ofport in flood_ports:
|
| 141 | verify_packet(self, pkt, ofport)
|
| 142 |
|
| 143 | verify_no_other_packets(self)
|
| 144 |
|
| 145 | for ofport in flood_ports:
|
| 146 | self.dataplane.send(ofport, pkt)
|
macauley | 53e64c4 | 2015-07-30 14:07:45 +0800 | [diff] [blame] | 147 | #self won't rx packet
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 148 | verify_no_packet(self, pkt, ofport)
|
macauley | 53e64c4 | 2015-07-30 14:07:45 +0800 | [diff] [blame] | 149 | #others will rx packet
|
| 150 | tmp_ports=[]
|
| 151 | for tmp in flood_ports:
|
| 152 | if tmp != ofport:
|
| 153 | tmp_ports.append(tmp)
|
| 154 | verify_packets(self, pkt, tmp_ports)
|
| 155 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 156 | verify_no_other_packets(self)
|
| 157 |
|
| 158 | parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
|
| 159 | pkt = str(parsed_pkt)
|
| 160 | self.dataplane.send(input_port, pkt)
|
| 161 | for ofport in flood_ports:
|
| 162 | verify_packet(self, pkt, ofport)
|
| 163 |
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 164 | class PacketInMiss(base_tests.SimpleDataPlane):
|
| 165 | """
|
| 166 | Test packet in function for a table-miss flow
|
| 167 |
|
| 168 | Send a packet to each dataplane port and verify that a packet
|
| 169 | in message is received from the controller for each
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 170 |
|
| 171 | NOTE: Verify This case the oft option shall not use --switch-ip
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 172 | """
|
| 173 |
|
| 174 | def runTest(self):
|
| 175 | delete_all_flows(self.controller)
|
| 176 | delete_all_groups(self.controller)
|
| 177 |
|
| 178 | parsed_pkt = simple_tcp_packet(pktlen=100)
|
| 179 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
|
| 180 | vlan_vid=0x1001, dl_vlan_enable=True)
|
| 181 | pkt = str(parsed_pkt)
|
| 182 | vlan_pkt = str(parsed_vlan_pkt)
|
| 183 | # table 10: vlan
|
| 184 | # send to table 20
|
| 185 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 186 |
|
| 187 | # group table
|
| 188 | # set up untag groups for each port
|
| 189 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
|
| 190 |
|
| 191 | # create match
|
| 192 | match = ofp.match()
|
| 193 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1001))
|
| 194 | request = ofp.message.flow_add(
|
| 195 | table_id=60,
|
| 196 | cookie=42,
|
| 197 | match=match,
|
| 198 | instructions=[
|
| 199 | ofp.instruction.apply_actions(
|
| 200 | actions=[
|
| 201 | ofp.action.output(
|
| 202 | port=ofp.OFPP_CONTROLLER,
|
| 203 | max_len=ofp.OFPCML_NO_BUFFER)]),
|
| 204 | ],
|
| 205 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 206 | priority=1)
|
| 207 |
|
| 208 | logging.info("Inserting packet in flow to controller")
|
| 209 | self.controller.message_send(request)
|
| 210 | do_barrier(self.controller)
|
| 211 |
|
| 212 | for of_port in config["port_map"].keys():
|
| 213 | logging.info("PacketInMiss test, port %d", of_port)
|
| 214 | self.dataplane.send(of_port, pkt)
|
| 215 |
|
| 216 | #AOS current packet in will not have vlan tag
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 217 | if config["cicada_poject"]:
|
| 218 | verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
|
| 219 | else:
|
| 220 | verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
|
| 221 |
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 222 | verify_no_other_packets(self)
|
| 223 |
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 224 | class PacketOut(base_tests.SimpleDataPlane):
|
| 225 | """
|
| 226 | Verify action Flood, ALL, in port
|
| 227 | """
|
| 228 |
|
| 229 | def runTest(self):
|
| 230 | if config["cicada_poject"]:
|
| 231 | pass
|
| 232 |
|
| 233 | delete_all_flows(self.controller)
|
| 234 | delete_all_groups(self.controller)
|
| 235 |
|
| 236 | parsed_pkt = simple_tcp_packet(pktlen=100)
|
| 237 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
|
| 238 | vlan_vid=0x1002, dl_vlan_enable=True)
|
| 239 |
|
| 240 | pkt = str(parsed_pkt)
|
| 241 | vlan_pkt = str(parsed_vlan_pkt)
|
| 242 |
|
| 243 |
|
| 244 | #packet out flood, untag packet
|
| 245 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 246 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 247 | actions=[ofp.action.output(
|
| 248 | port=ofp.OFPP_FLOOD)],
|
| 249 | data=pkt))
|
| 250 |
|
| 251 | for of_port in config["port_map"].keys():
|
| 252 | verify_packet(self, pkt, of_port)
|
| 253 |
|
| 254 | verify_no_other_packets(self)
|
| 255 |
|
| 256 | #packet out flood, tag packet, because it can't identify vlan has which port
|
| 257 | #so we do as all action.
|
| 258 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 259 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 260 | actions=[ofp.action.output(
|
| 261 | port=ofp.OFPP_FLOOD)],
|
| 262 | data=vlan_pkt))
|
| 263 |
|
| 264 | for of_port in config["port_map"].keys():
|
| 265 | verify_packet(self, vlan_pkt, of_port)
|
| 266 |
|
| 267 | verify_no_other_packets(self)
|
| 268 |
|
| 269 | #packet out all
|
| 270 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 271 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 272 | actions=[ofp.action.output(
|
| 273 | port=ofp.OFPP_FLOOD)],
|
| 274 | data=pkt))
|
| 275 |
|
| 276 | for of_port in config["port_map"].keys():
|
| 277 | verify_packet(self, pkt, of_port)
|
| 278 |
|
| 279 | verify_no_other_packets(self)
|
| 280 |
|
| 281 | #packet out to in port
|
| 282 | in_port = config["port_map"].keys()[0]
|
| 283 | self.controller.message_send(ofp.message.packet_out(in_port=in_port,
|
| 284 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 285 | actions=[ofp.action.output(
|
| 286 | port=in_port)],
|
| 287 | data=pkt))
|
| 288 |
|
| 289 | verify_packet(self, pkt, in_port)
|
| 290 | verify_no_other_packets(self)
|
| 291 |
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 292 | class L3UcastRoute(base_tests.SimpleDataPlane):
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 293 | """
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 294 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 295 | Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 296 | """
|
| 297 | def runTest(self):
|
| 298 | delete_all_flows(self.controller)
|
| 299 | delete_all_groups(self.controller)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 300 |
|
| 301 | if len(config["port_map"]) <2:
|
| 302 | logging.info("Port count less than 2, can't run this case")
|
| 303 | return
|
| 304 |
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 305 | vlan_id=1
|
| 306 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 307 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
|
| 308 | dip=0xc0a80001
|
| 309 | for port in config["port_map"].keys():
|
| 310 | #add l2 interface group
|
| 311 | add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
| 312 | dst_mac[5]=vlan_id
|
| 313 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
|
| 314 | #add vlan flow table
|
| 315 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 316 | #add termination flow
|
| 317 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
|
| 318 | #add unicast routing flow
|
| 319 | dst_ip = dip + (vlan_id<<8)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 320 | 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] | 321 | vlan_id += 1
|
| 322 |
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 323 | do_barrier(self.controller)
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 324 |
|
| 325 | port1=config["port_map"].keys()[0]
|
| 326 | port2=config["port_map"].keys()[1]
|
| 327 | #port 1 to port 2
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 328 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 329 | dst_mac[5]=1
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 330 | port1_mac=':'.join(['%02X' % x for x in dst_mac])
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 331 |
|
| 332 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 333 | eth_dst=switch_mac,
|
| 334 | eth_src=port1_mac,
|
| 335 | ip_ttl=64,
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 336 | ip_src="192.168.1.1",
|
| 337 | ip_dst='192.168.2.1')
|
| 338 | pkt=str(parsed_pkt)
|
| 339 | self.dataplane.send(port1, pkt)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 340 | #build expect packet
|
| 341 | dst_mac[5]=2
|
| 342 | port2_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 343 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 344 | eth_dst=port2_mac,
|
| 345 | eth_src=switch_mac,
|
| 346 | ip_ttl=63,
|
| 347 | ip_src="192.168.1.1",
|
| 348 | ip_dst='192.168.2.1')
|
| 349 | pkt=str(exp_pkt)
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 350 | verify_packet(self, pkt, port2)
|
| 351 | verify_no_other_packets(self)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 352 |
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 353 | #port 2 to port 1
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 354 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 355 | dst_mac[5]=2
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 356 | port2_mac=':'.join(['%02X' % x for x in dst_mac])
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 357 |
|
| 358 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 359 | eth_dst=switch_mac,
|
| 360 | eth_src=port2_mac,
|
| 361 | ip_ttl=64,
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 362 | ip_src="192.168.2.1",
|
| 363 | ip_dst='192.168.1.1')
|
| 364 | pkt=str(parsed_pkt)
|
| 365 | self.dataplane.send(port2, pkt)
|
macauley | fa788eb | 2015-07-23 15:13:54 +0800 | [diff] [blame] | 366 | #build expect packet
|
| 367 | dst_mac[5]=1
|
| 368 | port1_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 369 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 370 | eth_dst=port1_mac,
|
| 371 | eth_src=switch_mac,
|
| 372 | ip_ttl=63,
|
| 373 | ip_src="192.168.2.1",
|
| 374 | ip_dst='192.168.1.1')
|
| 375 | pkt=str(exp_pkt)
|
| 376 | verify_packet(self, pkt, port1)
|
| 377 | verify_no_other_packets(self)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 378 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 379 | class L3UcastECMP(base_tests.SimpleDataPlane):
|
| 380 | """
|
| 381 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
|
| 382 | Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
|
| 383 | """
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 384 | def runTest(self):
|
| 385 | delete_all_flows(self.controller)
|
| 386 | delete_all_groups(self.controller)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 387 |
|
| 388 | if len(config["port_map"]) <2:
|
| 389 | logging.info("Port count less than 2, can't run this case")
|
| 390 | return
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame] | 391 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 392 | vlan_id=1
|
| 393 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 394 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
|
| 395 | dip=0xc0a80001
|
| 396 | for port in config["port_map"].keys():
|
| 397 | #add l2 interface group
|
| 398 | add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
| 399 | dst_mac[5]=vlan_id
|
| 400 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
|
| 401 | ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [l3_msg.group_id])
|
| 402 | #add vlan flow table
|
| 403 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 404 | #add termination flow
|
| 405 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
|
| 406 | #add unicast routing flow
|
| 407 | dst_ip = dip + (vlan_id<<8)
|
| 408 | #ECMP shall have prefix not 32
|
| 409 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
|
| 410 | vlan_id += 1
|
| 411 |
|
| 412 | do_barrier(self.controller)
|
| 413 |
|
| 414 | port1=config["port_map"].keys()[0]
|
| 415 | port2=config["port_map"].keys()[1]
|
| 416 | #port 1 to port 2
|
| 417 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
| 418 | dst_mac[5]=1
|
| 419 | port1_mac=':'.join(['%02X' % x for x in dst_mac])
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 420 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 421 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 422 | eth_dst=switch_mac,
|
| 423 | eth_src=port1_mac,
|
| 424 | ip_ttl=64,
|
| 425 | ip_src="192.168.1.1",
|
| 426 | ip_dst='192.168.2.1')
|
| 427 | pkt=str(parsed_pkt)
|
| 428 | self.dataplane.send(port1, pkt)
|
| 429 | #build expect packet
|
| 430 | dst_mac[5]=2
|
| 431 | port2_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 432 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 433 | eth_dst=port2_mac,
|
| 434 | eth_src=switch_mac,
|
| 435 | ip_ttl=63,
|
| 436 | ip_src="192.168.1.1",
|
| 437 | ip_dst='192.168.2.1')
|
| 438 | pkt=str(exp_pkt)
|
| 439 | verify_packet(self, pkt, port2)
|
| 440 | verify_no_other_packets(self)
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 441 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 442 | #port 2 to port 1
|
| 443 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
|
| 444 | dst_mac[5]=2
|
| 445 | port2_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 446 |
|
| 447 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 448 | eth_dst=switch_mac,
|
| 449 | eth_src=port2_mac,
|
| 450 | ip_ttl=64,
|
| 451 | ip_src="192.168.2.1",
|
| 452 | ip_dst='192.168.1.1')
|
| 453 | pkt=str(parsed_pkt)
|
| 454 | self.dataplane.send(port2, pkt)
|
| 455 | #build expect packet
|
| 456 | dst_mac[5]=1
|
| 457 | port1_mac=':'.join(['%02X' % x for x in dst_mac])
|
| 458 | exp_pkt = simple_tcp_packet(pktlen=100,
|
| 459 | eth_dst=port1_mac,
|
| 460 | eth_src=switch_mac,
|
| 461 | ip_ttl=63,
|
| 462 | ip_src="192.168.2.1",
|
| 463 | ip_dst='192.168.1.1')
|
| 464 | pkt=str(exp_pkt)
|
| 465 | verify_packet(self, pkt, port1)
|
| 466 | verify_no_other_packets(self)
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 467 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 468 | class L3McastRoute1(base_tests.SimpleDataPlane):
|
| 469 | """
|
| 470 | Mcast routing, From VLAN 1 to VLAN 2
|
| 471 | """
|
| 472 | def runTest(self):
|
| 473 | """
|
| 474 | port1 (vlan 1)-> port 2 (vlan 2)
|
| 475 | """
|
| 476 | delete_all_flows(self.controller)
|
| 477 | delete_all_groups(self.controller)
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 478 |
|
| 479 | if len(config["port_map"]) <3:
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 480 | logging.info("Port count less than 2, can't run this case")
|
| 481 | return
|
| 482 |
|
| 483 | vlan_id =1
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 484 | port2_out_vlan=2
|
| 485 | port3_out_vlan=3
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 486 | in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
|
| 487 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 488 | intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
|
| 489 | dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
|
| 490 | dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
|
| 491 | port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
|
| 492 | port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
|
| 493 | src_ip=0xc0a80101
|
| 494 | src_ip_str="192.168.1.1"
|
| 495 | dst_ip=0xe0010101
|
| 496 | dst_ip_str="224.1.1.1"
|
| 497 |
|
| 498 | port1=config["port_map"].keys()[0]
|
| 499 | port2=config["port_map"].keys()[1]
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 500 | port3=config["port_map"].keys()[2]
|
| 501 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 502 | #add l2 interface group
|
| 503 | for port in config["port_map"].keys():
|
| 504 | add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
| 505 | #add vlan flow table
|
| 506 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 507 | vlan_id +=1
|
| 508 |
|
| 509 | #add termination flow
|
| 510 | add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
|
| 511 |
|
| 512 | #add l3 interface group
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 513 | port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
|
| 514 | port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
|
| 515 | 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] | 516 | add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
|
| 517 |
|
| 518 | parsed_pkt = simple_udp_packet(pktlen=100,
|
| 519 | eth_dst=dst_mac_str,
|
| 520 | eth_src=port1_mac_str,
|
| 521 | ip_ttl=64,
|
| 522 | ip_src=src_ip_str,
|
| 523 | ip_dst=dst_ip_str)
|
| 524 | pkt=str(parsed_pkt)
|
| 525 | self.dataplane.send(port1, pkt)
|
| 526 | parsed_pkt = simple_udp_packet(pktlen=100,
|
| 527 | eth_dst=dst_mac_str,
|
| 528 | eth_src=intf_src_mac_str,
|
| 529 | ip_ttl=63,
|
| 530 | ip_src=src_ip_str,
|
| 531 | ip_dst=dst_ip_str)
|
| 532 | pkt=str(parsed_pkt)
|
| 533 | verify_packet(self, pkt, port2)
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 534 | verify_packet(self, pkt, port3)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 535 | verify_no_other_packets(self)
|
| 536 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 537 | class L3McastRoute2(base_tests.SimpleDataPlane):
|
| 538 | """
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 539 | Mcast routing, but on same vlan (l2mcast)
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 540 | """
|
| 541 | def runTest(self):
|
| 542 | """
|
| 543 | port1 (vlan 1)-> port 2 (vlan 1)
|
| 544 | """
|
| 545 | delete_all_flows(self.controller)
|
| 546 | delete_all_groups(self.controller)
|
| 547 |
|
| 548 | if len(config["port_map"]) <2:
|
| 549 | logging.info("Port count less than 2, can't run this case")
|
| 550 | return
|
| 551 |
|
| 552 | vlan_id =1
|
| 553 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 554 | intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
|
| 555 | dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
|
| 556 | dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
|
| 557 | port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
|
| 558 | port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
|
| 559 | src_ip=0xc0a80101
|
| 560 | src_ip_str="192.168.1.1"
|
| 561 | dst_ip=0xe0010101
|
| 562 | dst_ip_str="224.1.1.1"
|
| 563 |
|
| 564 | port1=config["port_map"].keys()[0]
|
| 565 | port2=config["port_map"].keys()[1]
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 566 |
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 567 |
|
| 568 | #add l2 interface group
|
| 569 | l2_intf_group_list=[]
|
macauley | c8edafa | 2015-07-30 14:26:18 +0800 | [diff] [blame] | 570 | for port in config["port_map"].keys():
|
| 571 | if port != port1 and port !=port2:
|
| 572 | continue
|
macauley | 76cc8d2 | 2015-07-27 17:40:36 +0800 | [diff] [blame] | 573 | l2_intf_gid, msg=add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
| 574 | l2_intf_group_list.append(l2_intf_gid)
|
| 575 | #add vlan flow table
|
| 576 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 577 |
|
| 578 | #add termination flow
|
| 579 | add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
|
| 580 |
|
| 581 | #add l3 interface group
|
| 582 | mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
|
| 583 | add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
|
| 584 |
|
| 585 | parsed_pkt = simple_udp_packet(pktlen=100,
|
| 586 | eth_dst=dst_mac_str,
|
| 587 | eth_src=port1_mac_str,
|
| 588 | ip_ttl=64,
|
| 589 | ip_src=src_ip_str,
|
| 590 | ip_dst=dst_ip_str)
|
| 591 | pkt=str(parsed_pkt)
|
| 592 | self.dataplane.send(port1, pkt)
|
| 593 | verify_packet(self, pkt, port2)
|
| 594 | verify_no_other_packets(self)
|
| 595 |
|
| 596 |
|
| 597 | |