blob: bd0c1204c2d600ad69d0e6cbfa76714f076842ef [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
22
23TEST_VID_DEFAULT = 2
24
25IPV6_ETHERTYPE = 0x86dd
26ETHERTYPE_VLAN = 0x8100
27ETHERTYPE_MPLS = 0x8847
28TCP_PROTOCOL = 0x6
29UDP_PROTOCOL = 0x11
30ICMPV6_PROTOCOL = 0x3a
31
32
33# TESTS
34class MatchIPv6Simple(base_tests.SimpleDataPlane):
35 """
36 Just send a packet IPv6 to match a simple entry on the matching table
37 """
38 def runTest(self):
39
40 of_ports = config["port_map"].keys()
41 of_ports.sort()
42 ing_port = of_ports[0]
43 egr_port = of_ports[3]
44
45 # Remove all entries Add entry match all
46 rc = testutils.delete_all_flows(self.controller, logging)
47 self.assertEqual(rc, 0, "Failed to delete all flows")
48
49 # Add entry match
50
Rich Laneb6255512013-05-07 14:58:43 -070051 request = ofp.message.flow_add()
52 port = ofp.oxm.in_port(of_ports[0])
53 eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE)
54 eth_dst = ofp.oxm.eth_dst(oftest.parse.parse_mac("00:01:02:03:04:05"))
55 ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
Rich Laneea873262013-01-11 08:15:55 -080056
57 request.match_fields.tlvs.append(port)
58 request.match_fields.tlvs.append(eth_type)
59 request.match_fields.tlvs.append(eth_dst)
60 request.match_fields.tlvs.append(ipv6_src)
Rich Lane63393492013-01-11 09:21:12 -080061 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -080062 act.port = of_ports[3]
63 inst = ofp.instruction.instruction_apply_actions()
64 inst.actions.add(act)
65 request.instructions.add(inst)
66 request.buffer_id = 0xffffffff
67
68 request.priority = 1000
69 logging.debug("Adding flow ")
70
71 rv = self.controller.message_send(request)
72 self.assertTrue(rv != -1, "Failed to insert test flow")
73
74 #Send packet
75 pkt = testutils.simple_ipv6_packet(dl_dst='00:01:02:03:04:05',ip_src='fe80::2420:52ff:fe8f:5189')
76 logging.info("Sending IPv6 packet to " + str(ing_port))
77 logging.debug("Data: " + str(pkt).encode('hex'))
78 self.dataplane.send(ing_port, str(pkt))
79
80 #Receive packet
81 exp_pkt = testutils.simple_ipv6_packet()
82 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
83
84 #Remove flows
85 rc = testutils.delete_all_flows(self.controller, logging)
86 self.assertEqual(rc, 0, "Failed to delete all flows")
87
88
89class MatchICMPv6Simple(base_tests.SimpleDataPlane):
90 """
91 Match on an ICMPv6 packet
92 """
93 def runTest(self):
94 of_ports = config["port_map"].keys()
95 of_ports.sort()
96 ing_port = of_ports[0]
97 egr_port = of_ports[3]
98
99 # Remove all entries Add entry match all
100 rc = testutils.delete_all_flows(self.controller, logging)
101 self.assertEqual(rc, 0, "Failed to delete all flows")
102
103 # Add entry match
104
105 request = ofp.message.flow_mod()
106 request.match.type = ofp.OFPMT_OXM
107 port = ofp.match.in_port(of_ports[0])
108 eth_type = ofp.match.eth_type(IPV6_ETHERTYPE)
Rich Laneb6255512013-05-07 14:58:43 -0700109 ipv6_src = ofp.match.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
Rich Laneea873262013-01-11 08:15:55 -0800110 ip_proto = ofp.match.ip_proto(ICMPV6_PROTOCOL)
111 icmpv6_type = ofp.match.icmpv6_type(128)
112
113 request.match_fields.tlvs.append(port)
114 request.match_fields.tlvs.append(eth_type)
115 request.match_fields.tlvs.append(ipv6_src)
116 request.match_fields.tlvs.append(ip_proto)
117 request.match_fields.tlvs.append(icmpv6_type)
118
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]
121 inst = ofp.instruction.instruction_apply_actions()
122 inst.actions.add(act)
123 request.instructions.add(inst)
124 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
161 request = ofp.message.flow_mod()
162 request.match.type = ofp.OFPMT_OXM
163 port = ofp.match.in_port(of_ports[0])
164 eth_type = ofp.match.eth_type(IPV6_ETHERTYPE)
Rich Laneb6255512013-05-07 14:58:43 -0700165 ipv6_src = ofp.match.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
Rich Laneea873262013-01-11 08:15:55 -0800166
167 request.match_fields.tlvs.append(port)
168 request.match_fields.tlvs.append(eth_type)
169 request.match_fields.tlvs.append(ipv6_src)
170
Rich Laneb6255512013-05-07 14:58:43 -0700171 field_2b_set = ofp.match.ipv6_dst(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:DDDD'))
Rich Lane63393492013-01-11 09:21:12 -0800172 act_setfield = ofp.action.set_field()
Rich Laneea873262013-01-11 08:15:55 -0800173 act_setfield.field = field_2b_set
174
175# TODO: insert action set field properly
Rich Lane63393492013-01-11 09:21:12 -0800176 act_out = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -0800177 act_out.port = of_ports[3]
178
179
180 inst = ofp.instruction.instruction_apply_actions()
181 inst.actions.add(act_setfield)
182 inst.actions.add(act_out)
183 request.instructions.add(inst)
184 request.buffer_id = 0xffffffff
185
186 request.priority = 1000
187 logging.debug("Adding flow ")
188
189 rv = self.controller.message_send(request)
190 self.assertTrue(rv != -1, "Failed to insert test flow")
191
192 #Send packet
193 pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190')
194 logging.info("Sending IPv6 packet to " + str(ing_port))
195 logging.debug("Data: " + str(pkt).encode('hex'))
196 self.dataplane.send(ing_port, str(pkt))
197
198 #Receive packet
199 exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD')
200 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
201
202 #See flow match
203 response = testutils.flow_stats_get(self)
204 logging.debug("Response" + response.show())
205
206 #Remove flows
207 rc = testutils.delete_all_flows(self.controller, logging)
208 self.assertEqual(rc, 0, "Failed to delete all flows")
209
210
211class MatchIPv6TCP(base_tests.SimpleDataPlane):
212
213 def runTest(self):
214 # Config
215 of_ports = config["port_map"].keys()
216 of_ports.sort()
217 ing_port = of_ports[0]
218 egr_port = of_ports[3]
219
220 # Remove flows
221 rc = testutils.delete_all_flows(self.controller, logging)
222 self.assertEqual(rc, 0, "Failed to delete all flows")
223
224 # Add entry match
225
226 request = ofp.message.flow_mod()
227 request.match.type = ofp.OFPMT_OXM
228 port = ofp.match.in_port(of_ports[0])
229 eth_type = ofp.match.eth_type(IPV6_ETHERTYPE)
Rich Laneb6255512013-05-07 14:58:43 -0700230 ipv6_src = ofp.match.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189'))
Rich Laneea873262013-01-11 08:15:55 -0800231 ip_proto = ofp.match.ip_proto(TCP_PROTOCOL)
232 tcp_port = ofp.match.tcp_src(80)
233
234
235 request.match_fields.tlvs.append(port)
236 request.match_fields.tlvs.append(eth_type)
237 request.match_fields.tlvs.append(ipv6_src)
238 request.match_fields.tlvs.append(ip_proto)
239 request.match_fields.tlvs.append(tcp_port)
240
Rich Lane63393492013-01-11 09:21:12 -0800241 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -0800242 act.port = of_ports[3]
243 inst = ofp.instruction.instruction_apply_actions()
244 inst.actions.add(act)
245 request.instructions.add(inst)
246 request.buffer_id = 0xffffffff
247
248 request.priority = 1000
249 logging.debug("Adding flow ")
250
251 rv = self.controller.message_send(request)
252 self.assertTrue(rv != -1, "Failed to send test flow")
253
254 #Send packet
255 pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
256
257 logging.info("Sending IPv6 packet to " + str(ing_port))
258 logging.debug("Data: " + str(pkt).encode('hex'))
259
260 self.dataplane.send(ing_port, str(pkt))
261
262 #Receive packet
263 exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080)
264
265 testutils.receive_pkt_verify(self, egr_port, exp_pkt)
266
267 #Remove flows
268 rc = testutils.delete_all_flows(self.controller, logging)
269 self.assertEqual(rc, 0, "Failed to delete all flows")
270
271if __name__ == "__main__":
272 print "Please run through oft script: ./oft --test-spec=ipv6"