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