blob: 5a45e9dc5e60b19db9614af6798176100bb6dd26 [file] [log] [blame]
Rich Laneea873262013-01-11 08:15:55 -08001"""
2Test cases for testing actions taken on packets
3
4See basic.py for other info.
5
6It is recommended that these definitions be kept in their own
7namespace as different groups of tests will likely define
8similar identifiers.
9
10 The switch is actively attempting to contact the controller at the address
11indicated oin oft_config
12
13"""
14
15import logging
16import ipaddr
Rich Laneea873262013-01-11 08:15:55 -080017
18from oftest import config
19import ofp
20import oftest.oft12.testutils as testutils
21import oftest.base_tests as base_tests
Rich Lanecfff0ae2013-05-07 15:49:10 -070022import oftest.parse
Rich Laneea873262013-01-11 08:15:55 -080023
24TEST_VID_DEFAULT = 2
25
26IPV6_ETHERTYPE = 0x86dd
27ETHERTYPE_VLAN = 0x8100
28ETHERTYPE_MPLS = 0x8847
29TCP_PROTOCOL = 0x6
30UDP_PROTOCOL = 0x11
31ICMPV6_PROTOCOL = 0x3a
32
33
34# TESTS
35class MatchIPv6Simple(base_tests.SimpleDataPlane):
36 """
37 Just send a packet IPv6 to match a simple entry on the matching table
38 """
39 def runTest(self):
40
41 of_ports = config["port_map"].keys()
42 of_ports.sort()
43 ing_port = of_ports[0]
44 egr_port = of_ports[3]
45
46 # Remove all entries Add entry match all
47 rc = testutils.delete_all_flows(self.controller, logging)
48 self.assertEqual(rc, 0, "Failed to delete all flows")
49
50 # Add entry match
51
Rich Laneb6255512013-05-07 14:58:43 -070052 request = ofp.message.flow_add()
53 port = ofp.oxm.in_port(of_ports[0])
54 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
55 eth_dst = ofp.oxm.eth_dst(oftest.parse.parse_mac("00:01:02:03:04:05"))
56 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
Rich Laneea873262013-01-11 08:15:55 -080057
Rich Lanecfff0ae2013-05-07 15:49:10 -070058 request.match.oxm_list.append(port)
59 request.match.oxm_list.append(eth_type)
60 request.match.oxm_list.append(eth_dst)
61 request.match.oxm_list.append(ipv6_src)
Rich Lane63393492013-01-11 09:21:12 -080062 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -080063 act.port = of_ports[3]
Rich Lanecfff0ae2013-05-07 15:49:10 -070064 inst = ofp.instruction.apply_actions()
65 inst.actions.append(act)
66 request.instructions.append(inst)
Rich Laneea873262013-01-11 08:15:55 -080067 request.buffer_id = 0xffffffff
68
69 request.priority = 1000
70 logging.debug("Adding flow ")
71
72 rv = self.controller.message_send(request)
73 self.assertTrue(rv != -1, "Failed to insert test flow")
74
75 #Send packet
76 pkt = testutils.simple_ipv6_packet(dl_dst='00:01:02:03:04:05',ip_src='fe80::2420:52ff:fe8f:5189')
77 logging.info("Sending IPv6 packet to " + str(ing_port))
78 logging.debug("Data: " + str(pkt).encode('hex'))
79 self.dataplane.send(ing_port, str(pkt))
80
81 #Receive packet
82 exp_pkt = testutils.simple_ipv6_packet()
83 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
84
85 #Remove flows
86 rc = testutils.delete_all_flows(self.controller, logging)
87 self.assertEqual(rc, 0, "Failed to delete all flows")
88
89
90class MatchICMPv6Simple(base_tests.SimpleDataPlane):
91 """
92 Match on an ICMPv6 packet
93 """
94 def runTest(self):
95 of_ports = config["port_map"].keys()
96 of_ports.sort()
97 ing_port = of_ports[0]
98 egr_port = of_ports[3]
99
100 # Remove all entries Add entry match all
101 rc = testutils.delete_all_flows(self.controller, logging)
102 self.assertEqual(rc, 0, "Failed to delete all flows")
103
104 # Add entry match
105
Rich Lanecfff0ae2013-05-07 15:49:10 -0700106 request = ofp.message.flow_add()
107 port = ofp.oxm.in_port(of_ports[0])
108 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
109 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
110 ip_proto = ofp.oxm.ip_proto(ICMPV6_PROTOCOL)
111 icmpv6_type = ofp.oxm.icmpv6_type(128)
Rich Laneea873262013-01-11 08:15:55 -0800112
Rich Lanecfff0ae2013-05-07 15:49:10 -0700113 request.match.oxm_list.append(port)
114 request.match.oxm_list.append(eth_type)
115 request.match.oxm_list.append(ipv6_src)
116 request.match.oxm_list.append(ip_proto)
117 request.match.oxm_list.append(icmpv6_type)
Rich Laneea873262013-01-11 08:15:55 -0800118
Rich Lane63393492013-01-11 09:21:12 -0800119 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -0800120 act.port = of_ports[3]
Rich Lanecfff0ae2013-05-07 15:49:10 -0700121 inst = ofp.instruction.apply_actions()
122 inst.actions.append(act)
123 request.instructions.append(inst)
Rich Laneea873262013-01-11 08:15:55 -0800124 request.buffer_id = 0xffffffff
125
126 request.priority = 1000
127 logging.debug("Adding flow ")
128
129 rv = self.controller.message_send(request)
130 self.assertTrue(rv != -1, "Failed to insert test flow")
131
132 #Send packet
133 pkt = testutils.simple_icmpv6_packet()
134 logging.info("Sending IPv6 packet to " + str(ing_port))
135 logging.debug("Data: " + str(pkt).encode('hex'))
136 self.dataplane.send(ing_port, str(pkt))
137
138 #Receive packet
139 exp_pkt = testutils.simple_icmpv6_packet()
140 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
141
142 #Remove flows
143 rc = testutils.delete_all_flows(self.controller, logging)
144 self.assertEqual(rc, 0, "Failed to delete all flows")
145
146
147class IPv6SetField(base_tests.SimpleDataPlane):
148
149 def runTest(self):
150 of_ports = config["port_map"].keys()
151 of_ports.sort()
152 ing_port = of_ports[0]
153 egr_port = of_ports[3]
154
155 # Remove all entries Add entry match all
156 rc = testutils.delete_all_flows(self.controller, logging)
157 self.assertEqual(rc, 0, "Failed to delete all flows")
158
159 # Add entry match
160
Rich Lanecfff0ae2013-05-07 15:49:10 -0700161 request = ofp.message.flow_add()
162 port = ofp.oxm.in_port(of_ports[0])
163 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
164 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
Rich Laneea873262013-01-11 08:15:55 -0800165
Rich Lanecfff0ae2013-05-07 15:49:10 -0700166 request.match.oxm_list.append(port)
167 request.match.oxm_list.append(eth_type)
168 request.match.oxm_list.append(ipv6_src)
Rich Laneea873262013-01-11 08:15:55 -0800169
Rich Lanecfff0ae2013-05-07 15:49:10 -0700170 field_2b_set = ofp.oxm.ipv6_dst(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:DDDD'))
Rich Lane63393492013-01-11 09:21:12 -0800171 act_setfield = ofp.action.set_field()
Rich Lanecfff0ae2013-05-07 15:49:10 -0700172 act_setfield.field = field_2b_set.pack() # HACK
Rich Laneea873262013-01-11 08:15:55 -0800173
174# TODO: insert action set field properly
Rich Lane63393492013-01-11 09:21:12 -0800175 act_out = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -0800176 act_out.port = of_ports[3]
177
178
Rich Lanecfff0ae2013-05-07 15:49:10 -0700179 inst = ofp.instruction.apply_actions()
180 inst.actions.append(act_setfield)
181 inst.actions.append(act_out)
182 request.instructions.append(inst)
Rich Laneea873262013-01-11 08:15:55 -0800183 request.buffer_id = 0xffffffff
184
185 request.priority = 1000
186 logging.debug("Adding flow ")
187
188 rv = self.controller.message_send(request)
189 self.assertTrue(rv != -1, "Failed to insert test flow")
190
191 #Send packet
192 pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190')
193 logging.info("Sending IPv6 packet to " + str(ing_port))
194 logging.debug("Data: " + str(pkt).encode('hex'))
195 self.dataplane.send(ing_port, str(pkt))
196
197 #Receive packet
198 exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD')
199 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
200
201 #See flow match
202 response = testutils.flow_stats_get(self)
203 logging.debug("Response" + response.show())
204
205 #Remove flows
206 rc = testutils.delete_all_flows(self.controller, logging)
207 self.assertEqual(rc, 0, "Failed to delete all flows")
208
209
210class MatchIPv6TCP(base_tests.SimpleDataPlane):
211
212 def runTest(self):
213 # Config
214 of_ports = config["port_map"].keys()
215 of_ports.sort()
216 ing_port = of_ports[0]
217 egr_port = of_ports[3]
218
219 # Remove flows
220 rc = testutils.delete_all_flows(self.controller, logging)
221 self.assertEqual(rc, 0, "Failed to delete all flows")
222
223 # Add entry match
224
Rich Lanecfff0ae2013-05-07 15:49:10 -0700225 request = ofp.message.flow_add()
Rich Laneea873262013-01-11 08:15:55 -0800226 request.match.type = ofp.OFPMT_OXM
Rich Lanecfff0ae2013-05-07 15:49:10 -0700227 port = ofp.oxm.in_port(of_ports[0])
228 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
229 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
230 ip_proto = ofp.oxm.ip_proto(TCP_PROTOCOL)
231 tcp_port = ofp.oxm.tcp_src(80)
Rich Laneea873262013-01-11 08:15:55 -0800232
233
Rich Lanecfff0ae2013-05-07 15:49:10 -0700234 request.match.oxm_list.append(port)
235 request.match.oxm_list.append(eth_type)
236 request.match.oxm_list.append(ipv6_src)
237 request.match.oxm_list.append(ip_proto)
238 request.match.oxm_list.append(tcp_port)
Rich Laneea873262013-01-11 08:15:55 -0800239
Rich Lane63393492013-01-11 09:21:12 -0800240 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -0800241 act.port = of_ports[3]
Rich Lanecfff0ae2013-05-07 15:49:10 -0700242 inst = ofp.instruction.apply_actions()
243 inst.actions.append(act)
244 request.instructions.append(inst)
Rich Laneea873262013-01-11 08:15:55 -0800245 request.buffer_id = 0xffffffff
246
247 request.priority = 1000
248 logging.debug("Adding flow ")
249
250 rv = self.controller.message_send(request)
251 self.assertTrue(rv != -1, "Failed to send test flow")
252
253 #Send packet
254 pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
255
256 logging.info("Sending IPv6 packet to " + str(ing_port))
257 logging.debug("Data: " + str(pkt).encode('hex'))
258
259 self.dataplane.send(ing_port, str(pkt))
260
261 #Receive packet
262 exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
263
264 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
265
266 #Remove flows
267 rc = testutils.delete_all_flows(self.controller, logging)
268 self.assertEqual(rc, 0, "Failed to delete all flows")
269
270if __name__ == "__main__":
271 print "Please run through oft script: ./oft --test-spec=ipv6"