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") |
Admin | 5339559 | 2016-03-01 21:29:21 -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) |
| 812 | #wait for the rule to settle |
| 813 | time.sleep(3) |
| 814 | |
| 815 | installDoubleTaggingRule(1, 2, self.controller) |
| 816 | #wait for the rules to settle |
| 817 | time.sleep(3) |
| 818 | |
| 819 | stats = get_flow_stats(self, ofp.match()) |
| 820 | |
Admin | 5339559 | 2016-03-01 21:29:21 -0800 | [diff] [blame] | 821 | self.assertTrue(len(stats) == 3, \ |
alshabib | 9929a15 | 2016-03-01 21:25:18 -0800 | [diff] [blame] | 822 | "Wrong number of rules reports; reported %s, expected 3\n\n %s" % (len(stats), stats)) |
| 823 | |
| 824 | processEapolRule(self, onu_port, install = False) |
| 825 | time.sleep(3) |
| 826 | |
| 827 | stats = get_flow_stats(self, ofp.match()) |
| 828 | |
Admin | 5339559 | 2016-03-01 21:29:21 -0800 | [diff] [blame] | 829 | self.assertTrue(len(stats) == 2, \ |
alshabib | 9929a15 | 2016-03-01 21:25:18 -0800 | [diff] [blame] | 830 | "Wrong number of rules reports; reported %s, expected 2\n\n %s" % (len(stats), stats)) |
| 831 | |
| 832 | logging.info(stats) |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 833 | |
| 834 | |
| 835 | class MultipleDoubleTaggingForwarding(base_tests.SimpleDataPlane): |
| 836 | |
| 837 | def runTests(self): |
| 838 | logging.info("Testing multiple Q-in-Q rules") |
| 839 | pass |
| 840 | |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 841 | |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 842 | class DoubleVlanTest(base_tests.SimpleDataPlane): |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 843 | |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 844 | def runTest(self): |
| 845 | logging.info("Running double vlan tests") |
| 846 | delete_all_flows(self.controller) |
| 847 | |
| 848 | c_vlan_id = 100 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 849 | s_vlan_id = 102 |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 850 | |
| 851 | installDoubleTaggingRules(s_vlan_id, c_vlan_id, self.controller) |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 852 | |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 853 | # It takes some time for flows to propagate down to the data plane |
| 854 | time.sleep(10) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 855 | |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 856 | # Test packet flows |
| 857 | testPacketFlow(self, c_vlan_id, s_vlan_id) |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 858 | |
| 859 | # clean up the test |
| 860 | delete_all_flows(self.controller) |
| 861 | do_barrier(self.controller) |
| 862 | verify_no_errors(self.controller) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 863 | |
| 864 | |
| 865 | class TestCyclingDoubleVlan(base_tests.SimpleDataPlane): |
| 866 | """Cycle through vlans and test traffic flow""" |
| 867 | |
| 868 | def runTest(self): |
| 869 | logging.info("Running cycling vlan test") |
| 870 | |
alshabib | 2ecca69 | 2016-03-01 15:10:38 -0800 | [diff] [blame] | 871 | for stag in xrange(2, 4000, 100): |
| 872 | for ctag in xrange(2, 4000, 100): |
alshabib | f1f07dd | 2016-03-01 15:50:35 -0800 | [diff] [blame] | 873 | delete_all_flows(self.controller) |
| 874 | time.sleep(5) |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 875 | installDoubleTaggingRule(stag, ctag, self.controller) |
alshabib | f1f07dd | 2016-03-01 15:50:35 -0800 | [diff] [blame] | 876 | time.sleep(5) |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 877 | testPacketFlow(self, ctag, stag) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 878 | |
alshabib | 9929a15 | 2016-03-01 21:25:18 -0800 | [diff] [blame] | 879 | def processEapolRule(test, in_port, install = True): |
| 880 | match = ofp.match() |
| 881 | match.oxm_list.append(ofp.oxm.eth_type(0x888e)) |
| 882 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
| 883 | if install: |
| 884 | request = ofp.message.flow_add( |
| 885 | table_id=test_param_get("table", 0), |
| 886 | cookie=42, |
alshabib | d24fca6 | 2016-03-01 21:26:35 -0800 | [diff] [blame] | 887 | match=match, |
alshabib | 9929a15 | 2016-03-01 21:25:18 -0800 | [diff] [blame] | 888 | instructions=[ |
| 889 | ofp.instruction.apply_actions( |
| 890 | actions=[ |
| 891 | ofp.action.output( |
| 892 | port=ofp.OFPP_CONTROLLER, |
| 893 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 894 | buffer_id=ofp.OFP_NO_BUFFER, |
| 895 | priority=1000) |
| 896 | else: |
| 897 | request = ofp.message.flow_delete( |
| 898 | table_id=test_param_get("table", 0), |
| 899 | cookie=42, |
| 900 | match=m, |
| 901 | instructions=[ |
| 902 | ofp.instruction.apply_actions( |
| 903 | actions=[ |
| 904 | ofp.action.output( |
| 905 | port=ofp.OFPP_CONTROLLER, |
| 906 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 907 | buffer_id=ofp.OFP_NO_BUFFER, |
| 908 | priority=1000) |
| 909 | logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove") |
| 910 | test.controller.message_send(request) |
| 911 | do_barrier(test.controller) |
| 912 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 913 | def testPacketFlow(test, c_vlan_id, s_vlan_id): |
alshabib | b9b39a7 | 2016-03-01 15:52:03 -0800 | [diff] [blame] | 914 | |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 915 | incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=1) |
| 916 | zeroTaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 917 | untaggedPkt = simple_udp_packet(pktlen=96) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 918 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 919 | upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True, |
| 920 | c_vlan_vid=c_vlan_id, |
| 921 | s_vlan_vid=s_vlan_id, |
| 922 | c_vlan_pcp=0, s_vlan_pcp=0) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 923 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 924 | 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] | 925 | |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 926 | # test upstream untagged packet got double tag at OLT |
| 927 | self.dataplane.send(onu_port, str(zeroTaggedPkt)) |
| 928 | verify_packet(self, upstreamDoubleTaggedPkt, olt_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 929 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 930 | # test downstream doubletagged packet got untagged at ONU |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 931 | self.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt)) |
| 932 | if device_type == "pmc": |
| 933 | verify_packet(self, zeroTaggedPkt, onu_port) |
| 934 | else: |
| 935 | verify_packet(self, untaggedPkt, onu_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 936 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 937 | # test upstream doubletagged packet got dropped |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 938 | self.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt)) |
| 939 | verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 940 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 941 | # test downstream untagged packet got dropped at ONU |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 942 | self.dataplane.send(olt_port, str(untaggedPkt)) |
| 943 | verify_no_packet(self, untaggedPkt, onu_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 944 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 945 | # test upstream icorrectly tagged packet; should get dropped |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 946 | self.dataplane.send(onu_port, str(incorrectTagPkt)) |
| 947 | verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 948 | |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 949 | |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 950 | def installDoubleTaggingRules(s_vlan_id, c_vlan_id, controller, cookie=42): |
| 951 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 952 | # upstream flow rule |
| 953 | match = ofp.match() |
| 954 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 955 | if device_type == "cpqd": |
| 956 | match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE)) |
| 957 | actions = [ |
| 958 | ofp.action.push_vlan(ethertype=0x8100), |
| 959 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)), |
| 960 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)) |
| 961 | ] |
| 962 | else: # "pmc", "normal" |
| 963 | match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT)) |
| 964 | match.oxm_list.append(ofp.oxm.vlan_pcp(value=0)) |
| 965 | actions = [ |
| 966 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 967 | ] |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 968 | cookie += 1 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 969 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 970 | # push inner vlan (c-vlan) for upstream |
| 971 | request = ofp.message.flow_add( |
| 972 | table_id=test_param_get("table", 0), |
Admin | 965eeda | 2016-03-01 20:56:14 -0800 | [diff] [blame] | 973 | cookie=cookie, |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 974 | match=match, |
| 975 | instructions=[ |
Zsolt Haraszti | fe52550 | 2016-03-02 05:18:52 +0000 | [diff] [blame^] | 976 | ofp.instruction.apply_actions(actions=action), |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 977 | ofp.instruction.goto_table(1)], |
| 978 | buffer_id=ofp.OFP_NO_BUFFER, |
| 979 | priority=1000) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 980 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 981 | controller.message_send(request) |
Admin | 965eeda | 2016-03-01 20:56:14 -0800 | [diff] [blame] | 982 | do_barrier(controller) |
| 983 | verify_no_errors(controller) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 984 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 985 | # push outer vlan (s-vlan) for upstream |
| 986 | match = ofp.match() |
| 987 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 988 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 989 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 990 | cookie += 1 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 991 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 992 | request = ofp.message.flow_add( |
| 993 | table_id=test_param_get("table", 1), |
Admin | 965eeda | 2016-03-01 20:56:14 -0800 | [diff] [blame] | 994 | cookie=cookie, |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 995 | match=match, |
| 996 | instructions=[ |
| 997 | ofp.instruction.apply_actions( |
| 998 | actions=[ |
| 999 | ofp.action.push_vlan(ethertype=0x8100), |
| 1000 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)), |
| 1001 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)), |
| 1002 | ofp.action.output(port=olt_port)]), |
| 1003 | ], |
| 1004 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1005 | priority=1000) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 1006 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1007 | controller.message_send(request) |
Admin | 965eeda | 2016-03-01 20:56:14 -0800 | [diff] [blame] | 1008 | do_barrier(controller) |
| 1009 | verify_no_errors(controller) |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1010 | cookie += 1 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 1011 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1012 | # strip outer vlan (s-vlan) for downstream |
| 1013 | match = ofp.match() |
| 1014 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 1015 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)) |
| 1016 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 1017 | request = ofp.message.flow_add( |
| 1018 | table_id=test_param_get("table", 0), |
Admin | 965eeda | 2016-03-01 20:56:14 -0800 | [diff] [blame] | 1019 | cookie=cookie, |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1020 | match=match, |
| 1021 | instructions=[ |
| 1022 | ofp.instruction.apply_actions( |
| 1023 | actions=[ofp.action.pop_vlan()]), |
| 1024 | ofp.instruction.goto_table(1)], |
| 1025 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1026 | priority=1000) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 1027 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1028 | controller.message_send(request) |
Admin | 965eeda | 2016-03-01 20:56:14 -0800 | [diff] [blame] | 1029 | do_barrier(controller) |
| 1030 | verify_no_errors(controller) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 1031 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1032 | # rewrite inner vlan (c-vlan) to default (0) for downstream |
| 1033 | match = ofp.match() |
| 1034 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 1035 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 1036 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 1037 | cookie += 1 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 1038 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1039 | request = ofp.message.flow_add( |
| 1040 | table_id=test_param_get("table", 1), |
Admin | 965eeda | 2016-03-01 20:56:14 -0800 | [diff] [blame] | 1041 | cookie=cookie, |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1042 | match=match, |
| 1043 | instructions=[ |
| 1044 | ofp.instruction.apply_actions( |
| 1045 | actions=[ |
| 1046 | ofp.action.pop_vlan(), |
| 1047 | ofp.action.output(port=onu_port)]) |
| 1048 | ], |
| 1049 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1050 | priority=1000) |
alshabib | f1f07dd | 2016-03-01 15:50:35 -0800 | [diff] [blame] | 1051 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame] | 1052 | controller.message_send(request) |
Admin | 965eeda | 2016-03-01 20:56:14 -0800 | [diff] [blame] | 1053 | do_barrier(controller) |
| 1054 | verify_no_errors(controller) |