blob: 862633d9cc2d47850e4aee9804f27c0c6962609c [file] [log] [blame]
ShreyaPandita6fbff252012-11-13 16:56:48 -05001"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
2 Refer Documentation -- Detailed testing methodology
3 <Some of test-cases are directly taken from oftest> """
4
5"Test Suite 6 --> Flow Matches"
6
7
8import logging
9
10import unittest
11import random
12
13import oftest.controller as controller
14import oftest.cstruct as ofp
15import oftest.message as message
16import oftest.dataplane as dataplane
17import oftest.action as action
18import oftest.parse as parse
19import oftest.base_tests as base_tests
20import time
21
22from oftest.testutils import *
23from time import sleep
24from FuncUtils import *
25
ShreyaPanditaefdff312012-11-21 13:35:34 -050026
ShreyaPandita6fbff252012-11-13 16:56:48 -050027
28class AllWildcardMatch(base_tests.SimpleDataPlane):
29
30 """Verify for an all wildcarded flow all the injected packets would match that flow"""
31
32 def runTest(self):
33
34 logging.info("Running All Wildcard Match test")
35
36 of_ports = config["port_map"].keys()
37 of_ports.sort()
38 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
39
40 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080041 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -050042
43 logging.info("Inserting an all wildcarded flow and sending packets with various match fields")
44 logging.info("Expecting all sent packets to match")
45
ShreyaPanditaefdff312012-11-21 13:35:34 -050046 egress_port=of_ports[1]
47 no_ports=set(of_ports).difference([egress_port])
48 yes_ports = of_ports[1]
49
ShreyaPandita6fbff252012-11-13 16:56:48 -050050 #Insert an All Wildcarded flow.
51 wildcard_all(self,of_ports)
52
53 #check for different match fields and verify packet implements the action specified in the flow
54 pkt1 = simple_tcp_packet(dl_src="00:01:01:01:01:01");
55 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -050056 receive_pkt_check(self.dataplane,pkt1,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050057
ShreyaPandita6fbff252012-11-13 16:56:48 -050058 pkt2 = simple_tcp_packet(dl_dst="00:01:01:01:01:01");
59 self.dataplane.send(of_ports[0], str(pkt2))
ShreyaPandita6fbff252012-11-13 16:56:48 -050060 receive_pkt_check(self.dataplane,pkt2,[yes_ports],no_ports,self)
61
62 pkt3 = simple_tcp_packet(ip_src="192.168.2.1");
63 self.dataplane.send(of_ports[0], str(pkt3))
ShreyaPandita6fbff252012-11-13 16:56:48 -050064 receive_pkt_check(self.dataplane,pkt3,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050065
ShreyaPandita6fbff252012-11-13 16:56:48 -050066 pkt4 = simple_tcp_packet(ip_dst="192.168.2.2");
67 self.dataplane.send(of_ports[0], str(pkt4))
ShreyaPandita6fbff252012-11-13 16:56:48 -050068 receive_pkt_check(self.dataplane,pkt4,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050069
ShreyaPandita6fbff252012-11-13 16:56:48 -050070 pkt5 = simple_tcp_packet(ip_tos=2);
71 self.dataplane.send(of_ports[0], str(pkt5))
ShreyaPandita6fbff252012-11-13 16:56:48 -050072 receive_pkt_check(self.dataplane,pkt5,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050073
ShreyaPandita6fbff252012-11-13 16:56:48 -050074 pkt6 = simple_tcp_packet(tcp_sport=8080);
75 self.dataplane.send(of_ports[0], str(pkt6))
ShreyaPandita6fbff252012-11-13 16:56:48 -050076 receive_pkt_check(self.dataplane,pkt6,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050077
ShreyaPandita6fbff252012-11-13 16:56:48 -050078 pkt7 = simple_tcp_packet(tcp_dport=8081);
79 self.dataplane.send(of_ports[0], str(pkt7))
ShreyaPandita6fbff252012-11-13 16:56:48 -050080 receive_pkt_check(self.dataplane,pkt7,[yes_ports],no_ports,self)
81
82
83
84class EthernetSrcAddress(base_tests.SimpleDataPlane):
85
86 """Verify match on single header field -- Ethernet Src Address """
87
88 def runTest(self):
89
90 logging.info("Running Ethernet Src Address test")
91
92 of_ports = config["port_map"].keys()
93 of_ports.sort()
94 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
95
96 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080097 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -050098
ShreyaPanditaefdff312012-11-21 13:35:34 -050099 egress_port=of_ports[1]
100 no_ports=set(of_ports).difference([egress_port])
101 yes_ports = of_ports[1]
102
ShreyaPandita6fbff252012-11-13 16:56:48 -0500103 logging.info("Inserting a flow with match on Ethernet Source Address ")
104 logging.info("Sending matching and non-matching ethernet packets")
105 logging.info("Verifying only matching packets implements the action specified in the flow")
106
107 #Insert a Match On Ethernet Src Address flow
108 (pkt,match) = match_ethernet_src_address(self,of_ports)
109
110 #Sending packet matching the flow, verify it implements the action
111 self.dataplane.send(of_ports[0], str(pkt))
112
113 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500114 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
115
116 #Sending non matching packet , verify Packetin event gets triggered.
117 pkt2 = simple_eth_packet(dl_src='00:01:01:01:01:02');
118 self.dataplane.send(of_ports[0], str(pkt2))
119
120 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
121 self.assertTrue(response is not None, "PacketIn not received for non matching packets")
122
123class EthernetDstAddress(base_tests.SimpleDataPlane):
124
125 """Verify match on single Header Field Field -- Ethernet Dst Address """
126
127 def runTest(self):
128
129 logging.info("Running Ethernet Dst Address test")
130
131 of_ports = config["port_map"].keys()
132 of_ports.sort()
133 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
134
135 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800136 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500137
ShreyaPanditaefdff312012-11-21 13:35:34 -0500138 egress_port=of_ports[1]
139 no_ports=set(of_ports).difference([egress_port])
140 yes_ports = of_ports[1]
141
ShreyaPandita6fbff252012-11-13 16:56:48 -0500142 logging.info("Inserting a flow with match on Ethernet Destination Address ")
143 logging.info("Sending matching and non-matching ethernet packets")
144 logging.info("Verifying only matching packets implements the action specified in the flow")
145
146 #Insert a Match on Destination Address flow
147 (pkt,match) = match_ethernet_dst_address(self,of_ports)
148
149 #Send Packet matching the flow
150 self.dataplane.send(of_ports[0], str(pkt))
151
152 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500153 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
154
155 #Send Non-matching packet
156 pkt2 = simple_eth_packet(dl_dst='00:01:01:01:01:02');
157 self.dataplane.send(of_ports[0], str(pkt2))
158
159 #Verify PacketIn event gets triggered
160 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
161 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
162
163
164class EthernetType(base_tests.SimpleDataPlane):
165
166 """Verify match on single header field -- Ethernet Type """
167
168 def runTest(self):
169
170 logging.info("Running Ethernet Type test")
171
172 of_ports = config["port_map"].keys()
173 of_ports.sort()
174 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
175
176 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800177 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500178
ShreyaPanditaefdff312012-11-21 13:35:34 -0500179 egress_port=of_ports[1]
180 no_ports=set(of_ports).difference([egress_port])
181 yes_ports = of_ports[1]
182
ShreyaPandita6fbff252012-11-13 16:56:48 -0500183 logging.info("Inserting a flow with match on Ethernet Type ")
184 logging.info("Sending matching and non-matching ethernet packets")
185 logging.info("Verifying only matching packets implements the action specified in the flow")
186
187 #Insert a Match on Ethernet-Type flow
188 (pkt,match) = match_ethernet_type(self,of_ports)
189
190 #Sending packet matching the flow
191 self.dataplane.send(of_ports[0], str(pkt))
192
193 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500194 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
195
196 #Sending non matching packet ,
197 pkt2 = simple_eth_packet(dl_type=0x0806);
198 self.dataplane.send(of_ports[0], str(pkt2))
199
200 #verify Packetin event gets triggered.
201 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
202 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
203
204
205class IngressPort(base_tests.SimpleDataPlane):
206
207 """Verify match on single Header Field Field -- In_port """
208
209 def runTest(self):
210
211 logging.info("Running Ingress Port test")
212
213 of_ports = config["port_map"].keys()
214 of_ports.sort()
215 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
216
217 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800218 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500219
ShreyaPanditaefdff312012-11-21 13:35:34 -0500220 egress_port=of_ports[1]
221 no_ports=set(of_ports).difference([egress_port])
222 yes_ports = of_ports[1]
223
ShreyaPandita6fbff252012-11-13 16:56:48 -0500224 logging.info("Inserting a flow with match on Ingress Port ")
225 logging.info("Sending matching and non-matching packets")
226 logging.info("Verifying only matching packets implements the action specified in the flow")
227
228 #Insert a Match on Ingress Port FLow
229 (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0)
230
231 #Send Packet matching the flow i.e on in_port specified in the flow
232 self.dataplane.send(of_ports[0], str(pkt))
233
234 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500235 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
236
237 #Send Non-Matching Packet
238 self.dataplane.send(of_ports[1],str(pkt))
239
240 #Verify PacketIn event gets triggered
241 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
242 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
243
244class VlanId(base_tests.SimpleDataPlane):
245
246 """Verify match on single Header Field Field -- Vlan Id """
247
248 def runTest(self):
249
250 of_ports = config["port_map"].keys()
251 of_ports.sort()
252 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
253
254 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800255 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500256
ShreyaPanditaefdff312012-11-21 13:35:34 -0500257 egress_port=of_ports[1]
258 no_ports=set(of_ports).difference([egress_port])
259 yes_ports = of_ports[1]
260
ShreyaPandita6fbff252012-11-13 16:56:48 -0500261 logging.info("Inserting a flow with match on VLAN ID ")
262 logging.info("Sending matching and non-matching tagged packets")
263 logging.info("Verifying matching packets implements the action specified in the flow")
264
265 #Create a flow with match on Vlan Id
266 (pkt,match) = match_vlan_id(self,of_ports)
267
268 #Send tagged packet matching the flow i.e packet with same vlan id as in flow
269 self.dataplane.send(of_ports[0], str(pkt))
270
271 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500272 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
273
274 #Send Non-matching packet, i.e packet with different Vlan Id
275 pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=4);
276 self.dataplane.send(of_ports[0], str(pkt2))
277
278 #Verify PacketIn event gets triggered
279 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
280 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
281
282class VlanPCP(base_tests.SimpleDataPlane):
283
284 """"Verify match on single Header Field Field -- Vlan Priority"""
285
286 def runTest(self):
287
288 logging.info("Running VlanPCP1 test")
289
290 of_ports = config["port_map"].keys()
291 of_ports.sort()
292 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
293
294 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800295 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500296
297 egress_port=of_ports[1]
298 no_ports=set(of_ports).difference([egress_port])
299 yes_ports = of_ports[1]
300
ShreyaPandita6fbff252012-11-13 16:56:48 -0500301 logging.info("Inserting a flow with match on VLAN Priority ")
302 logging.info("Sending matching and non-matching tagged packets")
303 logging.info("Verifying matching packet implements the action specified in the flow")
304
305 #Create a flow matching on VLAN Priority
306 (pkt,match) = match_vlan_pcp(self,of_ports)
307
308 #Send tagged Packet matching the flow
309 self.dataplane.send(of_ports[0], str(pkt))
310
311 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500312 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
313
314 #Send tagged packet with same vlan_id but different vlan priority
315 pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=20);
ShreyaPanditaefdff312012-11-21 13:35:34 -0500316 self.dataplane.send(of_ports[0], str(pkt2))
317
318 #Verify Packet_In event gets triggered
319 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
320 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
ShreyaPandita6fbff252012-11-13 16:56:48 -0500321
322class MultipleHeaderFieldL2(base_tests.SimpleDataPlane):
323
324 """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """
325
326 def runTest(self):
327
328 logging.info("Running Multiple Header Field L2 test")
329
330 of_ports = config["port_map"].keys()
331 of_ports.sort()
332 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
333
334 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800335 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500336
ShreyaPanditaefdff312012-11-21 13:35:34 -0500337 egress_port=of_ports[1]
338 no_ports=set(of_ports).difference([egress_port])
339 yes_ports = of_ports[1]
340
ShreyaPandita6fbff252012-11-13 16:56:48 -0500341 logging.info("Inserting a flow with match on Multiple Header Fields in L2 ")
342 logging.info("Sending matching and non-matching packets")
343 logging.info("Verifying matching packets implements the action specified in the flow")
344
345 (pkt,match) = match_mul_l2(self,of_ports)
346
347 #Send eth packet matching the dl_type field, verify it implements the action
348 self.dataplane.send(of_ports[0], str(pkt))
349
350 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500351 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
352
353 #Sending non matching packet (only dl_dst is different) , verify Packetin event gets triggered.
354 pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:02:01:01');
355 self.dataplane.send(of_ports[0], str(pkt2))
356
357 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
358 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
359
360 #Sending non matching packet (only dl_src is different) , verify Packetin event gets triggered.
361 pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:02',dl_dst='00:01:01:01:01:02');
362 self.dataplane.send(of_ports[0], str(pkt2))
363
364 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
365 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
366
367 #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered.
368 pkt2 = simple_eth_packet(dl_type=0x0806,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02');
369 self.dataplane.send(of_ports[0], str(pkt2))
370
ShreyaPanditaefdff312012-11-21 13:35:34 -0500371 #Verify packet_in event gets triggered
ShreyaPandita6fbff252012-11-13 16:56:48 -0500372 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
373 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
374
375class IpTos(base_tests.SimpleDataPlane):
376
377 """"Verify match on single Header Field Field -- Type of service"""
378
379 def runTest(self):
380
381 logging.info("Running Ip_Tos test")
382
383 of_ports = config["port_map"].keys()
384 of_ports.sort()
385 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
386
387 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800388 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500389
390 egress_port=of_ports[1]
391 no_ports=set(of_ports).difference([egress_port])
392 yes_ports = of_ports[1]
393
ShreyaPandita6fbff252012-11-13 16:56:48 -0500394 logging.info("Inserting a flow with match on Ip_Tos ")
395 logging.info("Sending matching and non-matching tcp/ip packets")
396 logging.info("Verifying only matching packets implements the action specified in the flow")
397
398 #Create a flow matching on VLAN Priority
399 (pkt,match) = match_ip_tos(self,of_ports)
400
401 #Send Packet matching the flow
402 self.dataplane.send(of_ports[0], str(pkt))
403
404 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500405 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
406
407 #Create a non-matching packet , verify packet_in get generated
Rich Laneb5c73792012-12-03 17:12:32 -0800408 pkt2 = simple_tcp_packet(ip_tos=4);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500409 self.dataplane.send(of_ports[0], str(pkt2))
410 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
411 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
412
413class IpProtocol(base_tests.SimpleDataPlane):
414
415 """"Verify match on single Header Field Field -- Ip Protocol"""
416
417 def runTest(self):
418
419 logging.info("Running Ip Protocol test")
420
421 of_ports = config["port_map"].keys()
422 of_ports.sort()
423 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
424
425 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800426 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500427
428 egress_port=of_ports[1]
429 no_ports=set(of_ports).difference([egress_port])
430 yes_ports = of_ports[1]
431
ShreyaPandita6fbff252012-11-13 16:56:48 -0500432 logging.info("Inserting a flow with match on Ip Protocol ")
433 logging.info("Sending matching and non-matching tcp/ip packets")
434 logging.info("Verifying only matching packets implements the action specified in the flow")
435
436 #Create a flow matching on VLAN Priority
437 (pkt,match) = match_ip_protocol(self,of_ports)
438
439 #Send Packet matching the flow
440 self.dataplane.send(of_ports[0], str(pkt))
441
442 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500443 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
444
445 #Create a non-matching packet , verify packet_in get generated
446 pkt2 = simple_icmp_packet();
447 self.dataplane.send(of_ports[0], str(pkt2))
448 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
449 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
450
451
452class TcpSrcPort(base_tests.SimpleDataPlane):
453
454 """Verify match on Single header field -- Tcp Source Port, """
455
456 def runTest(self):
457
458 logging.info("Running Tcp Src Port test")
459
460 of_ports = config["port_map"].keys()
461 of_ports.sort()
462 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
463
464 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800465 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500466
ShreyaPanditaefdff312012-11-21 13:35:34 -0500467 egress_port=of_ports[1]
468 no_ports=set(of_ports).difference([egress_port])
469 yes_ports = of_ports[1]
470
ShreyaPandita6fbff252012-11-13 16:56:48 -0500471 logging.info("Inserting a flow with match on Tcp Tcp Source Port ")
472 logging.info("Sending matching and non-matching tcp packets")
473 logging.info("Verifying matching packets implements the action specified in the flow")
474
475 (pkt,match) = match_tcp_src(self,of_ports)
476
477 #Sending packet matching the tcp_sport, verify it implements the action
478 self.dataplane.send(of_ports[0], str(pkt))
479
480 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500481 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
482
483 #Sending non matching packet , verify Packetin event gets triggered.
484 pkt2 = simple_tcp_packet(tcp_sport=540);
485 self.dataplane.send(of_ports[0], str(pkt2))
486
487 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
488 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
489
490class TcpDstPort(base_tests.SimpleDataPlane):
491
492 """Verify match on Single header field -- Tcp Destination Port """
493
494 def runTest(self):
495
496 logging.info("Running Tcp Destination Port test")
497
498 of_ports = config["port_map"].keys()
499 of_ports.sort()
500 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
501
502 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800503 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500504
ShreyaPanditaefdff312012-11-21 13:35:34 -0500505 egress_port=of_ports[1]
506 no_ports=set(of_ports).difference([egress_port])
507 yes_ports = of_ports[1]
508
ShreyaPandita6fbff252012-11-13 16:56:48 -0500509 logging.info("Inserting a flow with match on Tcp Destination Port ")
510 logging.info("Sending matching and non-matching packets")
511 logging.info("Verifying matching packets implements the action specified in the flow")
512
513 (pkt,match) = match_tcp_dst(self,of_ports)
514
515 #Sending packet matching the tcp_dport, verify it implements the action
516 self.dataplane.send(of_ports[0], str(pkt))
517
518 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500519 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
520
521 #Sending non matching packet , verify Packetin event gets triggered.
522 pkt2 = simple_tcp_packet(tcp_dport=541);
523 self.dataplane.send(of_ports[0], str(pkt2))
524
525 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=10)
526 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
527
528
529class ExactMatch(base_tests.SimpleDataPlane):
530
531 """Verify match on Single header field -- Exact Match """
532
533 def runTest(self):
534
535 logging.info("Running Tcp Exact Match test")
536
537 of_ports = config["port_map"].keys()
538 of_ports.sort()
539 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
540
541 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800542 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500543
ShreyaPanditaefdff312012-11-21 13:35:34 -0500544 egress_port=of_ports[1]
545 no_ports=set(of_ports).difference([egress_port])
546 yes_ports = of_ports[1]
547
ShreyaPandita6fbff252012-11-13 16:56:48 -0500548 logging.info("Inserting a flow with match for Exact Match ")
549 logging.info("Sending matching and non-matching packets")
550 logging.info("Verifying matching packets implements the action specified in the flow")
551
552 (pkt,match) = exact_match(self,of_ports)
553
554 #Sending packet matching all the fields of a tcp_packet, verify it implements the action
555 self.dataplane.send(of_ports[0], str(pkt))
556
557 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500558 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
559
560 #Sending non matching packet , verify Packetin event gets triggered.
561 pkt2 = simple_tcp_packet(tcp_sport=540);
562 self.dataplane.send(of_ports[0], str(pkt2))
563
564 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
565 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
566
567
568class MultipleHeaderFieldL4(base_tests.SimpleDataPlane):
569
570 """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """
571
572 def runTest(self):
573
574 logging.info("Running Multiple Header Field L4 test")
575
576 of_ports = config["port_map"].keys()
577 of_ports.sort()
578 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
579
580 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800581 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500582
ShreyaPanditaefdff312012-11-21 13:35:34 -0500583 egress_port=of_ports[1]
584 no_ports=set(of_ports).difference([egress_port])
585 yes_ports = of_ports[1]
586
ShreyaPandita6fbff252012-11-13 16:56:48 -0500587 logging.info("Inserting a flow with match on Multiple Header Field L4 ")
588 logging.info("Sending matching and non-matching packets")
589 logging.info("Verifying matching packets implements the action specified in the flow")
590
591 (pkt,match) = match_mul_l4(self,of_ports)
592
593 #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
594 self.dataplane.send(of_ports[0], str(pkt))
595
596 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500597 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
598
ShreyaPanditaefdff312012-11-21 13:35:34 -0500599 #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered.
600 pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541);
601 self.dataplane.send(of_ports[0], str(pkt2))
602
603 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
604 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
605
606 #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered.
607 pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500608 self.dataplane.send(of_ports[0], str(pkt2))
609
610 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
611 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
612
613
614class ExactMatchPrio(base_tests.SimpleDataPlane):
615
616 """Verify that Exact Match has highest priority """
617
618 def runTest(self):
619
620 logging.info("Running Exact Match High Priority test")
621
622 of_ports = config["port_map"].keys()
623 of_ports.sort()
624 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
625
626 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800627 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500628
Rich Laneed130652012-12-31 17:35:33 -0800629 egress_port=of_ports[2]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500630 no_ports=set(of_ports).difference([egress_port])
Rich Laneed130652012-12-31 17:35:33 -0800631 yes_ports = egress_port
ShreyaPanditaefdff312012-11-21 13:35:34 -0500632
ShreyaPandita6fbff252012-11-13 16:56:48 -0500633 logging.info("Inserting a flow with Exact Match (low priority)")
634 logging.info("Inserting an overlapping wildcarded flow (higher priority)")
635 logging.info("Sending packets matching both the flows ")
636 logging.info("Verifying matching packets implements the action specified in the exact match flow")
637
638 #Insert two Overlapping Flows : Exact Match and Wildcard All.
639 (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
640 (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
641
642 #Sending packet matching both the flows ,
643 self.dataplane.send(of_ports[0], str(pkt2))
644
645 #verify it implements the action specified in Exact Match Flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500646 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
647
648
649class WildcardMatchPrio(base_tests.SimpleDataPlane):
650
651 """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
652
653 def runTest(self):
654
655 logging.info("Running Wildcard Match High Priority test")
656
657 of_ports = config["port_map"].keys()
658 of_ports.sort()
659 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
660
661 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800662 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500663
ShreyaPanditaefdff312012-11-21 13:35:34 -0500664 egress_port=of_ports[1]
665 no_ports=set(of_ports).difference([egress_port])
666 yes_ports = of_ports[1]
667
ShreyaPandita6fbff252012-11-13 16:56:48 -0500668 logging.info("Inserting two wildcarded flows with priorities ")
669 logging.info("Sending packets matching the flows")
670 logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
671
672 (pkt,match) = wildcard_all(self,of_ports,priority=20)
673 (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
674
675 #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
676 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500677 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
678
679
680
681
682