blob: dc91616f6fb65e2df301073826239011fa58edde [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
26
27
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
41 rc = delete_all_flows(self.controller)
42 self.assertEqual(rc, 0, "Failed to delete all flows")
43
44 logging.info("Inserting an all wildcarded flow and sending packets with various match fields")
45 logging.info("Expecting all sent packets to match")
46
47 #Insert an All Wildcarded flow.
48 wildcard_all(self,of_ports)
49
50 #check for different match fields and verify packet implements the action specified in the flow
51 pkt1 = simple_tcp_packet(dl_src="00:01:01:01:01:01");
52 self.dataplane.send(of_ports[0], str(pkt1))
53 egress_port=of_ports[1]
54 no_ports=set(of_ports).difference([egress_port])
55 yes_ports = of_ports[1]
56 receive_pkt_check(self.dataplane,pkt1,[yes_ports],no_ports,self)
57
58 pkt2 = simple_tcp_packet(dl_dst="00:01:01:01:01:01");
59 self.dataplane.send(of_ports[0], str(pkt2))
60 egress_port=of_ports[1]
61 no_ports=set(of_ports).difference([egress_port])
62 yes_ports = of_ports[1]
63 receive_pkt_check(self.dataplane,pkt2,[yes_ports],no_ports,self)
64
65 pkt3 = simple_tcp_packet(ip_src="192.168.2.1");
66 self.dataplane.send(of_ports[0], str(pkt3))
67 egress_port=of_ports[1]
68 no_ports=set(of_ports).difference([egress_port])
69 yes_ports = of_ports[1]
70 receive_pkt_check(self.dataplane,pkt3,[yes_ports],no_ports,self)
71
72 pkt4 = simple_tcp_packet(ip_dst="192.168.2.2");
73 self.dataplane.send(of_ports[0], str(pkt4))
74 egress_port=of_ports[1]
75 no_ports=set(of_ports).difference([egress_port])
76 yes_ports = of_ports[1]
77 receive_pkt_check(self.dataplane,pkt4,[yes_ports],no_ports,self)
78
79 pkt5 = simple_tcp_packet(ip_tos=2);
80 self.dataplane.send(of_ports[0], str(pkt5))
81 egress_port=of_ports[1]
82 no_ports=set(of_ports).difference([egress_port])
83 yes_ports = of_ports[1]
84 receive_pkt_check(self.dataplane,pkt5,[yes_ports],no_ports,self)
85
86 pkt6 = simple_tcp_packet(tcp_sport=8080);
87 self.dataplane.send(of_ports[0], str(pkt6))
88 egress_port=of_ports[1]
89 no_ports=set(of_ports).difference([egress_port])
90 yes_ports = of_ports[1]
91 receive_pkt_check(self.dataplane,pkt6,[yes_ports],no_ports,self)
92
93 pkt7 = simple_tcp_packet(tcp_dport=8081);
94 self.dataplane.send(of_ports[0], str(pkt7))
95 egress_port=of_ports[1]
96 no_ports=set(of_ports).difference([egress_port])
97 yes_ports = of_ports[1]
98 receive_pkt_check(self.dataplane,pkt7,[yes_ports],no_ports,self)
99
100
101
102class EthernetSrcAddress(base_tests.SimpleDataPlane):
103
104 """Verify match on single header field -- Ethernet Src Address """
105
106 def runTest(self):
107
108 logging.info("Running Ethernet Src Address test")
109
110 of_ports = config["port_map"].keys()
111 of_ports.sort()
112 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
113
114 #Clear Switch State
115 rc = delete_all_flows(self.controller)
116 self.assertEqual(rc, 0, "Failed to delete all flows")
117
118 logging.info("Inserting a flow with match on Ethernet Source Address ")
119 logging.info("Sending matching and non-matching ethernet packets")
120 logging.info("Verifying only matching packets implements the action specified in the flow")
121
122 #Insert a Match On Ethernet Src Address flow
123 (pkt,match) = match_ethernet_src_address(self,of_ports)
124
125 #Sending packet matching the flow, verify it implements the action
126 self.dataplane.send(of_ports[0], str(pkt))
127
128 #Verify packet implements the action specified in the flow
129 egress_port=of_ports[1]
130 no_ports=set(of_ports).difference([egress_port])
131 yes_ports = of_ports[1]
132 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
133
134 #Sending non matching packet , verify Packetin event gets triggered.
135 pkt2 = simple_eth_packet(dl_src='00:01:01:01:01:02');
136 self.dataplane.send(of_ports[0], str(pkt2))
137
138 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
139 self.assertTrue(response is not None, "PacketIn not received for non matching packets")
140
141class EthernetDstAddress(base_tests.SimpleDataPlane):
142
143 """Verify match on single Header Field Field -- Ethernet Dst Address """
144
145 def runTest(self):
146
147 logging.info("Running Ethernet Dst Address test")
148
149 of_ports = config["port_map"].keys()
150 of_ports.sort()
151 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
152
153 #Clear Switch State
154 rv = delete_all_flows(self.controller)
155 self.assertEqual(rv, 0, "Failed to delete all flows")
156
157 logging.info("Inserting a flow with match on Ethernet Destination Address ")
158 logging.info("Sending matching and non-matching ethernet packets")
159 logging.info("Verifying only matching packets implements the action specified in the flow")
160
161 #Insert a Match on Destination Address flow
162 (pkt,match) = match_ethernet_dst_address(self,of_ports)
163
164 #Send Packet matching the flow
165 self.dataplane.send(of_ports[0], str(pkt))
166
167 #Verify packet implements the action specified in the flow
168 egress_port=of_ports[1]
169 no_ports=set(of_ports).difference([egress_port])
170 yes_ports = of_ports[1]
171 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
172
173 #Send Non-matching packet
174 pkt2 = simple_eth_packet(dl_dst='00:01:01:01:01:02');
175 self.dataplane.send(of_ports[0], str(pkt2))
176
177 #Verify PacketIn event gets triggered
178 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
179 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
180
181
182class EthernetType(base_tests.SimpleDataPlane):
183
184 """Verify match on single header field -- Ethernet Type """
185
186 def runTest(self):
187
188 logging.info("Running Ethernet Type test")
189
190 of_ports = config["port_map"].keys()
191 of_ports.sort()
192 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
193
194 #Clear Switch State
195 rc = delete_all_flows(self.controller)
196 self.assertEqual(rc, 0, "Failed to delete all flows")
197
198 logging.info("Inserting a flow with match on Ethernet Type ")
199 logging.info("Sending matching and non-matching ethernet packets")
200 logging.info("Verifying only matching packets implements the action specified in the flow")
201
202 #Insert a Match on Ethernet-Type flow
203 (pkt,match) = match_ethernet_type(self,of_ports)
204
205 #Sending packet matching the flow
206 self.dataplane.send(of_ports[0], str(pkt))
207
208 #Verify packet implements the action specified in the flow
209 egress_port=of_ports[1]
210 no_ports=set(of_ports).difference([egress_port])
211 yes_ports = of_ports[1]
212 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
213
214 #Sending non matching packet ,
215 pkt2 = simple_eth_packet(dl_type=0x0806);
216 self.dataplane.send(of_ports[0], str(pkt2))
217
218 #verify Packetin event gets triggered.
219 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
220 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
221
222
223class IngressPort(base_tests.SimpleDataPlane):
224
225 """Verify match on single Header Field Field -- In_port """
226
227 def runTest(self):
228
229 logging.info("Running Ingress Port test")
230
231 of_ports = config["port_map"].keys()
232 of_ports.sort()
233 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
234
235 #Clear Switch State
236 rc = delete_all_flows(self.controller)
237 self.assertEqual(rc, 0, "Failed to delete all flows")
238
239 logging.info("Inserting a flow with match on Ingress Port ")
240 logging.info("Sending matching and non-matching packets")
241 logging.info("Verifying only matching packets implements the action specified in the flow")
242
243 #Insert a Match on Ingress Port FLow
244 (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0)
245
246 #Send Packet matching the flow i.e on in_port specified in the flow
247 self.dataplane.send(of_ports[0], str(pkt))
248
249 #Verify packet implements the action specified in the flow
250 egress_port=of_ports[1]
251 no_ports=set(of_ports).difference([egress_port])
252 yes_ports = of_ports[1]
253 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
254
255 #Send Non-Matching Packet
256 self.dataplane.send(of_ports[1],str(pkt))
257
258 #Verify PacketIn event gets triggered
259 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
260 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
261
262class VlanId(base_tests.SimpleDataPlane):
263
264 """Verify match on single Header Field Field -- Vlan Id """
265
266 def runTest(self):
267
268 of_ports = config["port_map"].keys()
269 of_ports.sort()
270 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
271
272 #Clear Switch State
273 rc = delete_all_flows(self.controller)
274 self.assertEqual(rc, 0, "Failed to delete all flows")
275
276 logging.info("Inserting a flow with match on VLAN ID ")
277 logging.info("Sending matching and non-matching tagged packets")
278 logging.info("Verifying matching packets implements the action specified in the flow")
279
280 #Create a flow with match on Vlan Id
281 (pkt,match) = match_vlan_id(self,of_ports)
282
283 #Send tagged packet matching the flow i.e packet with same vlan id as in flow
284 self.dataplane.send(of_ports[0], str(pkt))
285
286 #Verify packet implements the action specified in the flow
287 egress_port=of_ports[1]
288 no_ports=set(of_ports).difference([egress_port])
289 yes_ports = of_ports[1]
290 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
291
292 #Send Non-matching packet, i.e packet with different Vlan Id
293 pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=4);
294 self.dataplane.send(of_ports[0], str(pkt2))
295
296 #Verify PacketIn event gets triggered
297 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
298 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
299
300class VlanPCP(base_tests.SimpleDataPlane):
301
302 """"Verify match on single Header Field Field -- Vlan Priority"""
303
304 def runTest(self):
305
306 logging.info("Running VlanPCP1 test")
307
308 of_ports = config["port_map"].keys()
309 of_ports.sort()
310 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
311
312 #Clear Switch State
313 rv = delete_all_flows(self.controller)
314 self.assertEqual(rv, 0, "Failed to delete all flows")
315
316 logging.info("Inserting a flow with match on VLAN Priority ")
317 logging.info("Sending matching and non-matching tagged packets")
318 logging.info("Verifying matching packet implements the action specified in the flow")
319
320 #Create a flow matching on VLAN Priority
321 (pkt,match) = match_vlan_pcp(self,of_ports)
322
323 #Send tagged Packet matching the flow
324 self.dataplane.send(of_ports[0], str(pkt))
325
326 #Verify packet implements the action specified in the flow
327 egress_port=of_ports[1]
328 no_ports=set(of_ports).difference([egress_port])
329 yes_ports = of_ports[1]
330 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
331
332 #Send tagged packet with same vlan_id but different vlan priority
333 pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=20);
334 self.dataplane.send(in_port, str(pkt))
335
336class MultipleHeaderFieldL2(base_tests.SimpleDataPlane):
337
338 """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """
339
340 def runTest(self):
341
342 logging.info("Running Multiple Header Field L2 test")
343
344 of_ports = config["port_map"].keys()
345 of_ports.sort()
346 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
347
348 #Clear Switch State
349 rc = delete_all_flows(self.controller)
350 self.assertEqual(rc, 0, "Failed to delete all flows")
351
352 logging.info("Inserting a flow with match on Multiple Header Fields in L2 ")
353 logging.info("Sending matching and non-matching packets")
354 logging.info("Verifying matching packets implements the action specified in the flow")
355
356 (pkt,match) = match_mul_l2(self,of_ports)
357
358 #Send eth packet matching the dl_type field, verify it implements the action
359 self.dataplane.send(of_ports[0], str(pkt))
360
361 #Verify packet implements the action specified in the flow
362 egress_port=of_ports[1]
363 no_ports=set(of_ports).difference([egress_port])
364 yes_ports = of_ports[1]
365 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
366
367 #Sending non matching packet (only dl_dst is different) , verify Packetin event gets triggered.
368 pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:02:01:01');
369 self.dataplane.send(of_ports[0], str(pkt2))
370
371 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
372 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
373
374 #Sending non matching packet (only dl_src is different) , verify Packetin event gets triggered.
375 pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:02',dl_dst='00:01:01:01:01:02');
376 self.dataplane.send(of_ports[0], str(pkt2))
377
378 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
379 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
380
381 #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered.
382 pkt2 = simple_eth_packet(dl_type=0x0806,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02');
383 self.dataplane.send(of_ports[0], str(pkt2))
384
385 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
386 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
387
388class IpTos(base_tests.SimpleDataPlane):
389
390 """"Verify match on single Header Field Field -- Type of service"""
391
392 def runTest(self):
393
394 logging.info("Running Ip_Tos test")
395
396 of_ports = config["port_map"].keys()
397 of_ports.sort()
398 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
399
400 #Clear Switch State
401 rv = delete_all_flows(self.controller)
402 self.assertEqual(rv, 0, "Failed to delete all flows")
403
404 logging.info("Inserting a flow with match on Ip_Tos ")
405 logging.info("Sending matching and non-matching tcp/ip packets")
406 logging.info("Verifying only matching packets implements the action specified in the flow")
407
408 #Create a flow matching on VLAN Priority
409 (pkt,match) = match_ip_tos(self,of_ports)
410
411 #Send Packet matching the flow
412 self.dataplane.send(of_ports[0], str(pkt))
413
414 #Verify packet implements the action specified in the flow
415 egress_port=of_ports[1]
416 no_ports=set(of_ports).difference([egress_port])
417 yes_ports = of_ports[1]
418 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
419
420 #Create a non-matching packet , verify packet_in get generated
421 pkt2 = simple_tcp_packet(ip_tos=2);
422 self.dataplane.send(of_ports[0], str(pkt2))
423 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
424 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
425
426class IpProtocol(base_tests.SimpleDataPlane):
427
428 """"Verify match on single Header Field Field -- Ip Protocol"""
429
430 def runTest(self):
431
432 logging.info("Running Ip Protocol test")
433
434 of_ports = config["port_map"].keys()
435 of_ports.sort()
436 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
437
438 #Clear Switch State
439 rv = delete_all_flows(self.controller)
440 self.assertEqual(rv, 0, "Failed to delete all flows")
441
442 logging.info("Inserting a flow with match on Ip Protocol ")
443 logging.info("Sending matching and non-matching tcp/ip packets")
444 logging.info("Verifying only matching packets implements the action specified in the flow")
445
446 #Create a flow matching on VLAN Priority
447 (pkt,match) = match_ip_protocol(self,of_ports)
448
449 #Send Packet matching the flow
450 self.dataplane.send(of_ports[0], str(pkt))
451
452 #Verify packet implements the action specified in the flow
453 egress_port=of_ports[1]
454 no_ports=set(of_ports).difference([egress_port])
455 yes_ports = of_ports[1]
456 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
457
458 #Create a non-matching packet , verify packet_in get generated
459 pkt2 = simple_icmp_packet();
460 self.dataplane.send(of_ports[0], str(pkt2))
461 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
462 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
463
464
465class TcpSrcPort(base_tests.SimpleDataPlane):
466
467 """Verify match on Single header field -- Tcp Source Port, """
468
469 def runTest(self):
470
471 logging.info("Running Tcp Src Port test")
472
473 of_ports = config["port_map"].keys()
474 of_ports.sort()
475 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
476
477 #Clear Switch State
478 rc = delete_all_flows(self.controller)
479 self.assertEqual(rc, 0, "Failed to delete all flows")
480
481 logging.info("Inserting a flow with match on Tcp Tcp Source Port ")
482 logging.info("Sending matching and non-matching tcp packets")
483 logging.info("Verifying matching packets implements the action specified in the flow")
484
485 (pkt,match) = match_tcp_src(self,of_ports)
486
487 #Sending packet matching the tcp_sport, verify it implements the action
488 self.dataplane.send(of_ports[0], str(pkt))
489
490 #Verify packet implements the action specified in the flow
491 egress_port=of_ports[1]
492 no_ports=set(of_ports).difference([egress_port])
493 yes_ports = of_ports[1]
494 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
495
496 #Sending non matching packet , verify Packetin event gets triggered.
497 pkt2 = simple_tcp_packet(tcp_sport=540);
498 self.dataplane.send(of_ports[0], str(pkt2))
499
500 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
501 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
502
503class TcpDstPort(base_tests.SimpleDataPlane):
504
505 """Verify match on Single header field -- Tcp Destination Port """
506
507 def runTest(self):
508
509 logging.info("Running Tcp Destination Port test")
510
511 of_ports = config["port_map"].keys()
512 of_ports.sort()
513 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
514
515 #Clear Switch State
516 rc = delete_all_flows(self.controller)
517 self.assertEqual(rc, 0, "Failed to delete all flows")
518
519 logging.info("Inserting a flow with match on Tcp Destination Port ")
520 logging.info("Sending matching and non-matching packets")
521 logging.info("Verifying matching packets implements the action specified in the flow")
522
523 (pkt,match) = match_tcp_dst(self,of_ports)
524
525 #Sending packet matching the tcp_dport, verify it implements the action
526 self.dataplane.send(of_ports[0], str(pkt))
527
528 #Verify packet implements the action specified in the flow
529 egress_port=of_ports[1]
530 no_ports=set(of_ports).difference([egress_port])
531 yes_ports = of_ports[1]
532 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
533
534 #Sending non matching packet , verify Packetin event gets triggered.
535 pkt2 = simple_tcp_packet(tcp_dport=541);
536 self.dataplane.send(of_ports[0], str(pkt2))
537
538 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=10)
539 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
540
541
542class ExactMatch(base_tests.SimpleDataPlane):
543
544 """Verify match on Single header field -- Exact Match """
545
546 def runTest(self):
547
548 logging.info("Running Tcp Exact Match test")
549
550 of_ports = config["port_map"].keys()
551 of_ports.sort()
552 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
553
554 #Clear Switch State
555 rc = delete_all_flows(self.controller)
556 self.assertEqual(rc, 0, "Failed to delete all flows")
557
558 logging.info("Inserting a flow with match for Exact Match ")
559 logging.info("Sending matching and non-matching packets")
560 logging.info("Verifying matching packets implements the action specified in the flow")
561
562 (pkt,match) = exact_match(self,of_ports)
563
564 #Sending packet matching all the fields of a tcp_packet, verify it implements the action
565 self.dataplane.send(of_ports[0], str(pkt))
566
567 #Verify packet implements the action specified in the flow
568 egress_port=of_ports[1]
569 no_ports=set(of_ports).difference([egress_port])
570 yes_ports = of_ports[1]
571 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
572
573 #Sending non matching packet , verify Packetin event gets triggered.
574 pkt2 = simple_tcp_packet(tcp_sport=540);
575 self.dataplane.send(of_ports[0], str(pkt2))
576
577 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
578 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
579
580
581class MultipleHeaderFieldL4(base_tests.SimpleDataPlane):
582
583 """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """
584
585 def runTest(self):
586
587 logging.info("Running Multiple Header Field L4 test")
588
589 of_ports = config["port_map"].keys()
590 of_ports.sort()
591 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
592
593 #Clear Switch State
594 rc = delete_all_flows(self.controller)
595 self.assertEqual(rc, 0, "Failed to delete all flows")
596
597 logging.info("Inserting a flow with match on Multiple Header Field L4 ")
598 logging.info("Sending matching and non-matching packets")
599 logging.info("Verifying matching packets implements the action specified in the flow")
600
601 (pkt,match) = match_mul_l4(self,of_ports)
602
603 #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
604 self.dataplane.send(of_ports[0], str(pkt))
605
606 #Verify packet implements the action specified in the flow
607 egress_port=of_ports[1]
608 no_ports=set(of_ports).difference([egress_port])
609 yes_ports = of_ports[1]
610 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
611
612 #Sending non matching packet , verify Packetin event gets triggered.
613 pkt2 = simple_tcp_packet(tcp_sport=540,tcp_dport=541);
614 self.dataplane.send(of_ports[0], str(pkt2))
615
616 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
617 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
618
619
620class ExactMatchPrio(base_tests.SimpleDataPlane):
621
622 """Verify that Exact Match has highest priority """
623
624 def runTest(self):
625
626 logging.info("Running Exact Match High Priority test")
627
628 of_ports = config["port_map"].keys()
629 of_ports.sort()
630 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
631
632 #Clear Switch State
633 rc = delete_all_flows(self.controller)
634 self.assertEqual(rc, 0, "Failed to delete all flows")
635
636 logging.info("Inserting a flow with Exact Match (low priority)")
637 logging.info("Inserting an overlapping wildcarded flow (higher priority)")
638 logging.info("Sending packets matching both the flows ")
639 logging.info("Verifying matching packets implements the action specified in the exact match flow")
640
641 #Insert two Overlapping Flows : Exact Match and Wildcard All.
642 (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
643 (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
644
645 #Sending packet matching both the flows ,
646 self.dataplane.send(of_ports[0], str(pkt2))
647
648 #verify it implements the action specified in Exact Match Flow
649 egress_port=of_ports[2]
650 no_ports=set(of_ports).difference([egress_port])
651 yes_ports = egress_port
652 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
653
654
655class WildcardMatchPrio(base_tests.SimpleDataPlane):
656
657 """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
658
659 def runTest(self):
660
661 logging.info("Running Wildcard Match High Priority test")
662
663 of_ports = config["port_map"].keys()
664 of_ports.sort()
665 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
666
667 #Clear Switch State
668 rc = delete_all_flows(self.controller)
669 self.assertEqual(rc, 0, "Failed to delete all flows")
670
671 logging.info("Inserting two wildcarded flows with priorities ")
672 logging.info("Sending packets matching the flows")
673 logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
674
675 (pkt,match) = wildcard_all(self,of_ports,priority=20)
676 (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
677
678 #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
679 self.dataplane.send(of_ports[0], str(pkt1))
680
681 egress_port=of_ports[1]
682 no_ports=set(of_ports).difference([egress_port])
683 yes_ports = of_ports[1]
684 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
685
686
687
688
689