blob: 9edd4c0bce8a4b1531cfbbc5bb9f70376c5c7cf4 [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
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
ShreyaPanditaefdff312012-11-21 13:35:34 -050047 egress_port=of_ports[1]
48 no_ports=set(of_ports).difference([egress_port])
49 yes_ports = of_ports[1]
50
ShreyaPandita6fbff252012-11-13 16:56:48 -050051 #Insert an All Wildcarded flow.
52 wildcard_all(self,of_ports)
53
54 #check for different match fields and verify packet implements the action specified in the flow
55 pkt1 = simple_tcp_packet(dl_src="00:01:01:01:01:01");
56 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -050057 receive_pkt_check(self.dataplane,pkt1,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050058
ShreyaPandita6fbff252012-11-13 16:56:48 -050059 pkt2 = simple_tcp_packet(dl_dst="00:01:01:01:01:01");
60 self.dataplane.send(of_ports[0], str(pkt2))
ShreyaPandita6fbff252012-11-13 16:56:48 -050061 receive_pkt_check(self.dataplane,pkt2,[yes_ports],no_ports,self)
62
63 pkt3 = simple_tcp_packet(ip_src="192.168.2.1");
64 self.dataplane.send(of_ports[0], str(pkt3))
ShreyaPandita6fbff252012-11-13 16:56:48 -050065 receive_pkt_check(self.dataplane,pkt3,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050066
ShreyaPandita6fbff252012-11-13 16:56:48 -050067 pkt4 = simple_tcp_packet(ip_dst="192.168.2.2");
68 self.dataplane.send(of_ports[0], str(pkt4))
ShreyaPandita6fbff252012-11-13 16:56:48 -050069 receive_pkt_check(self.dataplane,pkt4,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050070
ShreyaPandita6fbff252012-11-13 16:56:48 -050071 pkt5 = simple_tcp_packet(ip_tos=2);
72 self.dataplane.send(of_ports[0], str(pkt5))
ShreyaPandita6fbff252012-11-13 16:56:48 -050073 receive_pkt_check(self.dataplane,pkt5,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050074
ShreyaPandita6fbff252012-11-13 16:56:48 -050075 pkt6 = simple_tcp_packet(tcp_sport=8080);
76 self.dataplane.send(of_ports[0], str(pkt6))
ShreyaPandita6fbff252012-11-13 16:56:48 -050077 receive_pkt_check(self.dataplane,pkt6,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050078
ShreyaPandita6fbff252012-11-13 16:56:48 -050079 pkt7 = simple_tcp_packet(tcp_dport=8081);
80 self.dataplane.send(of_ports[0], str(pkt7))
ShreyaPandita6fbff252012-11-13 16:56:48 -050081 receive_pkt_check(self.dataplane,pkt7,[yes_ports],no_ports,self)
82
83
84
85class EthernetSrcAddress(base_tests.SimpleDataPlane):
86
87 """Verify match on single header field -- Ethernet Src Address """
88
89 def runTest(self):
90
91 logging.info("Running Ethernet Src Address test")
92
93 of_ports = config["port_map"].keys()
94 of_ports.sort()
95 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
96
97 #Clear Switch State
98 rc = delete_all_flows(self.controller)
99 self.assertEqual(rc, 0, "Failed to delete all flows")
100
ShreyaPanditaefdff312012-11-21 13:35:34 -0500101 egress_port=of_ports[1]
102 no_ports=set(of_ports).difference([egress_port])
103 yes_ports = of_ports[1]
104
ShreyaPandita6fbff252012-11-13 16:56:48 -0500105 logging.info("Inserting a flow with match on Ethernet Source Address ")
106 logging.info("Sending matching and non-matching ethernet packets")
107 logging.info("Verifying only matching packets implements the action specified in the flow")
108
109 #Insert a Match On Ethernet Src Address flow
110 (pkt,match) = match_ethernet_src_address(self,of_ports)
111
112 #Sending packet matching the flow, verify it implements the action
113 self.dataplane.send(of_ports[0], str(pkt))
114
115 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500116 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
117
118 #Sending non matching packet , verify Packetin event gets triggered.
119 pkt2 = simple_eth_packet(dl_src='00:01:01:01:01:02');
120 self.dataplane.send(of_ports[0], str(pkt2))
121
122 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
123 self.assertTrue(response is not None, "PacketIn not received for non matching packets")
124
125class EthernetDstAddress(base_tests.SimpleDataPlane):
126
127 """Verify match on single Header Field Field -- Ethernet Dst Address """
128
129 def runTest(self):
130
131 logging.info("Running Ethernet Dst Address test")
132
133 of_ports = config["port_map"].keys()
134 of_ports.sort()
135 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
136
137 #Clear Switch State
138 rv = delete_all_flows(self.controller)
139 self.assertEqual(rv, 0, "Failed to delete all flows")
140
ShreyaPanditaefdff312012-11-21 13:35:34 -0500141 egress_port=of_ports[1]
142 no_ports=set(of_ports).difference([egress_port])
143 yes_ports = of_ports[1]
144
ShreyaPandita6fbff252012-11-13 16:56:48 -0500145 logging.info("Inserting a flow with match on Ethernet Destination Address ")
146 logging.info("Sending matching and non-matching ethernet packets")
147 logging.info("Verifying only matching packets implements the action specified in the flow")
148
149 #Insert a Match on Destination Address flow
150 (pkt,match) = match_ethernet_dst_address(self,of_ports)
151
152 #Send Packet matching the flow
153 self.dataplane.send(of_ports[0], str(pkt))
154
155 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500156 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
157
158 #Send Non-matching packet
159 pkt2 = simple_eth_packet(dl_dst='00:01:01:01:01:02');
160 self.dataplane.send(of_ports[0], str(pkt2))
161
162 #Verify PacketIn event gets triggered
163 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
164 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
165
166
167class EthernetType(base_tests.SimpleDataPlane):
168
169 """Verify match on single header field -- Ethernet Type """
170
171 def runTest(self):
172
173 logging.info("Running Ethernet Type test")
174
175 of_ports = config["port_map"].keys()
176 of_ports.sort()
177 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
178
179 #Clear Switch State
180 rc = delete_all_flows(self.controller)
181 self.assertEqual(rc, 0, "Failed to delete all flows")
182
ShreyaPanditaefdff312012-11-21 13:35:34 -0500183 egress_port=of_ports[1]
184 no_ports=set(of_ports).difference([egress_port])
185 yes_ports = of_ports[1]
186
ShreyaPandita6fbff252012-11-13 16:56:48 -0500187 logging.info("Inserting a flow with match on Ethernet Type ")
188 logging.info("Sending matching and non-matching ethernet packets")
189 logging.info("Verifying only matching packets implements the action specified in the flow")
190
191 #Insert a Match on Ethernet-Type flow
192 (pkt,match) = match_ethernet_type(self,of_ports)
193
194 #Sending packet matching the flow
195 self.dataplane.send(of_ports[0], str(pkt))
196
197 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500198 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
199
200 #Sending non matching packet ,
201 pkt2 = simple_eth_packet(dl_type=0x0806);
202 self.dataplane.send(of_ports[0], str(pkt2))
203
204 #verify Packetin event gets triggered.
205 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
206 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
207
208
209class IngressPort(base_tests.SimpleDataPlane):
210
211 """Verify match on single Header Field Field -- In_port """
212
213 def runTest(self):
214
215 logging.info("Running Ingress Port test")
216
217 of_ports = config["port_map"].keys()
218 of_ports.sort()
219 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
220
221 #Clear Switch State
222 rc = delete_all_flows(self.controller)
223 self.assertEqual(rc, 0, "Failed to delete all flows")
224
ShreyaPanditaefdff312012-11-21 13:35:34 -0500225 egress_port=of_ports[1]
226 no_ports=set(of_ports).difference([egress_port])
227 yes_ports = of_ports[1]
228
ShreyaPandita6fbff252012-11-13 16:56:48 -0500229 logging.info("Inserting a flow with match on Ingress Port ")
230 logging.info("Sending matching and non-matching packets")
231 logging.info("Verifying only matching packets implements the action specified in the flow")
232
233 #Insert a Match on Ingress Port FLow
234 (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0)
235
236 #Send Packet matching the flow i.e on in_port specified in the flow
237 self.dataplane.send(of_ports[0], str(pkt))
238
239 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500240 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
241
242 #Send Non-Matching Packet
243 self.dataplane.send(of_ports[1],str(pkt))
244
245 #Verify PacketIn event gets triggered
246 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
247 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
248
249class VlanId(base_tests.SimpleDataPlane):
250
251 """Verify match on single Header Field Field -- Vlan Id """
252
253 def runTest(self):
254
255 of_ports = config["port_map"].keys()
256 of_ports.sort()
257 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
258
259 #Clear Switch State
260 rc = delete_all_flows(self.controller)
261 self.assertEqual(rc, 0, "Failed to delete all flows")
262
ShreyaPanditaefdff312012-11-21 13:35:34 -0500263 egress_port=of_ports[1]
264 no_ports=set(of_ports).difference([egress_port])
265 yes_ports = of_ports[1]
266
ShreyaPandita6fbff252012-11-13 16:56:48 -0500267 logging.info("Inserting a flow with match on VLAN ID ")
268 logging.info("Sending matching and non-matching tagged packets")
269 logging.info("Verifying matching packets implements the action specified in the flow")
270
271 #Create a flow with match on Vlan Id
272 (pkt,match) = match_vlan_id(self,of_ports)
273
274 #Send tagged packet matching the flow i.e packet with same vlan id as in flow
275 self.dataplane.send(of_ports[0], str(pkt))
276
277 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500278 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
279
280 #Send Non-matching packet, i.e packet with different Vlan Id
281 pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=4);
282 self.dataplane.send(of_ports[0], str(pkt2))
283
284 #Verify PacketIn event gets triggered
285 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
286 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
287
288class VlanPCP(base_tests.SimpleDataPlane):
289
290 """"Verify match on single Header Field Field -- Vlan Priority"""
291
292 def runTest(self):
293
294 logging.info("Running VlanPCP1 test")
295
296 of_ports = config["port_map"].keys()
297 of_ports.sort()
298 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
299
300 #Clear Switch State
301 rv = delete_all_flows(self.controller)
302 self.assertEqual(rv, 0, "Failed to delete all flows")
ShreyaPanditaefdff312012-11-21 13:35:34 -0500303
304 egress_port=of_ports[1]
305 no_ports=set(of_ports).difference([egress_port])
306 yes_ports = of_ports[1]
307
ShreyaPandita6fbff252012-11-13 16:56:48 -0500308 logging.info("Inserting a flow with match on VLAN Priority ")
309 logging.info("Sending matching and non-matching tagged packets")
310 logging.info("Verifying matching packet implements the action specified in the flow")
311
312 #Create a flow matching on VLAN Priority
313 (pkt,match) = match_vlan_pcp(self,of_ports)
314
315 #Send tagged Packet matching the flow
316 self.dataplane.send(of_ports[0], str(pkt))
317
318 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500319 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
320
321 #Send tagged packet with same vlan_id but different vlan priority
322 pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=20);
ShreyaPanditaefdff312012-11-21 13:35:34 -0500323 self.dataplane.send(of_ports[0], str(pkt2))
324
325 #Verify Packet_In event gets triggered
326 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
327 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
ShreyaPandita6fbff252012-11-13 16:56:48 -0500328
329class MultipleHeaderFieldL2(base_tests.SimpleDataPlane):
330
331 """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """
332
333 def runTest(self):
334
335 logging.info("Running Multiple Header Field L2 test")
336
337 of_ports = config["port_map"].keys()
338 of_ports.sort()
339 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
340
341 #Clear Switch State
342 rc = delete_all_flows(self.controller)
343 self.assertEqual(rc, 0, "Failed to delete all flows")
344
ShreyaPanditaefdff312012-11-21 13:35:34 -0500345 egress_port=of_ports[1]
346 no_ports=set(of_ports).difference([egress_port])
347 yes_ports = of_ports[1]
348
ShreyaPandita6fbff252012-11-13 16:56:48 -0500349 logging.info("Inserting a flow with match on Multiple Header Fields in L2 ")
350 logging.info("Sending matching and non-matching packets")
351 logging.info("Verifying matching packets implements the action specified in the flow")
352
353 (pkt,match) = match_mul_l2(self,of_ports)
354
355 #Send eth packet matching the dl_type field, verify it implements the action
356 self.dataplane.send(of_ports[0], str(pkt))
357
358 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500359 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
360
361 #Sending non matching packet (only dl_dst is different) , verify Packetin event gets triggered.
362 pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:02:01:01');
363 self.dataplane.send(of_ports[0], str(pkt2))
364
365 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
366 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
367
368 #Sending non matching packet (only dl_src is different) , verify Packetin event gets triggered.
369 pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:02',dl_dst='00:01:01:01:01:02');
370 self.dataplane.send(of_ports[0], str(pkt2))
371
372 (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
375 #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered.
376 pkt2 = simple_eth_packet(dl_type=0x0806,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02');
377 self.dataplane.send(of_ports[0], str(pkt2))
378
ShreyaPanditaefdff312012-11-21 13:35:34 -0500379 #Verify packet_in event gets triggered
ShreyaPandita6fbff252012-11-13 16:56:48 -0500380 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
381 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
382
383class IpTos(base_tests.SimpleDataPlane):
384
385 """"Verify match on single Header Field Field -- Type of service"""
386
387 def runTest(self):
388
389 logging.info("Running Ip_Tos test")
390
391 of_ports = config["port_map"].keys()
392 of_ports.sort()
393 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
394
395 #Clear Switch State
396 rv = delete_all_flows(self.controller)
397 self.assertEqual(rv, 0, "Failed to delete all flows")
ShreyaPanditaefdff312012-11-21 13:35:34 -0500398
399 egress_port=of_ports[1]
400 no_ports=set(of_ports).difference([egress_port])
401 yes_ports = of_ports[1]
402
ShreyaPandita6fbff252012-11-13 16:56:48 -0500403 logging.info("Inserting a flow with match on Ip_Tos ")
404 logging.info("Sending matching and non-matching tcp/ip packets")
405 logging.info("Verifying only matching packets implements the action specified in the flow")
406
407 #Create a flow matching on VLAN Priority
408 (pkt,match) = match_ip_tos(self,of_ports)
409
410 #Send Packet matching the flow
411 self.dataplane.send(of_ports[0], str(pkt))
412
413 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500414 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
415
416 #Create a non-matching packet , verify packet_in get generated
417 pkt2 = simple_tcp_packet(ip_tos=2);
418 self.dataplane.send(of_ports[0], str(pkt2))
419 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
420 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
421
422class IpProtocol(base_tests.SimpleDataPlane):
423
424 """"Verify match on single Header Field Field -- Ip Protocol"""
425
426 def runTest(self):
427
428 logging.info("Running Ip Protocol test")
429
430 of_ports = config["port_map"].keys()
431 of_ports.sort()
432 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
433
434 #Clear Switch State
435 rv = delete_all_flows(self.controller)
436 self.assertEqual(rv, 0, "Failed to delete all flows")
ShreyaPanditaefdff312012-11-21 13:35:34 -0500437
438 egress_port=of_ports[1]
439 no_ports=set(of_ports).difference([egress_port])
440 yes_ports = of_ports[1]
441
ShreyaPandita6fbff252012-11-13 16:56:48 -0500442 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
ShreyaPandita6fbff252012-11-13 16:56:48 -0500453 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
454
455 #Create a non-matching packet , verify packet_in get generated
456 pkt2 = simple_icmp_packet();
457 self.dataplane.send(of_ports[0], str(pkt2))
458 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
459 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
460
461
462class TcpSrcPort(base_tests.SimpleDataPlane):
463
464 """Verify match on Single header field -- Tcp Source Port, """
465
466 def runTest(self):
467
468 logging.info("Running Tcp Src Port test")
469
470 of_ports = config["port_map"].keys()
471 of_ports.sort()
472 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
473
474 #Clear Switch State
475 rc = delete_all_flows(self.controller)
476 self.assertEqual(rc, 0, "Failed to delete all flows")
477
ShreyaPanditaefdff312012-11-21 13:35:34 -0500478 egress_port=of_ports[1]
479 no_ports=set(of_ports).difference([egress_port])
480 yes_ports = of_ports[1]
481
ShreyaPandita6fbff252012-11-13 16:56:48 -0500482 logging.info("Inserting a flow with match on Tcp Tcp Source Port ")
483 logging.info("Sending matching and non-matching tcp packets")
484 logging.info("Verifying matching packets implements the action specified in the flow")
485
486 (pkt,match) = match_tcp_src(self,of_ports)
487
488 #Sending packet matching the tcp_sport, verify it implements the action
489 self.dataplane.send(of_ports[0], str(pkt))
490
491 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500492 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
493
494 #Sending non matching packet , verify Packetin event gets triggered.
495 pkt2 = simple_tcp_packet(tcp_sport=540);
496 self.dataplane.send(of_ports[0], str(pkt2))
497
498 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
499 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
500
501class TcpDstPort(base_tests.SimpleDataPlane):
502
503 """Verify match on Single header field -- Tcp Destination Port """
504
505 def runTest(self):
506
507 logging.info("Running Tcp Destination Port test")
508
509 of_ports = config["port_map"].keys()
510 of_ports.sort()
511 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
512
513 #Clear Switch State
514 rc = delete_all_flows(self.controller)
515 self.assertEqual(rc, 0, "Failed to delete all flows")
516
ShreyaPanditaefdff312012-11-21 13:35:34 -0500517 egress_port=of_ports[1]
518 no_ports=set(of_ports).difference([egress_port])
519 yes_ports = of_ports[1]
520
ShreyaPandita6fbff252012-11-13 16:56:48 -0500521 logging.info("Inserting a flow with match on Tcp Destination Port ")
522 logging.info("Sending matching and non-matching packets")
523 logging.info("Verifying matching packets implements the action specified in the flow")
524
525 (pkt,match) = match_tcp_dst(self,of_ports)
526
527 #Sending packet matching the tcp_dport, verify it implements the action
528 self.dataplane.send(of_ports[0], str(pkt))
529
530 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500531 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
532
533 #Sending non matching packet , verify Packetin event gets triggered.
534 pkt2 = simple_tcp_packet(tcp_dport=541);
535 self.dataplane.send(of_ports[0], str(pkt2))
536
537 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=10)
538 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
539
540
541class ExactMatch(base_tests.SimpleDataPlane):
542
543 """Verify match on Single header field -- Exact Match """
544
545 def runTest(self):
546
547 logging.info("Running Tcp Exact Match test")
548
549 of_ports = config["port_map"].keys()
550 of_ports.sort()
551 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
552
553 #Clear Switch State
554 rc = delete_all_flows(self.controller)
555 self.assertEqual(rc, 0, "Failed to delete all flows")
556
ShreyaPanditaefdff312012-11-21 13:35:34 -0500557 egress_port=of_ports[1]
558 no_ports=set(of_ports).difference([egress_port])
559 yes_ports = of_ports[1]
560
ShreyaPandita6fbff252012-11-13 16:56:48 -0500561 logging.info("Inserting a flow with match for Exact Match ")
562 logging.info("Sending matching and non-matching packets")
563 logging.info("Verifying matching packets implements the action specified in the flow")
564
565 (pkt,match) = exact_match(self,of_ports)
566
567 #Sending packet matching all the fields of a tcp_packet, verify it implements the action
568 self.dataplane.send(of_ports[0], str(pkt))
569
570 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500571 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
ShreyaPanditaefdff312012-11-21 13:35:34 -0500597 egress_port=of_ports[1]
598 no_ports=set(of_ports).difference([egress_port])
599 yes_ports = of_ports[1]
600
ShreyaPandita6fbff252012-11-13 16:56:48 -0500601 logging.info("Inserting a flow with match on Multiple Header Field L4 ")
602 logging.info("Sending matching and non-matching packets")
603 logging.info("Verifying matching packets implements the action specified in the flow")
604
605 (pkt,match) = match_mul_l4(self,of_ports)
606
607 #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
608 self.dataplane.send(of_ports[0], str(pkt))
609
610 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500611 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
612
ShreyaPanditaefdff312012-11-21 13:35:34 -0500613 #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered.
614 pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541);
615 self.dataplane.send(of_ports[0], str(pkt2))
616
617 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
618 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
619
620 #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered.
621 pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500622 self.dataplane.send(of_ports[0], str(pkt2))
623
624 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
625 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
626
627
628class ExactMatchPrio(base_tests.SimpleDataPlane):
629
630 """Verify that Exact Match has highest priority """
631
632 def runTest(self):
633
634 logging.info("Running Exact Match High Priority test")
635
636 of_ports = config["port_map"].keys()
637 of_ports.sort()
638 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
639
640 #Clear Switch State
641 rc = delete_all_flows(self.controller)
642 self.assertEqual(rc, 0, "Failed to delete all flows")
643
ShreyaPanditaefdff312012-11-21 13:35:34 -0500644 egress_port=of_ports[1]
645 no_ports=set(of_ports).difference([egress_port])
646 yes_ports = of_ports[1]
647
ShreyaPandita6fbff252012-11-13 16:56:48 -0500648 logging.info("Inserting a flow with Exact Match (low priority)")
649 logging.info("Inserting an overlapping wildcarded flow (higher priority)")
650 logging.info("Sending packets matching both the flows ")
651 logging.info("Verifying matching packets implements the action specified in the exact match flow")
652
653 #Insert two Overlapping Flows : Exact Match and Wildcard All.
654 (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
655 (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
656
657 #Sending packet matching both the flows ,
658 self.dataplane.send(of_ports[0], str(pkt2))
659
660 #verify it implements the action specified in Exact Match Flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500661 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
662
663
664class WildcardMatchPrio(base_tests.SimpleDataPlane):
665
666 """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
667
668 def runTest(self):
669
670 logging.info("Running Wildcard Match High Priority test")
671
672 of_ports = config["port_map"].keys()
673 of_ports.sort()
674 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
675
676 #Clear Switch State
677 rc = delete_all_flows(self.controller)
678 self.assertEqual(rc, 0, "Failed to delete all flows")
679
ShreyaPanditaefdff312012-11-21 13:35:34 -0500680 egress_port=of_ports[1]
681 no_ports=set(of_ports).difference([egress_port])
682 yes_ports = of_ports[1]
683
ShreyaPandita6fbff252012-11-13 16:56:48 -0500684 logging.info("Inserting two wildcarded flows with priorities ")
685 logging.info("Sending packets matching the flows")
686 logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
687
688 (pkt,match) = wildcard_all(self,of_ports,priority=20)
689 (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
690
691 #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
692 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500693 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
694
695
696
697
698