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