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