blob: 71e36b883f94195c506476df13a715eeca4afc31 [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
Kiran Poolaff12e482013-07-02 14:19:52 -0700653class ArpOpcode(base_tests.SimpleDataPlane):
654
655 """"Verify match on single Header Field -- Arp Protocol"""
656
657 def runTest(self):
658
659 logging.info("Running Arp Protocol test")
660
661 of_ports = config["port_map"].keys()
662 of_ports.sort()
663 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
664
665 #Clear Switch State
666 delete_all_flows(self.controller)
667
668 egress_port=of_ports[1]
669 no_ports=set(of_ports).difference([egress_port])
670 yes_ports = of_ports[1]
671
672 logging.info("Inserting a flow with match on Arp Protocol Opcode")
673 logging.info("Sending matching and non-matching arp packets")
674 logging.info("Verifying only matching packets implements the action specified in the flow")
675
676 #Create a flow matching on ARP Opcode
677 (pkt,match) = match_arp_opcode(self,of_ports)
678
679 #Send Packet matching the flow
680 self.dataplane.send(of_ports[0], str(pkt))
681
682 #Verify packet implements the action specified in the flow
683 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
684
685 #Create a non-matching packet , verify packet_in get generated
686 pkt2 = simple_arp_packet(arp_op=2)
687 self.dataplane.send(of_ports[0], str(pkt2))
688 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500689
Shudong Zhoudceec932013-02-06 01:12:54 -0800690class ArpSenderIP(base_tests.SimpleDataPlane):
691
692 """"Verify match on single Header Field -- Arp Protocol"""
693
694 def runTest(self):
695
696 logging.info("Running Arp Protocol test")
697
698 of_ports = config["port_map"].keys()
699 of_ports.sort()
700 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
701
702 #Clear Switch State
703 delete_all_flows(self.controller)
704
705 egress_port=of_ports[1]
706 no_ports=set(of_ports).difference([egress_port])
707 yes_ports = of_ports[1]
708
709 logging.info("Inserting a flow with match on Arp Protocol ")
710 logging.info("Sending matching and non-matching arp packets")
711 logging.info("Verifying only matching packets implements the action specified in the flow")
712
713 #Create a flow matching on ARP sender IP
714 (pkt,match) = match_arp_sender(self,of_ports)
715
716 #Send Packet matching the flow
717 self.dataplane.send(of_ports[0], str(pkt))
718
719 #Verify packet implements the action specified in the flow
720 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
721
722 #Create a non-matching packet , verify packet_in get generated
723 pkt2 = simple_arp_packet(ip_snd="10.10.0.10");
724 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700725 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhoudceec932013-02-06 01:12:54 -0800726
727class ArpTargetIP(base_tests.SimpleDataPlane):
728
729 """"Verify match on single Header Field -- Arp Protocol"""
730
731 def runTest(self):
732
733 logging.info("Running Arp Protocol test")
734
735 of_ports = config["port_map"].keys()
736 of_ports.sort()
737 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
738
739 #Clear Switch State
740 delete_all_flows(self.controller)
741
742 egress_port=of_ports[1]
743 no_ports=set(of_ports).difference([egress_port])
744 yes_ports = of_ports[1]
745
746 logging.info("Inserting a flow with match on Arp Protocol ")
747 logging.info("Sending matching and non-matching arp packets")
748 logging.info("Verifying only matching packets implements the action specified in the flow")
749
750 #Create a flow matching on ARP target IP
751 (pkt,match) = match_arp_target(self,of_ports)
752
753 #Send Packet matching the flow
754 self.dataplane.send(of_ports[0], str(pkt))
755
756 #Verify packet implements the action specified in the flow
757 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
758
759 #Create a non-matching packet , verify packet_in get generated
760 pkt2 = simple_arp_packet(ip_tgt="10.10.0.10");
761 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700762 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhoudceec932013-02-06 01:12:54 -0800763
764
ShreyaPandita6fbff252012-11-13 16:56:48 -0500765class ExactMatch(base_tests.SimpleDataPlane):
766
767 """Verify match on Single header field -- Exact Match """
768
769 def runTest(self):
770
771 logging.info("Running Tcp Exact Match test")
772
773 of_ports = config["port_map"].keys()
774 of_ports.sort()
775 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
776
777 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800778 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500779
ShreyaPanditaefdff312012-11-21 13:35:34 -0500780 egress_port=of_ports[1]
781 no_ports=set(of_ports).difference([egress_port])
782 yes_ports = of_ports[1]
783
ShreyaPandita6fbff252012-11-13 16:56:48 -0500784 logging.info("Inserting a flow with match for Exact Match ")
785 logging.info("Sending matching and non-matching packets")
786 logging.info("Verifying matching packets implements the action specified in the flow")
787
788 (pkt,match) = exact_match(self,of_ports)
789
790 #Sending packet matching all the fields of a tcp_packet, verify it implements the action
791 self.dataplane.send(of_ports[0], str(pkt))
792
793 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500794 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
795
796 #Sending non matching packet , verify Packetin event gets triggered.
797 pkt2 = simple_tcp_packet(tcp_sport=540);
798 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700799 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500800
801
802class MultipleHeaderFieldL4(base_tests.SimpleDataPlane):
803
804 """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """
805
806 def runTest(self):
807
808 logging.info("Running Multiple Header Field L4 test")
809
810 of_ports = config["port_map"].keys()
811 of_ports.sort()
812 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
813
814 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800815 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500816
ShreyaPanditaefdff312012-11-21 13:35:34 -0500817 egress_port=of_ports[1]
818 no_ports=set(of_ports).difference([egress_port])
819 yes_ports = of_ports[1]
820
ShreyaPandita6fbff252012-11-13 16:56:48 -0500821 logging.info("Inserting a flow with match on Multiple Header Field L4 ")
822 logging.info("Sending matching and non-matching packets")
823 logging.info("Verifying matching packets implements the action specified in the flow")
824
825 (pkt,match) = match_mul_l4(self,of_ports)
826
827 #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
828 self.dataplane.send(of_ports[0], str(pkt))
829
830 #Verify packet implements the action specified in the flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500831 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
832
ShreyaPanditaefdff312012-11-21 13:35:34 -0500833 #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered.
834 pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541);
835 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700836 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500837
838 #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered.
839 pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500840 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700841 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500842
843
844class ExactMatchPrio(base_tests.SimpleDataPlane):
845
846 """Verify that Exact Match has highest priority """
847
848 def runTest(self):
849
850 logging.info("Running Exact Match High Priority test")
851
852 of_ports = config["port_map"].keys()
853 of_ports.sort()
854 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
855
856 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800857 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500858
Rich Laneed130652012-12-31 17:35:33 -0800859 egress_port=of_ports[2]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500860 no_ports=set(of_ports).difference([egress_port])
Rich Laneed130652012-12-31 17:35:33 -0800861 yes_ports = egress_port
ShreyaPanditaefdff312012-11-21 13:35:34 -0500862
ShreyaPandita6fbff252012-11-13 16:56:48 -0500863 logging.info("Inserting a flow with Exact Match (low priority)")
864 logging.info("Inserting an overlapping wildcarded flow (higher priority)")
865 logging.info("Sending packets matching both the flows ")
866 logging.info("Verifying matching packets implements the action specified in the exact match flow")
867
868 #Insert two Overlapping Flows : Exact Match and Wildcard All.
869 (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
870 (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
871
872 #Sending packet matching both the flows ,
873 self.dataplane.send(of_ports[0], str(pkt2))
874
875 #verify it implements the action specified in Exact Match Flow
ShreyaPandita6fbff252012-11-13 16:56:48 -0500876 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
877
878
879class WildcardMatchPrio(base_tests.SimpleDataPlane):
880
881 """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
882
883 def runTest(self):
884
885 logging.info("Running Wildcard Match High Priority test")
886
887 of_ports = config["port_map"].keys()
888 of_ports.sort()
889 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
890
891 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800892 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500893
ShreyaPanditaefdff312012-11-21 13:35:34 -0500894 egress_port=of_ports[1]
895 no_ports=set(of_ports).difference([egress_port])
896 yes_ports = of_ports[1]
897
ShreyaPandita6fbff252012-11-13 16:56:48 -0500898 logging.info("Inserting two wildcarded flows with priorities ")
899 logging.info("Sending packets matching the flows")
900 logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
901
902 (pkt,match) = wildcard_all(self,of_ports,priority=20)
903 (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
904
905 #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
906 self.dataplane.send(of_ports[0], str(pkt1))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500907 receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self)
908
909
910
911
912