blob: 141ac0cf4572ce2971d8e8c71214f724e70ae172 [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
Rich Lanee4b384d2013-09-13 14:33:40 -070045 in_port = of_ports[0]
46 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -050047
ShreyaPandita6fbff252012-11-13 16:56:48 -050048 #Insert an All Wildcarded flow.
49 wildcard_all(self,of_ports)
50
51 #check for different match fields and verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -070052 pkt1 = str(simple_tcp_packet(eth_src="00:01:01:01:01:01"))
53 self.dataplane.send(in_port, pkt1)
54 verify_packets(self, pkt1, [egress_port])
ShreyaPanditaefdff312012-11-21 13:35:34 -050055
Rich Lanee4b384d2013-09-13 14:33:40 -070056 pkt2 = str(simple_tcp_packet(eth_dst="00:01:01:01:01:01"))
57 self.dataplane.send(in_port, pkt2)
58 verify_packets(self, pkt2, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -050059
Rich Lanee4b384d2013-09-13 14:33:40 -070060 pkt3 = str(simple_tcp_packet(ip_src="192.168.2.1"))
61 self.dataplane.send(in_port, pkt3)
62 verify_packets(self, pkt3, [egress_port])
ShreyaPanditaefdff312012-11-21 13:35:34 -050063
Rich Lanee4b384d2013-09-13 14:33:40 -070064 pkt4 = str(simple_tcp_packet(ip_dst="192.168.2.2"))
65 self.dataplane.send(in_port, pkt4)
66 verify_packets(self, pkt4, [egress_port])
ShreyaPanditaefdff312012-11-21 13:35:34 -050067
Rich Lanee4b384d2013-09-13 14:33:40 -070068 pkt5 = str(simple_tcp_packet(ip_tos=2))
69 self.dataplane.send(in_port, pkt5)
70 verify_packets(self, pkt5, [egress_port])
ShreyaPanditaefdff312012-11-21 13:35:34 -050071
Rich Lanee4b384d2013-09-13 14:33:40 -070072 pkt6 = str(simple_tcp_packet(tcp_sport=8080))
73 self.dataplane.send(in_port, pkt6)
74 verify_packets(self, pkt6, [egress_port])
ShreyaPanditaefdff312012-11-21 13:35:34 -050075
Rich Lanee4b384d2013-09-13 14:33:40 -070076 pkt7 = str(simple_tcp_packet(tcp_dport=8081))
77 self.dataplane.send(in_port, pkt7)
78 verify_packets(self, pkt7, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -050079
80
81
82class EthernetSrcAddress(base_tests.SimpleDataPlane):
83
84 """Verify match on single header field -- Ethernet Src Address """
85
86 def runTest(self):
87
88 logging.info("Running Ethernet Src Address test")
89
90 of_ports = config["port_map"].keys()
91 of_ports.sort()
92 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
93
94 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080095 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -050096
Rich Lanee4b384d2013-09-13 14:33:40 -070097 in_port = of_ports[0]
98 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -050099
ShreyaPandita6fbff252012-11-13 16:56:48 -0500100 logging.info("Inserting a flow with match on Ethernet Source Address ")
101 logging.info("Sending matching and non-matching ethernet packets")
102 logging.info("Verifying only matching packets implements the action specified in the flow")
103
104 #Insert a Match On Ethernet Src Address flow
105 (pkt,match) = match_ethernet_src_address(self,of_ports)
106
107 #Sending packet matching the flow, verify it implements the action
Rich Lanee4b384d2013-09-13 14:33:40 -0700108 self.dataplane.send(in_port, str(pkt))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500109
110 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700111 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500112
113 #Sending non matching packet , verify Packetin event gets triggered.
Rich Laned0478ff2013-03-11 12:46:58 -0700114 pkt2 = simple_eth_packet(eth_src='00:01:01:01:01:02');
Rich Lanee4b384d2013-09-13 14:33:40 -0700115 self.dataplane.send(in_port, str(pkt2))
116 verify_packet_in(self, str(pkt2), in_port, ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500117
118class EthernetDstAddress(base_tests.SimpleDataPlane):
119
120 """Verify match on single Header Field Field -- Ethernet Dst Address """
121
122 def runTest(self):
123
124 logging.info("Running Ethernet Dst Address test")
125
126 of_ports = config["port_map"].keys()
127 of_ports.sort()
128 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
129
130 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800131 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500132
Rich Lanee4b384d2013-09-13 14:33:40 -0700133 in_port = of_ports[0]
134 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500135
ShreyaPandita6fbff252012-11-13 16:56:48 -0500136 logging.info("Inserting a flow with match on Ethernet Destination Address ")
137 logging.info("Sending matching and non-matching ethernet packets")
138 logging.info("Verifying only matching packets implements the action specified in the flow")
139
140 #Insert a Match on Destination Address flow
141 (pkt,match) = match_ethernet_dst_address(self,of_ports)
142
143 #Send Packet matching the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700144 self.dataplane.send(in_port, str(pkt))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500145
146 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700147 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500148
149 #Send Non-matching packet
Rich Laned0478ff2013-03-11 12:46:58 -0700150 pkt2 = simple_eth_packet(eth_dst='00:01:01:01:01:02');
Rich Lanee4b384d2013-09-13 14:33:40 -0700151 self.dataplane.send(in_port, str(pkt2))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500152
153 #Verify PacketIn event gets triggered
Rich Lanee4b384d2013-09-13 14:33:40 -0700154 verify_packet_in(self, str(pkt2), in_port, ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500155
156
157class EthernetType(base_tests.SimpleDataPlane):
158
159 """Verify match on single header field -- Ethernet Type """
160
161 def runTest(self):
162
163 logging.info("Running Ethernet Type test")
164
165 of_ports = config["port_map"].keys()
166 of_ports.sort()
167 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
168
169 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800170 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500171
Rich Lanee4b384d2013-09-13 14:33:40 -0700172 in_port = of_ports[0]
173 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500174
ShreyaPandita6fbff252012-11-13 16:56:48 -0500175 logging.info("Inserting a flow with match on Ethernet Type ")
176 logging.info("Sending matching and non-matching ethernet packets")
177 logging.info("Verifying only matching packets implements the action specified in the flow")
178
179 #Insert a Match on Ethernet-Type flow
180 (pkt,match) = match_ethernet_type(self,of_ports)
181
182 #Sending packet matching the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700183 self.dataplane.send(in_port, str(pkt))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500184
185 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700186 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500187
188 #Sending non matching packet ,
Rich Laned0478ff2013-03-11 12:46:58 -0700189 pkt2 = simple_eth_packet(eth_type=0x0806);
Rich Lanee4b384d2013-09-13 14:33:40 -0700190 self.dataplane.send(in_port, str(pkt2))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500191
192 #verify Packetin event gets triggered.
Rich Lanee4b384d2013-09-13 14:33:40 -0700193 verify_packet_in(self, str(pkt2), in_port, ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500194
195
196class IngressPort(base_tests.SimpleDataPlane):
197
198 """Verify match on single Header Field Field -- In_port """
199
200 def runTest(self):
201
202 logging.info("Running Ingress Port test")
203
204 of_ports = config["port_map"].keys()
205 of_ports.sort()
206 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
207
208 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800209 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500210
Rich Lanee4b384d2013-09-13 14:33:40 -0700211 in_port = of_ports[0]
212 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500213
ShreyaPandita6fbff252012-11-13 16:56:48 -0500214 logging.info("Inserting a flow with match on Ingress Port ")
215 logging.info("Sending matching and non-matching packets")
216 logging.info("Verifying only matching packets implements the action specified in the flow")
217
218 #Insert a Match on Ingress Port FLow
219 (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0)
220
221 #Send Packet matching the flow i.e on in_port specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700222 self.dataplane.send(in_port, str(pkt))
ShreyaPandita6fbff252012-11-13 16:56:48 -0500223
224 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700225 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500226
227 #Send Non-Matching Packet
228 self.dataplane.send(of_ports[1],str(pkt))
229
230 #Verify PacketIn event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700231 verify_packet_in(self, str(pkt), of_ports[1], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500232
233class VlanId(base_tests.SimpleDataPlane):
234
235 """Verify match on single Header Field Field -- Vlan Id """
236
237 def runTest(self):
238
239 of_ports = config["port_map"].keys()
240 of_ports.sort()
241 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
242
243 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800244 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500245
Rich Lanee4b384d2013-09-13 14:33:40 -0700246 in_port = of_ports[0]
247 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500248
ShreyaPandita6fbff252012-11-13 16:56:48 -0500249 logging.info("Inserting a flow with match on VLAN ID ")
250 logging.info("Sending matching and non-matching tagged packets")
251 logging.info("Verifying matching packets implements the action specified in the flow")
252
253 #Create a flow with match on Vlan Id
254 (pkt,match) = match_vlan_id(self,of_ports)
255
256 #Send tagged packet matching the flow i.e packet with same vlan id as in flow
257 self.dataplane.send(of_ports[0], str(pkt))
258
259 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700260 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500261
262 #Send Non-matching packet, i.e packet with different Vlan Id
Rich Laned0478ff2013-03-11 12:46:58 -0700263 pkt2 = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=4);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500264 self.dataplane.send(of_ports[0], str(pkt2))
265
266 #Verify PacketIn event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700267 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500268
269class VlanPCP(base_tests.SimpleDataPlane):
270
271 """"Verify match on single Header Field Field -- Vlan Priority"""
272
273 def runTest(self):
274
275 logging.info("Running VlanPCP1 test")
276
277 of_ports = config["port_map"].keys()
278 of_ports.sort()
279 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
280
281 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800282 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500283
Rich Lanee4b384d2013-09-13 14:33:40 -0700284 in_port = of_ports[0]
285 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500286
ShreyaPandita6fbff252012-11-13 16:56:48 -0500287 logging.info("Inserting a flow with match on VLAN Priority ")
288 logging.info("Sending matching and non-matching tagged packets")
289 logging.info("Verifying matching packet implements the action specified in the flow")
290
291 #Create a flow matching on VLAN Priority
292 (pkt,match) = match_vlan_pcp(self,of_ports)
293
294 #Send tagged Packet matching the flow
295 self.dataplane.send(of_ports[0], str(pkt))
296
297 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700298 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500299
300 #Send tagged packet with same vlan_id but different vlan priority
Rich Laned0478ff2013-03-11 12:46:58 -0700301 pkt2 = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=1,vlan_pcp=20);
ShreyaPanditaefdff312012-11-21 13:35:34 -0500302 self.dataplane.send(of_ports[0], str(pkt2))
303
304 #Verify Packet_In event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700305 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500306
307class MultipleHeaderFieldL2(base_tests.SimpleDataPlane):
308
309 """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """
310
311 def runTest(self):
312
313 logging.info("Running Multiple Header Field L2 test")
314
315 of_ports = config["port_map"].keys()
316 of_ports.sort()
317 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
318
319 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800320 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500321
Rich Lanee4b384d2013-09-13 14:33:40 -0700322 in_port = of_ports[0]
323 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500324
ShreyaPandita6fbff252012-11-13 16:56:48 -0500325 logging.info("Inserting a flow with match on Multiple Header Fields in L2 ")
326 logging.info("Sending matching and non-matching packets")
327 logging.info("Verifying matching packets implements the action specified in the flow")
328
329 (pkt,match) = match_mul_l2(self,of_ports)
330
Rich Laned0478ff2013-03-11 12:46:58 -0700331 #Send eth packet matching the eth_type field, verify it implements the action
ShreyaPandita6fbff252012-11-13 16:56:48 -0500332 self.dataplane.send(of_ports[0], str(pkt))
333
334 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700335 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500336
Rich Laned0478ff2013-03-11 12:46:58 -0700337 #Sending non matching packet (only eth_dst is different) , verify Packetin event gets triggered.
338 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 -0500339 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700340 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500341
Rich Laned0478ff2013-03-11 12:46:58 -0700342 #Sending non matching packet (only eth_src is different) , verify Packetin event gets triggered.
343 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 -0500344 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700345 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500346
347 #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered.
Rich Laned0478ff2013-03-11 12:46:58 -0700348 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 -0500349 self.dataplane.send(of_ports[0], str(pkt2))
350
ShreyaPanditaefdff312012-11-21 13:35:34 -0500351 #Verify packet_in event gets triggered
Rich Lane4c504f32013-06-07 17:24:14 -0700352 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500353
354class IpTos(base_tests.SimpleDataPlane):
355
356 """"Verify match on single Header Field Field -- Type of service"""
357
358 def runTest(self):
359
360 logging.info("Running Ip_Tos test")
361
362 of_ports = config["port_map"].keys()
363 of_ports.sort()
364 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
365
366 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800367 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500368
Rich Lanee4b384d2013-09-13 14:33:40 -0700369 in_port = of_ports[0]
370 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500371
ShreyaPandita6fbff252012-11-13 16:56:48 -0500372 logging.info("Inserting a flow with match on Ip_Tos ")
373 logging.info("Sending matching and non-matching tcp/ip packets")
374 logging.info("Verifying only matching packets implements the action specified in the flow")
375
376 #Create a flow matching on VLAN Priority
377 (pkt,match) = match_ip_tos(self,of_ports)
378
379 #Send Packet matching the flow
380 self.dataplane.send(of_ports[0], str(pkt))
381
382 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700383 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500384
385 #Create a non-matching packet , verify packet_in get generated
Rich Laneb5c73792012-12-03 17:12:32 -0800386 pkt2 = simple_tcp_packet(ip_tos=4);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500387 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700388 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500389
390class IpProtocol(base_tests.SimpleDataPlane):
391
392 """"Verify match on single Header Field Field -- Ip Protocol"""
393
394 def runTest(self):
395
396 logging.info("Running Ip Protocol test")
397
398 of_ports = config["port_map"].keys()
399 of_ports.sort()
400 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
401
402 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800403 delete_all_flows(self.controller)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500404
Rich Lanee4b384d2013-09-13 14:33:40 -0700405 in_port = of_ports[0]
406 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500407
ShreyaPandita6fbff252012-11-13 16:56:48 -0500408 logging.info("Inserting a flow with match on Ip Protocol ")
409 logging.info("Sending matching and non-matching tcp/ip packets")
410 logging.info("Verifying only matching packets implements the action specified in the flow")
411
412 #Create a flow matching on VLAN Priority
413 (pkt,match) = match_ip_protocol(self,of_ports)
414
415 #Send Packet matching the flow
416 self.dataplane.send(of_ports[0], str(pkt))
417
418 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700419 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500420
421 #Create a non-matching packet , verify packet_in get generated
422 pkt2 = simple_icmp_packet();
423 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700424 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500425
426
427class TcpSrcPort(base_tests.SimpleDataPlane):
428
429 """Verify match on Single header field -- Tcp Source Port, """
430
431 def runTest(self):
432
433 logging.info("Running Tcp Src Port test")
434
435 of_ports = config["port_map"].keys()
436 of_ports.sort()
437 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
438
439 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800440 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500441
Rich Lanee4b384d2013-09-13 14:33:40 -0700442 in_port = of_ports[0]
443 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500444
ShreyaPandita6fbff252012-11-13 16:56:48 -0500445 logging.info("Inserting a flow with match on Tcp Tcp Source Port ")
446 logging.info("Sending matching and non-matching tcp packets")
447 logging.info("Verifying matching packets implements the action specified in the flow")
448
449 (pkt,match) = match_tcp_src(self,of_ports)
450
451 #Sending packet matching the tcp_sport, verify it implements the action
452 self.dataplane.send(of_ports[0], str(pkt))
453
454 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700455 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500456
457 #Sending non matching packet , verify Packetin event gets triggered.
458 pkt2 = simple_tcp_packet(tcp_sport=540);
459 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700460 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500461
462class TcpDstPort(base_tests.SimpleDataPlane):
463
464 """Verify match on Single header field -- Tcp Destination Port """
465
466 def runTest(self):
467
468 logging.info("Running Tcp Destination Port test")
469
470 of_ports = config["port_map"].keys()
471 of_ports.sort()
472 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
473
474 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800475 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500476
Rich Lanee4b384d2013-09-13 14:33:40 -0700477 in_port = of_ports[0]
478 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500479
ShreyaPandita6fbff252012-11-13 16:56:48 -0500480 logging.info("Inserting a flow with match on Tcp Destination Port ")
481 logging.info("Sending matching and non-matching packets")
482 logging.info("Verifying matching packets implements the action specified in the flow")
483
484 (pkt,match) = match_tcp_dst(self,of_ports)
485
486 #Sending packet matching the tcp_dport, verify it implements the action
487 self.dataplane.send(of_ports[0], str(pkt))
488
489 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700490 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500491
492 #Sending non matching packet , verify Packetin event gets triggered.
493 pkt2 = simple_tcp_packet(tcp_dport=541);
494 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700495 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500496
Shudong Zhouc2f18762013-01-11 00:12:44 -0800497class UdpSrcPort(base_tests.SimpleDataPlane):
498
499 """Verify match on Single header field -- Udp Source Port, """
500
501 def runTest(self):
502
503 logging.info("Running Udp Src Port test")
504
505 of_ports = config["port_map"].keys()
506 of_ports.sort()
507 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
508
509 #Clear Switch State
510 delete_all_flows(self.controller)
511
Rich Lanee4b384d2013-09-13 14:33:40 -0700512 in_port = of_ports[0]
513 egress_port = of_ports[1]
Shudong Zhouc2f18762013-01-11 00:12:44 -0800514
515 logging.info("Inserting a flow with match on Udp Udp Source Port ")
516 logging.info("Sending matching and non-matching tcp packets")
517 logging.info("Verifying matching packets implements the action specified in the flow")
518
519 (pkt,match) = match_udp_src(self,of_ports)
520
521 #Sending packet matching the tcp_sport, verify it implements the action
522 self.dataplane.send(of_ports[0], str(pkt))
523
524 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700525 verify_packets(self, pkt, [egress_port])
Shudong Zhouc2f18762013-01-11 00:12:44 -0800526
527 #Sending non matching packet , verify Packetin event gets triggered.
528 pkt2 = simple_udp_packet(udp_sport=540);
529 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700530 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhouc2f18762013-01-11 00:12:44 -0800531
532class UdpDstPort(base_tests.SimpleDataPlane):
533
534 """Verify match on Single header field -- Udp Destination Port """
535
536 def runTest(self):
537
538 logging.info("Running Udp Destination Port test")
539
540 of_ports = config["port_map"].keys()
541 of_ports.sort()
542 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
543
544 #Clear Switch State
545 delete_all_flows(self.controller)
546
Rich Lanee4b384d2013-09-13 14:33:40 -0700547 in_port = of_ports[0]
548 egress_port = of_ports[1]
Shudong Zhouc2f18762013-01-11 00:12:44 -0800549
550 logging.info("Inserting a flow with match on Udp Destination Port ")
551 logging.info("Sending matching and non-matching packets")
552 logging.info("Verifying matching packets implements the action specified in the flow")
553
554 (pkt,match) = match_udp_dst(self,of_ports)
555
556 #Sending packet matching the tcp_dport, verify it implements the action
557 self.dataplane.send(of_ports[0], str(pkt))
558
559 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700560 verify_packets(self, pkt, [egress_port])
Shudong Zhouc2f18762013-01-11 00:12:44 -0800561
562 #Sending non matching packet , verify Packetin event gets triggered.
563 pkt2 = simple_udp_packet(udp_dport=541);
564 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700565 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhouc2f18762013-01-11 00:12:44 -0800566
567class ICMPType(base_tests.SimpleDataPlane):
568
569 """Verify match on Single header field -- ICMP type, """
570
571 def runTest(self):
572
573 logging.info("Running ICMP type test")
574
575 of_ports = config["port_map"].keys()
576 of_ports.sort()
577 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
578
579 #Clear Switch State
580 delete_all_flows(self.controller)
581
Rich Lanee4b384d2013-09-13 14:33:40 -0700582 in_port = of_ports[0]
583 egress_port = of_ports[1]
Shudong Zhouc2f18762013-01-11 00:12:44 -0800584
585 logging.info("Inserting a flow with match on ICMP type")
586 logging.info("Sending matching and non-matching ICMP packets")
587 logging.info("Verifying matching packets implements the action specified in the flow")
588
589 (pkt,match) = match_icmp_type(self,of_ports)
590
591 #Sending packet matching the tcp_sport, verify it implements the action
592 self.dataplane.send(of_ports[0], str(pkt))
593
594 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700595 verify_packets(self, pkt, [egress_port])
Shudong Zhouc2f18762013-01-11 00:12:44 -0800596
597 #Sending non matching packet , verify Packetin event gets triggered.
598 pkt2 = simple_icmp_packet(icmp_type=10);
599 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700600 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhouc2f18762013-01-11 00:12:44 -0800601
602class ICMPCode(base_tests.SimpleDataPlane):
603
604 """Verify match on Single header field -- ICMP code, """
605
606 def runTest(self):
607
608 logging.info("Running ICMP code test")
609
610 of_ports = config["port_map"].keys()
611 of_ports.sort()
612 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
613
614 #Clear Switch State
615 delete_all_flows(self.controller)
616
Rich Lanee4b384d2013-09-13 14:33:40 -0700617 in_port = of_ports[0]
618 egress_port = of_ports[1]
Shudong Zhouc2f18762013-01-11 00:12:44 -0800619
620 logging.info("Inserting a flow with match on ICMP type")
621 logging.info("Sending matching and non-matching ICMP packets")
622 logging.info("Verifying matching packets implements the action specified in the flow")
623
624 (pkt,match) = match_icmp_code(self,of_ports)
625
626 #Sending packet matching the tcp_dport, verify it implements the action
627 self.dataplane.send(of_ports[0], str(pkt))
628
629 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700630 verify_packets(self, pkt, [egress_port])
Shudong Zhouc2f18762013-01-11 00:12:44 -0800631
632 #Sending non matching packet , verify Packetin event gets triggered.
633 pkt2 = simple_icmp_packet(icmp_code=10);
634 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700635 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhouc2f18762013-01-11 00:12:44 -0800636
Kiran Poolaff12e482013-07-02 14:19:52 -0700637class ArpOpcode(base_tests.SimpleDataPlane):
638
639 """"Verify match on single Header Field -- Arp Protocol"""
640
641 def runTest(self):
642
643 logging.info("Running Arp Protocol test")
644
645 of_ports = config["port_map"].keys()
646 of_ports.sort()
647 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
648
649 #Clear Switch State
650 delete_all_flows(self.controller)
651
Rich Lanee4b384d2013-09-13 14:33:40 -0700652 in_port = of_ports[0]
653 egress_port = of_ports[1]
Kiran Poolaff12e482013-07-02 14:19:52 -0700654
655 logging.info("Inserting a flow with match on Arp Protocol Opcode")
656 logging.info("Sending matching and non-matching arp packets")
657 logging.info("Verifying only matching packets implements the action specified in the flow")
658
659 #Create a flow matching on ARP Opcode
660 (pkt,match) = match_arp_opcode(self,of_ports)
661
662 #Send Packet matching the flow
663 self.dataplane.send(of_ports[0], str(pkt))
664
665 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700666 verify_packets(self, pkt, [egress_port])
Kiran Poolaff12e482013-07-02 14:19:52 -0700667
668 #Create a non-matching packet , verify packet_in get generated
669 pkt2 = simple_arp_packet(arp_op=2)
670 self.dataplane.send(of_ports[0], str(pkt2))
671 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500672
Shudong Zhoudceec932013-02-06 01:12:54 -0800673class ArpSenderIP(base_tests.SimpleDataPlane):
674
675 """"Verify match on single Header Field -- Arp Protocol"""
676
677 def runTest(self):
678
679 logging.info("Running Arp Protocol test")
680
681 of_ports = config["port_map"].keys()
682 of_ports.sort()
683 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
684
685 #Clear Switch State
686 delete_all_flows(self.controller)
687
Rich Lanee4b384d2013-09-13 14:33:40 -0700688 in_port = of_ports[0]
689 egress_port = of_ports[1]
Shudong Zhoudceec932013-02-06 01:12:54 -0800690
691 logging.info("Inserting a flow with match on Arp Protocol ")
692 logging.info("Sending matching and non-matching arp packets")
693 logging.info("Verifying only matching packets implements the action specified in the flow")
694
695 #Create a flow matching on ARP sender IP
696 (pkt,match) = match_arp_sender(self,of_ports)
697
698 #Send Packet matching the flow
699 self.dataplane.send(of_ports[0], str(pkt))
700
701 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700702 verify_packets(self, pkt, [egress_port])
Shudong Zhoudceec932013-02-06 01:12:54 -0800703
704 #Create a non-matching packet , verify packet_in get generated
705 pkt2 = simple_arp_packet(ip_snd="10.10.0.10");
706 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700707 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhoudceec932013-02-06 01:12:54 -0800708
709class ArpTargetIP(base_tests.SimpleDataPlane):
710
711 """"Verify match on single Header Field -- Arp Protocol"""
712
713 def runTest(self):
714
715 logging.info("Running Arp Protocol test")
716
717 of_ports = config["port_map"].keys()
718 of_ports.sort()
719 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
720
721 #Clear Switch State
722 delete_all_flows(self.controller)
723
Rich Lanee4b384d2013-09-13 14:33:40 -0700724 in_port = of_ports[0]
725 egress_port = of_ports[1]
Shudong Zhoudceec932013-02-06 01:12:54 -0800726
727 logging.info("Inserting a flow with match on Arp Protocol ")
728 logging.info("Sending matching and non-matching arp packets")
729 logging.info("Verifying only matching packets implements the action specified in the flow")
730
731 #Create a flow matching on ARP target IP
732 (pkt,match) = match_arp_target(self,of_ports)
733
734 #Send Packet matching the flow
735 self.dataplane.send(of_ports[0], str(pkt))
736
737 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700738 verify_packets(self, pkt, [egress_port])
Shudong Zhoudceec932013-02-06 01:12:54 -0800739
740 #Create a non-matching packet , verify packet_in get generated
741 pkt2 = simple_arp_packet(ip_tgt="10.10.0.10");
742 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700743 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
Shudong Zhoudceec932013-02-06 01:12:54 -0800744
745
ShreyaPandita6fbff252012-11-13 16:56:48 -0500746class ExactMatch(base_tests.SimpleDataPlane):
747
748 """Verify match on Single header field -- Exact Match """
749
750 def runTest(self):
751
752 logging.info("Running Tcp Exact Match test")
753
754 of_ports = config["port_map"].keys()
755 of_ports.sort()
756 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
757
758 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800759 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500760
Rich Lanee4b384d2013-09-13 14:33:40 -0700761 in_port = of_ports[0]
762 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500763
ShreyaPandita6fbff252012-11-13 16:56:48 -0500764 logging.info("Inserting a flow with match for Exact Match ")
765 logging.info("Sending matching and non-matching packets")
766 logging.info("Verifying matching packets implements the action specified in the flow")
767
768 (pkt,match) = exact_match(self,of_ports)
769
770 #Sending packet matching all the fields of a tcp_packet, verify it implements the action
771 self.dataplane.send(of_ports[0], str(pkt))
772
773 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700774 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500775
776 #Sending non matching packet , verify Packetin event gets triggered.
777 pkt2 = simple_tcp_packet(tcp_sport=540);
778 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700779 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500780
781
782class MultipleHeaderFieldL4(base_tests.SimpleDataPlane):
783
784 """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """
785
786 def runTest(self):
787
788 logging.info("Running Multiple Header Field L4 test")
789
790 of_ports = config["port_map"].keys()
791 of_ports.sort()
792 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
793
794 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800795 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500796
Rich Lanee4b384d2013-09-13 14:33:40 -0700797 in_port = of_ports[0]
798 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500799
ShreyaPandita6fbff252012-11-13 16:56:48 -0500800 logging.info("Inserting a flow with match on Multiple Header Field L4 ")
801 logging.info("Sending matching and non-matching packets")
802 logging.info("Verifying matching packets implements the action specified in the flow")
803
804 (pkt,match) = match_mul_l4(self,of_ports)
805
806 #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action
807 self.dataplane.send(of_ports[0], str(pkt))
808
809 #Verify packet implements the action specified in the flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700810 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500811
ShreyaPanditaefdff312012-11-21 13:35:34 -0500812 #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered.
813 pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541);
814 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700815 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPanditaefdff312012-11-21 13:35:34 -0500816
817 #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered.
818 pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112);
ShreyaPandita6fbff252012-11-13 16:56:48 -0500819 self.dataplane.send(of_ports[0], str(pkt2))
Rich Lane4c504f32013-06-07 17:24:14 -0700820 verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500821
822
823class ExactMatchPrio(base_tests.SimpleDataPlane):
824
825 """Verify that Exact Match has highest priority """
826
827 def runTest(self):
828
829 logging.info("Running Exact Match High Priority test")
830
831 of_ports = config["port_map"].keys()
832 of_ports.sort()
833 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
834
835 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800836 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500837
Rich Lanee4b384d2013-09-13 14:33:40 -0700838 in_port = of_ports[0]
839 egress_port = of_ports[2]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500840
ShreyaPandita6fbff252012-11-13 16:56:48 -0500841 logging.info("Inserting a flow with Exact Match (low priority)")
842 logging.info("Inserting an overlapping wildcarded flow (higher priority)")
843 logging.info("Sending packets matching both the flows ")
844 logging.info("Verifying matching packets implements the action specified in the exact match flow")
845
846 #Insert two Overlapping Flows : Exact Match and Wildcard All.
847 (pkt,match) = exact_match_with_prio(self,of_ports,priority=10)
848 (pkt2,match2) = wildcard_all(self,of_ports,priority=20);
849
850 #Sending packet matching both the flows ,
851 self.dataplane.send(of_ports[0], str(pkt2))
852
853 #verify it implements the action specified in Exact Match Flow
Rich Lanee4b384d2013-09-13 14:33:40 -0700854 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500855
856
857class WildcardMatchPrio(base_tests.SimpleDataPlane):
858
859 """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """
860
861 def runTest(self):
862
863 logging.info("Running Wildcard Match High Priority test")
864
865 of_ports = config["port_map"].keys()
866 of_ports.sort()
867 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
868
869 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800870 delete_all_flows(self.controller)
ShreyaPandita6fbff252012-11-13 16:56:48 -0500871
Rich Lanee4b384d2013-09-13 14:33:40 -0700872 in_port = of_ports[0]
873 egress_port = of_ports[1]
ShreyaPanditaefdff312012-11-21 13:35:34 -0500874
ShreyaPandita6fbff252012-11-13 16:56:48 -0500875 logging.info("Inserting two wildcarded flows with priorities ")
876 logging.info("Sending packets matching the flows")
877 logging.info("Verifying matching packets implements the action specified in the flow with higher priority")
878
879 (pkt,match) = wildcard_all(self,of_ports,priority=20)
880 (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10)
881
882 #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow
883 self.dataplane.send(of_ports[0], str(pkt1))
Rich Lanee4b384d2013-09-13 14:33:40 -0700884 verify_packets(self, pkt, [egress_port])
ShreyaPandita6fbff252012-11-13 16:56:48 -0500885
886
887
888
889