blob: 0ef9dc153cdcc60912d1dbd8e97e4cc1337a07ff [file] [log] [blame]
ShreyaPandita60e45542012-09-27 15:11:16 -04001""" Defined Some common functions used by Conformance tests -- OF-SWITCH 1.0.0 Testcases """
2
3import sys
4import copy
5import random
6
7import oftest.controller as controller
8import oftest.cstruct as ofp
9import oftest.message as message
10import oftest.dataplane as dataplane
11import oftest.action as action
12import oftest.parse as parse
13import logging
14import types
ShreyaPandita66de26f2012-10-26 14:44:24 -040015
Rich Laneb90a1c42012-10-05 09:16:05 -070016import oftest.base_tests as base_tests
Rich Laneda3b5ad2012-10-03 09:05:32 -070017from oftest.testutils import *
ShreyaPandita60e45542012-09-27 15:11:16 -040018from time import sleep
19
20#################### Functions for various types of flow_mod ##########################################################################################
21
22def Exact_Match(self,of_ports,priority=0):
23# Generate ExactMatch flow .
24
25 #Create a simple tcp packet and generate exact flow match from it.
26 Pkt_ExactFlow = simple_tcp_packet()
27 match = parse.packet_to_flow_match(Pkt_ExactFlow)
28 self.assertTrue(match is not None, "Could not generate flow match from pkt")
29 match.in_port = of_ports[0]
30 #match.nw_src = 1
31 match.wildcards=0
32 msg = message.flow_mod()
33 msg.out_port = ofp.OFPP_NONE
34 msg.command = ofp.OFPFC_ADD
35 msg.buffer_id = 0xffffffff
36 msg.match = match
37 if priority != 0 :
38 msg.priority = priority
39
40 act = action.action_output()
41 act.port = of_ports[1]
42 self.assertTrue(msg.actions.add(act), "could not add action")
43
44 rv = self.controller.message_send(msg)
45 self.assertTrue(rv != -1, "Error installing flow mod")
46 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
47
48 return (Pkt_ExactFlow,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -040049
50def Exact_Match_With_Prio(self,of_ports,priority=0):
51 # Generate ExactMatch With Prority flow .
52
53 #Create a simple tcp packet and generate exact flow match from it.
54 Pkt_ExactFlow = simple_tcp_packet()
55 match = parse.packet_to_flow_match(Pkt_ExactFlow)
56 self.assertTrue(match is not None, "Could not generate flow match from pkt")
57 match.in_port = of_ports[0]
58 #match.nw_src = 1
59 match.wildcards=0
60 msg = message.flow_mod()
61 msg.out_port = ofp.OFPP_NONE
62 msg.command = ofp.OFPFC_ADD
63 msg.buffer_id = 0xffffffff
64 msg.match = match
65 if priority != 0 :
66 msg.priority = priority
67
68 act = action.action_output()
69 act.port = of_ports[2]
70 self.assertTrue(msg.actions.add(act), "could not add action")
71
72 rv = self.controller.message_send(msg)
73 self.assertTrue(rv != -1, "Error installing flow mod")
74 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
75
76 return (Pkt_ExactFlow,match)
77
ShreyaPandita60e45542012-09-27 15:11:16 -040078
79def Match_All_Except_Source_Address(self,of_ports,priority=0):
80# Generate Match_All_Except_Source_Address flow
81
82 #Create a simple tcp packet and generate match all except src address flow.
83 Pkt_WildcardSrc= simple_tcp_packet()
84 match1 = parse.packet_to_flow_match(Pkt_WildcardSrc)
85 self.assertTrue(match1 is not None, "Could not generate flow match from pkt")
86 match1.in_port = of_ports[0]
87 #match1.nw_src = 1
88 match1.wildcards = ofp.OFPFW_DL_SRC
89 msg1 = message.flow_mod()
90 msg1.out_port = ofp.OFPP_NONE
91 msg1.command = ofp.OFPFC_ADD
92 msg1.buffer_id = 0xffffffff
93 msg1.match = match1
94 if priority != 0 :
95 msg1.priority = priority
96
97 act1 = action.action_output()
98 act1.port = of_ports[1]
99 self.assertTrue(msg1.actions.add(act1), "could not add action")
100
101 rv = self.controller.message_send(msg1)
102 self.assertTrue(rv != -1, "Error installing flow mod")
103 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
104
105 return (Pkt_WildcardSrc,match1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400106
107def Match_Ethernet_Src_Address(self,of_ports,priority=0):
108 #Generate Match_Ethernet_SrC_Address flow
109
110 #Create a simple tcp packet and generate match on ethernet src address flow
111 pkt_MatchSrc = simple_tcp_packet(dl_src='00:01:01:01:01:01')
112 match = parse.packet_to_flow_match(pkt_MatchSrc)
113 self.assertTrue(match is not None, "Could not generate flow match from pkt")
114
115 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_SRC
ShreyaPandita60e45542012-09-27 15:11:16 -0400116
ShreyaPandita66de26f2012-10-26 14:44:24 -0400117 msg = message.flow_mod()
118 msg.out_port = ofp.OFPP_NONE
119 msg.command = ofp.OFPFC_ADD
120 msg.buffer_id = 0xffffffff
121 msg.match = match
122 if priority != 0 :
123 msg.priority = priority
124
125 act = action.action_output()
126 act.port = of_ports[1]
127 self.assertTrue(msg.actions.add(act), "could not add action")
128
129 rv = self.controller.message_send(msg)
130 self.assertTrue(rv != -1, "Error installing flow mod")
131 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
132
133 return (pkt_MatchSrc,match)
134
135def Match_Ethernet_Dst_Address(self,of_ports,priority=0):
136 #Generate Match_Ethernet_Dst_Address flow
137
138 #Create a simple tcp packet and generate match on ethernet dst address flow
139 pkt_MatchDst = simple_tcp_packet(dl_dst='00:01:01:01:01:01')
140 match = parse.packet_to_flow_match(pkt_MatchDst)
141 self.assertTrue(match is not None, "Could not generate flow match from pkt")
142
143 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_DST
144 msg = message.flow_mod()
145 msg.out_port = ofp.OFPP_NONE
146 msg.command = ofp.OFPFC_ADD
147 msg.buffer_id = 0xffffffff
148 msg.match = match
149 if priority != 0 :
150 msg.priority = priority
151
152 act = action.action_output()
153 act.port = of_ports[1]
154 self.assertTrue(msg.actions.add(act), "could not add action")
155
156 rv = self.controller.message_send(msg)
157 self.assertTrue(rv != -1, "Error installing flow mod")
158 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
159
160 return (pkt_MatchDst,match)
161
ShreyaPandita60e45542012-09-27 15:11:16 -0400162def Wildcard_All(self,of_ports,priority=0):
163# Generate a Wildcard_All Flow
164
165 #Create a simple tcp packet and generate wildcard all flow match from it.
166 Pkt_Wildcard = simple_tcp_packet()
167 match2 = parse.packet_to_flow_match(Pkt_Wildcard)
168 self.assertTrue(match2 is not None, "Could not generate flow match from pkt")
169 match2.wildcards=ofp.OFPFW_ALL
170 match2.in_port = of_ports[0]
171
172 msg2 = message.flow_mod()
173 msg2.out_port = ofp.OFPP_NONE
174 msg2.command = ofp.OFPFC_ADD
175 msg2.buffer_id = 0xffffffff
176 msg2.match = match2
177 act2 = action.action_output()
178 act2.port = of_ports[1]
179 self.assertTrue(msg2.actions.add(act2), "could not add action")
180 if priority != 0 :
181 msg2.priority = priority
182
183 rv = self.controller.message_send(msg2)
184 self.assertTrue(rv != -1, "Error installing flow mod")
185 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
186
187 return (Pkt_Wildcard,match2)
188
189def Wildcard_All_Except_Ingress(self,of_ports,priority=0):
190# Generate Wildcard_All_Except_Ingress_port flow
191
192
193 #Create a simple tcp packet and generate wildcard all except ingress_port flow.
194 Pkt_MatchIngress = simple_tcp_packet()
195 match3 = parse.packet_to_flow_match(Pkt_MatchIngress)
196 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
197 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
198 match3.in_port = of_ports[0]
199
200 msg3 = message.flow_mod()
201 msg3.command = ofp.OFPFC_ADD
202 msg3.match = match3
203 msg3.out_port = of_ports[2] # ignored by flow add,flow modify
204 msg3.cookie = random.randint(0,9007199254740992)
205 msg3.buffer_id = 0xffffffff
206 msg3.idle_timeout = 0
207 msg3.hard_timeout = 0
208 msg3.buffer_id = 0xffffffff
209
210 act3 = action.action_output()
211 act3.port = of_ports[1]
212 self.assertTrue(msg3.actions.add(act3), "could not add action")
213
214 if priority != 0 :
215 msg3.priority = priority
216
217 rv = self.controller.message_send(msg3)
218 self.assertTrue(rv != -1, "Error installing flow mod")
219 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
220
221 return (Pkt_MatchIngress,match3)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400222
ShreyaPanditada75f752012-10-26 16:26:35 -0400223def Wildcard_All_Except_Ingress1(self,of_ports,priority=0):
224# Generate Wildcard_All_Except_Ingress_port flow with action output to port egress_port 2
225
226
227 #Create a simple tcp packet and generate wildcard all except ingress_port flow.
228 Pkt_MatchIngress = simple_tcp_packet()
229 match3 = parse.packet_to_flow_match(Pkt_MatchIngress)
230 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
231 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
232 match3.in_port = of_ports[0]
233
234 msg3 = message.flow_mod()
235 msg3.command = ofp.OFPFC_ADD
236 msg3.match = match3
237 msg3.out_port = of_ports[2] # ignored by flow add,flow modify
238 msg3.cookie = random.randint(0,9007199254740992)
239 msg3.buffer_id = 0xffffffff
240 msg3.idle_timeout = 0
241 msg3.hard_timeout = 0
242 msg3.buffer_id = 0xffffffff
243
244 act3 = action.action_output()
245 act3.port = of_ports[2]
246 self.assertTrue(msg3.actions.add(act3), "could not add action")
247
248 if priority != 0 :
249 msg3.priority = priority
250
251 rv = self.controller.message_send(msg3)
252 self.assertTrue(rv != -1, "Error installing flow mod")
253 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
254
255 return (Pkt_MatchIngress,match3)
256
257
258
259
ShreyaPandita66de26f2012-10-26 14:44:24 -0400260def Match_Vlan_Id(self,of_ports,priority=0):
261 #Generate Match_Vlan_Id
262
263 #Create a simple tcp packet and generate match on ethernet dst address flow
264 pkt_MatchVlanId = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1)
265 match = parse.packet_to_flow_match(pkt_MatchVlanId)
266 self.assertTrue(match is not None, "Could not generate flow match from pkt")
267
268 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN
269 msg = message.flow_mod()
270 msg.out_port = ofp.OFPP_NONE
271 msg.command = ofp.OFPFC_ADD
272 msg.buffer_id = 0xffffffff
273 msg.match = match
274 if priority != 0 :
275 msg.priority = priority
276
277 act = action.action_output()
278 act.port = of_ports[1]
279 self.assertTrue(msg.actions.add(act), "could not add action")
280
281 rv = self.controller.message_send(msg)
282 self.assertTrue(rv != -1, "Error installing flow mod")
283 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
284
285 return (pkt_MatchVlanId,match)
286
287def Match_Vlan_Pcp(self,of_ports,priority=0):
288 #Generate Match_Vlan_Id
289
290 #Create a simple tcp packet and generate match on ethernet dst address flow
291 pkt_MatchVlanPcp = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=10)
292 match = parse.packet_to_flow_match(pkt_MatchVlanPcp)
293 self.assertTrue(match is not None, "Could not generate flow match from pkt")
294
295 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN_PCP
296 msg = message.flow_mod()
297 msg.out_port = ofp.OFPP_NONE
298 msg.command = ofp.OFPFC_ADD
299 msg.buffer_id = 0xffffffff
300 msg.match = match
301 if priority != 0 :
302 msg.priority = priority
303
304 act = action.action_output()
305 act.port = of_ports[1]
306 self.assertTrue(msg.actions.add(act), "could not add action")
307
308 rv = self.controller.message_send(msg)
309 self.assertTrue(rv != -1, "Error installing flow mod")
310 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
311
312 return (pkt_MatchVlanPcp,match)
313
314
315def Match_Mul_L2(self,of_ports,priority=0):
316 #Generate Match_Mul_L2 flow
317
318 #Create a simple eth packet and generate match on ethernet protocol flow
319 pkt_MulL2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02')
320 match = parse.packet_to_flow_match(pkt_MulL2)
321 self.assertTrue(match is not None, "Could not generate flow match from pkt")
322
323 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC
324 msg = message.flow_mod()
325 msg.out_port = ofp.OFPP_NONE
326 msg.command = ofp.OFPFC_ADD
327 msg.buffer_id = 0xffffffff
328 msg.match = match
329 if priority != 0 :
330 msg.priority = priority
331
332 act = action.action_output()
333 act.port = of_ports[1]
334 self.assertTrue(msg.actions.add(act), "could not add action")
335
336 rv = self.controller.message_send(msg)
337 self.assertTrue(rv != -1, "Error installing flow mod")
338 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
339
340 return (pkt_MulL2,match)
341
342
343def Match_Mul_L4(self,of_ports,priority=0):
344 #Generate Match_Mul_L4 flow
345
346 #Create a simple tcp packet and generate match on tcp protocol flow
347 pkt_MulL4 = simple_tcp_packet(tcp_sport=111,tcp_dport=112)
348 match = parse.packet_to_flow_match(pkt_MulL4)
349 self.assertTrue(match is not None, "Could not generate flow match from pkt")
350
351 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC ^ofp.OFPFW_TP_DST
352 msg = message.flow_mod()
353 msg.out_port = ofp.OFPP_NONE
354 msg.command = ofp.OFPFC_ADD
355 msg.buffer_id = 0xffffffff
356 msg.match = match
357 if priority != 0 :
358 msg.priority = priority
359
360 act = action.action_output()
361 act.port = of_ports[1]
362 self.assertTrue(msg.actions.add(act), "could not add action")
363
364 rv = self.controller.message_send(msg)
365 self.assertTrue(rv != -1, "Error installing flow mod")
366 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
367
368 return (pkt_MulL4,match)
369
370def Match_Ip_Tos(self,of_ports,priority=0):
371 #Generate a Match on IP Type of service flow
372
373 #Create a simple tcp packet and generate match on Type of service
374 pkt_IpTos = simple_tcp_packet(ip_tos=3)
375 match = parse.packet_to_flow_match(pkt_IpTos)
376 self.assertTrue(match is not None, "Could not generate flow match from pkt")
377
378 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_NW_TOS
379 msg = message.flow_mod()
380 msg.out_port = ofp.OFPP_NONE
381 msg.command = ofp.OFPFC_ADD
382 msg.buffer_id = 0xffffffff
383 msg.match = match
384 if priority != 0 :
385 msg.priority = priority
386
387 act = action.action_output()
388 act.port = of_ports[1]
389 self.assertTrue(msg.actions.add(act), "could not add action")
390
391 rv = self.controller.message_send(msg)
392 self.assertTrue(rv != -1, "Error installing flow mod")
393 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
394
395 return (pkt_IpTos,match)
396
397def Match_Tcp_Src(self,of_ports,priority=0):
398 #Generate Match_Tcp_Src
399
400 #Create a simple tcp packet and generate match on tcp source port flow
401 pkt_MatchTSrc = simple_tcp_packet(tcp_sport=111)
402 match = parse.packet_to_flow_match(pkt_MatchTSrc)
403 self.assertTrue(match is not None, "Could not generate flow match from pkt")
404
405 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC
406 msg = message.flow_mod()
407 msg.out_port = ofp.OFPP_NONE
408 msg.command = ofp.OFPFC_ADD
409 msg.buffer_id = 0xffffffff
410 msg.match = match
411 if priority != 0 :
412 msg.priority = priority
413
414 act = action.action_output()
415 act.port = of_ports[1]
416 self.assertTrue(msg.actions.add(act), "could not add action")
417
418 rv = self.controller.message_send(msg)
419 self.assertTrue(rv != -1, "Error installing flow mod")
420 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
421
422 return (pkt_MatchTSrc,match)
423
424def Match_Tcp_Dst(self,of_ports,priority=0):
425 #Generate Match_Tcp_Dst
426
427 #Create a simple tcp packet and generate match on tcp destination port flow
428 pkt_MatchTDst = simple_tcp_packet(tcp_dport=112)
429 match = parse.packet_to_flow_match(pkt_MatchTDst)
430 self.assertTrue(match is not None, "Could not generate flow match from pkt")
431
432 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_DST
433 msg = message.flow_mod()
434 msg.out_port = ofp.OFPP_NONE
435 msg.command = ofp.OFPFC_ADD
436 msg.buffer_id = 0xffffffff
437 msg.match = match
438 if priority != 0 :
439 msg.priority = priority
440
441 act = action.action_output()
442 act.port = of_ports[1]
443 self.assertTrue(msg.actions.add(act), "could not add action")
444
445 rv = self.controller.message_send(msg)
446 self.assertTrue(rv != -1, "Error installing flow mod")
447 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
448
449 return (pkt_MatchTDst,match)
450
451
452
453
454
455def Match_Ethernet_Type(self,of_ports,priority=0):
456 #Generate a Match_Ethernet_Type flow
457
458 #Create a simple tcp packet and generate match on ethernet type flow
459 pkt_MatchType = simple_eth_packet(dl_type=0x88cc)
460 match = parse.packet_to_flow_match(pkt_MatchType)
461 self.assertTrue(match is not None, "Could not generate flow match from pkt")
462
463 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE
464 msg = message.flow_mod()
465 msg.out_port = ofp.OFPP_NONE
466 msg.command = ofp.OFPFC_ADD
467 msg.buffer_id = 0xffffffff
468 msg.match = match
469 if priority != 0 :
470 msg.priority = priority
471
472 act = action.action_output()
473 act.port = of_ports[1]
474 self.assertTrue(msg.actions.add(act), "could not add action")
475
476 rv = self.controller.message_send(msg)
477 self.assertTrue(rv != -1, "Error installing flow mod")
478 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
479
480 return (pkt_MatchType,match)
481
482
ShreyaPandita60e45542012-09-27 15:11:16 -0400483
484def Strict_Modify_Flow_Action(self,egress_port,match,priority=0):
485# Strict Modify the flow Action
486
487 #Create a flow_mod message , command MODIFY_STRICT
488 msg5 = message.flow_mod()
489 msg5.match = match
490 msg5.cookie = random.randint(0,9007199254740992)
491 msg5.command = ofp.OFPFC_MODIFY_STRICT
492 msg5.buffer_id = 0xffffffff
493 act5 = action.action_output()
494 act5.port = egress_port
495 self.assertTrue(msg5.actions.add(act5), "could not add action")
496
497 if priority != 0 :
498 msg5.priority = priority
499
500 # Send the flow with action A'
501 rv = self.controller.message_send (msg5)
502 self.assertTrue(rv != -1, "Error installing flow mod")
503 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
504
505def Modify_Flow_Action(self,of_ports,match,priority=0):
506# Modify the flow action
507
508 #Create a flow_mod message , command MODIFY
509 msg8 = message.flow_mod()
510 msg8.match = match
511 msg8.cookie = random.randint(0,9007199254740992)
512 msg8.command = ofp.OFPFC_MODIFY
513 #Will be ignored for flow adds and flow modify (here for test-case Add_Modify_With_Outport)
514 msg8.out_port = of_ports[3]
515 msg8.buffer_id = 0xffffffff
516 act8 = action.action_output()
517 act8.port = of_ports[2]
518 self.assertTrue(msg8.actions.add(act8), "could not add action")
519
520 if priority != 0 :
521 msg8.priority = priority
522
523 # Send the flow with action A'
524 rv = self.controller.message_send (msg8)
525 self.assertTrue(rv != -1, "Error installing flow mod")
526 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
527
ShreyaPandita66de26f2012-10-26 14:44:24 -0400528def Enqueue(self,ingress_port,egress_port,egress_queue_id):
529#Generate a flow with enqueue action i.e output to a queue configured on a egress_port
530
531 pkt = simple_tcp_packet()
532 match = packet_to_flow_match(self, pkt)
533 match.wildcards &= ~ofp.OFPFW_IN_PORT
534 self.assertTrue(match is not None,
535 "Could not generate flow match from pkt")
536
537 match.in_port = ingress_port
538 request = message.flow_mod()
539 request.match = match
540 request.buffer_id = 0xffffffff
541 act = action.action_enqueue()
542 act.port = egress_port
543 act.queue_id = egress_queue_id
544 self.assertTrue(request.actions.add(act), "Could not add action")
545
546 logging.info("Inserting flow")
547 rv = self.controller.message_send(request)
548 self.assertTrue(rv != -1, "Error installing flow mod")
549 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
550
551 return (pkt,match)
552
553
554
ShreyaPandita60e45542012-09-27 15:11:16 -0400555
556########################### Verify Stats Functions ###########################################################################################
557
ShreyaPandita66de26f2012-10-26 14:44:24 -0400558
559def Get_QueueStats(self,port_num,queue_id):
560#Generate Queue Stats request
561
562 request = message.queue_stats_request()
563 request.port_no = port_num
564 request.queue_id = queue_id
565 (queue_stats, p) = self.controller.transact(request)
566 self.assertNotEqual(queue_stats, None, "Queue stats request failed")
567
568 return (queue_stats,p)
569
570def Verify_TableStats(self,active_entries=0):
ShreyaPandita60e45542012-09-27 15:11:16 -0400571#Verify Table_Stats
572
573 #Send Table_Stats_Request
574 request = message.table_stats_request()
575 response, pkt = self.controller.transact(request, timeout=1)
576 self.assertTrue(response is not None, "Did not get response")
577 active_count=0
578
579 #Verify active_count in the reply
580 for stat in response.stats:
581 active_count += stat.active_count
582 self.assertTrue(active_entries == active_count,"Incorrect no. of flows in Table")
583
ShreyaPandita66de26f2012-10-26 14:44:24 -0400584def Verify_TableStats1(self,current_lookedup,current_matched,expect_lookup,expect_match):
585
586 stat_req = message.table_stats_request()
587 response, pkt = self.controller.transact(stat_req,
588 timeout=5)
589 self.assertTrue(response is not None,
590 "No response to stats request")
591 lookedup = 0
592 matched = 0
593
594 for obj in response.stats:
595 lookedup += obj.lookup_count
596 matched += obj.matched_count
597
598 lookedup_counter = lookedup-current_lookedup
599 matched_counter = matched-current_matched
600
601 self.assertTrue(lookedup_counter==expect_lookup, "lookup counter is not incremented properly")
Rich Lane3f3b2492012-10-26 14:22:49 -0700602 self.assertTrue(matched_counter==expect_match, "matched counter is not incremented properly")
ShreyaPandita60e45542012-09-27 15:11:16 -0400603
604def Verify_FlowStats(self,match,byte_count=0,packet_count=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400605 # Verify flow counters : byte_count and packet_count
ShreyaPandita60e45542012-09-27 15:11:16 -0400606
607 stat_req = message.flow_stats_request()
608 stat_req.match = match
609 stat_req.table_id = 0xff
610 stat_req.out_port = ofp.OFPP_NONE
ShreyaPandita66de26f2012-10-26 14:44:24 -0400611 response, pkt = self.controller.transact(stat_req,
612 timeout=4)
613 self.assertTrue(response is not None,
ShreyaPandita60e45542012-09-27 15:11:16 -0400614 "No response to stats request")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400615 packetcounter=0
616 bytecounter=0
617 for obj in response.stats:
618 packetcounter += obj.packet_count
619 bytecounter += obj.byte_count
ShreyaPandita60e45542012-09-27 15:11:16 -0400620
ShreyaPandita66de26f2012-10-26 14:44:24 -0400621 self.assertTrue(packetcounter==packet_count, "packet counter is not incremented properly")
622 self.assertTrue(bytecounter==byte_count, "byte counter is not incremented properly")
ShreyaPandita60e45542012-09-27 15:11:16 -0400623
ShreyaPandita60e45542012-09-27 15:11:16 -0400624
625def Verify_PortStats(self,in_port,rx_dropped):
626#Verify Port counters like rx_dropped
627
628 port_stats_req = message.port_stats_request()
629 port_stats_req.port_no = in_port
630 resp,pkt = self.controller.transact(port_stats_req)
631 self.assertTrue(resp is not None,"No response received for port stats request")
632 self.assertTrue(resp.rx_dropped == rx_dropped, "Packets not dropped")
633
ShreyaPandita66de26f2012-10-26 14:44:24 -0400634def Verify_PortStats1(self,out_port,current_counter,rx_packets):
635#Verify Port counters like rx_packets
ShreyaPandita60e45542012-09-27 15:11:16 -0400636
ShreyaPandita66de26f2012-10-26 14:44:24 -0400637 port_stats_req = message.port_stats_request()
638 port_stats_req.port_no = out_port
639 response,pkt = self.controller.transact(port_stats_req)
640 self.assertTrue(response is not None,"No response received for port stats request")
641 rxpackets=0
642
643 for obj in response.stats:
644 rxpackets += obj.rx_packets
645 rx_packet_counter = rxpackets-current_counter
646 self.assertEqual(rx_packets,rx_packet_counter,"recieved packet counter is not incremented properly")
647
648def Verify_PortStats2(self,out_port,current_counter,tx_packets):
649#Verify Port counters like tx_packets
650
651 port_stats_req = message.port_stats_request()
652 port_stats_req.port_no = out_port
653 response,pkt = self.controller.transact(port_stats_req)
654 self.assertTrue(response is not None,"No response received for port stats request")
655 txpackets=0
656
657 for obj in response.stats:
658 txpackets += obj.tx_packets
659 tx_packet_counter = txpackets-current_counter
660 self.assertEqual(tx_packets,tx_packet_counter,"Transmitted packet counter is not incremented properly")
661
662
663def Verify_PortStats3(self,out_port,current_counter,rx_bytes):
664#Verify Port counters like rx_bytes
665
666 port_stats_req = message.port_stats_request()
667 port_stats_req.port_no = out_port
668 response,pkt = self.controller.transact(port_stats_req)
669 self.assertTrue(response is not None,"No response received for port stats request")
670 rxbytes=0
671
672 for obj in response.stats:
673 rxbytes += obj.rx_bytes
674 rx_byte_counter = rxbytes-current_counter
675 self.assertEqual(rx_bytes,rx_byte_counter,"Recieved byte counter is not incremented properly")
676
677def Verify_PortStats4(self,out_port,current_counter,tx_bytes):
678#Verify Port counters like tx_bytes
679
680 port_stats_req = message.port_stats_request()
681 port_stats_req.port_no = out_port
682 response,pkt = self.controller.transact(port_stats_req)
683 self.assertTrue(response is not None,"No response received for port stats request")
684 txbytes=0
685
686 for obj in response.stats:
687 txbytes += obj.tx_bytes
688 tx_byte_counter = txbytes-current_counter
689 self.assertEqual(tx_bytes,tx_byte_counter,"Transmitted byte counter is not incremented properly")
ShreyaPandita60e45542012-09-27 15:11:16 -0400690
691############################## Various delete commands #############################################################################################
692
693def Strict_Delete(self,match,priority=0):
694# Issue Strict Delete
695
696 #Create flow_mod message, command DELETE_STRICT
697 msg4 = message.flow_mod()
698 msg4.out_port = ofp.OFPP_NONE
699 msg4.command = ofp.OFPFC_DELETE_STRICT
700 msg4.buffer_id = 0xffffffff
701 msg4.match = match
702
703 if priority != 0 :
704 msg4.priority = priority
705
706 rv = self.controller.message_send(msg4)
707 self.assertTrue(rv!= -1, "Error installing flow mod")
708 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
709
710
711
712def NonStrict_Delete(self,match,priority=0):
713# Issue Non_Strict Delete
714
715 #Create flow_mod message, command DELETE
716 msg6 = message.flow_mod()
717 msg6.out_port = ofp.OFPP_NONE
718 msg6.command = ofp.OFPFC_DELETE
719 msg6.buffer_id = 0xffffffff
720 msg6.match = match
721
722 if priority != 0 :
723 msg6.priority = priority
724
725 rv = self.controller.message_send(msg6)
726 self.assertTrue(rv != -1, "Error installing flow mod")
727 self.assertEqual(do_barrier(self.controller),0, "Barrier failed")
728
729
730###########################################################################################################################################################
731
732def SendPacket(obj, pkt, ingress_port, egress_port):
733#Send Packets on a specified ingress_port and verify if its recieved on correct egress_port.
734
735 obj.dataplane.send(ingress_port, str(pkt))
736 exp_pkt_arg = pkt
737 exp_port = egress_port
738
739 (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(timeout=2,
740 port_number=exp_port,
741 exp_pkt=exp_pkt_arg)
742 obj.assertTrue(rcv_pkt is not None,
743 "Packet not received on port " + str(egress_port))
744 obj.assertEqual(rcv_port, egress_port,
745 "Packet received on port " + str(rcv_port) +
746 ", expected port " + str(egress_port))
747 obj.assertEqual(str(pkt), str(rcv_pkt),
748 'Response packet does not match send packet')
749
750
ShreyaPandita572e64b2012-09-28 14:41:06 -0400751def sw_supported_actions(parent,use_cache=False):
ShreyaPandita60e45542012-09-27 15:11:16 -0400752#Returns the switch's supported actions
753
754 cache_supported_actions = None
755 if cache_supported_actions is None or not use_cache:
756 request = message.features_request()
757 (reply, pkt) = parent.controller.transact(request)
758 parent.assertTrue(reply is not None, "Did not get response to ftr req")
759 cache_supported_actions = reply.actions
760 return cache_supported_actions
761
ShreyaPandita66de26f2012-10-26 14:44:24 -0400762##############################################################################################################################################################
763