blob: 19fc7f8d8fd43a2ab1d3745c6d120caa9267162f [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Rich Laneea873262013-01-11 08:15:55 -080017"""
18Test cases for testing actions taken on packets
19
20See basic.py for other info.
21
22It is recommended that these definitions be kept in their own
23namespace as different groups of tests will likely define
24similar identifiers.
25
26 The switch is actively attempting to contact the controller at the address
27indicated oin oft_config
28
29"""
30
31import logging
32import ipaddr
Rich Laneea873262013-01-11 08:15:55 -080033
34from oftest import config
35import ofp
36import oftest.oft12.testutils as testutils
37import oftest.base_tests as base_tests
Rich Lanecfff0ae2013-05-07 15:49:10 -070038import oftest.parse
Rich Laneea873262013-01-11 08:15:55 -080039
40TEST_VID_DEFAULT = 2
41
42IPV6_ETHERTYPE = 0x86dd
43ETHERTYPE_VLAN = 0x8100
44ETHERTYPE_MPLS = 0x8847
45TCP_PROTOCOL = 0x6
46UDP_PROTOCOL = 0x11
47ICMPV6_PROTOCOL = 0x3a
48
49
50# TESTS
51class MatchIPv6Simple(base_tests.SimpleDataPlane):
52 """
53 Just send a packet IPv6 to match a simple entry on the matching table
54 """
55 def runTest(self):
56
57 of_ports = config["port_map"].keys()
58 of_ports.sort()
59 ing_port = of_ports[0]
60 egr_port = of_ports[3]
61
62 # Remove all entries Add entry match all
63 rc = testutils.delete_all_flows(self.controller, logging)
64 self.assertEqual(rc, 0, "Failed to delete all flows")
65
66 # Add entry match
67
Rich Laneb6255512013-05-07 14:58:43 -070068 request = ofp.message.flow_add()
69 port = ofp.oxm.in_port(of_ports[0])
70 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
71 eth_dst = ofp.oxm.eth_dst(oftest.parse.parse_mac("00:01:02:03:04:05"))
72 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
Rich Laneea873262013-01-11 08:15:55 -080073
Rich Lanecfff0ae2013-05-07 15:49:10 -070074 request.match.oxm_list.append(port)
75 request.match.oxm_list.append(eth_type)
76 request.match.oxm_list.append(eth_dst)
77 request.match.oxm_list.append(ipv6_src)
Rich Lane63393492013-01-11 09:21:12 -080078 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -080079 act.port = of_ports[3]
Rich Lanecfff0ae2013-05-07 15:49:10 -070080 inst = ofp.instruction.apply_actions()
81 inst.actions.append(act)
82 request.instructions.append(inst)
Rich Laneea873262013-01-11 08:15:55 -080083 request.buffer_id = 0xffffffff
84
85 request.priority = 1000
86 logging.debug("Adding flow ")
87
88 rv = self.controller.message_send(request)
89 self.assertTrue(rv != -1, "Failed to insert test flow")
90
91 #Send packet
92 pkt = testutils.simple_ipv6_packet(dl_dst='00:01:02:03:04:05',ip_src='fe80::2420:52ff:fe8f:5189')
93 logging.info("Sending IPv6 packet to " + str(ing_port))
94 logging.debug("Data: " + str(pkt).encode('hex'))
95 self.dataplane.send(ing_port, str(pkt))
96
97 #Receive packet
98 exp_pkt = testutils.simple_ipv6_packet()
99 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
100
101 #Remove flows
102 rc = testutils.delete_all_flows(self.controller, logging)
103 self.assertEqual(rc, 0, "Failed to delete all flows")
104
105
106class MatchICMPv6Simple(base_tests.SimpleDataPlane):
107 """
108 Match on an ICMPv6 packet
109 """
110 def runTest(self):
111 of_ports = config["port_map"].keys()
112 of_ports.sort()
113 ing_port = of_ports[0]
114 egr_port = of_ports[3]
115
116 # Remove all entries Add entry match all
117 rc = testutils.delete_all_flows(self.controller, logging)
118 self.assertEqual(rc, 0, "Failed to delete all flows")
119
120 # Add entry match
121
Rich Lanecfff0ae2013-05-07 15:49:10 -0700122 request = ofp.message.flow_add()
123 port = ofp.oxm.in_port(of_ports[0])
124 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
125 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
126 ip_proto = ofp.oxm.ip_proto(ICMPV6_PROTOCOL)
127 icmpv6_type = ofp.oxm.icmpv6_type(128)
Rich Laneea873262013-01-11 08:15:55 -0800128
Rich Lanecfff0ae2013-05-07 15:49:10 -0700129 request.match.oxm_list.append(port)
130 request.match.oxm_list.append(eth_type)
131 request.match.oxm_list.append(ipv6_src)
132 request.match.oxm_list.append(ip_proto)
133 request.match.oxm_list.append(icmpv6_type)
Rich Laneea873262013-01-11 08:15:55 -0800134
Rich Lane63393492013-01-11 09:21:12 -0800135 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -0800136 act.port = of_ports[3]
Rich Lanecfff0ae2013-05-07 15:49:10 -0700137 inst = ofp.instruction.apply_actions()
138 inst.actions.append(act)
139 request.instructions.append(inst)
Rich Laneea873262013-01-11 08:15:55 -0800140 request.buffer_id = 0xffffffff
141
142 request.priority = 1000
143 logging.debug("Adding flow ")
144
145 rv = self.controller.message_send(request)
146 self.assertTrue(rv != -1, "Failed to insert test flow")
147
148 #Send packet
149 pkt = testutils.simple_icmpv6_packet()
150 logging.info("Sending IPv6 packet to " + str(ing_port))
151 logging.debug("Data: " + str(pkt).encode('hex'))
152 self.dataplane.send(ing_port, str(pkt))
153
154 #Receive packet
155 exp_pkt = testutils.simple_icmpv6_packet()
156 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
157
158 #Remove flows
159 rc = testutils.delete_all_flows(self.controller, logging)
160 self.assertEqual(rc, 0, "Failed to delete all flows")
161
162
163class IPv6SetField(base_tests.SimpleDataPlane):
164
165 def runTest(self):
166 of_ports = config["port_map"].keys()
167 of_ports.sort()
168 ing_port = of_ports[0]
169 egr_port = of_ports[3]
170
171 # Remove all entries Add entry match all
172 rc = testutils.delete_all_flows(self.controller, logging)
173 self.assertEqual(rc, 0, "Failed to delete all flows")
174
175 # Add entry match
176
Rich Lanecfff0ae2013-05-07 15:49:10 -0700177 request = ofp.message.flow_add()
178 port = ofp.oxm.in_port(of_ports[0])
179 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
180 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
Rich Laneea873262013-01-11 08:15:55 -0800181
Rich Lanecfff0ae2013-05-07 15:49:10 -0700182 request.match.oxm_list.append(port)
183 request.match.oxm_list.append(eth_type)
184 request.match.oxm_list.append(ipv6_src)
Rich Laneea873262013-01-11 08:15:55 -0800185
Rich Lanecfff0ae2013-05-07 15:49:10 -0700186 field_2b_set = ofp.oxm.ipv6_dst(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:DDDD'))
Rich Lane63393492013-01-11 09:21:12 -0800187 act_setfield = ofp.action.set_field()
Rich Lanecfff0ae2013-05-07 15:49:10 -0700188 act_setfield.field = field_2b_set.pack() # HACK
Rich Laneea873262013-01-11 08:15:55 -0800189
190# TODO: insert action set field properly
Rich Lane63393492013-01-11 09:21:12 -0800191 act_out = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -0800192 act_out.port = of_ports[3]
193
194
Rich Lanecfff0ae2013-05-07 15:49:10 -0700195 inst = ofp.instruction.apply_actions()
196 inst.actions.append(act_setfield)
197 inst.actions.append(act_out)
198 request.instructions.append(inst)
Rich Laneea873262013-01-11 08:15:55 -0800199 request.buffer_id = 0xffffffff
200
201 request.priority = 1000
202 logging.debug("Adding flow ")
203
204 rv = self.controller.message_send(request)
205 self.assertTrue(rv != -1, "Failed to insert test flow")
206
207 #Send packet
208 pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190')
209 logging.info("Sending IPv6 packet to " + str(ing_port))
210 logging.debug("Data: " + str(pkt).encode('hex'))
211 self.dataplane.send(ing_port, str(pkt))
212
213 #Receive packet
214 exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD')
215 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
216
217 #See flow match
218 response = testutils.flow_stats_get(self)
219 logging.debug("Response" + response.show())
220
221 #Remove flows
222 rc = testutils.delete_all_flows(self.controller, logging)
223 self.assertEqual(rc, 0, "Failed to delete all flows")
224
225
226class MatchIPv6TCP(base_tests.SimpleDataPlane):
227
228 def runTest(self):
229 # Config
230 of_ports = config["port_map"].keys()
231 of_ports.sort()
232 ing_port = of_ports[0]
233 egr_port = of_ports[3]
234
235 # Remove flows
236 rc = testutils.delete_all_flows(self.controller, logging)
237 self.assertEqual(rc, 0, "Failed to delete all flows")
238
239 # Add entry match
240
Rich Lanecfff0ae2013-05-07 15:49:10 -0700241 request = ofp.message.flow_add()
Rich Laneea873262013-01-11 08:15:55 -0800242 request.match.type = ofp.OFPMT_OXM
Rich Lanecfff0ae2013-05-07 15:49:10 -0700243 port = ofp.oxm.in_port(of_ports[0])
244 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
245 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
246 ip_proto = ofp.oxm.ip_proto(TCP_PROTOCOL)
247 tcp_port = ofp.oxm.tcp_src(80)
Rich Laneea873262013-01-11 08:15:55 -0800248
249
Rich Lanecfff0ae2013-05-07 15:49:10 -0700250 request.match.oxm_list.append(port)
251 request.match.oxm_list.append(eth_type)
252 request.match.oxm_list.append(ipv6_src)
253 request.match.oxm_list.append(ip_proto)
254 request.match.oxm_list.append(tcp_port)
Rich Laneea873262013-01-11 08:15:55 -0800255
Rich Lane63393492013-01-11 09:21:12 -0800256 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -0800257 act.port = of_ports[3]
Rich Lanecfff0ae2013-05-07 15:49:10 -0700258 inst = ofp.instruction.apply_actions()
259 inst.actions.append(act)
260 request.instructions.append(inst)
Rich Laneea873262013-01-11 08:15:55 -0800261 request.buffer_id = 0xffffffff
262
263 request.priority = 1000
264 logging.debug("Adding flow ")
265
266 rv = self.controller.message_send(request)
267 self.assertTrue(rv != -1, "Failed to send test flow")
268
269 #Send packet
270 pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
271
272 logging.info("Sending IPv6 packet to " + str(ing_port))
273 logging.debug("Data: " + str(pkt).encode('hex'))
274
275 self.dataplane.send(ing_port, str(pkt))
276
277 #Receive packet
278 exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
279
280 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
281
282 #Remove flows
283 rc = testutils.delete_all_flows(self.controller, logging)
284 self.assertEqual(rc, 0, "Failed to delete all flows")
285
286if __name__ == "__main__":
287 print "Please run through oft script: ./oft --test-spec=ipv6"