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