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 | |
| 14 | onu_port = test_param_get("onu_port", 1) |
| 15 | olt_port = test_param_get("olt_port", 129) |
| 16 | |
| 17 | def testPacketIn(self, match, parsed_pkt): |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 18 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 19 | delete_all_flows(self.controller) |
| 20 | |
| 21 | pkt = str(parsed_pkt) |
| 22 | |
| 23 | request = ofp.message.flow_add( |
| 24 | table_id=test_param_get("table", 0), |
| 25 | cookie=42, |
| 26 | match=match, |
| 27 | instructions=[ |
| 28 | ofp.instruction.apply_actions( |
| 29 | actions=[ |
| 30 | ofp.action.output( |
| 31 | port=ofp.OFPP_CONTROLLER, |
| 32 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 33 | buffer_id=ofp.OFP_NO_BUFFER, |
| 34 | priority=1000) |
| 35 | |
| 36 | logging.info("Inserting flow sending matching packets to controller") |
| 37 | self.controller.message_send(request) |
| 38 | do_barrier(self.controller) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 39 | |
| 40 | for of_port in config["port_map"]: |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 41 | logging.info("PacketInExact test, port %d", of_port) |
| 42 | self.dataplane.send(of_port, pkt) |
| 43 | verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION) |
| 44 | verify_packets(self, pkt, []) |
| 45 | |
| 46 | class EapolPacketIn(base_tests.SimpleDataPlane): |
| 47 | |
| 48 | """Verify packet-ins are sent for EAPOL packets """ |
| 49 | |
| 50 | def runTest(self): |
| 51 | logging.info("Running EAPOL Packet In test") |
| 52 | |
| 53 | match = ofp.match() |
| 54 | match.oxm_list.append(ofp.oxm.eth_type(0x888e)) |
| 55 | # Use ethertype 0x888e and multicast destination MAC address |
| 56 | pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e) |
| 57 | |
| 58 | testPacketIn(self, match, pkt) |
| 59 | |
| 60 | class ARPPacketIn(base_tests.SimpleDataPlane): |
| 61 | |
| 62 | """Verify packet-ins are sent for ARP packets """ |
| 63 | |
| 64 | def runTest(self): |
| 65 | logging.info("Running ARP Packet In test") |
| 66 | |
| 67 | match = ofp.match() |
| 68 | match.oxm_list.append(ofp.oxm.eth_type(0x0806)) |
| 69 | |
| 70 | # Use ethertype 0x0806 |
| 71 | pkt = simple_eth_packet(eth_type=0x0806) |
| 72 | |
| 73 | testPacketIn(self, match, pkt) |
| 74 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 75 | class DHCPPacketIn(base_tests.SimpleDataPlane): |
| 76 | |
| 77 | """Verify packet-ins are sent for DHCP packets """ |
| 78 | |
| 79 | def runTest(self): |
| 80 | logging.info("Running DHCP Packet In test") |
| 81 | |
| 82 | pkt = simple_udp_packet(udp_sport=68, udp_dport=67) |
| 83 | |
| 84 | match = ofp.match() |
| 85 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
| 86 | match.oxm_list.append(ofp.oxm.ip_proto(17)) |
| 87 | match.oxm_list.append(ofp.oxm.udp_src(68)) |
| 88 | match.oxm_list.append(ofp.oxm.udp_dst(67)) |
| 89 | |
| 90 | testPacketIn(self, match, pkt) |
| 91 | |
| 92 | # Other UDP packets should not match the rule |
| 93 | radiusPkt = simple_udp_packet(udp_sport=1812, udp_dport=1812) |
| 94 | |
| 95 | self.dataplane.send(1, str(radiusPkt)) |
| 96 | verify_no_packet_in(self, radiusPkt, 1) |
| 97 | |
| 98 | class IGMPPacketIn(base_tests.SimpleDataPlane): |
| 99 | |
| 100 | """Verify packet-ins are sent for IGMP packets """ |
| 101 | |
| 102 | def runTest(self): |
| 103 | logging.info("Running IGMP Packet In test") |
| 104 | |
| 105 | match = ofp.match() |
| 106 | match.oxm_list.append(ofp.oxm.eth_type(0x800)) |
| 107 | match.oxm_list.append(ofp.oxm.ip_proto(2)) |
| 108 | |
| 109 | pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \ |
| 110 | scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2) |
| 111 | |
| 112 | pkt = pkt/("0" * (100 - len(pkt))) |
| 113 | |
| 114 | testPacketIn(self, match, pkt) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 115 | |
| 116 | class TestMeter(base_tests.SimpleDataPlane): |
| 117 | |
| 118 | def runTest(self): |
| 119 | logging.info("Running Meter tests") |
| 120 | dropMeterBand = ofp.meter_band.drop(rate = 500) |
| 121 | meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ]) |
| 122 | self.controller.message_send(meter_mod) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 123 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 124 | time.sleep(1) |
| 125 | |
| 126 | verify_no_errors(self.controller) |
| 127 | |
| 128 | match = ofp.match() |
| 129 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 130 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201)) |
| 131 | |
| 132 | request = ofp.message.flow_add( |
| 133 | table_id=test_param_get("table", 0), |
| 134 | cookie=43, |
| 135 | match=match, |
| 136 | instructions=[ |
| 137 | ofp.instruction.apply_actions( |
| 138 | actions=[ |
| 139 | ofp.action.output(port=olt_port)]), |
| 140 | ofp.instruction.meter(meter_id = 1) |
| 141 | ], |
| 142 | buffer_id=ofp.OFP_NO_BUFFER, |
| 143 | priority=1000) |
| 144 | |
| 145 | self.controller.message_send(request) |
| 146 | |
| 147 | time.sleep(1) |
| 148 | |
| 149 | verify_no_errors(self.controller) |
| 150 | |
| 151 | class TestDuplicateMeter(base_tests.SimpleDataPlane): |
| 152 | |
| 153 | def runTest(self): |
| 154 | logging.info("Running Duplicate Meter Test") |
| 155 | dropMeterBand = ofp.meter_band.drop(rate = 500) |
| 156 | meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ]) |
| 157 | self.controller.message_send(meter_mod) |
| 158 | self.controller.message_send(meter_mod) |
| 159 | |
| 160 | time.sleep(1) |
| 161 | |
| 162 | try: |
| 163 | verify_no_errors(self.controller) |
| 164 | except AssertionError as e: |
| 165 | if (not e.message is "unexpected error type=12 code=1"): |
| 166 | raise AssertionError("Incorrect error type: %s" % e.message) |
| 167 | |
| 168 | |
| 169 | class VlanTest(base_tests.SimpleDataPlane): |
| 170 | |
| 171 | """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] | 172 | |
| 173 | def runTest(self): |
| 174 | logging.info("Running push VLAN test") |
| 175 | |
| 176 | vlan_id = 200 |
| 177 | |
| 178 | delete_all_flows(self.controller) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 179 | |
| 180 | #PUSH |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 181 | match = ofp.match() |
| 182 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 183 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT)) |
| 184 | match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0)) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 185 | |
| 186 | request = ofp.message.flow_add( |
| 187 | table_id=test_param_get("table", 0), |
| 188 | cookie=42, |
| 189 | match=match, |
| 190 | instructions=[ |
| 191 | ofp.instruction.apply_actions( |
| 192 | actions=[ |
| 193 | ofp.action.push_vlan(ethertype=0x8100), |
| 194 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)), |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 195 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)), |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 196 | ofp.action.output(port=olt_port)])], |
| 197 | buffer_id=ofp.OFP_NO_BUFFER, |
| 198 | priority=1000) |
| 199 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 200 | logging.info("Inserting flow tagging upstream") |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 201 | self.controller.message_send(request) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 202 | |
| 203 | #POP |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 204 | match = ofp.match() |
| 205 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 206 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 207 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 208 | request = ofp.message.flow_add( |
| 209 | table_id=test_param_get("table", 0), |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 210 | cookie=43, |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 211 | match=match, |
| 212 | instructions=[ |
| 213 | ofp.instruction.apply_actions( |
| 214 | actions=[ |
| 215 | ofp.action.pop_vlan(), |
| 216 | ofp.action.output(port=1)])], |
| 217 | buffer_id=ofp.OFP_NO_BUFFER, |
| 218 | priority=1000) |
| 219 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 220 | logging.info("Inserting flow tagging downstream") |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 221 | self.controller.message_send(request) |
| 222 | do_barrier(self.controller) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 223 | time.sleep(5) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 224 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 225 | inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 226 | outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, |
| 227 | vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0) |
| 228 | |
| 229 | # Send untagged packet in the ONU port and expect tagged packet out the OLT port |
| 230 | self.dataplane.send(onu_port, str(inPkt)) |
| 231 | verify_packet(self, outPkt, olt_port) |
| 232 | |
| 233 | # Send untagged packet in the OLT port and expect no packets to come out |
| 234 | self.dataplane.send(olt_port, str(inPkt)) |
| 235 | verify_packets(self, outPkt, []) |
| 236 | |
| 237 | inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 238 | vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 239 | outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 240 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 241 | # Send tagged packet in the OLT port and expect untagged packet out the OLT port |
| 242 | self.dataplane.send(olt_port, str(inPkt)) |
| 243 | verify_packet(self, outPkt, onu_port) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 244 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 245 | # Send tagged packet in the ONU port and expect no packets to come out |
| 246 | self.dataplane.send(onu_port, str(inPkt)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame^] | 247 | verify_packets(self, outPkt, []) |
| 248 | |