Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 1 | """ |
Flavio Castro | c36621e | 2015-12-08 12:57:07 -0500 | [diff] [blame] | 2 | The following tests are being done here |
Flavio Castro | 3aec890 | 2015-11-20 10:51:38 -0500 | [diff] [blame] | 3 | 1) PacketInSrcMacMiss |
castroflavio | 9e715f3 | 2015-12-08 14:04:12 -0500 | [diff] [blame] | 4 | 2) VlanSupport |
| 5 | 3) L2FloodQinQ |
| 6 | 4) L2FloodTagged |
| 7 | 5) L2Flood Tagged Unknown Src |
| 8 | 6) L2 Unicast Tagged |
| 9 | 7) MTU 1500 |
| 10 | 8) MTU 4100 |
| 11 | 9) MTU 4500 |
| 12 | 10) L3UnicastTagged |
| 13 | 11) L3VPNMPLS |
| 14 | 12) MPLS Termination |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 15 | """ |
| 16 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 17 | from oftest import config |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 18 | import logging |
| 19 | import oftest.base_tests as base_tests |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 20 | import ofp |
| 21 | from oftest.testutils import * |
| 22 | from accton_util import * |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 23 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 24 | class PacketInSrcMacMiss(base_tests.SimpleDataPlane): |
| 25 | """ |
| 26 | Test packet in function on a src-mac miss |
| 27 | Send a packet to each dataplane port and verify that a packet |
| 28 | in message is received from the controller for each |
| 29 | #todo verify you stop receiving after adding rule |
| 30 | """ |
| 31 | |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 32 | def runTest(self): |
| 33 | delete_all_flows(self.controller) |
| 34 | delete_all_groups(self.controller) |
| 35 | |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 36 | ports = sorted(config["port_map"].keys()) |
| 37 | for port in ports: |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 38 | add_one_l2_interface_group(self.controller, port, 1, True, False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 39 | add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 40 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 41 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104, |
| 42 | vlan_vid=0x1001, dl_vlan_enable=True) |
| 43 | vlan_pkt = str(parsed_vlan_pkt) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 44 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 45 | for of_port in config["port_map"].keys(): |
| 46 | logging.info("PacketInMiss test, port %d", of_port) |
| 47 | self.dataplane.send(of_port, vlan_pkt) |
| 48 | |
| 49 | verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH) |
| 50 | |
| 51 | verify_no_other_packets(self) |
| 52 | |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 53 | class PacketInUDP(base_tests.SimpleDataPlane): |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 54 | """ |
| 55 | Test packet in function for a table-miss flow |
| 56 | Send a packet to each dataplane port and verify that a packet |
| 57 | in message is received from the controller for each |
| 58 | |
| 59 | NOTE: Verify This case the oft option shall not use --switch-ip |
| 60 | """ |
| 61 | |
| 62 | def runTest(self): |
| 63 | delete_all_flows(self.controller) |
| 64 | delete_all_groups(self.controller) |
| 65 | |
| 66 | parsed_vlan_pkt = simple_udp_packet(pktlen=104, |
| 67 | vlan_vid=0x1001, dl_vlan_enable=True) |
| 68 | vlan_pkt = str(parsed_vlan_pkt) |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 69 | # create match |
| 70 | match = ofp.match() |
| 71 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
castroflavio | 4a09c96 | 2016-01-05 13:13:41 -0800 | [diff] [blame] | 72 | match.oxm_list.append(ofp.oxm.ip_proto(17)) |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 73 | request = ofp.message.flow_add( |
| 74 | table_id=60, |
| 75 | cookie=42, |
| 76 | match=match, |
| 77 | instructions=[ |
| 78 | ofp.instruction.apply_actions( |
| 79 | actions=[ |
| 80 | ofp.action.output( |
| 81 | port=ofp.OFPP_CONTROLLER, |
| 82 | max_len=ofp.OFPCML_NO_BUFFER)]), |
| 83 | ], |
| 84 | buffer_id=ofp.OFP_NO_BUFFER, |
| 85 | priority=1) |
| 86 | |
| 87 | logging.info("Inserting packet in flow to controller") |
| 88 | self.controller.message_send(request) |
| 89 | do_barrier(self.controller) |
| 90 | |
| 91 | for of_port in config["port_map"].keys(): |
| 92 | logging.info("PacketInMiss test, port %d", of_port) |
| 93 | self.dataplane.send(of_port, vlan_pkt) |
| 94 | |
| 95 | verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION) |
| 96 | |
| 97 | verify_no_other_packets(self) |
| 98 | |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 99 | class PacketInIPTable(base_tests.SimpleDataPlane): |
| 100 | """ |
| 101 | Test packet in function on IPTABLE |
| 102 | Send a packet to each dataplane port and verify that a packet |
| 103 | in message is received from the controller for each |
| 104 | #todo verify you stop receiving after adding rule |
| 105 | """ |
| 106 | |
| 107 | def runTest(self): |
| 108 | delete_all_flows(self.controller) |
| 109 | delete_all_groups(self.controller) |
| 110 | |
| 111 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 112 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 113 | dip=0xc0a80001 |
| 114 | ports = sorted(config["port_map"].keys()) |
| 115 | for port in ports: |
| 116 | #add l2 interface group |
| 117 | vlan_id=port |
| 118 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False) |
| 119 | dst_mac[5]=vlan_id |
| 120 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
| 121 | #add vlan flow table |
| 122 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 123 | #add termination flow |
| 124 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
| 125 | #add unicast routing flow |
| 126 | dst_ip = dip + (vlan_id<<8) |
| 127 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xfffffff0, l3_msg.group_id, send_ctrl=True) |
| 128 | |
| 129 | do_barrier(self.controller) |
| 130 | |
| 131 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 132 | for in_port in ports: |
| 133 | mac_src='00:00:00:22:22:%02X' % in_port |
| 134 | ip_src='192.168.%02d.1' % in_port |
| 135 | for out_port in ports: |
| 136 | if in_port == out_port: |
| 137 | continue |
| 138 | ip_dst='192.168.%02d.1' % out_port |
| 139 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 140 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, |
| 141 | ip_dst=ip_dst) |
| 142 | pkt=str(parsed_pkt) |
| 143 | self.dataplane.send(in_port, pkt) |
| 144 | verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION) |
| 145 | #verify_no_other_packets(self) |
| 146 | |
| 147 | |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 148 | class ArpNL2(base_tests.SimpleDataPlane): |
| 149 | def runTest(self): |
| 150 | delete_all_flows(self.controller) |
| 151 | delete_all_groups(self.controller) |
| 152 | |
| 153 | ports = sorted(config["port_map"].keys()) |
| 154 | match = ofp.match() |
| 155 | match.oxm_list.append(ofp.oxm.eth_type(0x0806)) |
| 156 | request = ofp.message.flow_add( |
| 157 | table_id=60, |
| 158 | cookie=42, |
| 159 | match=match, |
| 160 | instructions=[ |
| 161 | ofp.instruction.apply_actions( |
| 162 | actions=[ |
| 163 | ofp.action.output( |
| 164 | port=ofp.OFPP_CONTROLLER, |
| 165 | max_len=ofp.OFPCML_NO_BUFFER)]), |
| 166 | ], |
| 167 | buffer_id=ofp.OFP_NO_BUFFER, |
| 168 | priority=40000) |
| 169 | self.controller.message_send(request) |
| 170 | for port in ports: |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 171 | add_one_l2_interface_group(self.controller, port, 1, False, False) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 172 | add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 173 | group_id = encode_l2_interface_group_id(1, port) |
| 174 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
| 175 | do_barrier(self.controller) |
| 176 | parsed_arp_pkt = simple_arp_packet() |
| 177 | arp_pkt = str(parsed_arp_pkt) |
| 178 | |
| 179 | for out_port in ports: |
| 180 | self.dataplane.send(out_port, arp_pkt) |
| 181 | verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION) |
| 182 | # change dest based on port number |
| 183 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 184 | for in_port in ports: |
| 185 | if in_port == out_port: |
| 186 | continue |
| 187 | # change source based on port number to avoid packet-ins from learning |
| 188 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 189 | parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src) |
| 190 | pkt = str(parsed_pkt) |
| 191 | self.dataplane.send(in_port, pkt) |
| 192 | |
| 193 | for ofport in ports: |
| 194 | if ofport in [out_port]: |
| 195 | verify_packet(self, pkt, ofport) |
| 196 | else: |
| 197 | verify_no_packet(self, pkt, ofport) |
| 198 | |
| 199 | verify_no_other_packets(self) |
| 200 | |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 201 | class PacketInArp(base_tests.SimpleDataPlane): |
| 202 | """ |
| 203 | Test packet in function for a table-miss flow |
| 204 | Send a packet to each dataplane port and verify that a packet |
| 205 | in message is received from the controller for each |
| 206 | |
| 207 | NOTE: Verify This case the oft option shall not use --switch-ip |
| 208 | """ |
| 209 | |
| 210 | def runTest(self): |
| 211 | delete_all_flows(self.controller) |
| 212 | delete_all_groups(self.controller) |
| 213 | |
| 214 | parsed_arp_pkt = simple_arp_packet() |
| 215 | arp_pkt = str(parsed_arp_pkt) |
| 216 | ports = sorted(config["port_map"].keys()) |
| 217 | #for port in ports: |
| 218 | # add_one_l2_interface_group(self.controller, port, 1, True, False) |
| 219 | # add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 220 | |
| 221 | # create match |
| 222 | match = ofp.match() |
| 223 | match.oxm_list.append(ofp.oxm.eth_type(0x0806)) |
| 224 | request = ofp.message.flow_add( |
| 225 | table_id=60, |
| 226 | cookie=42, |
| 227 | match=match, |
| 228 | instructions=[ |
| 229 | ofp.instruction.apply_actions( |
| 230 | actions=[ |
| 231 | ofp.action.output( |
| 232 | port=ofp.OFPP_CONTROLLER, |
| 233 | max_len=ofp.OFPCML_NO_BUFFER)]), |
| 234 | ], |
| 235 | buffer_id=ofp.OFP_NO_BUFFER, |
| 236 | priority=1) |
| 237 | |
| 238 | logging.info("Inserting packet in flow to controller") |
| 239 | self.controller.message_send(request) |
| 240 | do_barrier(self.controller) |
| 241 | |
| 242 | for of_port in config["port_map"].keys(): |
| 243 | logging.info("PacketInMiss test, port %d", of_port) |
| 244 | self.dataplane.send(of_port, arp_pkt) |
| 245 | |
| 246 | verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION) |
| 247 | |
| 248 | verify_no_other_packets(self) |
| 249 | |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 250 | class L2FloodQinQ(base_tests.SimpleDataPlane): |
| 251 | """ |
Flavio Castro | c36621e | 2015-12-08 12:57:07 -0500 | [diff] [blame] | 252 | Test L2 flood of double tagged vlan packets (802.1Q) |
| 253 | Sends a double tagged packet and verifies flooding behavior according to outer vlan |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 254 | """ |
| 255 | def runTest(self): |
| 256 | ports = sorted(config["port_map"].keys()) |
| 257 | |
| 258 | delete_all_flows(self.controller) |
| 259 | delete_all_groups(self.controller) |
| 260 | |
| 261 | # Installing flows to avoid packet-in |
| 262 | for port in ports: |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 263 | add_one_l2_interface_group(self.controller, port, 1, True, False) |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 264 | add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 265 | |
| 266 | group_id = encode_l2_interface_group_id(1, port) |
| 267 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
| 268 | msg=add_l2_flood_group(self.controller, ports, 1, 1) |
| 269 | add_bridge_flow(self.controller, None, 1, msg.group_id, True) |
| 270 | do_barrier(self.controller) |
| 271 | |
| 272 | #verify flood |
| 273 | for ofport in ports: |
| 274 | # change dest based on port number |
| 275 | mac_src= '00:12:34:56:78:%02X' % ofport |
| 276 | parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=1, |
| 277 | in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src) |
| 278 | pkt = str(parsed_pkt) |
| 279 | self.dataplane.send(ofport, pkt) |
| 280 | #self won't rx packet |
| 281 | verify_no_packet(self, pkt, ofport) |
| 282 | #others will rx packet |
| 283 | tmp_ports=list(ports) |
| 284 | tmp_ports.remove(ofport) |
| 285 | verify_packets(self, pkt, tmp_ports) |
| 286 | |
| 287 | verify_no_other_packets(self) |
| 288 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 289 | class L2FloodTagged(base_tests.SimpleDataPlane): |
| 290 | """ |
| 291 | Test L2 flood to a vlan |
| 292 | Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport |
| 293 | #todo take in account unknown src |
| 294 | """ |
| 295 | def runTest(self): |
| 296 | ports = sorted(config["port_map"].keys()) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 297 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 298 | delete_all_flows(self.controller) |
| 299 | delete_all_groups(self.controller) |
| 300 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 301 | # Installing flows to avoid packet-in |
| 302 | for port in ports: |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 303 | add_one_l2_interface_group(self.controller, port, 1, True, False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 304 | add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 305 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 306 | group_id = encode_l2_interface_group_id(1, port) |
| 307 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 308 | msg=add_l2_flood_group(self.controller, ports, 1, 1) |
| 309 | add_bridge_flow(self.controller, None, 1, msg.group_id, True) |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 310 | do_barrier(self.controller) |
| 311 | |
| 312 | #verify flood |
| 313 | for ofport in ports: |
| 314 | # change dest based on port number |
| 315 | mac_src= '00:12:34:56:78:%02X' % ofport |
| 316 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src) |
| 317 | pkt = str(parsed_pkt) |
| 318 | self.dataplane.send(ofport, pkt) |
| 319 | #self won't rx packet |
| 320 | verify_no_packet(self, pkt, ofport) |
| 321 | #others will rx packet |
| 322 | tmp_ports=list(ports) |
| 323 | tmp_ports.remove(ofport) |
| 324 | verify_packets(self, pkt, tmp_ports) |
| 325 | |
| 326 | verify_no_other_packets(self) |
| 327 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 328 | class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane): |
| 329 | """ |
| 330 | Test L2 flood to a vlan |
| 331 | Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport |
| 332 | #todo take in account unknown src |
| 333 | """ |
| 334 | def runTest(self): |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 335 | delete_all_flows(self.controller) |
| 336 | delete_all_groups(self.controller) |
| 337 | |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 338 | ports = sorted(config["port_map"].keys()) |
| 339 | for port in ports: |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 340 | add_one_l2_interface_group(self.controller, port, 1, True, False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 341 | add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 342 | |
| 343 | msg=add_l2_flood_group(self.controller, ports, 1, 1) |
| 344 | add_bridge_flow(self.controller, None, 1, msg.group_id, True) |
| 345 | |
| 346 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a') |
| 347 | pkt = str(parsed_pkt) |
| 348 | #verify flood |
| 349 | for ofport in ports: |
| 350 | self.dataplane.send(ofport, pkt) |
| 351 | #self won't rx packet |
| 352 | verify_no_packet(self, pkt, ofport) |
| 353 | #others will rx packet |
| 354 | tmp_ports=list(ports) |
| 355 | tmp_ports.remove(ofport) |
| 356 | verify_packets(self, pkt, tmp_ports) |
| 357 | |
| 358 | verify_no_other_packets(self) |
| 359 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 360 | class L2UnicastTagged(base_tests.SimpleDataPlane): |
| 361 | """ |
| 362 | Test output function for an exact-match flow |
| 363 | |
| 364 | For each port A, adds a flow directing matching packets to that port. |
| 365 | Then, for all other ports B != A, verifies that sending a matching packet |
| 366 | to B results in an output to A. |
| 367 | """ |
| 368 | def runTest(self): |
| 369 | ports = sorted(config["port_map"].keys()) |
| 370 | |
| 371 | delete_all_flows(self.controller) |
| 372 | delete_all_groups(self.controller) |
| 373 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 374 | for port in ports: |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 375 | add_one_l2_interface_group(self.controller, port, 1, True, False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 376 | add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 377 | group_id = encode_l2_interface_group_id(1, port) |
| 378 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 379 | do_barrier(self.controller) |
| 380 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 381 | for out_port in ports: |
| 382 | # change dest based on port number |
| 383 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 384 | for in_port in ports: |
| 385 | if in_port == out_port: |
| 386 | continue |
| 387 | # change source based on port number to avoid packet-ins from learning |
| 388 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 389 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 390 | pkt = str(parsed_pkt) |
| 391 | self.dataplane.send(in_port, pkt) |
| 392 | |
| 393 | for ofport in ports: |
| 394 | if ofport in [out_port]: |
| 395 | verify_packet(self, pkt, ofport) |
| 396 | else: |
| 397 | verify_no_packet(self, pkt, ofport) |
| 398 | |
| 399 | verify_no_other_packets(self) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 400 | |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 401 | class Mtu1500(base_tests.SimpleDataPlane): |
| 402 | |
| 403 | def runTest(self): |
| 404 | ports = sorted(config["port_map"].keys()) |
| 405 | |
| 406 | delete_all_flows(self.controller) |
| 407 | delete_all_groups(self.controller) |
| 408 | |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 409 | # set up tag groups for each port |
Flavio Castro | d4c44d1 | 2015-12-08 14:44:18 -0500 | [diff] [blame] | 410 | add_l2_interface_group(self.controller, ports, 1, True, 1) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 411 | |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 412 | add_vlan_table_flow(self.controller, ports) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 413 | |
| 414 | for port in ports: |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 415 | add_one_l2_interface_group(self.controller, port, 1, True, False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 416 | add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 417 | group_id = encode_l2_interface_group_id(1, port) |
| 418 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
| 419 | do_barrier(self.controller) |
| 420 | |
| 421 | for out_port in ports: |
| 422 | # change dest based on port number |
| 423 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 424 | for in_port in ports: |
| 425 | if in_port == out_port: |
| 426 | continue |
| 427 | # change source based on port number to avoid packet-ins from learning |
| 428 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 429 | parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 430 | pkt = str(parsed_pkt) |
| 431 | self.dataplane.send(in_port, pkt) |
| 432 | |
| 433 | for ofport in ports: |
| 434 | if ofport in [out_port]: |
| 435 | verify_packet(self, pkt, ofport) |
| 436 | else: |
| 437 | verify_no_packet(self, pkt, ofport) |
| 438 | |
| 439 | verify_no_other_packets(self) |
| 440 | |
| 441 | |
| 442 | class Mtu4000(base_tests.SimpleDataPlane): |
| 443 | """ |
| 444 | Test output function for an exact-match flow |
| 445 | For each port A, adds a flow directing matching packets to that port. |
| 446 | Then, for all other ports B != A, verifies that sending a matching packet |
| 447 | to B results in an output to A. |
| 448 | """ |
| 449 | def runTest(self): |
| 450 | ports = sorted(config["port_map"].keys()) |
| 451 | |
| 452 | delete_all_flows(self.controller) |
| 453 | delete_all_groups(self.controller) |
| 454 | |
| 455 | add_vlan_table_flow(self.controller, config["port_map"].keys()) |
| 456 | |
| 457 | # set up tag groups for each port |
Flavio Castro | d4c44d1 | 2015-12-08 14:44:18 -0500 | [diff] [blame] | 458 | add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 459 | |
| 460 | for port in ports: |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 461 | add_one_l2_interface_group(self.controller, port, 1, True, False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 462 | add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 463 | group_id = encode_l2_interface_group_id(1, port) |
| 464 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
| 465 | do_barrier(self.controller) |
| 466 | |
| 467 | for out_port in ports: |
| 468 | # change dest based on port number |
| 469 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 470 | for in_port in ports: |
| 471 | if in_port == out_port: |
| 472 | continue |
| 473 | # change source based on port number to avoid packet-ins from learning |
| 474 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 475 | parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 476 | pkt = str(parsed_pkt) |
| 477 | self.dataplane.send(in_port, pkt) |
| 478 | |
| 479 | for ofport in ports: |
| 480 | if ofport in [out_port]: |
| 481 | verify_packet(self, pkt, ofport) |
| 482 | else: |
| 483 | verify_no_packet(self, pkt, ofport) |
| 484 | |
| 485 | verify_no_other_packets(self) |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 486 | |
| 487 | class L3UcastTagged(base_tests.SimpleDataPlane): |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 488 | """ |
Flavio Castro | 35e6439 | 2015-12-02 16:53:14 -0500 | [diff] [blame] | 489 | Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) , |
| 490 | Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1) |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 491 | """ |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 492 | def runTest(self): |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 493 | delete_all_flows(self.controller) |
| 494 | delete_all_groups(self.controller) |
| 495 | |
| 496 | if len(config["port_map"]) <2: |
| 497 | logging.info("Port count less than 2, can't run this case") |
| 498 | return |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 499 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 500 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 501 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 502 | dip=0xc0a80001 |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 503 | ports = config["port_map"].keys() |
| 504 | for port in ports: |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 505 | #add l2 interface group |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 506 | vlan_id=port |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 507 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False) |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 508 | dst_mac[5]=vlan_id |
| 509 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
| 510 | #add vlan flow table |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 511 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 512 | #add termination flow |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 513 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 514 | #add unicast routing flow |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 515 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 516 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 517 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 518 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 519 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 520 | |
| 521 | do_barrier(self.controller) |
| 522 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 523 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 524 | for in_port in ports: |
| 525 | mac_src='00:00:00:22:22:%02X' % in_port |
| 526 | ip_src='192.168.%02d.1' % in_port |
| 527 | for out_port in ports: |
| 528 | if in_port == out_port: |
| 529 | continue |
| 530 | ip_dst='192.168.%02d.1' % out_port |
| 531 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 532 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 533 | ip_dst=ip_dst) |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 534 | pkt=str(parsed_pkt) |
| 535 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 536 | #build expected packet |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 537 | mac_dst='00:00:00:22:22:%02X' % out_port |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 538 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port, |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 539 | eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, |
| 540 | ip_src=ip_src, ip_dst=ip_dst) |
| 541 | pkt=str(exp_pkt) |
| 542 | verify_packet(self, pkt, out_port) |
| 543 | verify_no_other_packets(self) |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 544 | |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 545 | class L3VPNMPLS(base_tests.SimpleDataPlane): |
| 546 | """ |
| 547 | Insert IP packet |
| 548 | Receive MPLS packet |
| 549 | """ |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 550 | def runTest(self): |
| 551 | delete_all_flows(self.controller) |
| 552 | delete_all_groups(self.controller) |
| 553 | |
| 554 | if len(config["port_map"]) <2: |
| 555 | logging.info("Port count less than 2, can't run this case") |
| 556 | return |
| 557 | |
| 558 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 559 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 560 | dip=0xc0a80001 |
| 561 | index=1 |
| 562 | ports = config["port_map"].keys() |
| 563 | for port in ports: |
| 564 | #add l2 interface group |
| 565 | vlan_id=port |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 566 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 567 | dst_mac[5]=vlan_id |
Flavio Castro | 35e6439 | 2015-12-02 16:53:14 -0500 | [diff] [blame] | 568 | #add MPLS interface group |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 569 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port) |
Flavio Castro | 35e6439 | 2015-12-02 16:53:14 -0500 | [diff] [blame] | 570 | #add MPLS L3 VPN group |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 571 | mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 572 | index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32) |
Flavio Castro | 5edf313 | 2016-01-27 15:45:08 -0500 | [diff] [blame] | 573 | ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid]) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 574 | do_barrier(self.controller) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 575 | #add vlan flow table |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 576 | add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 577 | #add termination flow |
| 578 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
Flavio Castro | 35e6439 | 2015-12-02 16:53:14 -0500 | [diff] [blame] | 579 | #add routing flow |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 580 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | 5edf313 | 2016-01-27 15:45:08 -0500 | [diff] [blame] | 581 | #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2) |
| 582 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id, vrf=2) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 583 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 584 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 585 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 586 | |
| 587 | do_barrier(self.controller) |
| 588 | |
| 589 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 590 | for in_port in ports: |
| 591 | mac_src='00:00:00:22:22:%02X' % in_port |
| 592 | ip_src='192.168.%02d.1' % in_port |
| 593 | for out_port in ports: |
| 594 | if in_port == out_port: |
| 595 | continue |
| 596 | ip_dst='192.168.%02d.1' % out_port |
| 597 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 598 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, |
| 599 | ip_dst=ip_dst) |
| 600 | pkt=str(parsed_pkt) |
| 601 | self.dataplane.send(in_port, pkt) |
| 602 | #build expect packet |
| 603 | mac_dst='00:00:00:22:22:%02X' % out_port |
| 604 | label = (out_port, 0, 1, 32) |
| 605 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src, |
| 606 | ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label]) |
| 607 | pkt=str(exp_pkt) |
| 608 | verify_packet(self, pkt, out_port) |
| 609 | verify_no_other_packets(self) |
castroflavio | ee29484 | 2016-01-06 15:54:28 -0800 | [diff] [blame] | 610 | |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 611 | |
| 612 | class L3VPN_32(base_tests.SimpleDataPlane): |
| 613 | """ |
| 614 | Insert IP packet |
| 615 | Receive MPLS packet |
| 616 | """ |
| 617 | def runTest(self): |
| 618 | delete_all_flows(self.controller) |
| 619 | delete_all_groups(self.controller) |
| 620 | |
| 621 | if len(config["port_map"]) <2: |
| 622 | logging.info("Port count less than 2, can't run this case") |
| 623 | return |
| 624 | |
| 625 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 626 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 627 | dip=0xc0a80001 |
| 628 | index=1 |
| 629 | ports = config["port_map"].keys() |
| 630 | for port in ports: |
| 631 | #add l2 interface group |
| 632 | vlan_id=port |
| 633 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True) |
| 634 | dst_mac[5]=vlan_id |
| 635 | #add MPLS interface group |
| 636 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port) |
| 637 | #add MPLS L3 VPN group |
| 638 | mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 639 | index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32) |
| 640 | #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid]) |
| 641 | do_barrier(self.controller) |
| 642 | #add vlan flow table |
| 643 | add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 644 | #add termination flow |
| 645 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
| 646 | #add routing flow |
| 647 | dst_ip = dip + (vlan_id<<8) |
| 648 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_gid, vrf=2) |
| 649 | #ecmp_msg.group_id, vrf=2) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 650 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 651 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 652 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 653 | |
| 654 | do_barrier(self.controller) |
| 655 | |
| 656 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 657 | for in_port in ports: |
| 658 | mac_src='00:00:00:22:22:%02X' % in_port |
| 659 | ip_src='192.168.%02d.1' % in_port |
| 660 | for out_port in ports: |
| 661 | if in_port == out_port: |
| 662 | continue |
| 663 | ip_dst='192.168.%02d.1' % out_port |
| 664 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 665 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, |
| 666 | ip_dst=ip_dst) |
| 667 | pkt=str(parsed_pkt) |
| 668 | self.dataplane.send(in_port, pkt) |
| 669 | #build expect packet |
| 670 | mac_dst='00:00:00:22:22:%02X' % out_port |
| 671 | label = (out_port, 0, 1, 32) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 672 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src, |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 673 | ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label]) |
| 674 | pkt=str(exp_pkt) |
| 675 | verify_packet(self, pkt, out_port) |
| 676 | verify_no_other_packets(self) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 677 | |
| 678 | class MplsTermination(base_tests.SimpleDataPlane): |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 679 | """ |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 680 | Insert IP packet |
| 681 | Receive MPLS packet |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 682 | """ |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 683 | def runTest(self): |
| 684 | delete_all_flows(self.controller) |
| 685 | delete_all_groups(self.controller) |
| 686 | |
| 687 | if len(config["port_map"]) <2: |
| 688 | logging.info("Port count less than 2, can't run this case") |
| 689 | return |
| 690 | |
| 691 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 692 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 693 | mcast_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x01] |
| 694 | |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 695 | dip=0xc0a80001 |
| 696 | index=1 |
| 697 | ports = config["port_map"].keys() |
| 698 | for port in ports: |
| 699 | #add l2 interface group |
| 700 | vlan_id=port |
castroflavio | dd17147 | 2015-12-08 13:55:58 -0500 | [diff] [blame] | 701 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 702 | dst_mac[5]=vlan_id |
| 703 | #add L3 Unicast group |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 704 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 705 | #add L3 ecmp group |
| 706 | ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id]) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 707 | #add vlan flow table |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 708 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 709 | #add termination flow |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 710 | add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 711 | #add routing flow |
| 712 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 713 | add_mpls_flow(self.controller, ecmp_msg.group_id, port) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 714 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 715 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 716 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 717 | |
| 718 | do_barrier(self.controller) |
| 719 | |
| 720 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 721 | for in_port in ports: |
| 722 | mac_src='00:00:00:22:22:%02X' % in_port |
| 723 | ip_src='192.168.%02d.1' % in_port |
| 724 | for out_port in ports: |
| 725 | if in_port == out_port: |
| 726 | continue |
| 727 | ip_dst='192.168.%02d.1' % out_port |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 728 | |
| 729 | label = (out_port, 0, 1, 32) |
| 730 | parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src, |
| 731 | ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label]) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 732 | pkt=str(parsed_pkt) |
| 733 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 734 | |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 735 | #build expect packet |
| 736 | mac_dst='00:00:00:22:22:%02X' % out_port |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 737 | mcast='01:00:5e:00:00:01' |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 738 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port, |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 739 | eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 740 | pkt=str(exp_pkt) |
| 741 | verify_packet(self, pkt, out_port) |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 742 | verify_no_other_packets(self) |
| 743 | |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 744 | class MPLSBUG(base_tests.SimpleDataPlane): |
| 745 | |
| 746 | def runTest(self): |
| 747 | delete_all_flows(self.controller) |
| 748 | delete_all_groups(self.controller) |
| 749 | |
| 750 | if len(config["port_map"]) <2: |
| 751 | logging.info("Port count less than 2, can't run this case") |
| 752 | return |
| 753 | |
| 754 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 755 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 756 | dip=0xc0a80001 |
| 757 | index=1 |
| 758 | ports = config["port_map"].keys() |
| 759 | for port in ports: |
| 760 | #add l2 interface group |
| 761 | vlan_id=port |
| 762 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False) |
| 763 | dst_mac[5]=vlan_id |
| 764 | #add L3 Unicast group |
| 765 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
| 766 | #add vlan flow table |
| 767 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 768 | #add termination flow |
| 769 | add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24) |
| 770 | #add mpls flow |
| 771 | add_mpls_flow(self.controller, l3_msg.group_id, port) |
| 772 | #add termination flow |
| 773 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
| 774 | #add unicast routing flow |
| 775 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 776 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 777 | |
| 778 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 779 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 780 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 781 | |
| 782 | do_barrier(self.controller) |
| 783 | |
| 784 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 785 | for in_port in ports: |
| 786 | mac_src='00:00:00:22:22:%02X' % in_port |
| 787 | ip_src='192.168.%02d.1' % in_port |
| 788 | for out_port in ports: |
| 789 | if in_port == out_port: |
| 790 | continue |
| 791 | ip_dst='192.168.%02d.1' % out_port |
| 792 | switch_mac = "00:00:00:cc:cc:cc" |
| 793 | label = (out_port, 0, 1, 32) |
| 794 | parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src, |
| 795 | ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label]) |
| 796 | pkt=str(parsed_pkt) |
| 797 | self.dataplane.send(in_port, pkt) |
| 798 | |
| 799 | #build expect packet |
| 800 | mac_dst='00:00:00:22:22:%02X' % out_port |
| 801 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port, |
| 802 | eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst) |
| 803 | pkt=str(exp_pkt) |
| 804 | verify_packet(self, pkt, out_port) |
| 805 | verify_no_other_packets(self) |
| 806 | |
| 807 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 808 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, |
| 809 | ip_dst=ip_dst) |
| 810 | pkt=str(parsed_pkt) |
| 811 | self.dataplane.send(in_port, pkt) |
| 812 | #build expected packet |
| 813 | mac_dst='00:00:00:22:22:%02X' % out_port |
| 814 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port, |
| 815 | eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, |
| 816 | ip_src=ip_src, ip_dst=ip_dst) |
| 817 | pkt=str(exp_pkt) |
| 818 | verify_packet(self, pkt, out_port) |
| 819 | verify_no_other_packets(self) |
| 820 | |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 821 | class L3McastToL2(base_tests.SimpleDataPlane): |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 822 | """ |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 823 | Mcast routing to L2 |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 824 | """ |
| 825 | def runTest(self): |
| 826 | """ |
| 827 | port1 (vlan 300)-> All Ports (vlan 300) |
| 828 | """ |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 829 | #delete_all_flows(self.controller) |
| 830 | #delete_all_groups(self.controller) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 831 | |
castroflavio | 4a09c96 | 2016-01-05 13:13:41 -0800 | [diff] [blame] | 832 | if len(config["port_map"]) <3: |
| 833 | logging.info("Port count less than 3, can't run this case") |
| 834 | assert(False) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 835 | return |
| 836 | |
| 837 | vlan_id =300 |
| 838 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 839 | intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac]) |
| 840 | dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01] |
| 841 | dst_mac_str=':'.join(['%02X' % x for x in dst_mac]) |
| 842 | port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11] |
| 843 | port1_mac_str=':'.join(['%02X' % x for x in port1_mac]) |
| 844 | src_ip=0xc0a80101 |
| 845 | src_ip_str="192.168.1.1" |
| 846 | dst_ip=0xe0010101 |
| 847 | dst_ip_str="224.1.1.1" |
| 848 | |
| 849 | port1=config["port_map"].keys()[0] |
| 850 | port2=config["port_map"].keys()[1] |
| 851 | |
| 852 | switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00] |
| 853 | |
| 854 | |
| 855 | #add l2 interface group |
| 856 | l2_intf_group_list=[] |
| 857 | for port in config["port_map"].keys(): |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 858 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=4) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 859 | if port == port2: |
| 860 | continue |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 861 | l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 862 | l2_intf_group_list.append(l2_intf_gid) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 863 | |
| 864 | #add termination flow |
| 865 | add_termination_flow(self.controller, port1, 0x0800, switch_mac, vlan_id) |
| 866 | |
| 867 | #add l3 interface group |
| 868 | mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list) |
| 869 | add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id) |
| 870 | |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 871 | parsed_pkt = simple_udp_packet(pktlen=100, |
| 872 | dl_vlan_enable=True, |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 873 | eth_dst=dst_mac_str, |
| 874 | eth_src=port1_mac_str, |
| 875 | ip_ttl=64, |
| 876 | ip_src=src_ip_str, |
| 877 | ip_dst=dst_ip_str) |
| 878 | pkt=str(parsed_pkt) |
| 879 | self.dataplane.send(port1, pkt) |
| 880 | for port in config["port_map"].keys(): |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 881 | if port == port2 or port == port1: |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 882 | verify_no_packet(self, pkt, port) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 883 | continue |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 884 | verify_packet(self, pkt, port) |
| 885 | verify_no_other_packets(self) |
| 886 | |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 887 | class L3McastToL3(base_tests.SimpleDataPlane): |
| 888 | """ |
| 889 | Mcast routing |
| 890 | """ |
| 891 | def runTest(self): |
| 892 | """ |
| 893 | port1 (vlan 1)-> port 2 (vlan 2) |
| 894 | """ |
| 895 | delete_all_flows(self.controller) |
| 896 | delete_all_groups(self.controller) |
| 897 | |
| 898 | if len(config["port_map"]) <3: |
castroflavio | 4a09c96 | 2016-01-05 13:13:41 -0800 | [diff] [blame] | 899 | logging.info("Port count less than 3, can't run this case") |
| 900 | assert(False) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 901 | return |
| 902 | |
| 903 | vlan_id =1 |
| 904 | port2_out_vlan=2 |
| 905 | port3_out_vlan=3 |
| 906 | in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan |
| 907 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 908 | intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac]) |
| 909 | dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01] |
| 910 | dst_mac_str=':'.join(['%02X' % x for x in dst_mac]) |
| 911 | port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11] |
| 912 | port1_mac_str=':'.join(['%02X' % x for x in port1_mac]) |
| 913 | src_ip=0xc0a80101 |
| 914 | src_ip_str="192.168.1.1" |
| 915 | dst_ip=0xe0010101 |
| 916 | dst_ip_str="224.1.1.1" |
| 917 | |
| 918 | port1=config["port_map"].keys()[0] |
| 919 | port2=config["port_map"].keys()[1] |
| 920 | port3=config["port_map"].keys()[2] |
| 921 | |
| 922 | #add l2 interface group |
| 923 | for port in config["port_map"].keys(): |
| 924 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
| 925 | #add vlan flow table |
| 926 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 927 | vlan_id +=1 |
| 928 | |
| 929 | #add termination flow |
| 930 | add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id) |
| 931 | |
| 932 | #add l3 interface group |
| 933 | port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac) |
| 934 | port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac) |
| 935 | mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id]) |
| 936 | add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id) |
| 937 | |
| 938 | parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1, |
| 939 | eth_dst=dst_mac_str, |
| 940 | eth_src=port1_mac_str, |
| 941 | ip_ttl=64, |
| 942 | ip_src=src_ip_str, |
| 943 | ip_dst=dst_ip_str) |
| 944 | pkt=str(parsed_pkt) |
| 945 | self.dataplane.send(port1, pkt) |
| 946 | parsed_pkt = simple_udp_packet(pktlen=96, |
| 947 | eth_dst=dst_mac_str, |
| 948 | eth_src=intf_src_mac_str, |
| 949 | ip_ttl=63, |
| 950 | ip_src=src_ip_str, |
| 951 | ip_dst=dst_ip_str) |
| 952 | pkt=str(parsed_pkt) |
| 953 | verify_packet(self, pkt, port2) |
| 954 | verify_packet(self, pkt, port3) |
| 955 | verify_no_other_packets(self) |
| 956 | |
| 957 | class L3McastToVPN(base_tests.SimpleDataPlane): |
| 958 | """ |
| 959 | Mcast routing |
| 960 | """ |
| 961 | def runTest(self): |
| 962 | """ |
| 963 | port1 (vlan 1)-> port 2 (vlan 2) |
| 964 | """ |
| 965 | #delete_all_flows(self.controller) |
| 966 | #delete_all_groups(self.controller) |
| 967 | |
| 968 | if len(config["port_map"]) <3: |
castroflavio | 4a09c96 | 2016-01-05 13:13:41 -0800 | [diff] [blame] | 969 | logging.info("Port count less than 3, can't run this case") |
| 970 | assert(False) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 971 | return |
| 972 | |
| 973 | vlan_id =1 |
| 974 | port2_out_vlan=2 |
| 975 | port3_out_vlan=3 |
| 976 | in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan |
| 977 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 978 | intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac]) |
| 979 | dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01] |
| 980 | dst_mac_str=':'.join(['%02X' % x for x in dst_mac]) |
| 981 | port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11] |
| 982 | port1_mac_str=':'.join(['%02X' % x for x in port1_mac]) |
| 983 | src_ip=0xc0a80101 |
| 984 | src_ip_str="192.168.1.1" |
| 985 | dst_ip=0xe0010101 |
| 986 | dst_ip_str="224.1.1.1" |
| 987 | |
| 988 | port1=config["port_map"].keys()[0] |
| 989 | port2=config["port_map"].keys()[1] |
| 990 | port3=config["port_map"].keys()[2] |
| 991 | |
| 992 | #add l2 interface group |
| 993 | for port in config["port_map"].keys(): |
| 994 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
| 995 | #add vlan flow table |
| 996 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 997 | vlan_id +=1 |
| 998 | |
| 999 | #add termination flow |
| 1000 | add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id) |
| 1001 | |
| 1002 | #add MPLS interface group |
| 1003 | l2_gid = encode_l2_interface_group_id(port2_out_vlan, port2) |
| 1004 | mpls_gid2, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, port2_out_vlan, port2) |
| 1005 | l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3) |
| 1006 | mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3) |
| 1007 | #add L3VPN groups |
| 1008 | mpls_label_gid2, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 1009 | index=(0x20000+port2), ref_gid= mpls_gid2, push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True) |
| 1010 | mpls_label_gid3, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 1011 | index=(0x10000+port3), ref_gid= mpls_gid3, push_mpls_header=True, set_mpls_label=port3, set_bos=1, cpy_ttl_outward=True) |
| 1012 | |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1013 | mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [0x92020022 , 0x92010023]) |
| 1014 | add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id) |
| 1015 | |
| 1016 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1, |
| 1017 | eth_dst=dst_mac_str, |
| 1018 | eth_src=port1_mac_str, |
| 1019 | ip_ttl=64, |
| 1020 | ip_src=src_ip_str, |
| 1021 | ip_dst=dst_ip_str) |
| 1022 | pkt=str(parsed_pkt) |
| 1023 | self.dataplane.send(port1, pkt) |
| 1024 | label = (in_vlan, 0, 1, 63) |
| 1025 | parsed_pkt = mpls_packet(pktlen=100, |
| 1026 | eth_dst=dst_mac_str, |
| 1027 | eth_src=intf_src_mac_str, |
| 1028 | ip_ttl=63, |
| 1029 | ip_src=src_ip_str, label= [label], |
| 1030 | ip_dst=dst_ip_str) |
| 1031 | pkt=str(parsed_pkt) |
| 1032 | verify_packet(self, pkt, port2) |
| 1033 | verify_packet(self, pkt, port3) |
| 1034 | verify_no_other_packets(self) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1035 | |
| 1036 | class LPM(base_tests.SimpleDataPlane): |
| 1037 | """ |
| 1038 | Insert IP packet |
| 1039 | Receive MPLS packet |
| 1040 | """ |
| 1041 | def runTest(self): |
| 1042 | delete_all_flows(self.controller) |
| 1043 | delete_all_groups(self.controller) |
| 1044 | |
| 1045 | if len(config["port_map"]) <2: |
| 1046 | logging.info("Port count less than 2, can't run this case") |
| 1047 | return |
| 1048 | |
| 1049 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 1050 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 1051 | dip=0xc0a80001 |
| 1052 | index=1 |
| 1053 | ports = config["port_map"].keys() |
| 1054 | for port in ports: |
| 1055 | #add l2 interface group |
| 1056 | vlan_id=port |
| 1057 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True) |
| 1058 | dst_mac[5]=vlan_id |
| 1059 | #add MPLS interface group |
| 1060 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port) |
| 1061 | #add MPLS L3 VPN group |
| 1062 | mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 1063 | index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32) |
Flavio Castro | 5edf313 | 2016-01-27 15:45:08 -0500 | [diff] [blame] | 1064 | ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid]) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1065 | do_barrier(self.controller) |
| 1066 | #add vlan flow table |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 1067 | add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1068 | #add termination flow |
| 1069 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
| 1070 | #add routing flow |
| 1071 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | 5edf313 | 2016-01-27 15:45:08 -0500 | [diff] [blame] | 1072 | #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid, vrf=2) |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 1073 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1074 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 1075 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 1076 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 1077 | port = ports[0] |
| 1078 | #add l2 interface group |
| 1079 | vlan_id=port |
| 1080 | l2_gid = encode_l2_interface_group_id(vlan_id, port) |
| 1081 | dst_mac[5]=vlan_id |
| 1082 | #add MPLS interface group |
| 1083 | mpls_gid = encode_mpls_interface_group_id(0, port) |
| 1084 | #add MPLS L3 VPN group |
| 1085 | mpls_label_gid = encode_mpls_label_group_id(OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=port) |
Flavio Castro | 5edf313 | 2016-01-27 15:45:08 -0500 | [diff] [blame] | 1086 | ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid]) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1087 | do_barrier(self.controller) |
| 1088 | #add routing flow |
| 1089 | dst_ip = 0x0 |
Flavio Castro | 5edf313 | 2016-01-27 15:45:08 -0500 | [diff] [blame] | 1090 | #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, mpls_label_gid, vrf=2) |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 1091 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, ecmp_msg.group_id) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1092 | |
| 1093 | do_barrier(self.controller) |
| 1094 | |
| 1095 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 1096 | for in_port in ports: |
| 1097 | mac_src='00:00:00:22:22:%02X' % in_port |
| 1098 | ip_src='192.168.%02d.1' % in_port |
| 1099 | for out_port in ports: |
| 1100 | if in_port == out_port: |
| 1101 | continue |
| 1102 | ip_dst='192.168.%02d.1' % out_port |
| 1103 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 1104 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, |
| 1105 | ip_dst=ip_dst) |
| 1106 | pkt=str(parsed_pkt) |
| 1107 | self.dataplane.send(in_port, pkt) |
| 1108 | #build expect packet |
| 1109 | mac_dst='00:00:00:22:22:%02X' % out_port |
| 1110 | label = (out_port, 0, 1, 32) |
| 1111 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src, |
| 1112 | ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label]) |
| 1113 | pkt=str(exp_pkt) |
| 1114 | verify_packet(self, pkt, out_port) |
| 1115 | verify_no_other_packets(self) |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 1116 | ip_dst='1.168.%02d.1' % ports[0] |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1117 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 1118 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst) |
| 1119 | pkt=str(parsed_pkt) |
| 1120 | self.dataplane.send(in_port, pkt) |
| 1121 | #build expect packet |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 1122 | mac_dst='00:00:00:22:22:%02X' % ports[0] |
| 1123 | label = (ports[0], 0, 1, 32) |
| 1124 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src, |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1125 | ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label]) |
| 1126 | pkt=str(exp_pkt) |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame^] | 1127 | verify_packet(self, pkt, ports[0]) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1128 | verify_no_other_packets(self) |