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