Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 1 | ''' |
| 2 | OFTests for functionality needed from the OLT. |
| 3 | ''' |
| 4 | import logging |
| 5 | from oftest import config |
| 6 | import oftest.base_tests as base_tests |
| 7 | import oftest.packet as scapy |
| 8 | |
| 9 | import ofp |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 10 | import time |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 11 | |
| 12 | from oftest.testutils import * |
| 13 | |
| 14 | onu_port = test_param_get("onu_port", 1) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 15 | onu_port2 = test_param_get("onu_port2", 2) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 16 | olt_port = test_param_get("olt_port", 129) |
| 17 | |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame^] | 18 | def double_vlan_udp_packet(pktlen=100, |
| 19 | eth_dst='00:01:02:03:04:05', |
| 20 | eth_src='00:06:07:08:09:0a', |
| 21 | dl_vlan_enable=False, |
| 22 | c_vlan_vid=0, |
| 23 | c_vlan_pcp=0, |
| 24 | s_vlan_vid=0, |
| 25 | s_vlan_pcp=0, |
| 26 | ip_src='192.168.0.1', |
| 27 | ip_dst='192.168.0.2', |
| 28 | ip_tos=0, |
| 29 | ip_ttl=64, |
| 30 | udp_sport=1234, |
| 31 | udp_dport=80, |
| 32 | ip_ihl=None, |
| 33 | ip_options=False |
| 34 | ): |
| 35 | """ |
| 36 | Return a double vlan tagged dataplane UDP packet |
| 37 | Supports a few parameters: |
| 38 | @param len Length of packet in bytes w/o CRC |
| 39 | @param eth_dst Destination MAC |
| 40 | @param eth_src Source MAC |
| 41 | @param dl_vlan_enable True if the packet is with vlan, False otherwise |
| 42 | @param c_vlan_vid CVLAN ID |
| 43 | @param c_vlan_pcp CVLAN priority |
| 44 | @param s_vlan_vid SVLAN ID |
| 45 | @param s_vlan_pcp SVLAN priority |
| 46 | @param ip_src IP source |
| 47 | @param ip_dst IP destination |
| 48 | @param ip_tos IP ToS |
| 49 | @param ip_ttl IP TTL |
| 50 | @param udp_dport UDP destination port |
| 51 | @param udp_sport UDP source port |
| 52 | |
| 53 | Generates a simple UDP packet. Users shouldn't assume anything about |
| 54 | this packet other than that it is a valid ethernet/IP/UDP frame. |
| 55 | """ |
| 56 | |
| 57 | if MINSIZE > pktlen: |
| 58 | pktlen = MINSIZE |
| 59 | |
| 60 | # Note Dot1Q.id is really CFI |
| 61 | if (dl_vlan_enable): |
| 62 | pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \ |
| 63 | scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid)/ \ |
| 64 | scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid)/ \ |
| 65 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \ |
| 66 | scapy.UDP(sport=udp_sport, dport=udp_dport) |
| 67 | else: |
| 68 | if not ip_options: |
| 69 | pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \ |
| 70 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \ |
| 71 | scapy.UDP(sport=udp_sport, dport=udp_dport) |
| 72 | |
| 73 | else: |
| 74 | pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \ |
| 75 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options)/ \ |
| 76 | scapy.UDP(sport=udp_sport, dport=udp_dport) |
| 77 | |
| 78 | pkt = pkt/("D" * (pktlen - len(pkt))) |
| 79 | |
| 80 | return pkt |
| 81 | |
| 82 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 83 | def testPacketIn(self, match, parsed_pkt): |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 84 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 85 | delete_all_flows(self.controller) |
| 86 | |
| 87 | pkt = str(parsed_pkt) |
| 88 | |
| 89 | request = ofp.message.flow_add( |
| 90 | table_id=test_param_get("table", 0), |
| 91 | cookie=42, |
| 92 | match=match, |
| 93 | instructions=[ |
| 94 | ofp.instruction.apply_actions( |
| 95 | actions=[ |
| 96 | ofp.action.output( |
| 97 | port=ofp.OFPP_CONTROLLER, |
| 98 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 99 | buffer_id=ofp.OFP_NO_BUFFER, |
| 100 | priority=1000) |
| 101 | |
| 102 | logging.info("Inserting flow sending matching packets to controller") |
| 103 | self.controller.message_send(request) |
| 104 | do_barrier(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 105 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 106 | for of_port in config["port_map"]: |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 107 | logging.info("PacketInExact test, port %d", of_port) |
| 108 | self.dataplane.send(of_port, pkt) |
| 109 | verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION) |
| 110 | verify_packets(self, pkt, []) |
| 111 | |
| 112 | class EapolPacketIn(base_tests.SimpleDataPlane): |
| 113 | |
| 114 | """Verify packet-ins are sent for EAPOL packets """ |
| 115 | |
| 116 | def runTest(self): |
| 117 | logging.info("Running EAPOL Packet In test") |
| 118 | |
| 119 | match = ofp.match() |
| 120 | match.oxm_list.append(ofp.oxm.eth_type(0x888e)) |
| 121 | # Use ethertype 0x888e and multicast destination MAC address |
| 122 | pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e) |
| 123 | |
| 124 | testPacketIn(self, match, pkt) |
| 125 | |
| 126 | class ARPPacketIn(base_tests.SimpleDataPlane): |
| 127 | |
| 128 | """Verify packet-ins are sent for ARP packets """ |
| 129 | |
| 130 | def runTest(self): |
| 131 | logging.info("Running ARP Packet In test") |
| 132 | |
| 133 | match = ofp.match() |
| 134 | match.oxm_list.append(ofp.oxm.eth_type(0x0806)) |
| 135 | |
| 136 | # Use ethertype 0x0806 |
| 137 | pkt = simple_eth_packet(eth_type=0x0806) |
| 138 | |
| 139 | testPacketIn(self, match, pkt) |
| 140 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 141 | class DHCPPacketIn(base_tests.SimpleDataPlane): |
| 142 | |
| 143 | """Verify packet-ins are sent for DHCP packets """ |
| 144 | |
| 145 | def runTest(self): |
| 146 | logging.info("Running DHCP Packet In test") |
| 147 | |
| 148 | pkt = simple_udp_packet(udp_sport=68, udp_dport=67) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 149 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 150 | match = ofp.match() |
| 151 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
| 152 | match.oxm_list.append(ofp.oxm.ip_proto(17)) |
| 153 | match.oxm_list.append(ofp.oxm.udp_src(68)) |
| 154 | match.oxm_list.append(ofp.oxm.udp_dst(67)) |
| 155 | |
| 156 | testPacketIn(self, match, pkt) |
| 157 | |
| 158 | # Other UDP packets should not match the rule |
| 159 | radiusPkt = simple_udp_packet(udp_sport=1812, udp_dport=1812) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 160 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 161 | self.dataplane.send(1, str(radiusPkt)) |
| 162 | verify_no_packet_in(self, radiusPkt, 1) |
| 163 | |
| 164 | class IGMPPacketIn(base_tests.SimpleDataPlane): |
| 165 | |
| 166 | """Verify packet-ins are sent for IGMP packets """ |
| 167 | |
| 168 | def runTest(self): |
| 169 | logging.info("Running IGMP Packet In test") |
| 170 | |
| 171 | match = ofp.match() |
| 172 | match.oxm_list.append(ofp.oxm.eth_type(0x800)) |
| 173 | match.oxm_list.append(ofp.oxm.ip_proto(2)) |
| 174 | |
| 175 | pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \ |
| 176 | scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2) |
| 177 | |
| 178 | pkt = pkt/("0" * (100 - len(pkt))) |
| 179 | |
| 180 | testPacketIn(self, match, pkt) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 181 | |
| 182 | class TestMeter(base_tests.SimpleDataPlane): |
| 183 | |
| 184 | def runTest(self): |
| 185 | logging.info("Running Meter tests") |
| 186 | dropMeterBand = ofp.meter_band.drop(rate = 500) |
| 187 | meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ]) |
| 188 | self.controller.message_send(meter_mod) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 189 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 190 | time.sleep(1) |
| 191 | |
| 192 | verify_no_errors(self.controller) |
| 193 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 194 | vlan_id = 201 |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 195 | match = ofp.match() |
| 196 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 197 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id )) |
| 198 | |
| 199 | request = ofp.message.flow_add( |
| 200 | table_id=test_param_get("table", 0), |
| 201 | cookie=42, |
| 202 | match=match, |
| 203 | instructions=[ |
| 204 | ofp.instruction.apply_actions( |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 205 | actions=[ofp.action.output(port=olt_port)] |
| 206 | ), |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 207 | ofp.instruction.meter(meter_id = 1) |
| 208 | ], |
| 209 | buffer_id=ofp.OFP_NO_BUFFER, |
| 210 | priority=1000) |
| 211 | |
| 212 | self.controller.message_send(request) |
| 213 | time.sleep(1) |
| 214 | verify_no_errors(self.controller) |
| 215 | |
| 216 | match = ofp.match() |
| 217 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 218 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 219 | |
| 220 | request = ofp.message.flow_add( |
| 221 | table_id=test_param_get("table", 0), |
| 222 | cookie=43, |
| 223 | match=match, |
| 224 | instructions=[ |
| 225 | ofp.instruction.apply_actions( |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 226 | actions=[ofp.action.output(port=onu_port)] |
| 227 | ), |
| 228 | ofp.instruction.meter(meter_id = 1) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 229 | ], |
| 230 | buffer_id=ofp.OFP_NO_BUFFER, |
| 231 | priority=1000) |
| 232 | |
| 233 | self.controller.message_send(request) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 234 | time.sleep(1) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 235 | verify_no_errors(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 236 | do_barrier(self.controller) |
| 237 | time.sleep(5) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 238 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 239 | inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0) |
| 240 | # downstream |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 241 | self.dataplane.send(olt_port, str(inPkt)) |
| 242 | verify_packet(self, inPkt, onu_port) |
| 243 | # upstream |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 244 | self.dataplane.send(onu_port, str(inPkt)) |
| 245 | verify_packet(self, inPkt, olt_port) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 246 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 247 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 248 | meter_mod = ofp.message.meter_mod(xid = 2, command = ofp.OFPMC_DELETE, meter_id = 1) |
| 249 | self.controller.message_send(meter_mod) |
| 250 | time.sleep(1) |
| 251 | delete_all_flows(self.controller) |
| 252 | verify_no_errors(self.controller) |
| 253 | |
| 254 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 255 | class TestDuplicateMeter(base_tests.SimpleDataPlane): |
| 256 | |
| 257 | def runTest(self): |
| 258 | logging.info("Running Duplicate Meter Test") |
| 259 | dropMeterBand = ofp.meter_band.drop(rate = 500) |
| 260 | meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ]) |
| 261 | self.controller.message_send(meter_mod) |
| 262 | self.controller.message_send(meter_mod) |
| 263 | |
| 264 | time.sleep(1) |
| 265 | |
| 266 | try: |
| 267 | verify_no_errors(self.controller) |
| 268 | except AssertionError as e: |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 269 | if (not e.message == "unexpected error type=12 code=1"): |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 270 | raise AssertionError("Incorrect error type: %s" % e.message) |
| 271 | |
| 272 | |
| 273 | class VlanTest(base_tests.SimpleDataPlane): |
| 274 | |
| 275 | """Verify the switch can push/pop a VLAN tag and forward out a port """ |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 276 | |
| 277 | def runTest(self): |
| 278 | logging.info("Running push VLAN test") |
| 279 | |
| 280 | vlan_id = 200 |
| 281 | |
| 282 | delete_all_flows(self.controller) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 283 | |
| 284 | #PUSH |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 285 | match = ofp.match() |
| 286 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 287 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT)) |
| 288 | match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0)) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 289 | |
| 290 | request = ofp.message.flow_add( |
| 291 | table_id=test_param_get("table", 0), |
| 292 | cookie=42, |
| 293 | match=match, |
| 294 | instructions=[ |
| 295 | ofp.instruction.apply_actions( |
| 296 | actions=[ |
| 297 | ofp.action.push_vlan(ethertype=0x8100), |
| 298 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)), |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 299 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)), |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 300 | ofp.action.output(port=olt_port)])], |
| 301 | buffer_id=ofp.OFP_NO_BUFFER, |
| 302 | priority=1000) |
| 303 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 304 | logging.info("Inserting flow tagging upstream") |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 305 | self.controller.message_send(request) |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame^] | 306 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 307 | #POP |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 308 | match = ofp.match() |
| 309 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 310 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 311 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 312 | request = ofp.message.flow_add( |
| 313 | table_id=test_param_get("table", 0), |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 314 | cookie=43, |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 315 | match=match, |
| 316 | instructions=[ |
| 317 | ofp.instruction.apply_actions( |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 318 | actions=[ |
| 319 | ofp.action.pop_vlan(), |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 320 | ofp.action.output(port=onu_port)])], |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 321 | buffer_id=ofp.OFP_NO_BUFFER, |
| 322 | priority=1000) |
| 323 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 324 | logging.info("Inserting flow tagging downstream") |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 325 | self.controller.message_send(request) |
| 326 | do_barrier(self.controller) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 327 | time.sleep(5) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 328 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 329 | inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 330 | outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, |
| 331 | vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0) |
| 332 | |
| 333 | # Send untagged packet in the ONU port and expect tagged packet out the OLT port |
| 334 | self.dataplane.send(onu_port, str(inPkt)) |
| 335 | verify_packet(self, outPkt, olt_port) |
| 336 | |
| 337 | # Send untagged packet in the OLT port and expect no packets to come out |
| 338 | self.dataplane.send(olt_port, str(inPkt)) |
| 339 | verify_packets(self, outPkt, []) |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame^] | 340 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 341 | inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 342 | vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 343 | outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 344 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 345 | # Send tagged packet in the OLT port and expect untagged packet out the OLT port |
| 346 | self.dataplane.send(olt_port, str(inPkt)) |
| 347 | verify_packet(self, outPkt, onu_port) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 348 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 349 | # Send tagged packet in the ONU port and expect no packets to come out |
| 350 | self.dataplane.send(onu_port, str(inPkt)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 351 | verify_packets(self, outPkt, []) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 352 | |
| 353 | def createAllGroupAdd(group_id, ports=[]): |
| 354 | buckets = [] |
| 355 | |
| 356 | for portNum in ports: |
| 357 | buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY, |
| 358 | actions=[ofp.action.output(port=portNum)])) |
| 359 | |
| 360 | group_add = ofp.message.group_add(group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets) |
| 361 | |
| 362 | return group_add |
| 363 | |
| 364 | def createAllGroupMod(group_id, ports=[]): |
| 365 | buckets = [] |
| 366 | |
| 367 | for portNum in ports: |
| 368 | buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY, |
| 369 | actions=[ofp.action.output(port=portNum)])) |
| 370 | |
| 371 | group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets) |
| 372 | |
| 373 | return group_mod |
| 374 | |
| 375 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 376 | class TestGroupAdd(base_tests.SimpleDataPlane): |
| 377 | |
| 378 | def runTest(self): |
| 379 | logging.info("Running Group tests") |
| 380 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 381 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 382 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 383 | test_group_id = 1 |
| 384 | |
| 385 | # output to two ONU |
| 386 | group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 387 | |
| 388 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 389 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 390 | verify_no_errors(self.controller) |
| 391 | |
| 392 | # Remove the group and then readd it. |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 393 | group_delete = ofp.message.group_delete(group_id = test_group_id) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 394 | self.controller.message_send(group_delete) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 395 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 396 | verify_no_errors(self.controller) |
| 397 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 398 | group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 399 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 400 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 401 | verify_no_errors(self.controller) |
| 402 | |
| 403 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 404 | # clean up the test |
| 405 | group_delete = ofp.message.group_delete(group_id = test_group_id) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 406 | self.controller.message_send(group_delete) |
| 407 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 408 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 409 | verify_no_errors(self.controller) |
| 410 | |
| 411 | class TestGroupMod(base_tests.SimpleDataPlane): |
| 412 | |
| 413 | def runTest(self): |
| 414 | logging.info("Running Group tests") |
| 415 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 416 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 417 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 418 | test_group_id = 1 |
| 419 | |
| 420 | group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 421 | |
| 422 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 423 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 424 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 425 | |
| 426 | # Modifying the group |
| 427 | group_mod = createAllGroupMod(test_group_id, [onu_port2]) |
| 428 | |
| 429 | self.controller.message_send(group_mod) |
| 430 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 431 | verify_no_errors(self.controller) |
| 432 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 433 | # Add a bucket into the group |
| 434 | group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2]) |
| 435 | self.controller.message_send(group_mod) |
| 436 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 437 | verify_no_errors(self.controller) |
| 438 | |
| 439 | # Modifying a non-existing group |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 440 | group_mod = createAllGroupMod(777, [onu_port2]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 441 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 442 | self.controller.message_send(group_mod) |
| 443 | do_barrier(self.controller) |
| 444 | errorExperienced = 0 |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 445 | try: |
| 446 | verify_no_errors(self.controller) |
| 447 | except AssertionError as e: |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 448 | errorExperienced = 1 |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 449 | if (not (e.message == "unexpected error type=6 code=8")): |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 450 | raise AssertionError("Incorrect error type: %s" % e.message) |
| 451 | if not errorExperienced: |
| 452 | raise AssertionError("An error message is expected, but not shown.") |
| 453 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 454 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 455 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 456 | group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id) |
| 457 | self.controller.message_send(group_delete) |
| 458 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 459 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 460 | verify_no_errors(self.controller) |
| 461 | |
| 462 | class TestDuplicateGroup(base_tests.SimpleDataPlane): |
| 463 | |
| 464 | def runTest(self): |
| 465 | logging.info("Running Group tests") |
| 466 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 467 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 468 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 469 | test_group_id = 1 |
| 470 | group_add = createAllGroupAdd(test_group_id, ports=[onu_port]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 471 | |
| 472 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 473 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 474 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 475 | |
| 476 | # Add the same group id |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 477 | duplicate_group_fail = 0 |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 478 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 479 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 480 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 481 | try: |
| 482 | verify_no_errors(self.controller) |
| 483 | except AssertionError as e: |
| 484 | duplicate_group_fail = 1 |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 485 | if (not e.message == "unexpected error type=6 code=0"): |
| 486 | raise AssertionError("Incorrect error type: %s" % e.message) |
| 487 | if not duplicate_group_fail: |
| 488 | raise AssertionError("Adding duplicate groups didn't raise an error.") |
| 489 | |
| 490 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 491 | group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id) |
| 492 | self.controller.message_send(group_delete) |
| 493 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 494 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 495 | verify_no_errors(self.controller) |
| 496 | |
| 497 | class TestGroupAndFlow(base_tests.SimpleDataPlane): |
| 498 | |
| 499 | def runTest(self): |
| 500 | logging.info("Running Group tests") |
| 501 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 502 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 503 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 504 | # Create a group |
| 505 | test_group_id = 1 |
| 506 | group_add = createAllGroupAdd(test_group_id, ports=[onu_port]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 507 | |
| 508 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 509 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 510 | verify_no_errors(self.controller) |
| 511 | |
| 512 | # Create a flow rule matching olt port and vlan id |
| 513 | match = ofp.match() |
| 514 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 515 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201)) |
| 516 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 517 | flow_pointing_to_group = ofp.message.flow_add( |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 518 | table_id=test_param_get("table", 0), |
| 519 | cookie=43, |
| 520 | match=match, |
| 521 | instructions=[ |
| 522 | ofp.instruction.apply_actions( |
| 523 | actions=[ ofp.action.group( group_id = test_group_id ) ] ) ], |
| 524 | buffer_id=ofp.OFP_NO_BUFFER, priority=1000) |
| 525 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 526 | self.controller.message_send(flow_pointing_to_group) |
| 527 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 528 | verify_no_errors(self.controller) |
| 529 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 530 | # After letting a flow rule point to the group, test we can do group_mod |
| 531 | group_mod = createAllGroupMod(test_group_id, ports=[onu_port2]) |
| 532 | self.controller.message_send(group_mod) |
| 533 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 534 | verify_no_errors(self.controller) |
| 535 | |
| 536 | # Test we can remove flows and then remove group |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 537 | flow_delete = ofp.message.flow_delete( table_id=test_param_get("table", 0)) |
| 538 | self.controller.message_send(flow_delete) |
| 539 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 540 | verify_no_errors(self.controller) |
| 541 | |
| 542 | group_delete = ofp.message.group_delete(xid = 3, group_id = test_group_id) |
| 543 | self.controller.message_send(group_delete) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 544 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 545 | verify_no_errors(self.controller) |
| 546 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 547 | # Add the group and flow back, test it we can first remove group and then remove the flow. |
| 548 | group_add = createAllGroupAdd(test_group_id, ports=[onu_port]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 549 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 550 | |
| 551 | self.controller.message_send(flow_pointing_to_group) |
| 552 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 553 | verify_no_errors(self.controller) |
| 554 | |
| 555 | group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id) |
| 556 | self.controller.message_send(group_delete) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 557 | |
| 558 | self.controller.message_send(flow_delete) |
| 559 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 560 | verify_no_errors(self.controller) |
| 561 | |
| 562 | |
| 563 | class TestGroupForwarding(base_tests.SimpleDataPlane): |
| 564 | |
| 565 | def runTest(self): |
| 566 | logging.info("Running Group datapath forwarding tests") |
| 567 | delete_all_flows(self.controller) |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 568 | #delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 569 | |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 570 | vlan_id = 201 |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 571 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 572 | # Create a group |
| 573 | test_group_id = 1 |
| 574 | group_add = createAllGroupAdd(test_group_id, [onu_port]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 575 | |
| 576 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 577 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 578 | verify_no_errors(self.controller) |
| 579 | |
| 580 | # Create a flow rule matching olt port and vlan id |
| 581 | match = ofp.match() |
| 582 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 583 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
| 584 | |
| 585 | request = ofp.message.flow_add( |
| 586 | table_id=test_param_get("table", 0), |
| 587 | cookie=43, |
| 588 | match=match, |
| 589 | instructions=[ |
| 590 | ofp.instruction.apply_actions( |
| 591 | actions=[ ofp.action.group( group_id = test_group_id ) ] ), |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 592 | ], |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 593 | buffer_id=ofp.OFP_NO_BUFFER, priority=1000) |
| 594 | |
| 595 | self.controller.message_send(request) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 596 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 597 | verify_no_errors(self.controller) |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 598 | |
| 599 | # It takes some time for flows to propagate down to the data plane |
| 600 | time.sleep(2) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 601 | |
| 602 | inPkt = simple_udp_packet(pktlen=104,dl_vlan_enable=True, |
| 603 | vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0) |
| 604 | outPkt = inPkt |
| 605 | self.dataplane.send(olt_port, str(inPkt)) |
| 606 | verify_packet(self, outPkt, onu_port) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 607 | |
| 608 | # Now put 2 ONU ports in the group and test that the input packet is |
| 609 | # duplicated out both ports |
| 610 | group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2]) |
| 611 | self.controller.message_send(group_mod) |
| 612 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 613 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 614 | |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 615 | # It takes some time for flows to propagate down to the data plane |
| 616 | time.sleep(2) |
| 617 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 618 | self.dataplane.send(olt_port, str(inPkt)) |
| 619 | verify_packet(self, outPkt, onu_port) |
| 620 | verify_packet(self, outPkt, onu_port2) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 621 | |
| 622 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 623 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 624 | request = ofp.message.flow_delete( table_id=test_param_get("table", 0)) |
| 625 | self.controller.message_send(request) |
| 626 | group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id) |
| 627 | self.controller.message_send(group_delete) |
| 628 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 629 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 630 | verify_no_errors(self.controller) |
| 631 | |
| 632 | class TransparentVlanTest(base_tests.SimpleDataPlane): |
| 633 | |
| 634 | def runTest(self): |
| 635 | logging.info("Running transparent vlan tests") |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 636 | delete_all_flows(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 637 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 638 | vlan_id = 201 |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 639 | match = ofp.match() |
| 640 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 641 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id )) |
| 642 | |
| 643 | request = ofp.message.flow_add( |
| 644 | table_id=test_param_get("table", 0), |
| 645 | cookie=42, |
| 646 | match=match, |
| 647 | instructions=[ |
| 648 | ofp.instruction.apply_actions( |
| 649 | actions=[ |
| 650 | ofp.action.output(port=olt_port)]), |
| 651 | ], |
| 652 | buffer_id=ofp.OFP_NO_BUFFER, |
| 653 | priority=1000) |
| 654 | |
| 655 | self.controller.message_send(request) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 656 | |
| 657 | match = ofp.match() |
| 658 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 659 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
| 660 | |
| 661 | request = ofp.message.flow_add( |
| 662 | table_id=test_param_get("table", 0), |
| 663 | cookie=43, |
| 664 | match=match, |
| 665 | instructions=[ |
| 666 | ofp.instruction.apply_actions( |
| 667 | actions=[ |
| 668 | ofp.action.output(port=onu_port)]), |
| 669 | ], |
| 670 | buffer_id=ofp.OFP_NO_BUFFER, |
| 671 | priority=1000) |
| 672 | |
| 673 | self.controller.message_send(request) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 674 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 675 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 676 | |
Admin | 09b5cc6 | 2015-10-11 13:53:59 -0700 | [diff] [blame] | 677 | # It takes some time for flows to propagate down to the data plane |
| 678 | time.sleep(2) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 679 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 680 | inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0) |
| 681 | # downstream |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 682 | self.dataplane.send(olt_port, str(inPkt)) |
| 683 | verify_packet(self, inPkt, onu_port) |
| 684 | # upstream |
| 685 | self.dataplane.send(onu_port, str(inPkt)) |
| 686 | verify_packet(self, inPkt, olt_port) |
| 687 | |
| 688 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 689 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 690 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame] | 691 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 692 | verify_no_errors(self.controller) |
| 693 | |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame^] | 694 | class DoubleVlanTest(base_tests.SimpleDataPlane): |
| 695 | |
| 696 | def runTest(self): |
| 697 | logging.info("Running double vlan tests") |
| 698 | delete_all_flows(self.controller) |
| 699 | |
| 700 | c_vlan_id = 100 |
| 701 | s_vlan_id = 102 |
| 702 | # upstream flow rule |
| 703 | match = ofp.match() |
| 704 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 705 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT)) |
| 706 | match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0)) |
| 707 | |
| 708 | # push inner vlan (c-vlan) for upstream |
| 709 | request = ofp.message.flow_add( |
| 710 | table_id=test_param_get("table", 0), |
| 711 | cookie=42, |
| 712 | match=match, |
| 713 | instructions=[ |
| 714 | ofp.instruction.apply_actions( |
| 715 | actions=[ |
| 716 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) ] ), |
| 717 | ofp.instruction.goto_table(1) ], |
| 718 | buffer_id=ofp.OFP_NO_BUFFER, |
| 719 | priority=1000) |
| 720 | |
| 721 | self.controller.message_send(request) |
| 722 | do_barrier(self.controller) |
| 723 | verify_no_errors(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 724 | |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame^] | 725 | # push outer vlan (s-vlan) for upstream |
| 726 | match = ofp.match() |
| 727 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 728 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 729 | match.oxm_list.append(ofp.oxm.vlan_pcp( 0 )) |
| 730 | |
| 731 | request = ofp.message.flow_add( |
| 732 | table_id=test_param_get("table", 1), |
| 733 | cookie=43, |
| 734 | match=match, |
| 735 | instructions=[ |
| 736 | ofp.instruction.apply_actions( |
| 737 | actions=[ |
| 738 | ofp.action.push_vlan(ethertype=0x8100), |
| 739 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)), |
| 740 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)), |
| 741 | ofp.action.output(port=olt_port)]), |
| 742 | ], |
| 743 | buffer_id=ofp.OFP_NO_BUFFER, |
| 744 | priority=1000) |
| 745 | |
| 746 | self.controller.message_send(request) |
| 747 | do_barrier(self.controller) |
| 748 | verify_no_errors(self.controller) |
| 749 | |
| 750 | # strip outer vlan (s-vlan) for downstream |
| 751 | match = ofp.match() |
| 752 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 753 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)) |
| 754 | match.oxm_list.append(ofp.oxm.vlan_pcp( 0 )) |
| 755 | request = ofp.message.flow_add( |
| 756 | table_id=test_param_get("table", 0), |
| 757 | cookie=44, |
| 758 | match=match, |
| 759 | instructions=[ |
| 760 | ofp.instruction.apply_actions( |
| 761 | actions=[ ofp.action.pop_vlan() ] ), |
| 762 | ofp.instruction.goto_table(1) ], |
| 763 | buffer_id=ofp.OFP_NO_BUFFER, |
| 764 | priority=1000) |
| 765 | |
| 766 | self.controller.message_send(request) |
| 767 | do_barrier(self.controller) |
| 768 | verify_no_errors(self.controller) |
| 769 | |
| 770 | # strip inner vlan (c-vlan) for downstream |
| 771 | match = ofp.match() |
| 772 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 773 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 774 | match.oxm_list.append(ofp.oxm.vlan_pcp( 0 )) |
| 775 | |
| 776 | request = ofp.message.flow_add( |
| 777 | table_id=test_param_get("table", 1), |
| 778 | cookie=45, |
| 779 | match=match, |
| 780 | instructions=[ |
| 781 | ofp.instruction.apply_actions( |
| 782 | actions=[ |
| 783 | ofp.action.pop_vlan(), |
| 784 | ofp.action.output(port=onu_port) ] ) |
| 785 | ], |
| 786 | buffer_id=ofp.OFP_NO_BUFFER, |
| 787 | priority=1000) |
| 788 | |
| 789 | self.controller.message_send(request) |
| 790 | do_barrier(self.controller) |
| 791 | verify_no_errors(self.controller) |
| 792 | # It takes some time for flows to propagate down to the data plane |
| 793 | time.sleep(10) |
| 794 | untaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 795 | doubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True, |
| 796 | c_vlan_vid=c_vlan_id, |
| 797 | s_vlan_vid=s_vlan_id, |
| 798 | c_vlan_pcp=0, s_vlan_pcp=0) |
| 799 | # test upstream untagged packet got double tag at OLT |
| 800 | logging.info(str(doubleTaggedPkt)) |
| 801 | self.dataplane.send(onu_port, str(untaggedPkt)) |
| 802 | verify_packet(self, doubleTaggedPkt, olt_port) |
| 803 | # test downstream doubletagged packet got untagged at ONU |
| 804 | self.dataplane.send(olt_port, str(doubleTaggedPkt)) |
| 805 | verify_packet(self, untaggedPkt, onu_port) |
| 806 | # test upstream doubletagged packet got dropped |
| 807 | self.dataplane.send(onu_port, str(doubleTaggedPkt)) |
| 808 | verify_packets(self, untaggedPkt, []) |
| 809 | # test downstream untagged packet got dropped at ONU |
| 810 | self.dataplane.send(olt_port, str(untaggedPkt)) |
| 811 | verify_packet(self, doubleTaggedPkt, []) |
| 812 | |
| 813 | |
| 814 | # clean up the test |
| 815 | delete_all_flows(self.controller) |
| 816 | do_barrier(self.controller) |
| 817 | verify_no_errors(self.controller) |