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