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