blob: 721d68bbdd79102e4a7ef9f7476466f6a30b7555 [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
Rich Laned7b0ffa2013-03-08 15:53:42 -080015import ofp
ShreyaPandita6fbff252012-11-13 16:56:48 -050016import oftest.dataplane as dataplane
ShreyaPandita6fbff252012-11-13 16:56:48 -050017import oftest.parse as parse
18import oftest.base_tests as base_tests
19import time
20
21from oftest.testutils import *
22from time import sleep
23from FuncUtils import *
24
ShreyaPanditaefdff312012-11-21 13:35:34 -050025
ShreyaPandita6fbff252012-11-13 16:56:48 -050026
27class AllWildcardMatch(base_tests.SimpleDataPlane):
28
29 """Verify for an all wildcarded flow all the injected packets would match that flow"""
30
31 def runTest(self):
32
33 logging.info("Running All Wildcard Match test")
34
35 of_ports = config["port_map"].keys()
36 of_ports.sort()
37 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
38
39 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080040 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -050041
42 logging.info("Inserting an all wildcarded flow and sending packets with various match fields")
43 logging.info("Expecting all sent packets to match")
44
ShreyaPanditaefdff312012-11-21 13:35:34 -050045 egress_port=of_ports[1]
46 no_ports=set(of_ports).difference([egress_port])
47 yes_ports = of_ports[1]
48
ShreyaPandita6fbff252012-11-13 16:56:48 -050049 #Insert an All Wildcarded flow.
50 wildcard_all(self,of_ports)
51
52 #check for different match fields and verify packet implements the action specified in the flow
Rich Laned0478ff2013-03-11 12:46:58 -070053 pkt1 = simple_tcp_packet(eth_src="00:01:01:01:01:01");
ShreyaPandita6fbff252012-11-13 16:56:48 -050054 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -050055 receive_pkt_check(self.dataplane,pkt1,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050056
Rich Laned0478ff2013-03-11 12:46:58 -070057 pkt2 = simple_tcp_packet(eth_dst="00:01:01:01:01:01");
ShreyaPandita6fbff252012-11-13 16:56:48 -050058 self.dataplane.send(of_ports[0], str(pkt2))
ShreyaPandita6fbff252012-11-13 16:56:48 -050059 receive_pkt_check(self.dataplane,pkt2,[yes_ports],no_ports,self)
60
61 pkt3 = simple_tcp_packet(ip_src="192.168.2.1");
62 self.dataplane.send(of_ports[0], str(pkt3))
ShreyaPandita6fbff252012-11-13 16:56:48 -050063 receive_pkt_check(self.dataplane,pkt3,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050064
ShreyaPandita6fbff252012-11-13 16:56:48 -050065 pkt4 = simple_tcp_packet(ip_dst="192.168.2.2");
66 self.dataplane.send(of_ports[0], str(pkt4))
ShreyaPandita6fbff252012-11-13 16:56:48 -050067 receive_pkt_check(self.dataplane,pkt4,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050068
ShreyaPandita6fbff252012-11-13 16:56:48 -050069 pkt5 = simple_tcp_packet(ip_tos=2);
70 self.dataplane.send(of_ports[0], str(pkt5))
ShreyaPandita6fbff252012-11-13 16:56:48 -050071 receive_pkt_check(self.dataplane,pkt5,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050072
ShreyaPandita6fbff252012-11-13 16:56:48 -050073 pkt6 = simple_tcp_packet(tcp_sport=8080);
74 self.dataplane.send(of_ports[0], str(pkt6))
ShreyaPandita6fbff252012-11-13 16:56:48 -050075 receive_pkt_check(self.dataplane,pkt6,[yes_ports],no_ports,self)
ShreyaPanditaefdff312012-11-21 13:35:34 -050076
ShreyaPandita6fbff252012-11-13 16:56:48 -050077 pkt7 = simple_tcp_packet(tcp_dport=8081);
78 self.dataplane.send(of_ports[0], str(pkt7))
ShreyaPandita6fbff252012-11-13 16:56:48 -050079 receive_pkt_check(self.dataplane,pkt7,[yes_ports],no_ports,self)
80
81
82
83class EthernetSrcAddress(base_tests.SimpleDataPlane):
84
85 """Verify match on single header field -- Ethernet Src Address """
86
87 def runTest(self):
88
89 logging.info("Running Ethernet Src Address test")
90
91 of_ports = config["port_map"].keys()
92 of_ports.sort()
93 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
94
95 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080096 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -050097
ShreyaPanditaefdff312012-11-21 13:35:34 -050098 egress_port=of_ports[1]
99 no_ports=set(of_ports).difference([egress_port])
100 yes_ports = of_ports[1]
101
ShreyaPandita6fbff252012-11-13 16:56:48 -0500102 logging.info("Inserting a flow with match on Ethernet Source Address ")
103 logging.info("Sending matching and non-matching ethernet packets")
104 logging.info("Verifying only matching packets implements the action specified in the flow")
105
106 #Insert a Match On Ethernet Src Address flow
107 (pkt,match) = match_ethernet_src_address(self,of_ports)
108
109 #Sending packet matching the flow, verify it implements the action
110 self.dataplane.send(of_ports[0], str(pkt))
111
112 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500113 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
114
115 #Sending non matching packet , verify Packetin event gets triggered.
Rich Laned0478ff2013-03-11 12:46:58 -0700116 pkt2 = simple_eth_packet(eth_src='00:01:01:01:01:02');
ShreyaPandita6fbff252012-11-13 16:56:48 -0500117 self.dataplane.send(of_ports[0], str(pkt2))
118
119 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
120 self.assertTrue(response is not None, "PacketIn not received for non matching packets")
121
122class EthernetDstAddress(base_tests.SimpleDataPlane):
123
124 """Verify match on single Header Field Field -- Ethernet Dst Address """
125
126 def runTest(self):
127
128 logging.info("Running Ethernet Dst Address test")
129
130 of_ports = config["port_map"].keys()
131 of_ports.sort()
132 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
133
134 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800135 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500136
ShreyaPanditaefdff312012-11-21 13:35:34 -0500137 egress_port=of_ports[1]
138 no_ports=set(of_ports).difference([egress_port])
139 yes_ports = of_ports[1]
140
ShreyaPandita6fbff252012-11-13 16:56:48 -0500141 logging.info("Inserting a flow with match on Ethernet Destination Address ")
142 logging.info("Sending matching and non-matching ethernet packets")
143 logging.info("Verifying only matching packets implements the action specified in the flow")
144
145 #Insert a Match on Destination Address flow
146 (pkt,match) = match_ethernet_dst_address(self,of_ports)
147
148 #Send Packet matching the flow
149 self.dataplane.send(of_ports[0], str(pkt))
150
151 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500152 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
153
154 #Send Non-matching packet
Rich Laned0478ff2013-03-11 12:46:58 -0700155 pkt2 = simple_eth_packet(eth_dst='00:01:01:01:01:02');
ShreyaPandita6fbff252012-11-13 16:56:48 -0500156 self.dataplane.send(of_ports[0], str(pkt2))
157
158 #Verify PacketIn event gets triggered
159 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
160 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
161
162
163class EthernetType(base_tests.SimpleDataPlane):
164
165 """Verify match on single header field -- Ethernet Type """
166
167 def runTest(self):
168
169 logging.info("Running Ethernet Type test")
170
171 of_ports = config["port_map"].keys()
172 of_ports.sort()
173 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
174
175 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800176 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500177
ShreyaPanditaefdff312012-11-21 13:35:34 -0500178 egress_port=of_ports[1]
179 no_ports=set(of_ports).difference([egress_port])
180 yes_ports = of_ports[1]
181
ShreyaPandita6fbff252012-11-13 16:56:48 -0500182 logging.info("Inserting a flow with match on Ethernet Type ")
183 logging.info("Sending matching and non-matching ethernet packets")
184 logging.info("Verifying only matching packets implements the action specified in the flow")
185
186 #Insert a Match on Ethernet-Type flow
187 (pkt,match) = match_ethernet_type(self,of_ports)
188
189 #Sending packet matching the flow
190 self.dataplane.send(of_ports[0], str(pkt))
191
192 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500193 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
194
195 #Sending non matching packet ,
Rich Laned0478ff2013-03-11 12:46:58 -0700196 pkt2 = simple_eth_packet(eth_type=0x0806);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500197 self.dataplane.send(of_ports[0], str(pkt2))
198
199 #verify Packetin event gets triggered.
200 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
201 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
202
203
204class IngressPort(base_tests.SimpleDataPlane):
205
206 """Verify match on single Header Field Field -- In_port """
207
208 def runTest(self):
209
210 logging.info("Running Ingress Port test")
211
212 of_ports = config["port_map"].keys()
213 of_ports.sort()
214 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
215
216 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800217 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500218
ShreyaPanditaefdff312012-11-21 13:35:34 -0500219 egress_port=of_ports[1]
220 no_ports=set(of_ports).difference([egress_port])
221 yes_ports = of_ports[1]
222
ShreyaPandita6fbff252012-11-13 16:56:48 -0500223 logging.info("Inserting a flow with match on Ingress Port ")
224 logging.info("Sending matching and non-matching packets")
225 logging.info("Verifying only matching packets implements the action specified in the flow")
226
227 #Insert a Match on Ingress Port FLow
228 (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0)
229
230 #Send Packet matching the flow i.e on in_port specified in the flow
231 self.dataplane.send(of_ports[0], str(pkt))
232
233 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500234 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
235
236 #Send Non-Matching Packet
237 self.dataplane.send(of_ports[1],str(pkt))
238
239 #Verify PacketIn event gets triggered
240 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
241 self.assertTrue(response is not None, "PacketIn not received for non-matching packet")
242
243class VlanId(base_tests.SimpleDataPlane):
244
245 """Verify match on single Header Field Field -- Vlan Id """
246
247 def runTest(self):
248
249 of_ports = config["port_map"].keys()
250 of_ports.sort()
251 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
252
253 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800254 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500255
ShreyaPanditaefdff312012-11-21 13:35:34 -0500256 egress_port=of_ports[1]
257 no_ports=set(of_ports).difference([egress_port])
258 yes_ports = of_ports[1]
259
ShreyaPandita6fbff252012-11-13 16:56:48 -0500260 logging.info("Inserting a flow with match on VLAN ID ")
261 logging.info("Sending matching and non-matching tagged packets")
262 logging.info("Verifying matching packets implements the action specified in the flow")
263
264 #Create a flow with match on Vlan Id
265 (pkt,match) = match_vlan_id(self,of_ports)
266
267 #Send tagged packet matching the flow i.e packet with same vlan id as in flow
268 self.dataplane.send(of_ports[0], str(pkt))
269
270 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500271 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
272
273 #Send Non-matching packet, i.e packet with different Vlan Id
Rich Laned0478ff2013-03-11 12:46:58 -0700274 pkt2 = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=4);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500275 self.dataplane.send(of_ports[0], str(pkt2))
276
277 #Verify PacketIn event gets triggered
278 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
279 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
280
281class VlanPCP(base_tests.SimpleDataPlane):
282
283 """"Verify match on single Header Field Field -- Vlan Priority"""
284
285 def runTest(self):
286
287 logging.info("Running VlanPCP1 test")
288
289 of_ports = config["port_map"].keys()
290 of_ports.sort()
291 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
292
293 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800294 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500295
296 egress_port=of_ports[1]
297 no_ports=set(of_ports).difference([egress_port])
298 yes_ports = of_ports[1]
299
ShreyaPandita6fbff252012-11-13 16:56:48 -0500300 logging.info("Inserting a flow with match on VLAN Priority ")
301 logging.info("Sending matching and non-matching tagged packets")
302 logging.info("Verifying matching packet implements the action specified in the flow")
303
304 #Create a flow matching on VLAN Priority
305 (pkt,match) = match_vlan_pcp(self,of_ports)
306
307 #Send tagged Packet matching the flow
308 self.dataplane.send(of_ports[0], str(pkt))
309
310 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500311 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
312
313 #Send tagged packet with same vlan_id but different vlan priority
Rich Laned0478ff2013-03-11 12:46:58 -0700314 pkt2 = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=1,vlan_pcp=20);
ShreyaPanditaefdff312012-11-21 13:35:34 -0500315 self.dataplane.send(of_ports[0], str(pkt2))
316
317 #Verify Packet_In event gets triggered
318 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
319 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
ShreyaPandita6fbff252012-11-13 16:56:48 -0500320
321class MultipleHeaderFieldL2(base_tests.SimpleDataPlane):
322
323 """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """
324
325 def runTest(self):
326
327 logging.info("Running Multiple Header Field L2 test")
328
329 of_ports = config["port_map"].keys()
330 of_ports.sort()
331 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
332
333 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800334 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500335
ShreyaPanditaefdff312012-11-21 13:35:34 -0500336 egress_port=of_ports[1]
337 no_ports=set(of_ports).difference([egress_port])
338 yes_ports = of_ports[1]
339
ShreyaPandita6fbff252012-11-13 16:56:48 -0500340 logging.info("Inserting a flow with match on Multiple Header Fields in L2 ")
341 logging.info("Sending matching and non-matching packets")
342 logging.info("Verifying matching packets implements the action specified in the flow")
343
344 (pkt,match) = match_mul_l2(self,of_ports)
345
Rich Laned0478ff2013-03-11 12:46:58 -0700346 #Send eth packet matching the eth_type field, verify it implements the action
ShreyaPandita6fbff252012-11-13 16:56:48 -0500347 self.dataplane.send(of_ports[0], str(pkt))
348
349 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500350 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
351
Rich Laned0478ff2013-03-11 12:46:58 -0700352 #Sending non matching packet (only eth_dst is different) , verify Packetin event gets triggered.
353 pkt2 = simple_eth_packet(eth_type=0x88cc,eth_src='00:01:01:01:01:01',eth_dst='00:01:01:02:01:01');
ShreyaPandita6fbff252012-11-13 16:56:48 -0500354 self.dataplane.send(of_ports[0], str(pkt2))
355
356 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
357 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
358
Rich Laned0478ff2013-03-11 12:46:58 -0700359 #Sending non matching packet (only eth_src is different) , verify Packetin event gets triggered.
360 pkt2 = simple_eth_packet(eth_type=0x88cc,eth_src='00:01:01:01:01:02',eth_dst='00:01:01:01:01:02');
ShreyaPandita6fbff252012-11-13 16:56:48 -0500361 self.dataplane.send(of_ports[0], str(pkt2))
362
363 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
364 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
365
366 #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered.
Rich Laned0478ff2013-03-11 12:46:58 -0700367 pkt2 = simple_eth_packet(eth_type=0x0806,eth_src='00:01:01:01:01:01',eth_dst='00:01:01:01:01:02');
ShreyaPandita6fbff252012-11-13 16:56:48 -0500368 self.dataplane.send(of_ports[0], str(pkt2))
369
ShreyaPanditaefdff312012-11-21 13:35:34 -0500370 #Verify packet_in event gets triggered
ShreyaPandita6fbff252012-11-13 16:56:48 -0500371 (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
374class IpTos(base_tests.SimpleDataPlane):
375
376 """"Verify match on single Header Field Field -- Type of service"""
377
378 def runTest(self):
379
380 logging.info("Running Ip_Tos test")
381
382 of_ports = config["port_map"].keys()
383 of_ports.sort()
384 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
385
386 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800387 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500388
389 egress_port=of_ports[1]
390 no_ports=set(of_ports).difference([egress_port])
391 yes_ports = of_ports[1]
392
ShreyaPandita6fbff252012-11-13 16:56:48 -0500393 logging.info("Inserting a flow with match on Ip_Tos ")
394 logging.info("Sending matching and non-matching tcp/ip packets")
395 logging.info("Verifying only matching packets implements the action specified in the flow")
396
397 #Create a flow matching on VLAN Priority
398 (pkt,match) = match_ip_tos(self,of_ports)
399
400 #Send Packet matching the flow
401 self.dataplane.send(of_ports[0], str(pkt))
402
403 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500404 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
405
406 #Create a non-matching packet , verify packet_in get generated
Rich Laneb5c73792012-12-03 17:12:32 -0800407 pkt2 = simple_tcp_packet(ip_tos=4);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500408 self.dataplane.send(of_ports[0], str(pkt2))
409 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
410 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
411
412class IpProtocol(base_tests.SimpleDataPlane):
413
414 """"Verify match on single Header Field Field -- Ip Protocol"""
415
416 def runTest(self):
417
418 logging.info("Running Ip Protocol test")
419
420 of_ports = config["port_map"].keys()
421 of_ports.sort()
422 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
423
424 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800425 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500426
427 egress_port=of_ports[1]
428 no_ports=set(of_ports).difference([egress_port])
429 yes_ports = of_ports[1]
430
ShreyaPandita6fbff252012-11-13 16:56:48 -0500431 logging.info("Inserting a flow with match on Ip Protocol ")
432 logging.info("Sending matching and non-matching tcp/ip packets")
433 logging.info("Verifying only matching packets implements the action specified in the flow")
434
435 #Create a flow matching on VLAN Priority
436 (pkt,match) = match_ip_protocol(self,of_ports)
437
438 #Send Packet matching the flow
439 self.dataplane.send(of_ports[0], str(pkt))
440
441 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500442 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
443
444 #Create a non-matching packet , verify packet_in get generated
445 pkt2 = simple_icmp_packet();
446 self.dataplane.send(of_ports[0], str(pkt2))
447 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
448 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
449
450
451class TcpSrcPort(base_tests.SimpleDataPlane):
452
453 """Verify match on Single header field -- Tcp Source Port, """
454
455 def runTest(self):
456
457 logging.info("Running Tcp Src Port test")
458
459 of_ports = config["port_map"].keys()
460 of_ports.sort()
461 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
462
463 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800464 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500465
ShreyaPanditaefdff312012-11-21 13:35:34 -0500466 egress_port=of_ports[1]
467 no_ports=set(of_ports).difference([egress_port])
468 yes_ports = of_ports[1]
469
ShreyaPandita6fbff252012-11-13 16:56:48 -0500470 logging.info("Inserting a flow with match on Tcp Tcp Source Port ")
471 logging.info("Sending matching and non-matching tcp packets")
472 logging.info("Verifying matching packets implements the action specified in the flow")
473
474 (pkt,match) = match_tcp_src(self,of_ports)
475
476 #Sending packet matching the tcp_sport, verify it implements the action
477 self.dataplane.send(of_ports[0], str(pkt))
478
479 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500480 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
481
482 #Sending non matching packet , verify Packetin event gets triggered.
483 pkt2 = simple_tcp_packet(tcp_sport=540);
484 self.dataplane.send(of_ports[0], str(pkt2))
485
486 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
487 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
488
489class TcpDstPort(base_tests.SimpleDataPlane):
490
491 """Verify match on Single header field -- Tcp Destination Port """
492
493 def runTest(self):
494
495 logging.info("Running Tcp Destination Port test")
496
497 of_ports = config["port_map"].keys()
498 of_ports.sort()
499 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
500
501 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800502 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500503
ShreyaPanditaefdff312012-11-21 13:35:34 -0500504 egress_port=of_ports[1]
505 no_ports=set(of_ports).difference([egress_port])
506 yes_ports = of_ports[1]
507
ShreyaPandita6fbff252012-11-13 16:56:48 -0500508 logging.info("Inserting a flow with match on Tcp Destination Port ")
509 logging.info("Sending matching and non-matching packets")
510 logging.info("Verifying matching packets implements the action specified in the flow")
511
512 (pkt,match) = match_tcp_dst(self,of_ports)
513
514 #Sending packet matching the tcp_dport, verify it implements the action
515 self.dataplane.send(of_ports[0], str(pkt))
516
517 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500518 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
519
520 #Sending non matching packet , verify Packetin event gets triggered.
521 pkt2 = simple_tcp_packet(tcp_dport=541);
522 self.dataplane.send(of_ports[0], str(pkt2))
523
524 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=10)
525 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
526
Shudong Zhouc2f18762013-01-11 00:12:44 -0800527class UdpSrcPort(base_tests.SimpleDataPlane):
528
529 """Verify match on Single header field -- Udp Source Port, """
530
531 def runTest(self):
532
533 logging.info("Running Udp Src Port test")
534
535 of_ports = config["port_map"].keys()
536 of_ports.sort()
537 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
538
539 #Clear Switch State
540 delete_all_flows(self.controller)
541
542 egress_port=of_ports[1]
543 no_ports=set(of_ports).difference([egress_port])
544 yes_ports = of_ports[1]
545
546 logging.info("Inserting a flow with match on Udp Udp Source Port ")
547 logging.info("Sending matching and non-matching tcp packets")
548 logging.info("Verifying matching packets implements the action specified in the flow")
549
550 (pkt,match) = match_udp_src(self,of_ports)
551
552 #Sending packet matching the tcp_sport, verify it implements the action
553 self.dataplane.send(of_ports[0], str(pkt))
554
555 #Verify packet implements the action specified in the flow
556 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
557
558 #Sending non matching packet , verify Packetin event gets triggered.
559 pkt2 = simple_udp_packet(udp_sport=540);
560 self.dataplane.send(of_ports[0], str(pkt2))
561
562 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
563 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
564
565class UdpDstPort(base_tests.SimpleDataPlane):
566
567 """Verify match on Single header field -- Udp Destination Port """
568
569 def runTest(self):
570
571 logging.info("Running Udp Destination Port test")
572
573 of_ports = config["port_map"].keys()
574 of_ports.sort()
575 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
576
577 #Clear Switch State
578 delete_all_flows(self.controller)
579
580 egress_port=of_ports[1]
581 no_ports=set(of_ports).difference([egress_port])
582 yes_ports = of_ports[1]
583
584 logging.info("Inserting a flow with match on Udp Destination Port ")
585 logging.info("Sending matching and non-matching packets")
586 logging.info("Verifying matching packets implements the action specified in the flow")
587
588 (pkt,match) = match_udp_dst(self,of_ports)
589
590 #Sending packet matching the tcp_dport, verify it implements the action
591 self.dataplane.send(of_ports[0], str(pkt))
592
593 #Verify packet implements the action specified in the flow
594 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
595
596 #Sending non matching packet , verify Packetin event gets triggered.
597 pkt2 = simple_udp_packet(udp_dport=541);
598 self.dataplane.send(of_ports[0], str(pkt2))
599
600 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=10)
601 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
602
603class ICMPType(base_tests.SimpleDataPlane):
604
605 """Verify match on Single header field -- ICMP type, """
606
607 def runTest(self):
608
609 logging.info("Running ICMP type test")
610
611 of_ports = config["port_map"].keys()
612 of_ports.sort()
613 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
614
615 #Clear Switch State
616 delete_all_flows(self.controller)
617
618 egress_port=of_ports[1]
619 no_ports=set(of_ports).difference([egress_port])
620 yes_ports = of_ports[1]
621
622 logging.info("Inserting a flow with match on ICMP type")
623 logging.info("Sending matching and non-matching ICMP packets")
624 logging.info("Verifying matching packets implements the action specified in the flow")
625
626 (pkt,match) = match_icmp_type(self,of_ports)
627
628 #Sending packet matching the tcp_sport, verify it implements the action
629 self.dataplane.send(of_ports[0], str(pkt))
630
631 #Verify packet implements the action specified in the flow
632 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
633
634 #Sending non matching packet , verify Packetin event gets triggered.
635 pkt2 = simple_icmp_packet(icmp_type=10);
636 self.dataplane.send(of_ports[0], str(pkt2))
637
638 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
639 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
640
641class ICMPCode(base_tests.SimpleDataPlane):
642
643 """Verify match on Single header field -- ICMP code, """
644
645 def runTest(self):
646
647 logging.info("Running ICMP code test")
648
649 of_ports = config["port_map"].keys()
650 of_ports.sort()
651 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
652
653 #Clear Switch State
654 delete_all_flows(self.controller)
655
656 egress_port=of_ports[1]
657 no_ports=set(of_ports).difference([egress_port])
658 yes_ports = of_ports[1]
659
660 logging.info("Inserting a flow with match on ICMP type")
661 logging.info("Sending matching and non-matching ICMP packets")
662 logging.info("Verifying matching packets implements the action specified in the flow")
663
664 (pkt,match) = match_icmp_code(self,of_ports)
665
666 #Sending packet matching the tcp_dport, verify it implements the action
667 self.dataplane.send(of_ports[0], str(pkt))
668
669 #Verify packet implements the action specified in the flow
670 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
671
672 #Sending non matching packet , verify Packetin event gets triggered.
673 pkt2 = simple_icmp_packet(icmp_code=10);
674 self.dataplane.send(of_ports[0], str(pkt2))
675
676 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
677 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
678
ShreyaPandita6fbff252012-11-13 16:56:48 -0500679
Shudong Zhoudceec932013-02-06 01:12:54 -0800680class ArpSenderIP(base_tests.SimpleDataPlane):
681
682 """"Verify match on single Header Field -- Arp Protocol"""
683
684 def runTest(self):
685
686 logging.info("Running Arp Protocol test")
687
688 of_ports = config["port_map"].keys()
689 of_ports.sort()
690 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
691
692 #Clear Switch State
693 delete_all_flows(self.controller)
694
695 egress_port=of_ports[1]
696 no_ports=set(of_ports).difference([egress_port])
697 yes_ports = of_ports[1]
698
699 logging.info("Inserting a flow with match on Arp Protocol ")
700 logging.info("Sending matching and non-matching arp packets")
701 logging.info("Verifying only matching packets implements the action specified in the flow")
702
703 #Create a flow matching on ARP sender IP
704 (pkt,match) = match_arp_sender(self,of_ports)
705
706 #Send Packet matching the flow
707 self.dataplane.send(of_ports[0], str(pkt))
708
709 #Verify packet implements the action specified in the flow
710 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
711
712 #Create a non-matching packet , verify packet_in get generated
713 pkt2 = simple_arp_packet(ip_snd="10.10.0.10");
714 self.dataplane.send(of_ports[0], str(pkt2))
715 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
716 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
717
718class ArpTargetIP(base_tests.SimpleDataPlane):
719
720 """"Verify match on single Header Field -- Arp Protocol"""
721
722 def runTest(self):
723
724 logging.info("Running Arp Protocol test")
725
726 of_ports = config["port_map"].keys()
727 of_ports.sort()
728 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
729
730 #Clear Switch State
731 delete_all_flows(self.controller)
732
733 egress_port=of_ports[1]
734 no_ports=set(of_ports).difference([egress_port])
735 yes_ports = of_ports[1]
736
737 logging.info("Inserting a flow with match on Arp Protocol ")
738 logging.info("Sending matching and non-matching arp packets")
739 logging.info("Verifying only matching packets implements the action specified in the flow")
740
741 #Create a flow matching on ARP target IP
742 (pkt,match) = match_arp_target(self,of_ports)
743
744 #Send Packet matching the flow
745 self.dataplane.send(of_ports[0], str(pkt))
746
747 #Verify packet implements the action specified in the flow
748 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
749
750 #Create a non-matching packet , verify packet_in get generated
751 pkt2 = simple_arp_packet(ip_tgt="10.10.0.10");
752 self.dataplane.send(of_ports[0], str(pkt2))
753 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
754 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
755
756
ShreyaPandita6fbff252012-11-13 16:56:48 -0500757class ExactMatch(base_tests.SimpleDataPlane):
758
759 """Verify match on Single header field -- Exact Match """
760
761 def runTest(self):
762
763 logging.info("Running Tcp Exact Match test")
764
765 of_ports = config["port_map"].keys()
766 of_ports.sort()
767 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
768
769 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800770 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500771
ShreyaPanditaefdff312012-11-21 13:35:34 -0500772 egress_port=of_ports[1]
773 no_ports=set(of_ports).difference([egress_port])
774 yes_ports = of_ports[1]
775
ShreyaPandita6fbff252012-11-13 16:56:48 -0500776 logging.info("Inserting a flow with match for Exact Match ")
777 logging.info("Sending matching and non-matching packets")
778 logging.info("Verifying matching packets implements the action specified in the flow")
779
780 (pkt,match) = exact_match(self,of_ports)
781
782 #Sending packet matching all the fields of a tcp_packet, verify it implements the action
783 self.dataplane.send(of_ports[0], str(pkt))
784
785 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500786 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
787
788 #Sending non matching packet , verify Packetin event gets triggered.
789 pkt2 = simple_tcp_packet(tcp_sport=540);
790 self.dataplane.send(of_ports[0], str(pkt2))
791
792 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
793 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
794
795
796class MultipleHeaderFieldL4(base_tests.SimpleDataPlane):
797
798 """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """
799
800 def runTest(self):
801
802 logging.info("Running Multiple Header Field L4 test")
803
804 of_ports = config["port_map"].keys()
805 of_ports.sort()
806 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
807
808 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800809 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500810
ShreyaPanditaefdff312012-11-21 13:35:34 -0500811 egress_port=of_ports[1]
812 no_ports=set(of_ports).difference([egress_port])
813 yes_ports = of_ports[1]
814
ShreyaPandita6fbff252012-11-13 16:56:48 -0500815 logging.info("Inserting a flow with match on Multiple Header Field L4 ")
816 logging.info("Sending matching and non-matching packets")
817 logging.info("Verifying matching packets implements the action specified in the flow")
818
819 (pkt,match) = match_mul_l4(self,of_ports)
820
821 #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
822 self.dataplane.send(of_ports[0], str(pkt))
823
824 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500825 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
826
ShreyaPanditaefdff312012-11-21 13:35:34 -0500827 #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered.
828 pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541);
829 self.dataplane.send(of_ports[0], str(pkt2))
830
831 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
832 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
833
834 #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered.
835 pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500836 self.dataplane.send(of_ports[0], str(pkt2))
837
838 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4)
839 self.assertTrue(response is not None, "PacketIn not received for non matching packet")
840
841
842class ExactMatchPrio(base_tests.SimpleDataPlane):
843
844 """Verify that Exact Match has highest priority """
845
846 def runTest(self):
847
848 logging.info("Running Exact Match High Priority test")
849
850 of_ports = config["port_map"].keys()
851 of_ports.sort()
852 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
853
854 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800855 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500856
Rich Laneed130652012-12-31 17:35:33 -0800857 egress_port=of_ports[2]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500858 no_ports=set(of_ports).difference([egress_port])
Rich Laneed130652012-12-31 17:35:33 -0800859 yes_ports = egress_port
ShreyaPanditaefdff312012-11-21 13:35:34 -0500860
ShreyaPandita6fbff252012-11-13 16:56:48 -0500861 logging.info("Inserting a flow with Exact Match (low priority)")
862 logging.info("Inserting an overlapping wildcarded flow (higher priority)")
863 logging.info("Sending packets matching both the flows ")
864 logging.info("Verifying matching packets implements the action specified in the exact match flow")
865
866 #Insert two Overlapping Flows : Exact Match and Wildcard All.
867 (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
868 (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
869
870 #Sending packet matching both the flows ,
871 self.dataplane.send(of_ports[0], str(pkt2))
872
873 #verify it implements the action specified in Exact Match Flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500874 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
875
876
877class WildcardMatchPrio(base_tests.SimpleDataPlane):
878
879 """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
880
881 def runTest(self):
882
883 logging.info("Running Wildcard Match High Priority test")
884
885 of_ports = config["port_map"].keys()
886 of_ports.sort()
887 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
888
889 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800890 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500891
ShreyaPanditaefdff312012-11-21 13:35:34 -0500892 egress_port=of_ports[1]
893 no_ports=set(of_ports).difference([egress_port])
894 yes_ports = of_ports[1]
895
ShreyaPandita6fbff252012-11-13 16:56:48 -0500896 logging.info("Inserting two wildcarded flows with priorities ")
897 logging.info("Sending packets matching the flows")
898 logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
899
900 (pkt,match) = wildcard_all(self,of_ports,priority=20)
901 (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
902
903 #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
904 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500905 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
906
907
908
909
910