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