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