Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 1 | """ |
Flavio Castro | c36621e | 2015-12-08 12:57:07 -0500 | [diff] [blame] | 2 | The following tests are being done here |
Flavio Castro | 3aec890 | 2015-11-20 10:51:38 -0500 | [diff] [blame] | 3 | 1) PacketInSrcMacMiss |
castroflavio | 9e715f3 | 2015-12-08 14:04:12 -0500 | [diff] [blame] | 4 | 2) VlanSupport |
| 5 | 3) L2FloodQinQ |
| 6 | 4) L2FloodTagged |
| 7 | 5) L2Flood Tagged Unknown Src |
| 8 | 6) L2 Unicast Tagged |
| 9 | 7) MTU 1500 |
| 10 | 8) MTU 4100 |
| 11 | 9) MTU 4500 |
| 12 | 10) L3UnicastTagged |
| 13 | 11) L3VPNMPLS |
| 14 | 12) MPLS Termination |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 15 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 16 | import Queue |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 17 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 18 | from oftest import config |
Flavio Castro | 67d8bd5 | 2016-02-03 14:22:14 -0500 | [diff] [blame] | 19 | import inspect |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 20 | import logging |
| 21 | import oftest.base_tests as base_tests |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 22 | import ofp |
| 23 | from oftest.testutils import * |
| 24 | from accton_util import * |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 25 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 26 | |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 27 | class PacketInUDP(base_tests.SimpleDataPlane): |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 28 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 29 | Verify a ACL rule that matches on IP_PROTO 2 will not match a UDP packet. |
| 30 | Next it verify a rule that matches on IP_PROTO 17 WILL match a UDP packet. |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 31 | """ |
| 32 | |
| 33 | def runTest(self): |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 34 | parsed_vlan_pkt = simple_udp_packet(pktlen=104, |
| 35 | vlan_vid=0x1001, |
| 36 | dl_vlan_enable=True) |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 37 | vlan_pkt = str(parsed_vlan_pkt) |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 38 | # create match |
| 39 | match = ofp.match() |
| 40 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 41 | match.oxm_list.append(ofp.oxm.ip_proto(2)) |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 42 | request = ofp.message.flow_add( |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 43 | table_id=60, |
| 44 | cookie=42, |
| 45 | match=match, |
| 46 | instructions=[ |
| 47 | ofp.instruction.apply_actions( |
| 48 | actions=[ |
| 49 | ofp.action.output( |
| 50 | port=ofp.OFPP_CONTROLLER, |
| 51 | max_len=ofp.OFPCML_NO_BUFFER)]), ], |
| 52 | buffer_id=ofp.OFP_NO_BUFFER, |
| 53 | priority=1) |
| 54 | logging.info("Inserting packet in flow to controller") |
| 55 | self.controller.message_send(request) |
| 56 | |
| 57 | for of_port in config["port_map"].keys(): |
| 58 | logging.info("PacketInMiss test, port %d", of_port) |
| 59 | self.dataplane.send(of_port, vlan_pkt) |
| 60 | |
Flavio Castro | 6da7e46 | 2016-02-04 18:56:29 -0500 | [diff] [blame] | 61 | verify_no_packet_in(self, vlan_pkt, of_port) |
| 62 | delete_all_flows(self.controller) |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 63 | do_barrier(self.controller) |
| 64 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 65 | match = ofp.match() |
| 66 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
| 67 | match.oxm_list.append(ofp.oxm.ip_proto(17)) |
| 68 | request = ofp.message.flow_add( |
| 69 | table_id=60, |
| 70 | cookie=42, |
| 71 | match=match, |
| 72 | instructions=[ |
| 73 | ofp.instruction.apply_actions( |
| 74 | actions=[ |
| 75 | ofp.action.output( |
| 76 | port=ofp.OFPP_CONTROLLER, |
| 77 | max_len=ofp.OFPCML_NO_BUFFER)]), ], |
| 78 | buffer_id=ofp.OFP_NO_BUFFER, |
| 79 | priority=1) |
| 80 | logging.info("Inserting packet in flow to controller") |
| 81 | self.controller.message_send(request) |
Flavio Castro | 6da7e46 | 2016-02-04 18:56:29 -0500 | [diff] [blame] | 82 | do_barrier(self.controller) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 83 | |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 84 | for of_port in config["port_map"].keys(): |
| 85 | logging.info("PacketInMiss test, port %d", of_port) |
| 86 | self.dataplane.send(of_port, vlan_pkt) |
| 87 | |
| 88 | verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION) |
| 89 | |
| 90 | verify_no_other_packets(self) |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 91 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 92 | delete_all_flows(self.controller) |
| 93 | |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 94 | |
Flavio Castro | 67d8bd5 | 2016-02-03 14:22:14 -0500 | [diff] [blame] | 95 | @disabled |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 96 | class ArpNL2(base_tests.SimpleDataPlane): |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 97 | def runTest(self): |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 98 | delete_all_flows(self.controller) |
| 99 | delete_all_groups(self.controller) |
| 100 | |
| 101 | ports = sorted(config["port_map"].keys()) |
| 102 | match = ofp.match() |
| 103 | match.oxm_list.append(ofp.oxm.eth_type(0x0806)) |
| 104 | request = ofp.message.flow_add( |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 105 | table_id=60, |
| 106 | cookie=42, |
| 107 | match=match, |
| 108 | instructions=[ |
| 109 | ofp.instruction.apply_actions( |
| 110 | actions=[ |
| 111 | ofp.action.output( |
| 112 | port=ofp.OFPP_CONTROLLER, |
| 113 | max_len=ofp.OFPCML_NO_BUFFER)]), |
| 114 | ], |
| 115 | buffer_id=ofp.OFP_NO_BUFFER, |
| 116 | priority=40000) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 117 | self.controller.message_send(request) |
| 118 | for port in ports: |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 119 | add_one_l2_interface_group(self.controller, port, 1, False, False) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 120 | add_one_vlan_table_flow(self.controller, port, 1, |
| 121 | flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 122 | group_id = encode_l2_interface_group_id(1, port) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 123 | add_bridge_flow(self.controller, |
| 124 | [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, |
| 125 | True) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 126 | do_barrier(self.controller) |
| 127 | parsed_arp_pkt = simple_arp_packet() |
| 128 | arp_pkt = str(parsed_arp_pkt) |
| 129 | |
| 130 | for out_port in ports: |
| 131 | self.dataplane.send(out_port, arp_pkt) |
| 132 | verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION) |
| 133 | # change dest based on port number |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 134 | mac_dst = '00:12:34:56:78:%02X' % out_port |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 135 | for in_port in ports: |
| 136 | if in_port == out_port: |
| 137 | continue |
| 138 | # change source based on port number to avoid packet-ins from learning |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 139 | mac_src = '00:12:34:56:78:%02X' % in_port |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 140 | parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src) |
| 141 | pkt = str(parsed_pkt) |
| 142 | self.dataplane.send(in_port, pkt) |
| 143 | |
| 144 | for ofport in ports: |
| 145 | if ofport in [out_port]: |
| 146 | verify_packet(self, pkt, ofport) |
| 147 | else: |
| 148 | verify_no_packet(self, pkt, ofport) |
| 149 | |
| 150 | verify_no_other_packets(self) |
| 151 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 152 | |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 153 | class PacketInArp(base_tests.SimpleDataPlane): |
| 154 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 155 | Verify an ACL rule matching on ethertyper 0x806 will result in a packet-in |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 156 | """ |
| 157 | |
| 158 | def runTest(self): |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 159 | parsed_arp_pkt = simple_arp_packet() |
| 160 | arp_pkt = str(parsed_arp_pkt) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 161 | # create match |
| 162 | match = ofp.match() |
| 163 | match.oxm_list.append(ofp.oxm.eth_type(0x0806)) |
| 164 | request = ofp.message.flow_add( |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 165 | table_id=60, |
| 166 | cookie=42, |
| 167 | match=match, |
| 168 | instructions=[ |
| 169 | ofp.instruction.apply_actions( |
| 170 | actions=[ |
| 171 | ofp.action.output( |
| 172 | port=ofp.OFPP_CONTROLLER, |
| 173 | max_len=ofp.OFPCML_NO_BUFFER)]), |
| 174 | ], |
| 175 | buffer_id=ofp.OFP_NO_BUFFER, |
| 176 | priority=1) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 177 | |
| 178 | logging.info("Inserting packet in flow to controller") |
| 179 | self.controller.message_send(request) |
| 180 | do_barrier(self.controller) |
| 181 | |
| 182 | for of_port in config["port_map"].keys(): |
| 183 | logging.info("PacketInMiss test, port %d", of_port) |
| 184 | self.dataplane.send(of_port, arp_pkt) |
| 185 | |
| 186 | verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION) |
| 187 | |
| 188 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 189 | delete_all_flows(self.controller) |
| 190 | |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame^] | 191 | class PacketInIPTable(base_tests.SimpleDataPlane): |
| 192 | """ |
| 193 | Test packet in function on IPTABLE |
| 194 | Send a packet to each dataplane port and verify that a packet |
| 195 | in message is received from the controller for each |
| 196 | #todo verify you stop receiving after adding rule |
| 197 | """ |
| 198 | |
| 199 | def runTest(self): |
| 200 | |
| 201 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 202 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 203 | dip=0xc0a80001 |
| 204 | ports = sorted(config["port_map"].keys()) |
| 205 | Groups = Queue.LifoQueue() |
| 206 | |
| 207 | for port in ports: |
| 208 | #add l2 interface group |
| 209 | vlan_id=port |
| 210 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False) |
| 211 | dst_mac[5]=vlan_id |
| 212 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
| 213 | #add vlan flow table |
| 214 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 215 | #add termination flow |
| 216 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
| 217 | #add unicast routing flow |
| 218 | dst_ip = dip + (vlan_id<<8) |
| 219 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id, send_ctrl=True) |
| 220 | Groups.put(l3_msg.group_id) |
| 221 | |
| 222 | do_barrier(self.controller) |
| 223 | |
| 224 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 225 | for in_port in ports: |
| 226 | mac_src='00:00:00:22:22:%02X' % in_port |
| 227 | ip_src='192.168.%02d.1' % in_port |
| 228 | for out_port in ports: |
| 229 | if in_port == out_port: |
| 230 | continue |
| 231 | ip_dst='192.168.%02d.1' % out_port |
| 232 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 233 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, |
| 234 | ip_dst=ip_dst) |
| 235 | pkt=str(parsed_pkt) |
| 236 | self.dataplane.send(in_port, pkt) |
| 237 | verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION) |
| 238 | #verify_no_other_packets(self) |
| 239 | delete_all_flows(self.controller) |
| 240 | delete_groups(self.controller, Groups) |
| 241 | |
| 242 | |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 243 | |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 244 | class L2FloodQinQ(base_tests.SimpleDataPlane): |
| 245 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 246 | Verify a tagged frame can be flooded based on its outer vlan |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 247 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 248 | |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 249 | def runTest(self): |
| 250 | ports = sorted(config["port_map"].keys()) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 251 | vlan_id = 1 |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 252 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 253 | Groups = Queue.LifoQueue() |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 254 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 255 | L2gid, l2msg = add_one_l2_interface_group(self.controller, port, |
| 256 | vlan_id, True, False) |
| 257 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 258 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 259 | Groups.put(L2gid) |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 260 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 261 | msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id) |
Flavio Castro | 6da7e46 | 2016-02-04 18:56:29 -0500 | [diff] [blame] | 262 | Groups.put(msg.group_id) |
Flavio Castro | 8628adb | 2016-02-03 17:30:57 -0500 | [diff] [blame] | 263 | add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True) |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 264 | do_barrier(self.controller) |
| 265 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 266 | # verify flood |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 267 | for ofport in ports: |
| 268 | # change dest based on port number |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 269 | mac_src = '00:12:34:56:78:%02X' % ofport |
| 270 | parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, |
| 271 | out_dl_vlan_enable=True, |
| 272 | out_vlan_vid=vlan_id, |
| 273 | in_dl_vlan_enable=True, |
| 274 | in_vlan_vid=10, |
| 275 | eth_dst='00:12:34:56:78:9a', |
| 276 | eth_src=mac_src) |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 277 | pkt = str(parsed_pkt) |
| 278 | self.dataplane.send(ofport, pkt) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 279 | # self won't rx packet |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 280 | verify_no_packet(self, pkt, ofport) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 281 | # others will rx packet |
| 282 | tmp_ports = list(ports) |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 283 | tmp_ports.remove(ofport) |
| 284 | verify_packets(self, pkt, tmp_ports) |
| 285 | |
| 286 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 287 | delete_all_flows(self.controller) |
| 288 | delete_groups(self.controller, Groups) |
| 289 | |
Flavio Castro | 1b5c21d | 2015-12-08 12:41:56 -0500 | [diff] [blame] | 290 | |
Flavio Castro | ce3bfeb | 2016-02-04 14:06:55 -0500 | [diff] [blame] | 291 | @disabled |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 292 | class L2FloodTagged(base_tests.SimpleDataPlane): |
| 293 | """ |
| 294 | Test L2 flood to a vlan |
| 295 | Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 296 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 297 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 298 | def runTest(self): |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 299 | # Hashes Test Name and uses it as id for installing unique groups |
| 300 | vlan_id = abs(hash(inspect.stack()[0][3])) % (256) |
Flavio Castro | ce3bfeb | 2016-02-04 14:06:55 -0500 | [diff] [blame] | 301 | print vlan_id |
Flavio Castro | aba28ff | 2016-02-03 16:47:48 -0500 | [diff] [blame] | 302 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 303 | ports = sorted(config["port_map"].keys()) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 304 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 305 | delete_all_flows(self.controller) |
| 306 | delete_all_groups(self.controller) |
| 307 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 308 | # Installing flows to avoid packet-in |
| 309 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 310 | add_one_l2_interface_group(self.controller, port, vlan_id, True, |
| 311 | False) |
| 312 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 313 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 314 | msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id) |
Flavio Castro | aba28ff | 2016-02-03 16:47:48 -0500 | [diff] [blame] | 315 | add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True) |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 316 | do_barrier(self.controller) |
| 317 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 318 | # verify flood |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 319 | for ofport in ports: |
| 320 | # change dest based on port number |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 321 | pkt = str(simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, |
| 322 | eth_dst='00:12:34:56:78:9a')) |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 323 | self.dataplane.send(ofport, pkt) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 324 | # self won't rx packet |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 325 | verify_no_packet(self, pkt, ofport) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 326 | # others will rx packet |
| 327 | tmp_ports = list(ports) |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 328 | tmp_ports.remove(ofport) |
| 329 | verify_packets(self, pkt, tmp_ports) |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame] | 330 | verify_no_other_packets(self) |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 331 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 332 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 333 | class L2UnicastTagged(base_tests.SimpleDataPlane): |
| 334 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 335 | Verify L2 forwarding works |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 336 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 337 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 338 | def runTest(self): |
| 339 | ports = sorted(config["port_map"].keys()) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 340 | vlan_id = 1; |
| 341 | Groups = Queue.LifoQueue() |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 342 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 343 | L2gid, l2msg = add_one_l2_interface_group(self.controller, port, |
| 344 | vlan_id, True, False) |
| 345 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 346 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 347 | Groups.put(L2gid) |
| 348 | add_bridge_flow(self.controller, |
| 349 | [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id, |
| 350 | L2gid, True) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 351 | do_barrier(self.controller) |
| 352 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 353 | for out_port in ports: |
| 354 | # change dest based on port number |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 355 | mac_dst = '00:12:34:56:78:%02X' % out_port |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 356 | for in_port in ports: |
| 357 | if in_port == out_port: |
| 358 | continue |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 359 | pkt = str( |
| 360 | simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, |
| 361 | eth_dst=mac_dst)) |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 362 | self.dataplane.send(in_port, pkt) |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 363 | for ofport in ports: |
| 364 | if ofport in [out_port]: |
| 365 | verify_packet(self, pkt, ofport) |
| 366 | else: |
| 367 | verify_no_packet(self, pkt, ofport) |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 368 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 369 | delete_all_flows(self.controller) |
| 370 | delete_groups(self.controller, Groups) |
| 371 | |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 372 | |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 373 | class Mtu1500(base_tests.SimpleDataPlane): |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 374 | def runTest(self): |
| 375 | ports = sorted(config["port_map"].keys()) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 376 | vlan_id = 18 |
| 377 | Groups = Queue.LifoQueue() |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 378 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 379 | L2gid, msg = add_one_l2_interface_group(self.controller, port, |
| 380 | vlan_id, True, False) |
| 381 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 382 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 383 | Groups.put(L2gid) |
| 384 | add_bridge_flow(self.controller, |
| 385 | [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id, |
| 386 | L2gid, True) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 387 | do_barrier(self.controller) |
| 388 | |
| 389 | for out_port in ports: |
| 390 | # change dest based on port number |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 391 | mac_dst = '00:12:34:56:78:%02X' % out_port |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 392 | for in_port in ports: |
| 393 | if in_port == out_port: |
| 394 | continue |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 395 | pkt = str(simple_tcp_packet(pktlen=1500, dl_vlan_enable=True, |
| 396 | vlan_vid=vlan_id, eth_dst=mac_dst)) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 397 | self.dataplane.send(in_port, pkt) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 398 | for ofport in ports: |
| 399 | if ofport in [out_port]: |
| 400 | verify_packet(self, pkt, ofport) |
| 401 | else: |
| 402 | verify_no_packet(self, pkt, ofport) |
Flavio Castro | b677303 | 2015-11-19 22:49:24 -0500 | [diff] [blame] | 403 | verify_no_other_packets(self) |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 404 | delete_all_flows(self.controller) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 405 | delete_groups(self.controller, Groups) |
| 406 | |
| 407 | |
| 408 | class _32UcastTagged(base_tests.SimpleDataPlane): |
| 409 | """ |
| 410 | Verify a IP forwarding works for a /32 rule to L3 Unicast Interface |
| 411 | """ |
| 412 | |
| 413 | def runTest(self): |
| 414 | test_id = 26 |
| 415 | if len(config["port_map"]) < 2: |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 416 | logging.info("Port count less than 2, can't run this case") |
| 417 | return |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 418 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 419 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 420 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 421 | dip = 0xc0a80001 |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 422 | ports = config["port_map"].keys() |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 423 | Groups = Queue.LifoQueue() |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 424 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 425 | # add l2 interface group |
| 426 | vlan_id = port + test_id |
| 427 | l2gid, msg = add_one_l2_interface_group(self.controller, port, |
| 428 | vlan_id=vlan_id, |
| 429 | is_tagged=True, |
| 430 | send_barrier=False) |
| 431 | dst_mac[5] = vlan_id |
| 432 | l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id, |
| 433 | id=vlan_id, src_mac=intf_src_mac, |
| 434 | dst_mac=dst_mac) |
| 435 | # add vlan flow table |
| 436 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 437 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 438 | # add termination flow |
| 439 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 440 | vlan_id) |
| 441 | # add unicast routing flow |
| 442 | dst_ip = dip + (vlan_id << 8) |
| 443 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
| 444 | 0xffffffff, l3_msg.group_id) |
| 445 | Groups.put(l2gid) |
| 446 | Groups.put(l3_msg.group_id) |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 447 | do_barrier(self.controller) |
| 448 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 449 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 450 | for in_port in ports: |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame^] | 451 | mac_src = '00:00:00:22:32:%02X' % (test_id + in_port) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 452 | ip_src = '192.168.%02d.1' % (test_id + in_port) |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 453 | for out_port in ports: |
| 454 | if in_port == out_port: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 455 | continue |
| 456 | ip_dst = '192.168.%02d.1' % (test_id + out_port) |
| 457 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 458 | vlan_vid=(test_id + in_port), |
| 459 | eth_dst=switch_mac, |
| 460 | eth_src=mac_src, ip_ttl=64, |
| 461 | ip_src=ip_src, |
| 462 | ip_dst=ip_dst) |
| 463 | pkt = str(parsed_pkt) |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 464 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 465 | # build expected packet |
| 466 | mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port) |
| 467 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 468 | vlan_vid=(test_id + out_port), |
| 469 | eth_dst=mac_dst, eth_src=switch_mac, |
| 470 | ip_ttl=63, |
| 471 | ip_src=ip_src, ip_dst=ip_dst) |
| 472 | pkt = str(exp_pkt) |
Flavio Castro | a823386 | 2015-12-02 14:41:11 -0500 | [diff] [blame] | 473 | verify_packet(self, pkt, out_port) |
| 474 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 475 | delete_all_flows(self.controller) |
| 476 | delete_groups(self.controller, Groups) |
| 477 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 478 | |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 479 | class _32VPN(base_tests.SimpleDataPlane): |
| 480 | """ |
| 481 | Insert IP packet |
| 482 | Receive MPLS packet |
| 483 | """ |
| 484 | |
| 485 | def runTest(self): |
| 486 | if len(config["port_map"]) < 2: |
| 487 | logging.info("Port count less than 2, can't run this case") |
| 488 | return |
| 489 | |
| 490 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 491 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 492 | dip = 0xc0a80001 |
| 493 | ports = config["port_map"].keys() |
| 494 | Groups = Queue.LifoQueue() |
| 495 | for port in ports: |
| 496 | # add l2 interface group |
| 497 | id = port |
| 498 | vlan_id = port |
| 499 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, |
| 500 | vlan_id, True, True) |
| 501 | dst_mac[5] = vlan_id |
| 502 | # add MPLS interface group |
| 503 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, |
| 504 | dst_mac, intf_src_mac, |
| 505 | vlan_id, id) |
| 506 | # add MPLS L3 VPN group |
| 507 | mpls_label_gid, mpls_label_msg = add_mpls_label_group( |
| 508 | self.controller, |
| 509 | subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 510 | index=id, ref_gid=mpls_gid, push_mpls_header=True, |
| 511 | set_mpls_label=port, set_bos=1, set_ttl=32) |
| 512 | # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid]) |
| 513 | do_barrier(self.controller) |
| 514 | # add vlan flow table |
Flavio Castro | bcc3dbc | 2016-04-06 11:05:03 -0400 | [diff] [blame] | 515 | add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2, |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 516 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 517 | # add termination flow |
| 518 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 519 | vlan_id) |
| 520 | # add routing flow |
| 521 | dst_ip = dip + (vlan_id << 8) |
| 522 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
Flavio Castro | bcc3dbc | 2016-04-06 11:05:03 -0400 | [diff] [blame] | 523 | 0xffffffff, mpls_label_gid,vrf=2) |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 524 | Groups._put(l2_gid) |
| 525 | Groups._put(mpls_gid) |
| 526 | Groups._put(mpls_label_gid) |
| 527 | do_barrier(self.controller) |
| 528 | |
| 529 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 530 | for in_port in ports: |
| 531 | ip_src = '192.168.%02d.1' % (in_port) |
| 532 | for out_port in ports: |
| 533 | if in_port == out_port: |
| 534 | continue |
| 535 | ip_dst = '192.168.%02d.1' % (out_port) |
| 536 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 537 | vlan_vid=(in_port), |
| 538 | eth_dst=switch_mac, ip_ttl=64, |
| 539 | ip_src=ip_src, |
| 540 | ip_dst=ip_dst) |
| 541 | pkt = str(parsed_pkt) |
| 542 | self.dataplane.send(in_port, pkt) |
| 543 | # build expect packet |
| 544 | mac_dst = '00:00:00:22:22:%02X' % (out_port) |
| 545 | label = (out_port, 0, 1, 32) |
| 546 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, |
| 547 | vlan_vid=(out_port), ip_ttl=63, |
| 548 | ip_src=ip_src, |
| 549 | ip_dst=ip_dst, eth_dst=mac_dst, |
| 550 | eth_src=switch_mac, label=[label]) |
| 551 | pkt = str(exp_pkt) |
| 552 | verify_packet(self, pkt, out_port) |
| 553 | verify_no_other_packets(self) |
| 554 | delete_all_flows(self.controller) |
| 555 | delete_groups(self.controller, Groups) |
| 556 | |
| 557 | class _32EcmpVpn(base_tests.SimpleDataPlane): |
| 558 | """ |
| 559 | Insert IP packet |
| 560 | Receive MPLS packet |
| 561 | """ |
| 562 | |
| 563 | def runTest(self): |
| 564 | if len(config["port_map"]) < 2: |
| 565 | logging.info("Port count less than 2, can't run this case") |
| 566 | return |
| 567 | |
| 568 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 569 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 570 | dip = 0xc0a80001 |
| 571 | ports = config["port_map"].keys() |
| 572 | Groups = Queue.LifoQueue() |
| 573 | for port in ports: |
| 574 | # add l2 interface group |
| 575 | id = port |
| 576 | vlan_id = port |
| 577 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, |
| 578 | vlan_id, True, True) |
| 579 | dst_mac[5] = vlan_id |
| 580 | # add MPLS interface group |
| 581 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, |
| 582 | dst_mac, intf_src_mac, |
| 583 | vlan_id, id) |
| 584 | # add MPLS L3 VPN group |
| 585 | mpls_label_gid, mpls_label_msg = add_mpls_label_group( |
| 586 | self.controller, |
| 587 | subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 588 | index=id, ref_gid=mpls_gid, push_mpls_header=True, |
| 589 | set_mpls_label=port, set_bos=1, set_ttl=32) |
| 590 | ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid]) |
| 591 | do_barrier(self.controller) |
| 592 | # add vlan flow table |
| 593 | add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, |
| 594 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 595 | # add termination flow |
| 596 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 597 | vlan_id) |
| 598 | # add routing flow |
| 599 | dst_ip = dip + (vlan_id << 8) |
| 600 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
| 601 | 0xffffffff, ecmp_msg.group_id) |
| 602 | Groups._put(l2_gid) |
| 603 | Groups._put(mpls_gid) |
| 604 | Groups._put(mpls_label_gid) |
| 605 | Groups._put(ecmp_msg.group_id) |
| 606 | do_barrier(self.controller) |
| 607 | |
| 608 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 609 | for in_port in ports: |
| 610 | ip_src = '192.168.%02d.1' % (in_port) |
| 611 | for out_port in ports: |
| 612 | if in_port == out_port: |
| 613 | continue |
| 614 | ip_dst = '192.168.%02d.1' % (out_port) |
| 615 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 616 | vlan_vid=(in_port), |
| 617 | eth_dst=switch_mac, ip_ttl=64, |
| 618 | ip_src=ip_src, |
| 619 | ip_dst=ip_dst) |
| 620 | pkt = str(parsed_pkt) |
| 621 | self.dataplane.send(in_port, pkt) |
| 622 | # build expect packet |
| 623 | mac_dst = '00:00:00:22:22:%02X' % (out_port) |
| 624 | label = (out_port, 0, 1, 32) |
| 625 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, |
| 626 | vlan_vid=(out_port), ip_ttl=63, |
| 627 | ip_src=ip_src, |
| 628 | ip_dst=ip_dst, eth_dst=mac_dst, |
| 629 | eth_src=switch_mac, label=[label]) |
| 630 | pkt = str(exp_pkt) |
| 631 | verify_packet(self, pkt, out_port) |
| 632 | verify_no_other_packets(self) |
| 633 | delete_all_flows(self.controller) |
| 634 | delete_groups(self.controller, Groups) |
| 635 | |
| 636 | class _32ECMPL3(base_tests.SimpleDataPlane): |
| 637 | """ |
| 638 | Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) , |
| 639 | Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1) |
| 640 | """ |
| 641 | |
| 642 | def runTest(self): |
| 643 | Groups = Queue.LifoQueue() |
| 644 | if len(config["port_map"]) < 2: |
| 645 | logging.info("Port count less than 2, can't run this case") |
| 646 | return |
| 647 | |
| 648 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 649 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 650 | dip = 0xc0a80001 |
| 651 | # Hashes Test Name and uses it as id for installing unique groups |
| 652 | ports = config["port_map"].keys() |
| 653 | for port in ports: |
| 654 | vlan_id = port |
| 655 | id = port |
| 656 | # add l2 interface group |
| 657 | l2_gid, msg = add_one_l2_interface_group(self.controller, port, |
| 658 | vlan_id=vlan_id, |
| 659 | is_tagged=True, |
| 660 | send_barrier=False) |
| 661 | dst_mac[5] = vlan_id |
| 662 | l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id, |
| 663 | id=id, src_mac=intf_src_mac, |
| 664 | dst_mac=dst_mac) |
| 665 | ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id]) |
| 666 | # add vlan flow table |
| 667 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 668 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 669 | # add termination flow |
| 670 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 671 | vlan_id) |
| 672 | # add unicast routing flow |
| 673 | dst_ip = dip + (vlan_id << 8) |
| 674 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
| 675 | 0xffffffff, ecmp_msg.group_id) |
| 676 | Groups._put(l2_gid) |
| 677 | Groups._put(l3_msg.group_id) |
| 678 | Groups._put(ecmp_msg.group_id) |
| 679 | do_barrier(self.controller) |
| 680 | |
| 681 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 682 | for in_port in ports: |
| 683 | mac_src = '00:00:00:22:22:%02X' % in_port |
| 684 | ip_src = '192.168.%02d.1' % in_port |
| 685 | for out_port in ports: |
| 686 | if in_port == out_port: |
| 687 | continue |
| 688 | ip_dst = '192.168.%02d.1' % out_port |
| 689 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 690 | vlan_vid=in_port, |
| 691 | eth_dst=switch_mac, |
| 692 | eth_src=mac_src, ip_ttl=64, |
| 693 | ip_src=ip_src, |
| 694 | ip_dst=ip_dst) |
| 695 | pkt = str(parsed_pkt) |
| 696 | self.dataplane.send(in_port, pkt) |
| 697 | # build expected packet |
| 698 | mac_dst = '00:00:00:22:22:%02X' % out_port |
| 699 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 700 | vlan_vid=out_port, |
| 701 | eth_dst=mac_dst, eth_src=switch_mac, |
| 702 | ip_ttl=63, |
| 703 | ip_src=ip_src, ip_dst=ip_dst) |
| 704 | pkt = str(exp_pkt) |
| 705 | verify_packet(self, pkt, out_port) |
| 706 | verify_no_other_packets(self) |
| 707 | delete_all_flows(self.controller) |
| 708 | delete_groups(self.controller, Groups) |
| 709 | |
| 710 | |
| 711 | class _24VPN(base_tests.SimpleDataPlane): |
| 712 | """ |
| 713 | Insert IP packet |
| 714 | Receive MPLS packet |
| 715 | """ |
| 716 | |
| 717 | def runTest(self): |
| 718 | if len(config["port_map"]) < 2: |
| 719 | logging.info("Port count less than 2, can't run this case") |
| 720 | return |
| 721 | |
| 722 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 723 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 724 | dip = 0xc0a80001 |
| 725 | ports = config["port_map"].keys() |
| 726 | Groups = Queue.LifoQueue() |
| 727 | for port in ports: |
| 728 | # add l2 interface group |
| 729 | id = port |
| 730 | vlan_id = port |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame^] | 731 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True) |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 732 | dst_mac[5] = vlan_id |
| 733 | # add MPLS interface group |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame^] | 734 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, id) |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 735 | # add MPLS L3 VPN group |
| 736 | mpls_label_gid, mpls_label_msg = add_mpls_label_group( |
| 737 | self.controller, |
| 738 | subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 739 | index=id, ref_gid=mpls_gid, push_mpls_header=True, |
| 740 | set_mpls_label=port, set_bos=1, set_ttl=32) |
| 741 | # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid]) |
| 742 | do_barrier(self.controller) |
| 743 | # add vlan flow table |
| 744 | add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, |
| 745 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 746 | # add termination flow |
| 747 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 748 | vlan_id) |
| 749 | # add routing flow |
| 750 | dst_ip = dip + (vlan_id << 8) |
| 751 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
| 752 | 0xffffff00, mpls_label_gid) |
| 753 | Groups._put(l2_gid) |
| 754 | Groups._put(mpls_gid) |
| 755 | Groups._put(mpls_label_gid) |
| 756 | do_barrier(self.controller) |
| 757 | |
| 758 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 759 | for in_port in ports: |
| 760 | ip_src = '192.168.%02d.1' % (in_port) |
| 761 | for out_port in ports: |
| 762 | if in_port == out_port: |
| 763 | continue |
| 764 | ip_dst = '192.168.%02d.1' % (out_port) |
| 765 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 766 | vlan_vid=(in_port), |
| 767 | eth_dst=switch_mac, ip_ttl=64, |
| 768 | ip_src=ip_src, |
| 769 | ip_dst=ip_dst) |
| 770 | pkt = str(parsed_pkt) |
| 771 | self.dataplane.send(in_port, pkt) |
| 772 | # build expect packet |
| 773 | mac_dst = '00:00:00:22:22:%02X' % (out_port) |
| 774 | label = (out_port, 0, 1, 32) |
| 775 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, |
| 776 | vlan_vid=(out_port), ip_ttl=63, |
| 777 | ip_src=ip_src, |
| 778 | ip_dst=ip_dst, eth_dst=mac_dst, |
| 779 | eth_src=switch_mac, label=[label]) |
| 780 | pkt = str(exp_pkt) |
| 781 | verify_packet(self, pkt, out_port) |
| 782 | verify_no_other_packets(self) |
| 783 | delete_all_flows(self.controller) |
| 784 | delete_groups(self.controller, Groups) |
| 785 | |
| 786 | |
| 787 | class _24EcmpVpn(base_tests.SimpleDataPlane): |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 788 | """ |
| 789 | Insert IP packet |
| 790 | Receive MPLS packet |
| 791 | """ |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 792 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 793 | def runTest(self): |
| 794 | if len(config["port_map"]) < 2: |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 795 | logging.info("Port count less than 2, can't run this case") |
| 796 | return |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 797 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 798 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 799 | dip = 0xc0a80001 |
| 800 | Groups = Queue.LifoQueue() |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 801 | ports = config["port_map"].keys() |
| 802 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 803 | # add l2 interface group |
| 804 | id = port |
| 805 | vlan_id = id |
| 806 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, |
| 807 | vlan_id, True, True) |
| 808 | dst_mac[5] = vlan_id |
| 809 | # add MPLS interface group |
| 810 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, |
| 811 | dst_mac, intf_src_mac, |
| 812 | vlan_id, id) |
| 813 | # add MPLS L3 VPN group |
| 814 | mpls_label_gid, mpls_label_msg = add_mpls_label_group( |
| 815 | self.controller, |
| 816 | subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 817 | index=id, ref_gid=mpls_gid, push_mpls_header=True, |
| 818 | set_mpls_label=port, set_bos=1, set_ttl=32) |
| 819 | ecmp_msg = add_l3_ecmp_group(self.controller, id, [mpls_label_gid]) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 820 | do_barrier(self.controller) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 821 | # add vlan flow table |
| 822 | add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, |
| 823 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 824 | # add termination flow |
| 825 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 826 | vlan_id) |
| 827 | # add routing flow |
| 828 | dst_ip = dip + (vlan_id << 8) |
| 829 | # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2) |
| 830 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
| 831 | 0xffffff00, ecmp_msg.group_id, vrf=0) |
| 832 | Groups._put(l2_gid) |
| 833 | Groups._put(mpls_gid) |
| 834 | Groups._put(mpls_label_gid) |
| 835 | Groups._put(ecmp_msg.group_id) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 836 | |
| 837 | do_barrier(self.controller) |
| 838 | |
| 839 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 840 | for in_port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 841 | mac_src = '00:00:00:22:22:%02X' % (in_port) |
| 842 | ip_src = '192.168.%02d.1' % (in_port) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 843 | for out_port in ports: |
| 844 | if in_port == out_port: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 845 | continue |
| 846 | ip_dst = '192.168.%02d.1' % (out_port) |
| 847 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 848 | vlan_vid=(in_port), |
| 849 | eth_dst=switch_mac, |
| 850 | eth_src=mac_src, ip_ttl=64, |
| 851 | ip_src=ip_src, |
| 852 | ip_dst=ip_dst) |
| 853 | pkt = str(parsed_pkt) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 854 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 855 | # build expect packet |
| 856 | mac_dst = '00:00:00:22:22:%02X' % out_port |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 857 | label = (out_port, 0, 1, 32) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 858 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, |
| 859 | vlan_vid=(out_port), ip_ttl=63, |
| 860 | ip_src=ip_src, |
| 861 | ip_dst=ip_dst, eth_dst=mac_dst, |
| 862 | eth_src=switch_mac, label=[label]) |
| 863 | pkt = str(exp_pkt) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 864 | verify_packet(self, pkt, out_port) |
| 865 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 866 | delete_all_flows(self.controller) |
| 867 | delete_groups(self.controller, Groups) |
| 868 | |
castroflavio | ee29484 | 2016-01-06 15:54:28 -0800 | [diff] [blame] | 869 | |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 870 | |
| 871 | class _24ECMPL3(base_tests.SimpleDataPlane): |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 872 | """ |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 873 | Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) , |
| 874 | Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 875 | """ |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 876 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 877 | def runTest(self): |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 878 | Groups = Queue.LifoQueue() |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 879 | if len(config["port_map"]) < 2: |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 880 | logging.info("Port count less than 2, can't run this case") |
| 881 | return |
| 882 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 883 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 884 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 885 | dip = 0xc0a80001 |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 886 | # Hashes Test Name and uses it as id for installing unique groups |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 887 | ports = config["port_map"].keys() |
| 888 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 889 | vlan_id = port |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 890 | id = port |
| 891 | # add l2 interface group |
| 892 | l2_gid, msg = add_one_l2_interface_group(self.controller, port, |
| 893 | vlan_id=vlan_id, |
| 894 | is_tagged=True, |
| 895 | send_barrier=False) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 896 | dst_mac[5] = vlan_id |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 897 | l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id, |
| 898 | id=id, src_mac=intf_src_mac, |
| 899 | dst_mac=dst_mac) |
| 900 | ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id]) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 901 | # add vlan flow table |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 902 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 903 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 904 | # add termination flow |
| 905 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 906 | vlan_id) |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 907 | # add unicast routing flow |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 908 | dst_ip = dip + (vlan_id << 8) |
| 909 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 910 | 0xffffff00, ecmp_msg.group_id) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 911 | Groups._put(l2_gid) |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 912 | Groups._put(l3_msg.group_id) |
| 913 | Groups._put(ecmp_msg.group_id) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 914 | do_barrier(self.controller) |
| 915 | |
| 916 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 917 | for in_port in ports: |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 918 | mac_src = '00:00:00:22:22:%02X' % in_port |
| 919 | ip_src = '192.168.%02d.1' % in_port |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 920 | for out_port in ports: |
| 921 | if in_port == out_port: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 922 | continue |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 923 | ip_dst = '192.168.%02d.1' % out_port |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 924 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 925 | vlan_vid=in_port, |
| 926 | eth_dst=switch_mac, |
| 927 | eth_src=mac_src, ip_ttl=64, |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 928 | ip_src=ip_src, |
| 929 | ip_dst=ip_dst) |
| 930 | pkt = str(parsed_pkt) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 931 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 2262fd4 | 2016-02-04 19:03:36 -0500 | [diff] [blame] | 932 | # build expected packet |
| 933 | mac_dst = '00:00:00:22:22:%02X' % out_port |
| 934 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 935 | vlan_vid=out_port, |
| 936 | eth_dst=mac_dst, eth_src=switch_mac, |
| 937 | ip_ttl=63, |
| 938 | ip_src=ip_src, ip_dst=ip_dst) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 939 | pkt = str(exp_pkt) |
Flavio Castro | 72a45d5 | 2015-12-02 16:37:05 -0500 | [diff] [blame] | 940 | verify_packet(self, pkt, out_port) |
| 941 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 942 | delete_all_flows(self.controller) |
| 943 | delete_groups(self.controller, Groups) |
| 944 | |
Flavio Castro | aba28ff | 2016-02-03 16:47:48 -0500 | [diff] [blame] | 945 | @disabled |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 946 | class MPLSBUG(base_tests.SimpleDataPlane): |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 947 | def runTest(self): |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 948 | if len(config["port_map"]) < 2: |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 949 | logging.info("Port count less than 2, can't run this case") |
| 950 | return |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 951 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 952 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 953 | dip = 0xc0a80001 |
| 954 | Groups = Queue.LifoQueue() |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 955 | ports = config["port_map"].keys() |
| 956 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 957 | # add l2 interface group |
| 958 | vlan_id = port |
| 959 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, |
| 960 | vlan_id, True, False) |
| 961 | dst_mac[5] = vlan_id |
| 962 | # add L3 Unicast group |
| 963 | l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id, |
| 964 | id=vlan_id, src_mac=intf_src_mac, |
| 965 | dst_mac=dst_mac) |
| 966 | # add vlan flow table |
| 967 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 968 | flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 969 | # add termination flow |
| 970 | add_termination_flow(self.controller, port, 0x8847, intf_src_mac, |
| 971 | vlan_id, goto_table=24) |
| 972 | # add mpls flow |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 973 | add_mpls_flow(self.controller, l3_msg.group_id, port) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 974 | # add termination flow |
| 975 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 976 | vlan_id) |
| 977 | # add unicast routing flow |
| 978 | dst_ip = dip + (vlan_id << 8) |
| 979 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
| 980 | 0xffffffff, l3_msg.group_id) |
| 981 | Groups._put(l2_gid) |
| 982 | Groups._put(l3_msg.group_id) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 983 | do_barrier(self.controller) |
| 984 | |
| 985 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 986 | for in_port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 987 | mac_src = '00:00:00:22:22:%02X' % in_port |
| 988 | ip_src = '192.168.%02d.1' % in_port |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 989 | for out_port in ports: |
| 990 | if in_port == out_port: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 991 | continue |
| 992 | ip_dst = '192.168.%02d.1' % out_port |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 993 | switch_mac = "00:00:00:cc:cc:cc" |
| 994 | label = (out_port, 0, 1, 32) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 995 | parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, |
| 996 | vlan_vid=in_port, ip_src=ip_src, |
| 997 | ip_dst=ip_dst, eth_dst=switch_mac, |
| 998 | eth_src=mac_src, label=[label]) |
| 999 | pkt = str(parsed_pkt) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 1000 | self.dataplane.send(in_port, pkt) |
| 1001 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1002 | # build expect packet |
| 1003 | mac_dst = '00:00:00:22:22:%02X' % out_port |
| 1004 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 1005 | vlan_vid=out_port, |
| 1006 | eth_dst=mac_dst, eth_src=switch_mac, |
| 1007 | ip_ttl=31, ip_src=ip_src, |
| 1008 | ip_dst=ip_dst) |
| 1009 | pkt = str(exp_pkt) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 1010 | verify_packet(self, pkt, out_port) |
| 1011 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1012 | |
| 1013 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 1014 | vlan_vid=in_port, |
| 1015 | eth_dst=switch_mac, |
| 1016 | eth_src=mac_src, ip_ttl=64, |
| 1017 | ip_src=ip_src, |
| 1018 | ip_dst=ip_dst) |
| 1019 | pkt = str(parsed_pkt) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 1020 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1021 | # build expected packet |
| 1022 | mac_dst = '00:00:00:22:22:%02X' % out_port |
| 1023 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 1024 | vlan_vid=out_port, |
| 1025 | eth_dst=mac_dst, eth_src=switch_mac, |
| 1026 | ip_ttl=63, |
| 1027 | ip_src=ip_src, ip_dst=ip_dst) |
| 1028 | pkt = str(exp_pkt) |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 1029 | verify_packet(self, pkt, out_port) |
| 1030 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1031 | delete_all_flows(self.controller) |
| 1032 | delete_groups(self.controller, Groups) |
| 1033 | |
Flavio Castro | 8073082 | 2015-12-11 15:38:47 -0500 | [diff] [blame] | 1034 | |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1035 | class L3McastToL2(base_tests.SimpleDataPlane): |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1036 | """ |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1037 | Mcast routing to L2 |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1038 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1039 | |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1040 | def runTest(self): |
| 1041 | """ |
| 1042 | port1 (vlan 300)-> All Ports (vlan 300) |
| 1043 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1044 | if len(config["port_map"]) < 3: |
castroflavio | 4a09c96 | 2016-01-05 13:13:41 -0800 | [diff] [blame] | 1045 | logging.info("Port count less than 3, can't run this case") |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1046 | assert (False) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1047 | return |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1048 | Groups = Queue.LifoQueue() |
| 1049 | vlan_id = 300 |
| 1050 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 1051 | intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 1052 | dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01] |
| 1053 | dst_mac_str = ':'.join(['%02X' % x for x in dst_mac]) |
| 1054 | port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11] |
| 1055 | port1_mac_str = ':'.join(['%02X' % x for x in port1_mac]) |
| 1056 | src_ip = 0xc0a80101 |
| 1057 | src_ip_str = "192.168.1.1" |
| 1058 | dst_ip = 0xe0010101 |
| 1059 | dst_ip_str = "224.1.1.1" |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1060 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1061 | port1 = config["port_map"].keys()[0] |
| 1062 | port2 = config["port_map"].keys()[1] |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1063 | |
| 1064 | switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00] |
| 1065 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1066 | # add l2 interface group |
| 1067 | l2_intf_group_list = [] |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1068 | for port in config["port_map"].keys(): |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1069 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 1070 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1071 | if port == port2: |
| 1072 | continue |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1073 | l2_intf_gid, msg = add_one_l2_interface_group(self.controller, port, |
| 1074 | vlan_id=vlan_id, |
| 1075 | is_tagged=True, |
| 1076 | send_barrier=False) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1077 | l2_intf_group_list.append(l2_intf_gid) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1078 | Groups.put(l2_intf_gid) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1079 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1080 | # add termination flow |
| 1081 | add_termination_flow(self.controller, port1, 0x0800, switch_mac, |
| 1082 | vlan_id) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1083 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1084 | # add l3 interface group |
| 1085 | mcat_group_msg = add_l3_mcast_group(self.controller, vlan_id, 2, |
| 1086 | l2_intf_group_list) |
| 1087 | add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, |
| 1088 | mcat_group_msg.group_id) |
| 1089 | Groups._put(mcat_group_msg.group_id) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1090 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1091 | parsed_pkt = simple_udp_packet(pktlen=100, |
Flavio Castro | 89933f2 | 2016-02-03 15:53:16 -0500 | [diff] [blame] | 1092 | dl_vlan_enable=True, |
| 1093 | vlan_vid=vlan_id, |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1094 | eth_dst=dst_mac_str, |
| 1095 | eth_src=port1_mac_str, |
| 1096 | ip_ttl=64, |
| 1097 | ip_src=src_ip_str, |
| 1098 | ip_dst=dst_ip_str) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1099 | pkt = str(parsed_pkt) |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1100 | self.dataplane.send(port1, pkt) |
| 1101 | for port in config["port_map"].keys(): |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1102 | if port == port2 or port == port1: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1103 | verify_no_packet(self, pkt, port) |
| 1104 | continue |
castroflavio | cc403a9 | 2015-12-15 14:04:19 -0500 | [diff] [blame] | 1105 | verify_packet(self, pkt, port) |
| 1106 | verify_no_other_packets(self) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1107 | delete_all_flows(self.controller) |
| 1108 | delete_groups(self.controller, Groups) |
| 1109 | |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1110 | class L3McastToL3(base_tests.SimpleDataPlane): |
| 1111 | """ |
| 1112 | Mcast routing |
| 1113 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1114 | |
| 1115 | def runTest(self): |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1116 | """ |
| 1117 | port1 (vlan 1)-> port 2 (vlan 2) |
| 1118 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1119 | Groups = Queue.LifoQueue() |
| 1120 | if len(config["port_map"]) < 3: |
castroflavio | 4a09c96 | 2016-01-05 13:13:41 -0800 | [diff] [blame] | 1121 | logging.info("Port count less than 3, can't run this case") |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1122 | assert (False) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1123 | return |
| 1124 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1125 | vlan_id = 1 |
| 1126 | port2_out_vlan = 2 |
| 1127 | port3_out_vlan = 3 |
| 1128 | in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan |
| 1129 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 1130 | intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 1131 | dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01] |
| 1132 | dst_mac_str = ':'.join(['%02X' % x for x in dst_mac]) |
| 1133 | port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11] |
| 1134 | port1_mac_str = ':'.join(['%02X' % x for x in port1_mac]) |
| 1135 | src_ip = 0xc0a80101 |
| 1136 | src_ip_str = "192.168.1.1" |
| 1137 | dst_ip = 0xe0010101 |
| 1138 | dst_ip_str = "224.1.1.1" |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1139 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1140 | port1 = config["port_map"].keys()[0] |
| 1141 | port2 = config["port_map"].keys()[1] |
| 1142 | port3 = config["port_map"].keys()[2] |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1143 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1144 | # add l2 interface group |
| 1145 | for port in config["port_map"].keys(): |
| 1146 | l2gid, msg = add_one_l2_interface_group(self.controller, port, |
| 1147 | vlan_id=vlan_id, |
| 1148 | is_tagged=False, |
| 1149 | send_barrier=False) |
| 1150 | # add vlan flow table |
| 1151 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 1152 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 1153 | vlan_id += 1 |
| 1154 | Groups._put(l2gid) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1155 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1156 | # add termination flow |
| 1157 | add_termination_flow(self.controller, port1, 0x0800, |
| 1158 | [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id) |
| 1159 | |
| 1160 | # add l3 interface group |
| 1161 | port2_ucast_msg = add_l3_interface_group(self.controller, port2, |
| 1162 | port2_out_vlan, 2, |
| 1163 | intf_src_mac) |
| 1164 | port3_ucast_msg = add_l3_interface_group(self.controller, port3, |
| 1165 | port3_out_vlan, 3, |
| 1166 | intf_src_mac) |
| 1167 | mcat_group_msg = add_l3_mcast_group(self.controller, in_vlan, 2, |
| 1168 | [port2_ucast_msg.group_id, |
| 1169 | port3_ucast_msg.group_id]) |
| 1170 | add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, |
| 1171 | mcat_group_msg.group_id) |
| 1172 | Groups._put(port2_ucast_msg.group_id) |
| 1173 | Groups._put(port3_ucast_msg.group_id) |
| 1174 | Groups._put(mcat_group_msg.group_id) |
| 1175 | parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, |
| 1176 | vlan_vid=1, |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1177 | eth_dst=dst_mac_str, |
| 1178 | eth_src=port1_mac_str, |
| 1179 | ip_ttl=64, |
| 1180 | ip_src=src_ip_str, |
| 1181 | ip_dst=dst_ip_str) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1182 | pkt = str(parsed_pkt) |
| 1183 | self.dataplane.send(port1, pkt) |
| 1184 | parsed_pkt = simple_udp_packet(pktlen=96, |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1185 | eth_dst=dst_mac_str, |
| 1186 | eth_src=intf_src_mac_str, |
| 1187 | ip_ttl=63, |
| 1188 | ip_src=src_ip_str, |
| 1189 | ip_dst=dst_ip_str) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1190 | pkt = str(parsed_pkt) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1191 | verify_packet(self, pkt, port2) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1192 | verify_packet(self, pkt, port3) |
| 1193 | verify_no_other_packets(self) |
| 1194 | delete_all_flows(self.controller) |
| 1195 | delete_groups(self.controller, Groups) |
Flavio Castro | 5494794 | 2016-02-03 16:05:20 -0500 | [diff] [blame] | 1196 | |
| 1197 | |
Flavio Castro | b702a2f | 2016-04-10 22:01:48 -0400 | [diff] [blame] | 1198 | class _MplsFwd(base_tests.SimpleDataPlane): |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 1199 | """ |
Flavio Castro | 5494794 | 2016-02-03 16:05:20 -0500 | [diff] [blame] | 1200 | Insert IP packet |
| 1201 | Receive MPLS packet |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1202 | """ |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1203 | def runTest(self): |
| 1204 | Groups = Queue.LifoQueue() |
| 1205 | if len(config["port_map"]) < 2: |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1206 | logging.info("Port count less than 2, can't run this case") |
| 1207 | return |
Flavio Castro | bcc3dbc | 2016-04-06 11:05:03 -0400 | [diff] [blame] | 1208 | dip = 0xc0a80001 |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1209 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 1210 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 1211 | # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1212 | ports = config["port_map"].keys() |
| 1213 | for port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1214 | # add l2 interface group |
| 1215 | id = port |
| 1216 | vlan_id = id |
| 1217 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, |
| 1218 | vlan_id, True, False) |
| 1219 | dst_mac[5] = vlan_id |
Flavio Castro | b702a2f | 2016-04-10 22:01:48 -0400 | [diff] [blame] | 1220 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, |
| 1221 | dst_mac, intf_src_mac, |
| 1222 | vlan_id, id) |
| 1223 | mpls_label_gid, mpls_label_msg = add_mpls_label_group( |
| 1224 | self.controller, |
| 1225 | subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL, |
| 1226 | index=id, ref_gid=mpls_gid, push_mpls_header=False, |
| 1227 | set_mpls_label=port, set_bos=1) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1228 | # add vlan flow table |
| 1229 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 1230 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 1231 | # add termination flow |
| 1232 | add_termination_flow(self.controller, port, 0x8847, intf_src_mac, |
| 1233 | vlan_id, goto_table=24) |
Flavio Castro | 8ca5254 | 2016-04-11 11:24:49 -0400 | [diff] [blame] | 1234 | add_mpls_flow(self.controller, mpls_label_gid, port, goto_table=29) |
Flavio Castro | bcc3dbc | 2016-04-06 11:05:03 -0400 | [diff] [blame] | 1235 | dst_ip = dip + (vlan_id << 8) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1236 | Groups._put(l2_gid) |
Flavio Castro | b702a2f | 2016-04-10 22:01:48 -0400 | [diff] [blame] | 1237 | Groups._put(mpls_gid) |
Flavio Castro | 8ca5254 | 2016-04-11 11:24:49 -0400 | [diff] [blame] | 1238 | Groups._put(mpls_label_gid) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1239 | do_barrier(self.controller) |
| 1240 | |
| 1241 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 1242 | for in_port in ports: |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1243 | ip_src = '192.168.%02d.1' % (in_port) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1244 | for out_port in ports: |
| 1245 | if in_port == out_port: |
Flavio Castro | 5494794 | 2016-02-03 16:05:20 -0500 | [diff] [blame] | 1246 | continue |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1247 | ip_dst = '192.168.%02d.1' % (out_port) |
Flavio Castro | 5494794 | 2016-02-03 16:05:20 -0500 | [diff] [blame] | 1248 | |
| 1249 | label = (out_port, 0, 1, 32) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1250 | parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, |
| 1251 | vlan_vid=(in_port), ip_src=ip_src, |
| 1252 | ip_dst=ip_dst, eth_dst=switch_mac, |
| 1253 | label=[label]) |
| 1254 | pkt = str(parsed_pkt) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1255 | self.dataplane.send(in_port, pkt) |
Flavio Castro | 5494794 | 2016-02-03 16:05:20 -0500 | [diff] [blame] | 1256 | |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1257 | # build expect packet |
| 1258 | mac_dst = '00:00:00:22:22:%02X' % (out_port) |
Flavio Castro | b702a2f | 2016-04-10 22:01:48 -0400 | [diff] [blame] | 1259 | label = (out_port, 0, 1, 31) |
| 1260 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, |
| 1261 | vlan_vid=(out_port), ip_src=ip_src, |
| 1262 | ip_dst=ip_dst, eth_src=switch_mac, |
| 1263 | eth_dst=mac_dst,label=[label]) |
| 1264 | pkt = str(exp_pkt) |
| 1265 | verify_packet(self, pkt, out_port) |
| 1266 | verify_no_other_packets(self) |
| 1267 | delete_all_flows(self.controller) |
| 1268 | delete_groups(self.controller, Groups) |
| 1269 | |
| 1270 | class _MplsTermination(base_tests.SimpleDataPlane): |
| 1271 | """ |
| 1272 | Insert IP packet |
| 1273 | Receive MPLS packet |
| 1274 | """ |
| 1275 | def runTest(self): |
| 1276 | Groups = Queue.LifoQueue() |
| 1277 | if len(config["port_map"]) < 2: |
| 1278 | logging.info("Port count less than 2, can't run this case") |
| 1279 | return |
| 1280 | dip = 0xc0a80001 |
| 1281 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 1282 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 1283 | # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules |
| 1284 | ports = config["port_map"].keys() |
| 1285 | for port in ports: |
| 1286 | # add l2 interface group |
| 1287 | vlan_id, id, dst_mac[5] = port, port, port |
| 1288 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, |
| 1289 | vlan_id, True, False) |
| 1290 | # add L3 Unicast group |
| 1291 | l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id, |
| 1292 | id=id, src_mac=intf_src_mac,dst_mac=dst_mac) |
| 1293 | # add L3 ecmp group |
| 1294 | ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id]) |
| 1295 | # add vlan flow table |
| 1296 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 1297 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 1298 | # add termination flow |
| 1299 | add_termination_flow(self.controller, port, 0x8847, intf_src_mac, |
| 1300 | vlan_id, goto_table=24) |
| 1301 | #add_mpls_flow(self.controller, ecmp_msg.group_id, port) |
| 1302 | add_mpls_flow(self.controller, label=port) |
| 1303 | dst_ip = dip + (vlan_id << 8) |
| 1304 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, |
| 1305 | ecmp_msg.group_id, 1) |
| 1306 | Groups._put(l2_gid) |
| 1307 | Groups._put(l3_msg.group_id) |
| 1308 | Groups._put(ecmp_msg.group_id) |
| 1309 | do_barrier(self.controller) |
| 1310 | |
| 1311 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 1312 | for in_port in ports: |
| 1313 | ip_src = '192.168.%02d.1' % (in_port) |
| 1314 | for out_port in ports: |
| 1315 | if in_port == out_port: |
| 1316 | continue |
| 1317 | ip_dst = '192.168.%02d.1' % (out_port) |
| 1318 | label = (out_port, 0, 1, 32) |
| 1319 | parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,vlan_vid=(in_port), |
| 1320 | ip_src=ip_src,ip_dst=ip_dst, eth_dst=switch_mac,label=[label]) |
| 1321 | pkt = str(parsed_pkt) |
| 1322 | self.dataplane.send(in_port, pkt) |
| 1323 | # build expect packet |
| 1324 | mac_dst = '00:00:00:22:22:%02X' % (out_port) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1325 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 1326 | vlan_vid=(out_port), |
| 1327 | eth_dst=mac_dst, eth_src=switch_mac, |
| 1328 | ip_ttl=31, ip_src=ip_src, |
| 1329 | ip_dst=ip_dst) |
| 1330 | pkt = str(exp_pkt) |
castroflavio | 30c6cc5 | 2016-01-07 15:19:42 -0800 | [diff] [blame] | 1331 | verify_packet(self, pkt, out_port) |
| 1332 | verify_no_other_packets(self) |
Flavio Castro | 76af648 | 2016-04-06 11:42:29 -0400 | [diff] [blame] | 1333 | delete_all_flows(self.controller) |
| 1334 | delete_groups(self.controller, Groups) |
Flavio Castro | 1c9b125 | 2016-02-04 18:42:58 -0500 | [diff] [blame] | 1335 | |
| 1336 | |
| 1337 | class _24UcastTagged(base_tests.SimpleDataPlane): |
| 1338 | """ |
| 1339 | Verify a IP forwarding works for a /32 rule to L3 Unicast Interface |
| 1340 | """ |
| 1341 | |
| 1342 | def runTest(self): |
| 1343 | test_id = 26 |
| 1344 | if len(config["port_map"]) < 2: |
| 1345 | logging.info("Port count less than 2, can't run this case") |
| 1346 | return |
| 1347 | |
| 1348 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 1349 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 1350 | dip = 0xc0a80001 |
| 1351 | ports = config["port_map"].keys() |
| 1352 | Groups = Queue.LifoQueue() |
| 1353 | for port in ports: |
| 1354 | # add l2 interface group |
| 1355 | vlan_id = port + test_id |
| 1356 | l2gid, msg = add_one_l2_interface_group(self.controller, port, |
| 1357 | vlan_id=vlan_id, |
| 1358 | is_tagged=True, |
| 1359 | send_barrier=False) |
| 1360 | dst_mac[5] = vlan_id |
| 1361 | l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id, |
| 1362 | id=vlan_id, src_mac=intf_src_mac, |
| 1363 | dst_mac=dst_mac) |
| 1364 | # add vlan flow table |
| 1365 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 1366 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 1367 | # add termination flow |
| 1368 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 1369 | vlan_id) |
| 1370 | # add unicast routing flow |
| 1371 | dst_ip = dip + (vlan_id << 8) |
| 1372 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
| 1373 | 0xffffff00, l3_msg.group_id) |
| 1374 | Groups.put(l2gid) |
| 1375 | Groups.put(l3_msg.group_id) |
| 1376 | do_barrier(self.controller) |
| 1377 | |
| 1378 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 1379 | for in_port in ports: |
| 1380 | mac_src = '00:00:00:22:22:%02X' % (test_id + in_port) |
| 1381 | ip_src = '192.168.%02d.1' % (test_id + in_port) |
| 1382 | for out_port in ports: |
| 1383 | if in_port == out_port: |
| 1384 | continue |
| 1385 | ip_dst = '192.168.%02d.1' % (test_id + out_port) |
| 1386 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 1387 | vlan_vid=(test_id + in_port), |
| 1388 | eth_dst=switch_mac, |
| 1389 | eth_src=mac_src, ip_ttl=64, |
| 1390 | ip_src=ip_src, |
| 1391 | ip_dst=ip_dst) |
| 1392 | pkt = str(parsed_pkt) |
| 1393 | self.dataplane.send(in_port, pkt) |
| 1394 | # build expected packet |
| 1395 | mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port) |
| 1396 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 1397 | vlan_vid=(test_id + out_port), |
| 1398 | eth_dst=mac_dst, eth_src=switch_mac, |
| 1399 | ip_ttl=63, |
| 1400 | ip_src=ip_src, ip_dst=ip_dst) |
| 1401 | pkt = str(exp_pkt) |
| 1402 | verify_packet(self, pkt, out_port) |
| 1403 | verify_no_other_packets(self) |
| 1404 | delete_all_flows(self.controller) |
| 1405 | delete_groups(self.controller, Groups) |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame^] | 1406 | |
| 1407 | class _0Ucast(base_tests.SimpleDataPlane): |
| 1408 | """ |
| 1409 | Verify a IP forwarding works for a /0 rule to L3 Unicast Interface |
| 1410 | """ |
| 1411 | |
| 1412 | def runTest(self): |
| 1413 | if len(config["port_map"]) < 2: |
| 1414 | logging.info("Port count less than 2, can't run this case") |
| 1415 | return |
| 1416 | |
| 1417 | intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 1418 | dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 1419 | dip = 0xc0a80001 |
| 1420 | ports = config["port_map"].keys() |
| 1421 | Groups = Queue.LifoQueue() |
| 1422 | for port in ports: |
| 1423 | # add l2 interface group |
| 1424 | vlan_id = port |
| 1425 | l2gid, msg = add_one_l2_interface_group(self.controller, port, |
| 1426 | vlan_id=vlan_id, |
| 1427 | is_tagged=True, |
| 1428 | send_barrier=False) |
| 1429 | dst_mac[5] = vlan_id |
| 1430 | l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id, |
| 1431 | id=vlan_id, src_mac=intf_src_mac, |
| 1432 | dst_mac=dst_mac) |
| 1433 | # add vlan flow table |
| 1434 | add_one_vlan_table_flow(self.controller, port, vlan_id, |
| 1435 | flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 1436 | # add termination flow |
| 1437 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, |
| 1438 | vlan_id) |
| 1439 | # add unicast routing flow |
| 1440 | dst_ip = dip + (vlan_id << 8) |
| 1441 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, |
| 1442 | 0xffffffff, l3_msg.group_id) |
| 1443 | Groups.put(l2gid) |
| 1444 | Groups.put(l3_msg.group_id) |
| 1445 | l3_gid = encode_l3_unicast_group_id(ports[0]) |
| 1446 | dst_ip = 0x0 |
| 1447 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, l3_gid) |
| 1448 | do_barrier(self.controller) |
| 1449 | |
| 1450 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 1451 | for in_port in ports: |
| 1452 | mac_src = '00:00:00:22:22:%02X' % (in_port) |
| 1453 | ip_src = '192.168.%02d.1' % (in_port) |
| 1454 | for out_port in ports: |
| 1455 | if in_port == out_port: |
| 1456 | continue |
| 1457 | ip_dst = '192.168.%02d.1' % (out_port) |
| 1458 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 1459 | vlan_vid=(in_port), |
| 1460 | eth_dst=switch_mac, |
| 1461 | eth_src=mac_src, ip_ttl=64, |
| 1462 | ip_src=ip_src, |
| 1463 | ip_dst=ip_dst) |
| 1464 | pkt = str(parsed_pkt) |
| 1465 | self.dataplane.send(in_port, pkt) |
| 1466 | # build expected packet |
| 1467 | mac_dst = '00:00:00:22:22:%02X' % (out_port) |
| 1468 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
| 1469 | vlan_vid=(out_port), |
| 1470 | eth_dst=mac_dst, eth_src=switch_mac, |
| 1471 | ip_ttl=63, |
| 1472 | ip_src=ip_src, ip_dst=ip_dst) |
| 1473 | pkt = str(exp_pkt) |
| 1474 | verify_packet(self, pkt, out_port) |
| 1475 | verify_no_other_packets(self) |
| 1476 | ip_dst='1.168.%02d.1' % ports[0] |
| 1477 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port, |
| 1478 | eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst) |
| 1479 | pkt=str(parsed_pkt) |
| 1480 | self.dataplane.send(in_port, pkt) |
| 1481 | #build expect packet |
| 1482 | mac_dst='00:00:00:22:22:%02X' % ports[0] |
| 1483 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src, |
| 1484 | ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac) |
| 1485 | pkt=str(exp_pkt) |
| 1486 | verify_packet(self, pkt, ports[0]) |
| 1487 | verify_no_other_packets(self) |
| 1488 | |
| 1489 | delete_all_flows(self.controller) |
| 1490 | delete_groups(self.controller, Groups) |
| 1491 | |
| 1492 | |
| 1493 | |