blob: 95a51f6641f664e7d5fb054402bd2fdffd69b738 [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
10
11from oftest.testutils import *
12
13onu_port = test_param_get("onu_port", 1)
14olt_port = test_param_get("olt_port", 129)
15
16def testPacketIn(self, match, parsed_pkt):
17 delete_all_flows(self.controller)
18
19 pkt = str(parsed_pkt)
20
21 request = ofp.message.flow_add(
22 table_id=test_param_get("table", 0),
23 cookie=42,
24 match=match,
25 instructions=[
26 ofp.instruction.apply_actions(
27 actions=[
28 ofp.action.output(
29 port=ofp.OFPP_CONTROLLER,
30 max_len=ofp.OFPCML_NO_BUFFER)])],
31 buffer_id=ofp.OFP_NO_BUFFER,
32 priority=1000)
33
34 logging.info("Inserting flow sending matching packets to controller")
35 self.controller.message_send(request)
36 do_barrier(self.controller)
37
38 for of_port in config["port_map"].keys():
39 logging.info("PacketInExact test, port %d", of_port)
40 self.dataplane.send(of_port, pkt)
41 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
42 verify_packets(self, pkt, [])
43
44class EapolPacketIn(base_tests.SimpleDataPlane):
45
46 """Verify packet-ins are sent for EAPOL packets """
47
48 def runTest(self):
49 logging.info("Running EAPOL Packet In test")
50
51 match = ofp.match()
52 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
53 # Use ethertype 0x888e and multicast destination MAC address
54 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
55
56 testPacketIn(self, match, pkt)
57
58class ARPPacketIn(base_tests.SimpleDataPlane):
59
60 """Verify packet-ins are sent for ARP packets """
61
62 def runTest(self):
63 logging.info("Running ARP Packet In test")
64
65 match = ofp.match()
66 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
67
68 # Use ethertype 0x0806
69 pkt = simple_eth_packet(eth_type=0x0806)
70
71 testPacketIn(self, match, pkt)
72
73class RadiusPacketIn(base_tests.SimpleDataPlane):
74
75 """Verify packet-ins are sent for Radius packets """
76
77 def runTest(self):
78 logging.info("Running Radius Packet In test")
79
80 pkt = simple_udp_packet(udp_sport=1812, udp_dport=1812)
81
82 match = ofp.match()
83 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
84 match.oxm_list.append(ofp.oxm.ip_proto(17))
85 match.oxm_list.append(ofp.oxm.udp_src(1812))
86 match.oxm_list.append(ofp.oxm.udp_dst(1812))
87
88 testPacketIn(self, match, pkt)
89
90 # Other UDP packets should not match the rule
91 dhcpPkt = simple_udp_packet(udp_sport=68, udp_dport=67)
92
93 self.dataplane.send(1, str(dhcpPkt))
94 verify_no_packet_in(self, dhcpPkt, 1)
95
96
97class DHCPPacketIn(base_tests.SimpleDataPlane):
98
99 """Verify packet-ins are sent for DHCP packets """
100
101 def runTest(self):
102 logging.info("Running DHCP Packet In test")
103
104 pkt = simple_udp_packet(udp_sport=68, udp_dport=67)
105
106 match = ofp.match()
107 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
108 match.oxm_list.append(ofp.oxm.ip_proto(17))
109 match.oxm_list.append(ofp.oxm.udp_src(68))
110 match.oxm_list.append(ofp.oxm.udp_dst(67))
111
112 testPacketIn(self, match, pkt)
113
114 # Other UDP packets should not match the rule
115 radiusPkt = simple_udp_packet(udp_sport=1812, udp_dport=1812)
116
117 self.dataplane.send(1, str(radiusPkt))
118 verify_no_packet_in(self, radiusPkt, 1)
119
120class IGMPPacketIn(base_tests.SimpleDataPlane):
121
122 """Verify packet-ins are sent for IGMP packets """
123
124 def runTest(self):
125 logging.info("Running IGMP Packet In test")
126
127 match = ofp.match()
128 match.oxm_list.append(ofp.oxm.eth_type(0x800))
129 match.oxm_list.append(ofp.oxm.ip_proto(2))
130
131 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \
132 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
133
134 pkt = pkt/("0" * (100 - len(pkt)))
135
136 testPacketIn(self, match, pkt)
137
138class PushVlan(base_tests.SimpleDataPlane):
139
140 """Verify the switch can push a VLAN tag and forward out a port """
141
142 def runTest(self):
143 logging.info("Running push VLAN test")
144
145 vlan_id = 200
146
147 delete_all_flows(self.controller)
148
149 match = ofp.match()
150 match.oxm_list.append(ofp.oxm.in_port(onu_port))
151 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFP_VLAN_NONE))
152
153 request = ofp.message.flow_add(
154 table_id=test_param_get("table", 0),
155 cookie=42,
156 match=match,
157 instructions=[
158 ofp.instruction.apply_actions(
159 actions=[
160 ofp.action.push_vlan(ethertype=0x8100),
161 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
162 ofp.action.output(port=olt_port)])],
163 buffer_id=ofp.OFP_NO_BUFFER,
164 priority=1000)
165
166 logging.info("Inserting flow sending matching packets to controller")
167 self.controller.message_send(request)
168 do_barrier(self.controller)
169
170 inPkt = simple_udp_packet()
171 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
172 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
173
174 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
175 self.dataplane.send(onu_port, str(inPkt))
176 verify_packet(self, outPkt, olt_port)
177
178 # Send untagged packet in the OLT port and expect no packets to come out
179 self.dataplane.send(olt_port, str(inPkt))
180 verify_packets(self, outPkt, [])
181
182class PopVlan(base_tests.SimpleDataPlane):
183
184 """Verify the switch can pop a VLAN tag and forward out a port """
185
186 def runTest(self):
187 logging.info("Running pop VLAN test")
188
189 vlan_id = 200
190
191 delete_all_flows(self.controller)
192
193 match = ofp.match()
194 match.oxm_list.append(ofp.oxm.in_port(olt_port))
195 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
196
197 request = ofp.message.flow_add(
198 table_id=test_param_get("table", 0),
199 cookie=42,
200 match=match,
201 instructions=[
202 ofp.instruction.apply_actions(
203 actions=[
204 ofp.action.pop_vlan(),
205 ofp.action.output(port=1)])],
206 buffer_id=ofp.OFP_NO_BUFFER,
207 priority=1000)
208
209 logging.info("Inserting flow sending matching packets to controller")
210 self.controller.message_send(request)
211 do_barrier(self.controller)
212
213 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
214 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
215 outPkt = simple_udp_packet()
216
217 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
218 self.dataplane.send(olt_port, str(inPkt))
219 verify_packet(self, outPkt, onu_port)
220
221 # Send tagged packet in the ONU port and expect no packets to come out
222 self.dataplane.send(onu_port, str(inPkt))
223 verify_packets(self, outPkt, [])