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 | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 765 | class RemoveRuleTest(base_tests.SimpleDataPlane): |
| 766 | |
| 767 | def runTest(self): |
| 768 | logging.info("Testing Rule removal") |
| 769 | pass |
| 770 | |
| 771 | |
| 772 | class MultipleDoubleTaggingForwarding(base_tests.SimpleDataPlane): |
| 773 | |
| 774 | def runTests(self): |
| 775 | logging.info("Testing multiple Q-in-Q rules") |
| 776 | pass |
| 777 | |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 778 | |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 779 | class DoubleVlanTest(base_tests.SimpleDataPlane): |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 780 | def runTest(self): |
| 781 | logging.info("Running double vlan tests") |
| 782 | delete_all_flows(self.controller) |
| 783 | |
| 784 | c_vlan_id = 100 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 785 | s_vlan_id = 102 |
| 786 | # upstream flow rule |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 787 | installDoubleTaggingRule(s_vlan_id, c_vlan_id, self.controller) |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 788 | |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 789 | # It takes some time for flows to propagate down to the data plane |
| 790 | time.sleep(10) |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 791 | testPacketFlow(self, c_vlan_id, s_vlan_id) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 792 | |
| 793 | time.sleep(2) |
Admin | b17b166 | 2015-10-19 15:50:53 -0700 | [diff] [blame] | 794 | |
| 795 | # clean up the test |
| 796 | delete_all_flows(self.controller) |
| 797 | do_barrier(self.controller) |
| 798 | verify_no_errors(self.controller) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 799 | |
| 800 | |
| 801 | class TestCyclingDoubleVlan(base_tests.SimpleDataPlane): |
| 802 | """Cycle through vlans and test traffic flow""" |
| 803 | |
| 804 | def runTest(self): |
| 805 | logging.info("Running cycling vlan test") |
| 806 | |
alshabib | 2ecca69 | 2016-03-01 15:10:38 -0800 | [diff] [blame] | 807 | for stag in xrange(2, 4000, 100): |
| 808 | for ctag in xrange(2, 4000, 100): |
alshabib | f1f07dd | 2016-03-01 15:50:35 -0800 | [diff] [blame] | 809 | delete_all_flows(self.controller) |
| 810 | time.sleep(5) |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 811 | installDoubleTaggingRule(stag, ctag, self.controller) |
alshabib | f1f07dd | 2016-03-01 15:50:35 -0800 | [diff] [blame] | 812 | time.sleep(5) |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 813 | testPacketFlow(self, ctag, stag) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 814 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 815 | def testPacketFlow(test, c_vlan_id, s_vlan_id): |
alshabib | b9b39a7 | 2016-03-01 15:52:03 -0800 | [diff] [blame] | 816 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 817 | incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=0) |
| 818 | 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] | 819 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 820 | upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True, |
| 821 | c_vlan_vid=c_vlan_id, |
| 822 | s_vlan_vid=s_vlan_id, |
| 823 | c_vlan_pcp=0, s_vlan_pcp=0) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 824 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 825 | 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] | 826 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 827 | test.dataplane.send(onu_port, str(untaggedPkt)) |
| 828 | verify_packet(test, upstreamDoubleTaggedPkt, olt_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 829 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 830 | # test downstream doubletagged packet got untagged at ONU |
| 831 | test.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt)) |
| 832 | verify_packet(test, untaggedPkt, onu_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 833 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 834 | # test upstream doubletagged packet got dropped |
| 835 | test.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt)) |
| 836 | verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 837 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 838 | # test downstream untagged packet got dropped at ONU |
| 839 | test.dataplane.send(olt_port, str(untaggedPkt)) |
| 840 | verify_no_packet(test, untaggedPkt, onu_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 841 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 842 | # test upstream icorrectly tagged packet; should get dropped |
| 843 | test.dataplane.send(onu_port, str(incorrectTagPkt)) |
| 844 | verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 845 | |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 846 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 847 | def installDoubleTaggingRule(s_vlan_id, c_vlan_id, controller, cookie = 42): |
| 848 | # upstream flow rule |
| 849 | match = ofp.match() |
| 850 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 851 | match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT)) |
| 852 | match.oxm_list.append(ofp.oxm.vlan_pcp(value=0)) |
| 853 | cookie += 1 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 854 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 855 | # push inner vlan (c-vlan) for upstream |
| 856 | request = ofp.message.flow_add( |
| 857 | table_id=test_param_get("table", 0), |
| 858 | cookie=self.cookie, |
| 859 | match=match, |
| 860 | instructions=[ |
| 861 | ofp.instruction.apply_actions( |
| 862 | actions=[ |
| 863 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))]), |
| 864 | ofp.instruction.goto_table(1)], |
| 865 | buffer_id=ofp.OFP_NO_BUFFER, |
| 866 | priority=1000) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 867 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 868 | controller.message_send(request) |
| 869 | do_barrier(self.controller) |
| 870 | verify_no_errors(self.controller) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 871 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 872 | # push outer vlan (s-vlan) for upstream |
| 873 | match = ofp.match() |
| 874 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 875 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 876 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 877 | cookie += 1 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 878 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 879 | request = ofp.message.flow_add( |
| 880 | table_id=test_param_get("table", 1), |
| 881 | cookie=self.cookie, |
| 882 | match=match, |
| 883 | instructions=[ |
| 884 | ofp.instruction.apply_actions( |
| 885 | actions=[ |
| 886 | ofp.action.push_vlan(ethertype=0x8100), |
| 887 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)), |
| 888 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)), |
| 889 | ofp.action.output(port=olt_port)]), |
| 890 | ], |
| 891 | buffer_id=ofp.OFP_NO_BUFFER, |
| 892 | priority=1000) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 893 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 894 | controller.message_send(request) |
| 895 | do_barrier(self.controller) |
| 896 | verify_no_errors(self.controller) |
| 897 | cookie += 1 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 898 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 899 | # strip outer vlan (s-vlan) for downstream |
| 900 | match = ofp.match() |
| 901 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 902 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)) |
| 903 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 904 | request = ofp.message.flow_add( |
| 905 | table_id=test_param_get("table", 0), |
| 906 | cookie=self.cookie, |
| 907 | match=match, |
| 908 | instructions=[ |
| 909 | ofp.instruction.apply_actions( |
| 910 | actions=[ofp.action.pop_vlan()]), |
| 911 | ofp.instruction.goto_table(1)], |
| 912 | buffer_id=ofp.OFP_NO_BUFFER, |
| 913 | priority=1000) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 914 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 915 | controller.message_send(request) |
| 916 | do_barrier(self.controller) |
| 917 | verify_no_errors(self.controller) |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 918 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 919 | # rewrite inner vlan (c-vlan) to default (0) for downstream |
| 920 | match = ofp.match() |
| 921 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 922 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 923 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 924 | cookie += 1 |
alshabib | b9d4ee8 | 2016-03-01 14:12:42 -0800 | [diff] [blame] | 925 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 926 | request = ofp.message.flow_add( |
| 927 | table_id=test_param_get("table", 1), |
| 928 | cookie=self.cookie, |
| 929 | match=match, |
| 930 | instructions=[ |
| 931 | ofp.instruction.apply_actions( |
| 932 | actions=[ |
| 933 | ofp.action.pop_vlan(), |
| 934 | ofp.action.output(port=onu_port)]) |
| 935 | ], |
| 936 | buffer_id=ofp.OFP_NO_BUFFER, |
| 937 | priority=1000) |
alshabib | f1f07dd | 2016-03-01 15:50:35 -0800 | [diff] [blame] | 938 | |
alshabib | 28c03c3 | 2016-03-01 20:33:51 -0800 | [diff] [blame^] | 939 | controller.message_send(request) |
| 940 | do_barrier(self.controller) |
| 941 | verify_no_errors(self.controller) |
| 942 | |
| 943 | |
| 944 | |