blob: 22168998a4da4857a3cedd5403c79844480378a5 [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))
Rich Lane4c504f32013-06-07 17:24:14 -0700118 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500119
120class EthernetDstAddress(base_tests.SimpleDataPlane):
121
122 """Verify match on single Header Field Field -- Ethernet Dst Address """
123
124 def runTest(self):
125
126 logging.info("Running Ethernet Dst Address test")
127
128 of_ports = config["port_map"].keys()
129 of_ports.sort()
130 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
131
132 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800133 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500134
ShreyaPanditaefdff312012-11-21 13:35:34 -0500135 egress_port=of_ports[1]
136 no_ports=set(of_ports).difference([egress_port])
137 yes_ports = of_ports[1]
138
ShreyaPandita6fbff252012-11-13 16:56:48 -0500139 logging.info("Inserting a flow with match on Ethernet Destination Address ")
140 logging.info("Sending matching and non-matching ethernet packets")
141 logging.info("Verifying only matching packets implements the action specified in the flow")
142
143 #Insert a Match on Destination Address flow
144 (pkt,match) = match_ethernet_dst_address(self,of_ports)
145
146 #Send Packet matching the flow
147 self.dataplane.send(of_ports[0], str(pkt))
148
149 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500150 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
151
152 #Send Non-matching packet
Rich Laned0478ff2013-03-11 12:46:58 -0700153 pkt2 = simple_eth_packet(eth_dst='00:01:01:01:01:02');
ShreyaPandita6fbff252012-11-13 16:56:48 -0500154 self.dataplane.send(of_ports[0], str(pkt2))
155
156 #Verify PacketIn event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700157 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500158
159
160class EthernetType(base_tests.SimpleDataPlane):
161
162 """Verify match on single header field -- Ethernet Type """
163
164 def runTest(self):
165
166 logging.info("Running Ethernet Type test")
167
168 of_ports = config["port_map"].keys()
169 of_ports.sort()
170 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
171
172 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800173 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500174
ShreyaPanditaefdff312012-11-21 13:35:34 -0500175 egress_port=of_ports[1]
176 no_ports=set(of_ports).difference([egress_port])
177 yes_ports = of_ports[1]
178
ShreyaPandita6fbff252012-11-13 16:56:48 -0500179 logging.info("Inserting a flow with match on Ethernet Type ")
180 logging.info("Sending matching and non-matching ethernet packets")
181 logging.info("Verifying only matching packets implements the action specified in the flow")
182
183 #Insert a Match on Ethernet-Type flow
184 (pkt,match) = match_ethernet_type(self,of_ports)
185
186 #Sending packet matching the flow
187 self.dataplane.send(of_ports[0], str(pkt))
188
189 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500190 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
191
192 #Sending non matching packet ,
Rich Laned0478ff2013-03-11 12:46:58 -0700193 pkt2 = simple_eth_packet(eth_type=0x0806);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500194 self.dataplane.send(of_ports[0], str(pkt2))
195
196 #verify Packetin event gets triggered.
Rich Lane4c504f32013-06-07 17:24:14 -0700197 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500198
199
200class IngressPort(base_tests.SimpleDataPlane):
201
202 """Verify match on single Header Field Field -- In_port """
203
204 def runTest(self):
205
206 logging.info("Running Ingress Port test")
207
208 of_ports = config["port_map"].keys()
209 of_ports.sort()
210 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
211
212 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800213 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500214
ShreyaPanditaefdff312012-11-21 13:35:34 -0500215 egress_port=of_ports[1]
216 no_ports=set(of_ports).difference([egress_port])
217 yes_ports = of_ports[1]
218
ShreyaPandita6fbff252012-11-13 16:56:48 -0500219 logging.info("Inserting a flow with match on Ingress Port ")
220 logging.info("Sending matching and non-matching packets")
221 logging.info("Verifying only matching packets implements the action specified in the flow")
222
223 #Insert a Match on Ingress Port FLow
224 (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0)
225
226 #Send Packet matching the flow i.e on in_port specified in the flow
227 self.dataplane.send(of_ports[0], str(pkt))
228
229 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500230 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
231
232 #Send Non-Matching Packet
233 self.dataplane.send(of_ports[1],str(pkt))
234
235 #Verify PacketIn event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700236 verify_packet_in(self, str(pkt), of_ports[1], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500237
238class VlanId(base_tests.SimpleDataPlane):
239
240 """Verify match on single Header Field Field -- Vlan Id """
241
242 def runTest(self):
243
244 of_ports = config["port_map"].keys()
245 of_ports.sort()
246 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
247
248 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800249 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500250
ShreyaPanditaefdff312012-11-21 13:35:34 -0500251 egress_port=of_ports[1]
252 no_ports=set(of_ports).difference([egress_port])
253 yes_ports = of_ports[1]
254
ShreyaPandita6fbff252012-11-13 16:56:48 -0500255 logging.info("Inserting a flow with match on VLAN ID ")
256 logging.info("Sending matching and non-matching tagged packets")
257 logging.info("Verifying matching packets implements the action specified in the flow")
258
259 #Create a flow with match on Vlan Id
260 (pkt,match) = match_vlan_id(self,of_ports)
261
262 #Send tagged packet matching the flow i.e packet with same vlan id as in flow
263 self.dataplane.send(of_ports[0], str(pkt))
264
265 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500266 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
267
268 #Send Non-matching packet, i.e packet with different Vlan Id
Rich Laned0478ff2013-03-11 12:46:58 -0700269 pkt2 = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=4);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500270 self.dataplane.send(of_ports[0], str(pkt2))
271
272 #Verify PacketIn event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700273 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500274
275class VlanPCP(base_tests.SimpleDataPlane):
276
277 """"Verify match on single Header Field Field -- Vlan Priority"""
278
279 def runTest(self):
280
281 logging.info("Running VlanPCP1 test")
282
283 of_ports = config["port_map"].keys()
284 of_ports.sort()
285 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
286
287 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800288 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500289
290 egress_port=of_ports[1]
291 no_ports=set(of_ports).difference([egress_port])
292 yes_ports = of_ports[1]
293
ShreyaPandita6fbff252012-11-13 16:56:48 -0500294 logging.info("Inserting a flow with match on VLAN Priority ")
295 logging.info("Sending matching and non-matching tagged packets")
296 logging.info("Verifying matching packet implements the action specified in the flow")
297
298 #Create a flow matching on VLAN Priority
299 (pkt,match) = match_vlan_pcp(self,of_ports)
300
301 #Send tagged Packet matching the flow
302 self.dataplane.send(of_ports[0], str(pkt))
303
304 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500305 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
306
307 #Send tagged packet with same vlan_id but different vlan priority
Rich Laned0478ff2013-03-11 12:46:58 -0700308 pkt2 = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=1,vlan_pcp=20);
ShreyaPanditaefdff312012-11-21 13:35:34 -0500309 self.dataplane.send(of_ports[0], str(pkt2))
310
311 #Verify Packet_In event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700312 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500313
314class MultipleHeaderFieldL2(base_tests.SimpleDataPlane):
315
316 """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """
317
318 def runTest(self):
319
320 logging.info("Running Multiple Header Field L2 test")
321
322 of_ports = config["port_map"].keys()
323 of_ports.sort()
324 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
325
326 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800327 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500328
ShreyaPanditaefdff312012-11-21 13:35:34 -0500329 egress_port=of_ports[1]
330 no_ports=set(of_ports).difference([egress_port])
331 yes_ports = of_ports[1]
332
ShreyaPandita6fbff252012-11-13 16:56:48 -0500333 logging.info("Inserting a flow with match on Multiple Header Fields in L2 ")
334 logging.info("Sending matching and non-matching packets")
335 logging.info("Verifying matching packets implements the action specified in the flow")
336
337 (pkt,match) = match_mul_l2(self,of_ports)
338
Rich Laned0478ff2013-03-11 12:46:58 -0700339 #Send eth packet matching the eth_type field, verify it implements the action
ShreyaPandita6fbff252012-11-13 16:56:48 -0500340 self.dataplane.send(of_ports[0], str(pkt))
341
342 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500343 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
344
Rich Laned0478ff2013-03-11 12:46:58 -0700345 #Sending non matching packet (only eth_dst is different) , verify Packetin event gets triggered.
346 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 -0500347 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700348 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500349
Rich Laned0478ff2013-03-11 12:46:58 -0700350 #Sending non matching packet (only eth_src is different) , verify Packetin event gets triggered.
351 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 -0500352 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700353 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500354
355 #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered.
Rich Laned0478ff2013-03-11 12:46:58 -0700356 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 -0500357 self.dataplane.send(of_ports[0], str(pkt2))
358
ShreyaPanditaefdff312012-11-21 13:35:34 -0500359 #Verify packet_in event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700360 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500361
362class IpTos(base_tests.SimpleDataPlane):
363
364 """"Verify match on single Header Field Field -- Type of service"""
365
366 def runTest(self):
367
368 logging.info("Running Ip_Tos test")
369
370 of_ports = config["port_map"].keys()
371 of_ports.sort()
372 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
373
374 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800375 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500376
377 egress_port=of_ports[1]
378 no_ports=set(of_ports).difference([egress_port])
379 yes_ports = of_ports[1]
380
ShreyaPandita6fbff252012-11-13 16:56:48 -0500381 logging.info("Inserting a flow with match on Ip_Tos ")
382 logging.info("Sending matching and non-matching tcp/ip packets")
383 logging.info("Verifying only matching packets implements the action specified in the flow")
384
385 #Create a flow matching on VLAN Priority
386 (pkt,match) = match_ip_tos(self,of_ports)
387
388 #Send Packet matching the flow
389 self.dataplane.send(of_ports[0], str(pkt))
390
391 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500392 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
393
394 #Create a non-matching packet , verify packet_in get generated
Rich Laneb5c73792012-12-03 17:12:32 -0800395 pkt2 = simple_tcp_packet(ip_tos=4);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500396 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700397 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500398
399class IpProtocol(base_tests.SimpleDataPlane):
400
401 """"Verify match on single Header Field Field -- Ip Protocol"""
402
403 def runTest(self):
404
405 logging.info("Running Ip Protocol test")
406
407 of_ports = config["port_map"].keys()
408 of_ports.sort()
409 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
410
411 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800412 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500413
414 egress_port=of_ports[1]
415 no_ports=set(of_ports).difference([egress_port])
416 yes_ports = of_ports[1]
417
ShreyaPandita6fbff252012-11-13 16:56:48 -0500418 logging.info("Inserting a flow with match on Ip Protocol ")
419 logging.info("Sending matching and non-matching tcp/ip packets")
420 logging.info("Verifying only matching packets implements the action specified in the flow")
421
422 #Create a flow matching on VLAN Priority
423 (pkt,match) = match_ip_protocol(self,of_ports)
424
425 #Send Packet matching the flow
426 self.dataplane.send(of_ports[0], str(pkt))
427
428 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500429 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
430
431 #Create a non-matching packet , verify packet_in get generated
432 pkt2 = simple_icmp_packet();
433 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700434 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500435
436
437class TcpSrcPort(base_tests.SimpleDataPlane):
438
439 """Verify match on Single header field -- Tcp Source Port, """
440
441 def runTest(self):
442
443 logging.info("Running Tcp Src Port test")
444
445 of_ports = config["port_map"].keys()
446 of_ports.sort()
447 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
448
449 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800450 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500451
ShreyaPanditaefdff312012-11-21 13:35:34 -0500452 egress_port=of_ports[1]
453 no_ports=set(of_ports).difference([egress_port])
454 yes_ports = of_ports[1]
455
ShreyaPandita6fbff252012-11-13 16:56:48 -0500456 logging.info("Inserting a flow with match on Tcp Tcp Source Port ")
457 logging.info("Sending matching and non-matching tcp packets")
458 logging.info("Verifying matching packets implements the action specified in the flow")
459
460 (pkt,match) = match_tcp_src(self,of_ports)
461
462 #Sending packet matching the tcp_sport, verify it implements the action
463 self.dataplane.send(of_ports[0], str(pkt))
464
465 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500466 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
467
468 #Sending non matching packet , verify Packetin event gets triggered.
469 pkt2 = simple_tcp_packet(tcp_sport=540);
470 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700471 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500472
473class TcpDstPort(base_tests.SimpleDataPlane):
474
475 """Verify match on Single header field -- Tcp Destination Port """
476
477 def runTest(self):
478
479 logging.info("Running Tcp Destination Port test")
480
481 of_ports = config["port_map"].keys()
482 of_ports.sort()
483 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
484
485 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800486 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500487
ShreyaPanditaefdff312012-11-21 13:35:34 -0500488 egress_port=of_ports[1]
489 no_ports=set(of_ports).difference([egress_port])
490 yes_ports = of_ports[1]
491
ShreyaPandita6fbff252012-11-13 16:56:48 -0500492 logging.info("Inserting a flow with match on Tcp Destination Port ")
493 logging.info("Sending matching and non-matching packets")
494 logging.info("Verifying matching packets implements the action specified in the flow")
495
496 (pkt,match) = match_tcp_dst(self,of_ports)
497
498 #Sending packet matching the tcp_dport, verify it implements the action
499 self.dataplane.send(of_ports[0], str(pkt))
500
501 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500502 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
503
504 #Sending non matching packet , verify Packetin event gets triggered.
505 pkt2 = simple_tcp_packet(tcp_dport=541);
506 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700507 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500508
Shudong Zhouc2f18762013-01-11 00:12:44 -0800509class UdpSrcPort(base_tests.SimpleDataPlane):
510
511 """Verify match on Single header field -- Udp Source Port, """
512
513 def runTest(self):
514
515 logging.info("Running Udp Src Port test")
516
517 of_ports = config["port_map"].keys()
518 of_ports.sort()
519 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
520
521 #Clear Switch State
522 delete_all_flows(self.controller)
523
524 egress_port=of_ports[1]
525 no_ports=set(of_ports).difference([egress_port])
526 yes_ports = of_ports[1]
527
528 logging.info("Inserting a flow with match on Udp Udp Source Port ")
529 logging.info("Sending matching and non-matching tcp packets")
530 logging.info("Verifying matching packets implements the action specified in the flow")
531
532 (pkt,match) = match_udp_src(self,of_ports)
533
534 #Sending packet matching the tcp_sport, verify it implements the action
535 self.dataplane.send(of_ports[0], str(pkt))
536
537 #Verify packet implements the action specified in the flow
538 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
539
540 #Sending non matching packet , verify Packetin event gets triggered.
541 pkt2 = simple_udp_packet(udp_sport=540);
542 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700543 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhouc2f18762013-01-11 00:12:44 -0800544
545class UdpDstPort(base_tests.SimpleDataPlane):
546
547 """Verify match on Single header field -- Udp Destination Port """
548
549 def runTest(self):
550
551 logging.info("Running Udp Destination Port test")
552
553 of_ports = config["port_map"].keys()
554 of_ports.sort()
555 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
556
557 #Clear Switch State
558 delete_all_flows(self.controller)
559
560 egress_port=of_ports[1]
561 no_ports=set(of_ports).difference([egress_port])
562 yes_ports = of_ports[1]
563
564 logging.info("Inserting a flow with match on Udp Destination Port ")
565 logging.info("Sending matching and non-matching packets")
566 logging.info("Verifying matching packets implements the action specified in the flow")
567
568 (pkt,match) = match_udp_dst(self,of_ports)
569
570 #Sending packet matching the tcp_dport, verify it implements the action
571 self.dataplane.send(of_ports[0], str(pkt))
572
573 #Verify packet implements the action specified in the flow
574 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
575
576 #Sending non matching packet , verify Packetin event gets triggered.
577 pkt2 = simple_udp_packet(udp_dport=541);
578 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700579 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhouc2f18762013-01-11 00:12:44 -0800580
581class ICMPType(base_tests.SimpleDataPlane):
582
583 """Verify match on Single header field -- ICMP type, """
584
585 def runTest(self):
586
587 logging.info("Running ICMP type 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 delete_all_flows(self.controller)
595
596 egress_port=of_ports[1]
597 no_ports=set(of_ports).difference([egress_port])
598 yes_ports = of_ports[1]
599
600 logging.info("Inserting a flow with match on ICMP type")
601 logging.info("Sending matching and non-matching ICMP packets")
602 logging.info("Verifying matching packets implements the action specified in the flow")
603
604 (pkt,match) = match_icmp_type(self,of_ports)
605
606 #Sending packet matching the tcp_sport, verify it implements the action
607 self.dataplane.send(of_ports[0], str(pkt))
608
609 #Verify packet implements the action specified in the flow
610 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
611
612 #Sending non matching packet , verify Packetin event gets triggered.
613 pkt2 = simple_icmp_packet(icmp_type=10);
614 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700615 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhouc2f18762013-01-11 00:12:44 -0800616
617class ICMPCode(base_tests.SimpleDataPlane):
618
619 """Verify match on Single header field -- ICMP code, """
620
621 def runTest(self):
622
623 logging.info("Running ICMP code test")
624
625 of_ports = config["port_map"].keys()
626 of_ports.sort()
627 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
628
629 #Clear Switch State
630 delete_all_flows(self.controller)
631
632 egress_port=of_ports[1]
633 no_ports=set(of_ports).difference([egress_port])
634 yes_ports = of_ports[1]
635
636 logging.info("Inserting a flow with match on ICMP type")
637 logging.info("Sending matching and non-matching ICMP packets")
638 logging.info("Verifying matching packets implements the action specified in the flow")
639
640 (pkt,match) = match_icmp_code(self,of_ports)
641
642 #Sending packet matching the tcp_dport, verify it implements the action
643 self.dataplane.send(of_ports[0], str(pkt))
644
645 #Verify packet implements the action specified in the flow
646 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
647
648 #Sending non matching packet , verify Packetin event gets triggered.
649 pkt2 = simple_icmp_packet(icmp_code=10);
650 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700651 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhouc2f18762013-01-11 00:12:44 -0800652
ShreyaPandita6fbff252012-11-13 16:56:48 -0500653
Shudong Zhoudceec932013-02-06 01:12:54 -0800654class ArpSenderIP(base_tests.SimpleDataPlane):
655
656 """"Verify match on single Header Field -- Arp Protocol"""
657
658 def runTest(self):
659
660 logging.info("Running Arp Protocol test")
661
662 of_ports = config["port_map"].keys()
663 of_ports.sort()
664 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
665
666 #Clear Switch State
667 delete_all_flows(self.controller)
668
669 egress_port=of_ports[1]
670 no_ports=set(of_ports).difference([egress_port])
671 yes_ports = of_ports[1]
672
673 logging.info("Inserting a flow with match on Arp Protocol ")
674 logging.info("Sending matching and non-matching arp packets")
675 logging.info("Verifying only matching packets implements the action specified in the flow")
676
677 #Create a flow matching on ARP sender IP
678 (pkt,match) = match_arp_sender(self,of_ports)
679
680 #Send Packet matching the flow
681 self.dataplane.send(of_ports[0], str(pkt))
682
683 #Verify packet implements the action specified in the flow
684 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
685
686 #Create a non-matching packet , verify packet_in get generated
687 pkt2 = simple_arp_packet(ip_snd="10.10.0.10");
688 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700689 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhoudceec932013-02-06 01:12:54 -0800690
691class ArpTargetIP(base_tests.SimpleDataPlane):
692
693 """"Verify match on single Header Field -- Arp Protocol"""
694
695 def runTest(self):
696
697 logging.info("Running Arp Protocol test")
698
699 of_ports = config["port_map"].keys()
700 of_ports.sort()
701 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
702
703 #Clear Switch State
704 delete_all_flows(self.controller)
705
706 egress_port=of_ports[1]
707 no_ports=set(of_ports).difference([egress_port])
708 yes_ports = of_ports[1]
709
710 logging.info("Inserting a flow with match on Arp Protocol ")
711 logging.info("Sending matching and non-matching arp packets")
712 logging.info("Verifying only matching packets implements the action specified in the flow")
713
714 #Create a flow matching on ARP target IP
715 (pkt,match) = match_arp_target(self,of_ports)
716
717 #Send Packet matching the flow
718 self.dataplane.send(of_ports[0], str(pkt))
719
720 #Verify packet implements the action specified in the flow
721 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
722
723 #Create a non-matching packet , verify packet_in get generated
724 pkt2 = simple_arp_packet(ip_tgt="10.10.0.10");
725 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700726 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhoudceec932013-02-06 01:12:54 -0800727
728
ShreyaPandita6fbff252012-11-13 16:56:48 -0500729class ExactMatch(base_tests.SimpleDataPlane):
730
731 """Verify match on Single header field -- Exact Match """
732
733 def runTest(self):
734
735 logging.info("Running Tcp Exact Match test")
736
737 of_ports = config["port_map"].keys()
738 of_ports.sort()
739 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
740
741 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800742 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500743
ShreyaPanditaefdff312012-11-21 13:35:34 -0500744 egress_port=of_ports[1]
745 no_ports=set(of_ports).difference([egress_port])
746 yes_ports = of_ports[1]
747
ShreyaPandita6fbff252012-11-13 16:56:48 -0500748 logging.info("Inserting a flow with match for Exact Match ")
749 logging.info("Sending matching and non-matching packets")
750 logging.info("Verifying matching packets implements the action specified in the flow")
751
752 (pkt,match) = exact_match(self,of_ports)
753
754 #Sending packet matching all the fields of a tcp_packet, verify it implements the action
755 self.dataplane.send(of_ports[0], str(pkt))
756
757 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500758 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
759
760 #Sending non matching packet , verify Packetin event gets triggered.
761 pkt2 = simple_tcp_packet(tcp_sport=540);
762 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700763 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500764
765
766class MultipleHeaderFieldL4(base_tests.SimpleDataPlane):
767
768 """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """
769
770 def runTest(self):
771
772 logging.info("Running Multiple Header Field L4 test")
773
774 of_ports = config["port_map"].keys()
775 of_ports.sort()
776 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
777
778 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800779 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500780
ShreyaPanditaefdff312012-11-21 13:35:34 -0500781 egress_port=of_ports[1]
782 no_ports=set(of_ports).difference([egress_port])
783 yes_ports = of_ports[1]
784
ShreyaPandita6fbff252012-11-13 16:56:48 -0500785 logging.info("Inserting a flow with match on Multiple Header Field L4 ")
786 logging.info("Sending matching and non-matching packets")
787 logging.info("Verifying matching packets implements the action specified in the flow")
788
789 (pkt,match) = match_mul_l4(self,of_ports)
790
791 #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
792 self.dataplane.send(of_ports[0], str(pkt))
793
794 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500795 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
796
ShreyaPanditaefdff312012-11-21 13:35:34 -0500797 #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered.
798 pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541);
799 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700800 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500801
802 #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered.
803 pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500804 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700805 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500806
807
808class ExactMatchPrio(base_tests.SimpleDataPlane):
809
810 """Verify that Exact Match has highest priority """
811
812 def runTest(self):
813
814 logging.info("Running Exact Match High Priority test")
815
816 of_ports = config["port_map"].keys()
817 of_ports.sort()
818 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
819
820 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800821 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500822
Rich Laneed130652012-12-31 17:35:33 -0800823 egress_port=of_ports[2]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500824 no_ports=set(of_ports).difference([egress_port])
Rich Laneed130652012-12-31 17:35:33 -0800825 yes_ports = egress_port
ShreyaPanditaefdff312012-11-21 13:35:34 -0500826
ShreyaPandita6fbff252012-11-13 16:56:48 -0500827 logging.info("Inserting a flow with Exact Match (low priority)")
828 logging.info("Inserting an overlapping wildcarded flow (higher priority)")
829 logging.info("Sending packets matching both the flows ")
830 logging.info("Verifying matching packets implements the action specified in the exact match flow")
831
832 #Insert two Overlapping Flows : Exact Match and Wildcard All.
833 (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
834 (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
835
836 #Sending packet matching both the flows ,
837 self.dataplane.send(of_ports[0], str(pkt2))
838
839 #verify it implements the action specified in Exact Match Flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500840 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
841
842
843class WildcardMatchPrio(base_tests.SimpleDataPlane):
844
845 """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
846
847 def runTest(self):
848
849 logging.info("Running Wildcard Match High Priority test")
850
851 of_ports = config["port_map"].keys()
852 of_ports.sort()
853 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
854
855 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800856 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500857
ShreyaPanditaefdff312012-11-21 13:35:34 -0500858 egress_port=of_ports[1]
859 no_ports=set(of_ports).difference([egress_port])
860 yes_ports = of_ports[1]
861
ShreyaPandita6fbff252012-11-13 16:56:48 -0500862 logging.info("Inserting two wildcarded flows with priorities ")
863 logging.info("Sending packets matching the flows")
864 logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
865
866 (pkt,match) = wildcard_all(self,of_ports,priority=20)
867 (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
868
869 #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
870 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500871 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
872
873
874
875
876