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