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