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