Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 1 | """ |
| 2 | Flow Test |
Flavio Castro | 3aec890 | 2015-11-20 10:51:38 -0500 | [diff] [blame] | 3 | 1) PacketInSrcMacMiss |
| 4 | 2) L2FloodTagged |
| 5 | 3) L2Flood Tagged Unknown Src |
| 6 | 4) L2 Unicast Tagged |
| 7 | 5) L3 Unicast Tagged |
| 8 | 6) MTU 1500 |
| 9 | 7) MTU 4100 |
| 10 | 8) MTU 4500 |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 11 | """ |
| 12 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 13 | from oftest import config |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame^] | 14 | import logging |
| 15 | import oftest.base_tests as base_tests |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 16 | import ofp |
| 17 | from oftest.testutils import * |
| 18 | from accton_util import * |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 19 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 20 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 21 | class PacketInSrcMacMiss(base_tests.SimpleDataPlane): |
| 22 | """ |
| 23 | Test packet in function on a src-mac miss |
| 24 | Send a packet to each dataplane port and verify that a packet |
| 25 | in message is received from the controller for each |
| 26 | #todo verify you stop receiving after adding rule |
| 27 | """ |
| 28 | |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 29 | def runTest(self): |
| 30 | delete_all_flows(self.controller) |
| 31 | delete_all_groups(self.controller) |
| 32 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 33 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104, |
| 34 | vlan_vid=0x1001, dl_vlan_enable=True) |
| 35 | vlan_pkt = str(parsed_vlan_pkt) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 36 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 37 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 38 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 39 | # group table |
| 40 | # set up untag groups for each port |
| 41 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1) |
| 42 | |
| 43 | for of_port in config["port_map"].keys(): |
| 44 | logging.info("PacketInMiss test, port %d", of_port) |
| 45 | self.dataplane.send(of_port, vlan_pkt) |
| 46 | |
| 47 | verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH) |
| 48 | |
| 49 | verify_no_other_packets(self) |
| 50 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 51 | class L2FloodTagged(base_tests.SimpleDataPlane): |
| 52 | """ |
| 53 | Test L2 flood to a vlan |
| 54 | Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport |
| 55 | #todo take in account unknown src |
| 56 | """ |
| 57 | def runTest(self): |
| 58 | ports = sorted(config["port_map"].keys()) |
| 59 | delete_all_flows(self.controller) |
| 60 | delete_all_groups(self.controller) |
| 61 | |
| 62 | add_vlan_table_flow(self.controller, ports, 1) |
| 63 | |
| 64 | # set up tagged groups for each port |
| 65 | add_l2_interface_grouop(self.controller, ports, 1, True, 1) |
| 66 | |
| 67 | msg=add_l2_flood_group(self.controller, ports, 1, 1) |
| 68 | add_bridge_flow(self.controller, None, 1, msg.group_id, True) |
| 69 | # Installing flows to avoid packet-in |
| 70 | for port in ports: |
| 71 | group_id = encode_l2_interface_group_id(1, port) |
| 72 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
| 73 | do_barrier(self.controller) |
| 74 | |
| 75 | #verify flood |
| 76 | for ofport in ports: |
| 77 | # change dest based on port number |
| 78 | mac_src= '00:12:34:56:78:%02X' % ofport |
| 79 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src) |
| 80 | pkt = str(parsed_pkt) |
| 81 | self.dataplane.send(ofport, pkt) |
| 82 | #self won't rx packet |
| 83 | verify_no_packet(self, pkt, ofport) |
| 84 | #others will rx packet |
| 85 | tmp_ports=list(ports) |
| 86 | tmp_ports.remove(ofport) |
| 87 | verify_packets(self, pkt, tmp_ports) |
| 88 | |
| 89 | verify_no_other_packets(self) |
| 90 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 91 | class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane): |
| 92 | """ |
| 93 | Test L2 flood to a vlan |
| 94 | Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport |
| 95 | #todo take in account unknown src |
| 96 | """ |
| 97 | def runTest(self): |
| 98 | ports = sorted(config["port_map"].keys()) |
| 99 | delete_all_flows(self.controller) |
| 100 | delete_all_groups(self.controller) |
| 101 | |
| 102 | add_vlan_table_flow(self.controller, ports, 1) |
| 103 | |
| 104 | # set up tagged groups for each port |
| 105 | add_l2_interface_grouop(self.controller, ports, 1, True, 1) |
| 106 | |
| 107 | msg=add_l2_flood_group(self.controller, ports, 1, 1) |
| 108 | add_bridge_flow(self.controller, None, 1, msg.group_id, True) |
| 109 | |
| 110 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a') |
| 111 | pkt = str(parsed_pkt) |
| 112 | #verify flood |
| 113 | for ofport in ports: |
| 114 | self.dataplane.send(ofport, pkt) |
| 115 | #self won't rx packet |
| 116 | verify_no_packet(self, pkt, ofport) |
| 117 | #others will rx packet |
| 118 | tmp_ports=list(ports) |
| 119 | tmp_ports.remove(ofport) |
| 120 | verify_packets(self, pkt, tmp_ports) |
| 121 | |
| 122 | verify_no_other_packets(self) |
| 123 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 124 | class L2UnicastTagged(base_tests.SimpleDataPlane): |
| 125 | """ |
| 126 | Test output function for an exact-match flow |
| 127 | |
| 128 | For each port A, adds a flow directing matching packets to that port. |
| 129 | Then, for all other ports B != A, verifies that sending a matching packet |
| 130 | to B results in an output to A. |
| 131 | """ |
| 132 | def runTest(self): |
| 133 | ports = sorted(config["port_map"].keys()) |
| 134 | |
| 135 | delete_all_flows(self.controller) |
| 136 | delete_all_groups(self.controller) |
| 137 | |
| 138 | add_vlan_table_flow(self.controller, config["port_map"].keys()) |
| 139 | |
| 140 | # set up tag groups for each port |
| 141 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1) |
| 142 | |
| 143 | for port in ports: |
| 144 | group_id = encode_l2_interface_group_id(1, port) |
| 145 | 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] | 146 | do_barrier(self.controller) |
| 147 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 148 | for out_port in ports: |
| 149 | # change dest based on port number |
| 150 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 151 | for in_port in ports: |
| 152 | if in_port == out_port: |
| 153 | continue |
| 154 | # change source based on port number to avoid packet-ins from learning |
| 155 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 156 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 157 | pkt = str(parsed_pkt) |
| 158 | self.dataplane.send(in_port, pkt) |
| 159 | |
| 160 | for ofport in ports: |
| 161 | if ofport in [out_port]: |
| 162 | verify_packet(self, pkt, ofport) |
| 163 | else: |
| 164 | verify_no_packet(self, pkt, ofport) |
| 165 | |
| 166 | verify_no_other_packets(self) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 167 | |
| 168 | |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 169 | class Mtu4500(base_tests.SimpleDataPlane): |
| 170 | |
| 171 | def runTest(self): |
| 172 | ports = sorted(config["port_map"].keys()) |
| 173 | |
| 174 | delete_all_flows(self.controller) |
| 175 | delete_all_groups(self.controller) |
| 176 | |
| 177 | add_vlan_table_flow(self.controller, config["port_map"].keys()) |
| 178 | |
| 179 | # set up tag groups for each port |
| 180 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1) |
| 181 | |
| 182 | for port in ports: |
| 183 | group_id = encode_l2_interface_group_id(1, port) |
| 184 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
| 185 | do_barrier(self.controller) |
| 186 | |
| 187 | for out_port in ports: |
| 188 | # change dest based on port number |
| 189 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 190 | for in_port in ports: |
| 191 | if in_port == out_port: |
| 192 | continue |
| 193 | # change source based on port number to avoid packet-ins from learning |
| 194 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 195 | parsed_pkt = simple_tcp_packet(pktlen=4500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 196 | pkt = str(parsed_pkt) |
| 197 | self.dataplane.send(in_port, pkt) |
| 198 | |
| 199 | for ofport in ports: |
| 200 | if ofport in [out_port]: |
| 201 | verify_packet(self, pkt, ofport) |
| 202 | else: |
| 203 | verify_no_packet(self, pkt, ofport) |
| 204 | |
| 205 | verify_no_other_packets(self) |
| 206 | |
| 207 | |
| 208 | class Mtu1500(base_tests.SimpleDataPlane): |
| 209 | |
| 210 | def runTest(self): |
| 211 | ports = sorted(config["port_map"].keys()) |
| 212 | |
| 213 | delete_all_flows(self.controller) |
| 214 | delete_all_groups(self.controller) |
| 215 | |
| 216 | add_vlan_table_flow(self.controller, config["port_map"].keys()) |
| 217 | |
| 218 | # set up tag groups for each port |
| 219 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1) |
| 220 | |
| 221 | for port in ports: |
| 222 | group_id = encode_l2_interface_group_id(1, port) |
| 223 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
| 224 | do_barrier(self.controller) |
| 225 | |
| 226 | for out_port in ports: |
| 227 | # change dest based on port number |
| 228 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 229 | for in_port in ports: |
| 230 | if in_port == out_port: |
| 231 | continue |
| 232 | # change source based on port number to avoid packet-ins from learning |
| 233 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 234 | parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 235 | pkt = str(parsed_pkt) |
| 236 | self.dataplane.send(in_port, pkt) |
| 237 | |
| 238 | for ofport in ports: |
| 239 | if ofport in [out_port]: |
| 240 | verify_packet(self, pkt, ofport) |
| 241 | else: |
| 242 | verify_no_packet(self, pkt, ofport) |
| 243 | |
| 244 | verify_no_other_packets(self) |
| 245 | |
| 246 | |
| 247 | class Mtu4000(base_tests.SimpleDataPlane): |
| 248 | """ |
| 249 | Test output function for an exact-match flow |
| 250 | For each port A, adds a flow directing matching packets to that port. |
| 251 | Then, for all other ports B != A, verifies that sending a matching packet |
| 252 | to B results in an output to A. |
| 253 | """ |
| 254 | def runTest(self): |
| 255 | ports = sorted(config["port_map"].keys()) |
| 256 | |
| 257 | delete_all_flows(self.controller) |
| 258 | delete_all_groups(self.controller) |
| 259 | |
| 260 | add_vlan_table_flow(self.controller, config["port_map"].keys()) |
| 261 | |
| 262 | # set up tag groups for each port |
| 263 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1) |
| 264 | |
| 265 | for port in ports: |
| 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 | do_barrier(self.controller) |
| 269 | |
| 270 | for out_port in ports: |
| 271 | # change dest based on port number |
| 272 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 273 | for in_port in ports: |
| 274 | if in_port == out_port: |
| 275 | continue |
| 276 | # change source based on port number to avoid packet-ins from learning |
| 277 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 278 | parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 279 | pkt = str(parsed_pkt) |
| 280 | self.dataplane.send(in_port, pkt) |
| 281 | |
| 282 | for ofport in ports: |
| 283 | if ofport in [out_port]: |
| 284 | verify_packet(self, pkt, ofport) |
| 285 | else: |
| 286 | verify_no_packet(self, pkt, ofport) |
| 287 | |
| 288 | verify_no_other_packets(self) |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 289 | |
| 290 | class L3UcastTagged(base_tests.SimpleDataPlane): |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 291 | """ |
Flavio Castro | 35e6439 | 2015-12-02 16:53:14 -0500 | [diff] [blame] | 292 | Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) , |
| 293 | 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] | 294 | """ |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 295 | def runTest(self): |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 296 | delete_all_flows(self.controller) |
| 297 | delete_all_groups(self.controller) |
| 298 | |
| 299 | if len(config["port_map"]) <2: |
| 300 | logging.info("Port count less than 2, can't run this case") |
| 301 | return |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 302 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 303 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 304 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 305 | dip=0xc0a80001 |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 306 | ports = config["port_map"].keys() |
| 307 | for port in ports: |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 308 | #add l2 interface group |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 309 | vlan_id=port |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 310 | add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False) |
| 311 | dst_mac[5]=vlan_id |
| 312 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
| 313 | #add vlan flow table |
| 314 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 315 | #add termination flow |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 316 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 317 | #add unicast routing flow |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 318 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 319 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 320 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 321 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 322 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 323 | |
| 324 | do_barrier(self.controller) |
| 325 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 326 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 327 | for in_port in ports: |
| 328 | mac_src='00:00:00:22:22:%02X' % in_port |
| 329 | ip_src='192.168.%02d.1' % in_port |
| 330 | for out_port in ports: |
| 331 | if in_port == out_port: |
| 332 | continue |
| 333 | ip_dst='192.168.%02d.1' % out_port |
| 334 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 335 | 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] | 336 | ip_dst=ip_dst) |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 337 | pkt=str(parsed_pkt) |
| 338 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 339 | #build expected packet |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 340 | mac_dst='00:00:00:22:22:%02X' % out_port |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 341 | 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] | 342 | eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, |
| 343 | ip_src=ip_src, ip_dst=ip_dst) |
| 344 | pkt=str(exp_pkt) |
| 345 | verify_packet(self, pkt, out_port) |
| 346 | verify_no_other_packets(self) |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 347 | |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 348 | class L3VPNMPLS(base_tests.SimpleDataPlane): |
| 349 | """ |
| 350 | Insert IP packet |
| 351 | Receive MPLS packet |
| 352 | """ |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 353 | def runTest(self): |
| 354 | delete_all_flows(self.controller) |
| 355 | delete_all_groups(self.controller) |
| 356 | |
| 357 | if len(config["port_map"]) <2: |
| 358 | logging.info("Port count less than 2, can't run this case") |
| 359 | return |
| 360 | |
| 361 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 362 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 363 | dip=0xc0a80001 |
| 364 | index=1 |
| 365 | ports = config["port_map"].keys() |
| 366 | for port in ports: |
| 367 | #add l2 interface group |
| 368 | vlan_id=port |
| 369 | l2_gid, l2_msg = add_one_l2_interface_grouop(self.controller, port, vlan_id, True, False) |
| 370 | dst_mac[5]=vlan_id |
Flavio Castro | 35e6439 | 2015-12-02 16:53:14 -0500 | [diff] [blame] | 371 | #add MPLS interface group |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 372 | 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] | 373 | #add MPLS L3 VPN group |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 374 | 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] | 375 | index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32) |
| 376 | #add vlan flow table |
| 377 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 378 | #add termination flow |
| 379 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
Flavio Castro | 35e6439 | 2015-12-02 16:53:14 -0500 | [diff] [blame] | 380 | #add routing flow |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 381 | dst_ip = dip + (vlan_id<<8) |
| 382 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 383 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 384 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 385 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 386 | |
| 387 | do_barrier(self.controller) |
| 388 | |
| 389 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 390 | for in_port in ports: |
| 391 | mac_src='00:00:00:22:22:%02X' % in_port |
| 392 | ip_src='192.168.%02d.1' % in_port |
| 393 | for out_port in ports: |
| 394 | if in_port == out_port: |
| 395 | continue |
| 396 | ip_dst='192.168.%02d.1' % out_port |
| 397 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 398 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, |
| 399 | ip_dst=ip_dst) |
| 400 | pkt=str(parsed_pkt) |
| 401 | self.dataplane.send(in_port, pkt) |
| 402 | #build expect packet |
| 403 | mac_dst='00:00:00:22:22:%02X' % out_port |
| 404 | label = (out_port, 0, 1, 32) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 405 | exp_pkt = mpls_packet(dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=64, ip_src=ip_src, |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 406 | ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label]) |
| 407 | pkt=str(exp_pkt) |
| 408 | verify_packet(self, pkt, out_port) |
| 409 | verify_no_other_packets(self) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 410 | |
| 411 | class MplsTermination(base_tests.SimpleDataPlane): |
| 412 | ''' |
| 413 | Insert IP packet |
| 414 | Receive MPLS packet |
| 415 | ''' |
| 416 | def runTest(self): |
| 417 | delete_all_flows(self.controller) |
| 418 | delete_all_groups(self.controller) |
| 419 | |
| 420 | if len(config["port_map"]) <2: |
| 421 | logging.info("Port count less than 2, can't run this case") |
| 422 | return |
| 423 | |
| 424 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 425 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 426 | dip=0xc0a80001 |
| 427 | index=1 |
| 428 | ports = config["port_map"].keys() |
| 429 | for port in ports: |
| 430 | #add l2 interface group |
| 431 | vlan_id=port |
| 432 | l2_gid, l2_msg = add_one_l2_interface_grouop(self.controller, port, vlan_id, True, False) |
| 433 | dst_mac[5]=vlan_id |
| 434 | #add L3 Unicast group |
| 435 | 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^] | 436 | #add L3 ecmp group |
| 437 | 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] | 438 | #add vlan flow table |
| 439 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 440 | #add termination flow |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame^] | 441 | 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] | 442 | #add routing flow |
| 443 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame^] | 444 | add_mpls_flow(self.controller, ecmp_msg.group_id, port) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 445 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 446 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 447 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 448 | |
| 449 | do_barrier(self.controller) |
| 450 | |
| 451 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 452 | for in_port in ports: |
| 453 | mac_src='00:00:00:22:22:%02X' % in_port |
| 454 | ip_src='192.168.%02d.1' % in_port |
| 455 | for out_port in ports: |
| 456 | if in_port == out_port: |
| 457 | continue |
| 458 | ip_dst='192.168.%02d.1' % out_port |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame^] | 459 | |
| 460 | label = (out_port, 0, 1, 32) |
| 461 | parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src, |
| 462 | 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] | 463 | pkt=str(parsed_pkt) |
| 464 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame^] | 465 | |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 466 | #build expect packet |
| 467 | mac_dst='00:00:00:22:22:%02X' % out_port |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame^] | 468 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port, |
| 469 | 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] | 470 | pkt=str(exp_pkt) |
| 471 | verify_packet(self, pkt, out_port) |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame^] | 472 | verify_no_other_packets(self) |
| 473 | |