blob: 0db8111393f7ab46ce4e0c2620bb713d479ea1eb [file] [log] [blame]
Jonathan Hartf2511ca2015-07-07 14:18:19 -07001'''
2OFTests for functionality needed from the OLT.
3'''
4import logging
5from oftest import config
6import oftest.base_tests as base_tests
7import oftest.packet as scapy
8
9import ofp
Admin7e9c91d2015-08-25 15:53:49 -070010import time
Jonathan Hartf2511ca2015-07-07 14:18:19 -070011
12from oftest.testutils import *
13
14onu_port = test_param_get("onu_port", 1)
15olt_port = test_param_get("olt_port", 129)
16
17def testPacketIn(self, match, parsed_pkt):
Admin7e9c91d2015-08-25 15:53:49 -070018
Jonathan Hartf2511ca2015-07-07 14:18:19 -070019 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)
Admin7e9c91d2015-08-25 15:53:49 -070039
40 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -070041 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
46class 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
60class 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 Hartf2511ca2015-07-07 14:18:19 -070075class 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
98class 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)
Admin7e9c91d2015-08-25 15:53:49 -0700115
116class 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 Hartf2511ca2015-07-07 14:18:19 -0700123
Admin7e9c91d2015-08-25 15:53:49 -0700124 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
151class 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
169class VlanTest(base_tests.SimpleDataPlane):
170
171 """Verify the switch can push/pop a VLAN tag and forward out a port """
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700172
173 def runTest(self):
174 logging.info("Running push VLAN test")
175
176 vlan_id = 200
177
178 delete_all_flows(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700179
180 #PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700181 match = ofp.match()
182 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin7e9c91d2015-08-25 15:53:49 -0700183 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 Hartf2511ca2015-07-07 14:18:19 -0700185
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)),
Admin7e9c91d2015-08-25 15:53:49 -0700195 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700196 ofp.action.output(port=olt_port)])],
197 buffer_id=ofp.OFP_NO_BUFFER,
198 priority=1000)
199
Admin7e9c91d2015-08-25 15:53:49 -0700200 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700201 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700202
203 #POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700204 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))
Admin7e9c91d2015-08-25 15:53:49 -0700207
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700208 request = ofp.message.flow_add(
209 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700210 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700211 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
Admin7e9c91d2015-08-25 15:53:49 -0700220 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700221 self.controller.message_send(request)
222 do_barrier(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700223 time.sleep(5)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700224
Admin7e9c91d2015-08-25 15:53:49 -0700225 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 Hartf2511ca2015-07-07 14:18:19 -0700238 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Admin7e9c91d2015-08-25 15:53:49 -0700239 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
240
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700241 # 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)
Admin7e9c91d2015-08-25 15:53:49 -0700244
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700245 # Send tagged packet in the ONU port and expect no packets to come out
246 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700247 verify_packets(self, outPkt, [])
248