blob: 105b17885c54dc8c5d68922f3d4bed366dba792b [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
Rich Lanecd97d3d2013-01-07 18:50:06 -080013from oftest import config
ShreyaPandita6fbff252012-11-13 16:56:48 -050014import oftest.controller as controller
15import oftest.cstruct as ofp
16import oftest.message as message
17import oftest.dataplane as dataplane
18import oftest.action as action
19import oftest.parse as parse
20import oftest.base_tests as base_tests
21import time
22
23from oftest.testutils import *
24from time import sleep
25from FuncUtils import *
26
ShreyaPanditaefdff312012-11-21 13:35:34 -050027
ShreyaPandita6fbff252012-11-13 16:56:48 -050028
29class AllWildcardMatch(base_tests.SimpleDataPlane):
30
31 """Verify for an all wildcarded flow all the injected packets would match that flow"""
32
33 def runTest(self):
34
35 logging.info("Running All Wildcard Match test")
36
37 of_ports = config["port_map"].keys()
38 of_ports.sort()
39 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
40
41 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080042 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -050043
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
Rich Lane32bf9482013-01-03 17:26:30 -080098 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -050099
ShreyaPanditaefdff312012-11-21 13:35:34 -0500100 egress_port=of_ports[1]
101 no_ports=set(of_ports).difference([egress_port])
102 yes_ports = of_ports[1]
103
ShreyaPandita6fbff252012-11-13 16:56:48 -0500104 logging.info("Inserting a flow with match on Ethernet Source Address ")
105 logging.info("Sending matching and non-matching ethernet packets")
106 logging.info("Verifying only matching packets implements the action specified in the flow")
107
108 #Insert a Match On Ethernet Src Address flow
109 (pkt,match) = match_ethernet_src_address(self,of_ports)
110
111 #Sending packet matching the flow, verify it implements the action
112 self.dataplane.send(of_ports[0], str(pkt))
113
114 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500115 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
116
117 #Sending non matching packet , verify Packetin event gets triggered.
118 pkt2 = simple_eth_packet(dl_src='00:01:01:01:01:02');
119 self.dataplane.send(of_ports[0], str(pkt2))
120
121 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
122 self.assertTrue(response is not None, "PacketIn not received for non matching packets")
123
124class EthernetDstAddress(base_tests.SimpleDataPlane):
125
126 """Verify match on single Header Field Field -- Ethernet Dst Address """
127
128 def runTest(self):
129
130 logging.info("Running Ethernet Dst Address test")
131
132 of_ports = config["port_map"].keys()
133 of_ports.sort()
134 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
135
136 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800137 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500138
ShreyaPanditaefdff312012-11-21 13:35:34 -0500139 egress_port=of_ports[1]
140 no_ports=set(of_ports).difference([egress_port])
141 yes_ports = of_ports[1]
142
ShreyaPandita6fbff252012-11-13 16:56:48 -0500143 logging.info("Inserting a flow with match on Ethernet Destination Address ")
144 logging.info("Sending matching and non-matching ethernet packets")
145 logging.info("Verifying only matching packets implements the action specified in the flow")
146
147 #Insert a Match on Destination Address flow
148 (pkt,match) = match_ethernet_dst_address(self,of_ports)
149
150 #Send Packet matching the flow
151 self.dataplane.send(of_ports[0], str(pkt))
152
153 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500154 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
155
156 #Send Non-matching packet
157 pkt2 = simple_eth_packet(dl_dst='00:01:01:01:01:02');
158 self.dataplane.send(of_ports[0], str(pkt2))
159
160 #Verify PacketIn event gets triggered
161 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
162 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
163
164
165class EthernetType(base_tests.SimpleDataPlane):
166
167 """Verify match on single header field -- Ethernet Type """
168
169 def runTest(self):
170
171 logging.info("Running Ethernet Type test")
172
173 of_ports = config["port_map"].keys()
174 of_ports.sort()
175 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
176
177 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800178 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500179
ShreyaPanditaefdff312012-11-21 13:35:34 -0500180 egress_port=of_ports[1]
181 no_ports=set(of_ports).difference([egress_port])
182 yes_ports = of_ports[1]
183
ShreyaPandita6fbff252012-11-13 16:56:48 -0500184 logging.info("Inserting a flow with match on Ethernet Type ")
185 logging.info("Sending matching and non-matching ethernet packets")
186 logging.info("Verifying only matching packets implements the action specified in the flow")
187
188 #Insert a Match on Ethernet-Type flow
189 (pkt,match) = match_ethernet_type(self,of_ports)
190
191 #Sending packet matching the flow
192 self.dataplane.send(of_ports[0], str(pkt))
193
194 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500195 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
196
197 #Sending non matching packet ,
198 pkt2 = simple_eth_packet(dl_type=0x0806);
199 self.dataplane.send(of_ports[0], str(pkt2))
200
201 #verify Packetin event gets triggered.
202 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
203 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
204
205
206class IngressPort(base_tests.SimpleDataPlane):
207
208 """Verify match on single Header Field Field -- In_port """
209
210 def runTest(self):
211
212 logging.info("Running Ingress Port test")
213
214 of_ports = config["port_map"].keys()
215 of_ports.sort()
216 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
217
218 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800219 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500220
ShreyaPanditaefdff312012-11-21 13:35:34 -0500221 egress_port=of_ports[1]
222 no_ports=set(of_ports).difference([egress_port])
223 yes_ports = of_ports[1]
224
ShreyaPandita6fbff252012-11-13 16:56:48 -0500225 logging.info("Inserting a flow with match on Ingress Port ")
226 logging.info("Sending matching and non-matching packets")
227 logging.info("Verifying only matching packets implements the action specified in the flow")
228
229 #Insert a Match on Ingress Port FLow
230 (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0)
231
232 #Send Packet matching the flow i.e on in_port specified in the flow
233 self.dataplane.send(of_ports[0], str(pkt))
234
235 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500236 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
237
238 #Send Non-Matching Packet
239 self.dataplane.send(of_ports[1],str(pkt))
240
241 #Verify PacketIn event gets triggered
242 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
243 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
244
245class VlanId(base_tests.SimpleDataPlane):
246
247 """Verify match on single Header Field Field -- Vlan Id """
248
249 def runTest(self):
250
251 of_ports = config["port_map"].keys()
252 of_ports.sort()
253 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
254
255 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800256 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500257
ShreyaPanditaefdff312012-11-21 13:35:34 -0500258 egress_port=of_ports[1]
259 no_ports=set(of_ports).difference([egress_port])
260 yes_ports = of_ports[1]
261
ShreyaPandita6fbff252012-11-13 16:56:48 -0500262 logging.info("Inserting a flow with match on VLAN ID ")
263 logging.info("Sending matching and non-matching tagged packets")
264 logging.info("Verifying matching packets implements the action specified in the flow")
265
266 #Create a flow with match on Vlan Id
267 (pkt,match) = match_vlan_id(self,of_ports)
268
269 #Send tagged packet matching the flow i.e packet with same vlan id as in flow
270 self.dataplane.send(of_ports[0], str(pkt))
271
272 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500273 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
274
275 #Send Non-matching packet, i.e packet with different Vlan Id
276 pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=4);
277 self.dataplane.send(of_ports[0], str(pkt2))
278
279 #Verify PacketIn event gets triggered
280 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
281 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
282
283class VlanPCP(base_tests.SimpleDataPlane):
284
285 """"Verify match on single Header Field Field -- Vlan Priority"""
286
287 def runTest(self):
288
289 logging.info("Running VlanPCP1 test")
290
291 of_ports = config["port_map"].keys()
292 of_ports.sort()
293 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
294
295 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800296 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500297
298 egress_port=of_ports[1]
299 no_ports=set(of_ports).difference([egress_port])
300 yes_ports = of_ports[1]
301
ShreyaPandita6fbff252012-11-13 16:56:48 -0500302 logging.info("Inserting a flow with match on VLAN Priority ")
303 logging.info("Sending matching and non-matching tagged packets")
304 logging.info("Verifying matching packet implements the action specified in the flow")
305
306 #Create a flow matching on VLAN Priority
307 (pkt,match) = match_vlan_pcp(self,of_ports)
308
309 #Send tagged Packet matching the flow
310 self.dataplane.send(of_ports[0], str(pkt))
311
312 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500313 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
314
315 #Send tagged packet with same vlan_id but different vlan priority
316 pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=20);
ShreyaPanditaefdff312012-11-21 13:35:34 -0500317 self.dataplane.send(of_ports[0], str(pkt2))
318
319 #Verify Packet_In event gets triggered
320 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
321 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
ShreyaPandita6fbff252012-11-13 16:56:48 -0500322
323class MultipleHeaderFieldL2(base_tests.SimpleDataPlane):
324
325 """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """
326
327 def runTest(self):
328
329 logging.info("Running Multiple Header Field L2 test")
330
331 of_ports = config["port_map"].keys()
332 of_ports.sort()
333 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
334
335 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800336 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500337
ShreyaPanditaefdff312012-11-21 13:35:34 -0500338 egress_port=of_ports[1]
339 no_ports=set(of_ports).difference([egress_port])
340 yes_ports = of_ports[1]
341
ShreyaPandita6fbff252012-11-13 16:56:48 -0500342 logging.info("Inserting a flow with match on Multiple Header Fields in L2 ")
343 logging.info("Sending matching and non-matching packets")
344 logging.info("Verifying matching packets implements the action specified in the flow")
345
346 (pkt,match) = match_mul_l2(self,of_ports)
347
348 #Send eth packet matching the dl_type field, verify it implements the action
349 self.dataplane.send(of_ports[0], str(pkt))
350
351 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500352 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
353
354 #Sending non matching packet (only dl_dst is different) , verify Packetin event gets triggered.
355 pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:02:01:01');
356 self.dataplane.send(of_ports[0], str(pkt2))
357
358 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
359 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
360
361 #Sending non matching packet (only dl_src is different) , verify Packetin event gets triggered.
362 pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:02',dl_dst='00:01:01:01:01:02');
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 ether_type is different) , verify Packetin event gets triggered.
369 pkt2 = simple_eth_packet(dl_type=0x0806,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02');
370 self.dataplane.send(of_ports[0], str(pkt2))
371
ShreyaPanditaefdff312012-11-21 13:35:34 -0500372 #Verify packet_in event gets triggered
ShreyaPandita6fbff252012-11-13 16:56:48 -0500373 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
374 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
375
376class IpTos(base_tests.SimpleDataPlane):
377
378 """"Verify match on single Header Field Field -- Type of service"""
379
380 def runTest(self):
381
382 logging.info("Running Ip_Tos test")
383
384 of_ports = config["port_map"].keys()
385 of_ports.sort()
386 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
387
388 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800389 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500390
391 egress_port=of_ports[1]
392 no_ports=set(of_ports).difference([egress_port])
393 yes_ports = of_ports[1]
394
ShreyaPandita6fbff252012-11-13 16:56:48 -0500395 logging.info("Inserting a flow with match on Ip_Tos ")
396 logging.info("Sending matching and non-matching tcp/ip packets")
397 logging.info("Verifying only matching packets implements the action specified in the flow")
398
399 #Create a flow matching on VLAN Priority
400 (pkt,match) = match_ip_tos(self,of_ports)
401
402 #Send Packet matching the flow
403 self.dataplane.send(of_ports[0], str(pkt))
404
405 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500406 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
407
408 #Create a non-matching packet , verify packet_in get generated
Rich Laneb5c73792012-12-03 17:12:32 -0800409 pkt2 = simple_tcp_packet(ip_tos=4);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500410 self.dataplane.send(of_ports[0], str(pkt2))
411 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
412 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
413
414class IpProtocol(base_tests.SimpleDataPlane):
415
416 """"Verify match on single Header Field Field -- Ip Protocol"""
417
418 def runTest(self):
419
420 logging.info("Running Ip Protocol test")
421
422 of_ports = config["port_map"].keys()
423 of_ports.sort()
424 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
425
426 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800427 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500428
429 egress_port=of_ports[1]
430 no_ports=set(of_ports).difference([egress_port])
431 yes_ports = of_ports[1]
432
ShreyaPandita6fbff252012-11-13 16:56:48 -0500433 logging.info("Inserting a flow with match on Ip Protocol ")
434 logging.info("Sending matching and non-matching tcp/ip packets")
435 logging.info("Verifying only matching packets implements the action specified in the flow")
436
437 #Create a flow matching on VLAN Priority
438 (pkt,match) = match_ip_protocol(self,of_ports)
439
440 #Send Packet matching the flow
441 self.dataplane.send(of_ports[0], str(pkt))
442
443 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500444 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
445
446 #Create a non-matching packet , verify packet_in get generated
447 pkt2 = simple_icmp_packet();
448 self.dataplane.send(of_ports[0], str(pkt2))
449 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
450 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
451
452
453class TcpSrcPort(base_tests.SimpleDataPlane):
454
455 """Verify match on Single header field -- Tcp Source Port, """
456
457 def runTest(self):
458
459 logging.info("Running Tcp Src Port test")
460
461 of_ports = config["port_map"].keys()
462 of_ports.sort()
463 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
464
465 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800466 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500467
ShreyaPanditaefdff312012-11-21 13:35:34 -0500468 egress_port=of_ports[1]
469 no_ports=set(of_ports).difference([egress_port])
470 yes_ports = of_ports[1]
471
ShreyaPandita6fbff252012-11-13 16:56:48 -0500472 logging.info("Inserting a flow with match on Tcp Tcp Source Port ")
473 logging.info("Sending matching and non-matching tcp packets")
474 logging.info("Verifying matching packets implements the action specified in the flow")
475
476 (pkt,match) = match_tcp_src(self,of_ports)
477
478 #Sending packet matching the tcp_sport, verify it implements the action
479 self.dataplane.send(of_ports[0], str(pkt))
480
481 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500482 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
483
484 #Sending non matching packet , verify Packetin event gets triggered.
485 pkt2 = simple_tcp_packet(tcp_sport=540);
486 self.dataplane.send(of_ports[0], str(pkt2))
487
488 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
489 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
490
491class TcpDstPort(base_tests.SimpleDataPlane):
492
493 """Verify match on Single header field -- Tcp Destination Port """
494
495 def runTest(self):
496
497 logging.info("Running Tcp Destination Port test")
498
499 of_ports = config["port_map"].keys()
500 of_ports.sort()
501 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
502
503 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800504 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500505
ShreyaPanditaefdff312012-11-21 13:35:34 -0500506 egress_port=of_ports[1]
507 no_ports=set(of_ports).difference([egress_port])
508 yes_ports = of_ports[1]
509
ShreyaPandita6fbff252012-11-13 16:56:48 -0500510 logging.info("Inserting a flow with match on Tcp Destination Port ")
511 logging.info("Sending matching and non-matching packets")
512 logging.info("Verifying matching packets implements the action specified in the flow")
513
514 (pkt,match) = match_tcp_dst(self,of_ports)
515
516 #Sending packet matching the tcp_dport, verify it implements the action
517 self.dataplane.send(of_ports[0], str(pkt))
518
519 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500520 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
521
522 #Sending non matching packet , verify Packetin event gets triggered.
523 pkt2 = simple_tcp_packet(tcp_dport=541);
524 self.dataplane.send(of_ports[0], str(pkt2))
525
526 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=10)
527 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
528
529
530class ExactMatch(base_tests.SimpleDataPlane):
531
532 """Verify match on Single header field -- Exact Match """
533
534 def runTest(self):
535
536 logging.info("Running Tcp Exact Match test")
537
538 of_ports = config["port_map"].keys()
539 of_ports.sort()
540 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
541
542 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800543 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500544
ShreyaPanditaefdff312012-11-21 13:35:34 -0500545 egress_port=of_ports[1]
546 no_ports=set(of_ports).difference([egress_port])
547 yes_ports = of_ports[1]
548
ShreyaPandita6fbff252012-11-13 16:56:48 -0500549 logging.info("Inserting a flow with match for Exact Match ")
550 logging.info("Sending matching and non-matching packets")
551 logging.info("Verifying matching packets implements the action specified in the flow")
552
553 (pkt,match) = exact_match(self,of_ports)
554
555 #Sending packet matching all the fields of a tcp_packet, verify it implements the action
556 self.dataplane.send(of_ports[0], str(pkt))
557
558 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500559 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
560
561 #Sending non matching packet , verify Packetin event gets triggered.
562 pkt2 = simple_tcp_packet(tcp_sport=540);
563 self.dataplane.send(of_ports[0], str(pkt2))
564
565 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
566 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
567
568
569class MultipleHeaderFieldL4(base_tests.SimpleDataPlane):
570
571 """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """
572
573 def runTest(self):
574
575 logging.info("Running Multiple Header Field L4 test")
576
577 of_ports = config["port_map"].keys()
578 of_ports.sort()
579 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
580
581 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800582 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500583
ShreyaPanditaefdff312012-11-21 13:35:34 -0500584 egress_port=of_ports[1]
585 no_ports=set(of_ports).difference([egress_port])
586 yes_ports = of_ports[1]
587
ShreyaPandita6fbff252012-11-13 16:56:48 -0500588 logging.info("Inserting a flow with match on Multiple Header Field L4 ")
589 logging.info("Sending matching and non-matching packets")
590 logging.info("Verifying matching packets implements the action specified in the flow")
591
592 (pkt,match) = match_mul_l4(self,of_ports)
593
594 #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
595 self.dataplane.send(of_ports[0], str(pkt))
596
597 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500598 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
599
ShreyaPanditaefdff312012-11-21 13:35:34 -0500600 #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered.
601 pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541);
602 self.dataplane.send(of_ports[0], str(pkt2))
603
604 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
605 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
606
607 #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered.
608 pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500609 self.dataplane.send(of_ports[0], str(pkt2))
610
611 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
612 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
613
614
615class ExactMatchPrio(base_tests.SimpleDataPlane):
616
617 """Verify that Exact Match has highest priority """
618
619 def runTest(self):
620
621 logging.info("Running Exact Match High Priority test")
622
623 of_ports = config["port_map"].keys()
624 of_ports.sort()
625 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
626
627 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800628 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500629
Rich Laneed130652012-12-31 17:35:33 -0800630 egress_port=of_ports[2]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500631 no_ports=set(of_ports).difference([egress_port])
Rich Laneed130652012-12-31 17:35:33 -0800632 yes_ports = egress_port
ShreyaPanditaefdff312012-11-21 13:35:34 -0500633
ShreyaPandita6fbff252012-11-13 16:56:48 -0500634 logging.info("Inserting a flow with Exact Match (low priority)")
635 logging.info("Inserting an overlapping wildcarded flow (higher priority)")
636 logging.info("Sending packets matching both the flows ")
637 logging.info("Verifying matching packets implements the action specified in the exact match flow")
638
639 #Insert two Overlapping Flows : Exact Match and Wildcard All.
640 (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
641 (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
642
643 #Sending packet matching both the flows ,
644 self.dataplane.send(of_ports[0], str(pkt2))
645
646 #verify it implements the action specified in Exact Match Flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500647 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
648
649
650class WildcardMatchPrio(base_tests.SimpleDataPlane):
651
652 """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
653
654 def runTest(self):
655
656 logging.info("Running Wildcard Match High Priority test")
657
658 of_ports = config["port_map"].keys()
659 of_ports.sort()
660 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
661
662 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800663 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500664
ShreyaPanditaefdff312012-11-21 13:35:34 -0500665 egress_port=of_ports[1]
666 no_ports=set(of_ports).difference([egress_port])
667 yes_ports = of_ports[1]
668
ShreyaPandita6fbff252012-11-13 16:56:48 -0500669 logging.info("Inserting two wildcarded flows with priorities ")
670 logging.info("Sending packets matching the flows")
671 logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
672
673 (pkt,match) = wildcard_all(self,of_ports,priority=20)
674 (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
675
676 #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
677 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500678 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
679
680
681
682
683