blob: 61f285c47774d256961bb27a5470b028a80f3260 [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
223def Match_Vlan_Id(self,of_ports,priority=0):
224 #Generate Match_Vlan_Id
225
226 #Create a simple tcp packet and generate match on ethernet dst address flow
227 pkt_MatchVlanId = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1)
228 match = parse.packet_to_flow_match(pkt_MatchVlanId)
229 self.assertTrue(match is not None, "Could not generate flow match from pkt")
230
231 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN
232 msg = message.flow_mod()
233 msg.out_port = ofp.OFPP_NONE
234 msg.command = ofp.OFPFC_ADD
235 msg.buffer_id = 0xffffffff
236 msg.match = match
237 if priority != 0 :
238 msg.priority = priority
239
240 act = action.action_output()
241 act.port = of_ports[1]
242 self.assertTrue(msg.actions.add(act), "could not add action")
243
244 rv = self.controller.message_send(msg)
245 self.assertTrue(rv != -1, "Error installing flow mod")
246 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
247
248 return (pkt_MatchVlanId,match)
249
250def Match_Vlan_Pcp(self,of_ports,priority=0):
251 #Generate Match_Vlan_Id
252
253 #Create a simple tcp packet and generate match on ethernet dst address flow
254 pkt_MatchVlanPcp = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=10)
255 match = parse.packet_to_flow_match(pkt_MatchVlanPcp)
256 self.assertTrue(match is not None, "Could not generate flow match from pkt")
257
258 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN_PCP
259 msg = message.flow_mod()
260 msg.out_port = ofp.OFPP_NONE
261 msg.command = ofp.OFPFC_ADD
262 msg.buffer_id = 0xffffffff
263 msg.match = match
264 if priority != 0 :
265 msg.priority = priority
266
267 act = action.action_output()
268 act.port = of_ports[1]
269 self.assertTrue(msg.actions.add(act), "could not add action")
270
271 rv = self.controller.message_send(msg)
272 self.assertTrue(rv != -1, "Error installing flow mod")
273 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
274
275 return (pkt_MatchVlanPcp,match)
276
277
278def Match_Mul_L2(self,of_ports,priority=0):
279 #Generate Match_Mul_L2 flow
280
281 #Create a simple eth packet and generate match on ethernet protocol flow
282 pkt_MulL2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02')
283 match = parse.packet_to_flow_match(pkt_MulL2)
284 self.assertTrue(match is not None, "Could not generate flow match from pkt")
285
286 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC
287 msg = message.flow_mod()
288 msg.out_port = ofp.OFPP_NONE
289 msg.command = ofp.OFPFC_ADD
290 msg.buffer_id = 0xffffffff
291 msg.match = match
292 if priority != 0 :
293 msg.priority = priority
294
295 act = action.action_output()
296 act.port = of_ports[1]
297 self.assertTrue(msg.actions.add(act), "could not add action")
298
299 rv = self.controller.message_send(msg)
300 self.assertTrue(rv != -1, "Error installing flow mod")
301 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
302
303 return (pkt_MulL2,match)
304
305
306def Match_Mul_L4(self,of_ports,priority=0):
307 #Generate Match_Mul_L4 flow
308
309 #Create a simple tcp packet and generate match on tcp protocol flow
310 pkt_MulL4 = simple_tcp_packet(tcp_sport=111,tcp_dport=112)
311 match = parse.packet_to_flow_match(pkt_MulL4)
312 self.assertTrue(match is not None, "Could not generate flow match from pkt")
313
314 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC ^ofp.OFPFW_TP_DST
315 msg = message.flow_mod()
316 msg.out_port = ofp.OFPP_NONE
317 msg.command = ofp.OFPFC_ADD
318 msg.buffer_id = 0xffffffff
319 msg.match = match
320 if priority != 0 :
321 msg.priority = priority
322
323 act = action.action_output()
324 act.port = of_ports[1]
325 self.assertTrue(msg.actions.add(act), "could not add action")
326
327 rv = self.controller.message_send(msg)
328 self.assertTrue(rv != -1, "Error installing flow mod")
329 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
330
331 return (pkt_MulL4,match)
332
333def Match_Ip_Tos(self,of_ports,priority=0):
334 #Generate a Match on IP Type of service flow
335
336 #Create a simple tcp packet and generate match on Type of service
337 pkt_IpTos = simple_tcp_packet(ip_tos=3)
338 match = parse.packet_to_flow_match(pkt_IpTos)
339 self.assertTrue(match is not None, "Could not generate flow match from pkt")
340
341 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_NW_TOS
342 msg = message.flow_mod()
343 msg.out_port = ofp.OFPP_NONE
344 msg.command = ofp.OFPFC_ADD
345 msg.buffer_id = 0xffffffff
346 msg.match = match
347 if priority != 0 :
348 msg.priority = priority
349
350 act = action.action_output()
351 act.port = of_ports[1]
352 self.assertTrue(msg.actions.add(act), "could not add action")
353
354 rv = self.controller.message_send(msg)
355 self.assertTrue(rv != -1, "Error installing flow mod")
356 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
357
358 return (pkt_IpTos,match)
359
360def Match_Tcp_Src(self,of_ports,priority=0):
361 #Generate Match_Tcp_Src
362
363 #Create a simple tcp packet and generate match on tcp source port flow
364 pkt_MatchTSrc = simple_tcp_packet(tcp_sport=111)
365 match = parse.packet_to_flow_match(pkt_MatchTSrc)
366 self.assertTrue(match is not None, "Could not generate flow match from pkt")
367
368 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC
369 msg = message.flow_mod()
370 msg.out_port = ofp.OFPP_NONE
371 msg.command = ofp.OFPFC_ADD
372 msg.buffer_id = 0xffffffff
373 msg.match = match
374 if priority != 0 :
375 msg.priority = priority
376
377 act = action.action_output()
378 act.port = of_ports[1]
379 self.assertTrue(msg.actions.add(act), "could not add action")
380
381 rv = self.controller.message_send(msg)
382 self.assertTrue(rv != -1, "Error installing flow mod")
383 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
384
385 return (pkt_MatchTSrc,match)
386
387def Match_Tcp_Dst(self,of_ports,priority=0):
388 #Generate Match_Tcp_Dst
389
390 #Create a simple tcp packet and generate match on tcp destination port flow
391 pkt_MatchTDst = simple_tcp_packet(tcp_dport=112)
392 match = parse.packet_to_flow_match(pkt_MatchTDst)
393 self.assertTrue(match is not None, "Could not generate flow match from pkt")
394
395 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_DST
396 msg = message.flow_mod()
397 msg.out_port = ofp.OFPP_NONE
398 msg.command = ofp.OFPFC_ADD
399 msg.buffer_id = 0xffffffff
400 msg.match = match
401 if priority != 0 :
402 msg.priority = priority
403
404 act = action.action_output()
405 act.port = of_ports[1]
406 self.assertTrue(msg.actions.add(act), "could not add action")
407
408 rv = self.controller.message_send(msg)
409 self.assertTrue(rv != -1, "Error installing flow mod")
410 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
411
412 return (pkt_MatchTDst,match)
413
414
415
416
417
418def Match_Ethernet_Type(self,of_ports,priority=0):
419 #Generate a Match_Ethernet_Type flow
420
421 #Create a simple tcp packet and generate match on ethernet type flow
422 pkt_MatchType = simple_eth_packet(dl_type=0x88cc)
423 match = parse.packet_to_flow_match(pkt_MatchType)
424 self.assertTrue(match is not None, "Could not generate flow match from pkt")
425
426 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE
427 msg = message.flow_mod()
428 msg.out_port = ofp.OFPP_NONE
429 msg.command = ofp.OFPFC_ADD
430 msg.buffer_id = 0xffffffff
431 msg.match = match
432 if priority != 0 :
433 msg.priority = priority
434
435 act = action.action_output()
436 act.port = of_ports[1]
437 self.assertTrue(msg.actions.add(act), "could not add action")
438
439 rv = self.controller.message_send(msg)
440 self.assertTrue(rv != -1, "Error installing flow mod")
441 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
442
443 return (pkt_MatchType,match)
444
445
ShreyaPandita60e45542012-09-27 15:11:16 -0400446
447def Strict_Modify_Flow_Action(self,egress_port,match,priority=0):
448# Strict Modify the flow Action
449
450 #Create a flow_mod message , command MODIFY_STRICT
451 msg5 = message.flow_mod()
452 msg5.match = match
453 msg5.cookie = random.randint(0,9007199254740992)
454 msg5.command = ofp.OFPFC_MODIFY_STRICT
455 msg5.buffer_id = 0xffffffff
456 act5 = action.action_output()
457 act5.port = egress_port
458 self.assertTrue(msg5.actions.add(act5), "could not add action")
459
460 if priority != 0 :
461 msg5.priority = priority
462
463 # Send the flow with action A'
464 rv = self.controller.message_send (msg5)
465 self.assertTrue(rv != -1, "Error installing flow mod")
466 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
467
468def Modify_Flow_Action(self,of_ports,match,priority=0):
469# Modify the flow action
470
471 #Create a flow_mod message , command MODIFY
472 msg8 = message.flow_mod()
473 msg8.match = match
474 msg8.cookie = random.randint(0,9007199254740992)
475 msg8.command = ofp.OFPFC_MODIFY
476 #Will be ignored for flow adds and flow modify (here for test-case Add_Modify_With_Outport)
477 msg8.out_port = of_ports[3]
478 msg8.buffer_id = 0xffffffff
479 act8 = action.action_output()
480 act8.port = of_ports[2]
481 self.assertTrue(msg8.actions.add(act8), "could not add action")
482
483 if priority != 0 :
484 msg8.priority = priority
485
486 # Send the flow with action A'
487 rv = self.controller.message_send (msg8)
488 self.assertTrue(rv != -1, "Error installing flow mod")
489 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
490
ShreyaPandita66de26f2012-10-26 14:44:24 -0400491def Enqueue(self,ingress_port,egress_port,egress_queue_id):
492#Generate a flow with enqueue action i.e output to a queue configured on a egress_port
493
494 pkt = simple_tcp_packet()
495 match = packet_to_flow_match(self, pkt)
496 match.wildcards &= ~ofp.OFPFW_IN_PORT
497 self.assertTrue(match is not None,
498 "Could not generate flow match from pkt")
499
500 match.in_port = ingress_port
501 request = message.flow_mod()
502 request.match = match
503 request.buffer_id = 0xffffffff
504 act = action.action_enqueue()
505 act.port = egress_port
506 act.queue_id = egress_queue_id
507 self.assertTrue(request.actions.add(act), "Could not add action")
508
509 logging.info("Inserting flow")
510 rv = self.controller.message_send(request)
511 self.assertTrue(rv != -1, "Error installing flow mod")
512 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
513
514 return (pkt,match)
515
516
517
ShreyaPandita60e45542012-09-27 15:11:16 -0400518
519########################### Verify Stats Functions ###########################################################################################
520
ShreyaPandita66de26f2012-10-26 14:44:24 -0400521
522def Get_QueueStats(self,port_num,queue_id):
523#Generate Queue Stats request
524
525 request = message.queue_stats_request()
526 request.port_no = port_num
527 request.queue_id = queue_id
528 (queue_stats, p) = self.controller.transact(request)
529 self.assertNotEqual(queue_stats, None, "Queue stats request failed")
530
531 return (queue_stats,p)
532
533def Verify_TableStats(self,active_entries=0):
ShreyaPandita60e45542012-09-27 15:11:16 -0400534#Verify Table_Stats
535
536 #Send Table_Stats_Request
537 request = message.table_stats_request()
538 response, pkt = self.controller.transact(request, timeout=1)
539 self.assertTrue(response is not None, "Did not get response")
540 active_count=0
541
542 #Verify active_count in the reply
543 for stat in response.stats:
544 active_count += stat.active_count
545 self.assertTrue(active_entries == active_count,"Incorrect no. of flows in Table")
546
ShreyaPandita66de26f2012-10-26 14:44:24 -0400547def Verify_TableStats1(self,current_lookedup,current_matched,expect_lookup,expect_match):
548
549 stat_req = message.table_stats_request()
550 response, pkt = self.controller.transact(stat_req,
551 timeout=5)
552 self.assertTrue(response is not None,
553 "No response to stats request")
554 lookedup = 0
555 matched = 0
556
557 for obj in response.stats:
558 lookedup += obj.lookup_count
559 matched += obj.matched_count
560
561 lookedup_counter = lookedup-current_lookedup
562 matched_counter = matched-current_matched
563
564 self.assertTrue(lookedup_counter==expect_lookup, "lookup counter is not incremented properly")
Rich Lane3f3b2492012-10-26 14:22:49 -0700565 self.assertTrue(matched_counter==expect_match, "matched counter is not incremented properly")
ShreyaPandita60e45542012-09-27 15:11:16 -0400566
567def Verify_FlowStats(self,match,byte_count=0,packet_count=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400568 # Verify flow counters : byte_count and packet_count
ShreyaPandita60e45542012-09-27 15:11:16 -0400569
570 stat_req = message.flow_stats_request()
571 stat_req.match = match
572 stat_req.table_id = 0xff
573 stat_req.out_port = ofp.OFPP_NONE
ShreyaPandita66de26f2012-10-26 14:44:24 -0400574 response, pkt = self.controller.transact(stat_req,
575 timeout=4)
576 self.assertTrue(response is not None,
ShreyaPandita60e45542012-09-27 15:11:16 -0400577 "No response to stats request")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400578 packetcounter=0
579 bytecounter=0
580 for obj in response.stats:
581 packetcounter += obj.packet_count
582 bytecounter += obj.byte_count
ShreyaPandita60e45542012-09-27 15:11:16 -0400583
ShreyaPandita66de26f2012-10-26 14:44:24 -0400584 self.assertTrue(packetcounter==packet_count, "packet counter is not incremented properly")
585 self.assertTrue(bytecounter==byte_count, "byte counter is not incremented properly")
ShreyaPandita60e45542012-09-27 15:11:16 -0400586
ShreyaPandita60e45542012-09-27 15:11:16 -0400587
588def Verify_PortStats(self,in_port,rx_dropped):
589#Verify Port counters like rx_dropped
590
591 port_stats_req = message.port_stats_request()
592 port_stats_req.port_no = in_port
593 resp,pkt = self.controller.transact(port_stats_req)
594 self.assertTrue(resp is not None,"No response received for port stats request")
595 self.assertTrue(resp.rx_dropped == rx_dropped, "Packets not dropped")
596
ShreyaPandita66de26f2012-10-26 14:44:24 -0400597def Verify_PortStats1(self,out_port,current_counter,rx_packets):
598#Verify Port counters like rx_packets
ShreyaPandita60e45542012-09-27 15:11:16 -0400599
ShreyaPandita66de26f2012-10-26 14:44:24 -0400600 port_stats_req = message.port_stats_request()
601 port_stats_req.port_no = out_port
602 response,pkt = self.controller.transact(port_stats_req)
603 self.assertTrue(response is not None,"No response received for port stats request")
604 rxpackets=0
605
606 for obj in response.stats:
607 rxpackets += obj.rx_packets
608 rx_packet_counter = rxpackets-current_counter
609 self.assertEqual(rx_packets,rx_packet_counter,"recieved packet counter is not incremented properly")
610
611def Verify_PortStats2(self,out_port,current_counter,tx_packets):
612#Verify Port counters like tx_packets
613
614 port_stats_req = message.port_stats_request()
615 port_stats_req.port_no = out_port
616 response,pkt = self.controller.transact(port_stats_req)
617 self.assertTrue(response is not None,"No response received for port stats request")
618 txpackets=0
619
620 for obj in response.stats:
621 txpackets += obj.tx_packets
622 tx_packet_counter = txpackets-current_counter
623 self.assertEqual(tx_packets,tx_packet_counter,"Transmitted packet counter is not incremented properly")
624
625
626def Verify_PortStats3(self,out_port,current_counter,rx_bytes):
627#Verify Port counters like rx_bytes
628
629 port_stats_req = message.port_stats_request()
630 port_stats_req.port_no = out_port
631 response,pkt = self.controller.transact(port_stats_req)
632 self.assertTrue(response is not None,"No response received for port stats request")
633 rxbytes=0
634
635 for obj in response.stats:
636 rxbytes += obj.rx_bytes
637 rx_byte_counter = rxbytes-current_counter
638 self.assertEqual(rx_bytes,rx_byte_counter,"Recieved byte counter is not incremented properly")
639
640def Verify_PortStats4(self,out_port,current_counter,tx_bytes):
641#Verify Port counters like tx_bytes
642
643 port_stats_req = message.port_stats_request()
644 port_stats_req.port_no = out_port
645 response,pkt = self.controller.transact(port_stats_req)
646 self.assertTrue(response is not None,"No response received for port stats request")
647 txbytes=0
648
649 for obj in response.stats:
650 txbytes += obj.tx_bytes
651 tx_byte_counter = txbytes-current_counter
652 self.assertEqual(tx_bytes,tx_byte_counter,"Transmitted byte counter is not incremented properly")
ShreyaPandita60e45542012-09-27 15:11:16 -0400653
654############################## Various delete commands #############################################################################################
655
656def Strict_Delete(self,match,priority=0):
657# Issue Strict Delete
658
659 #Create flow_mod message, command DELETE_STRICT
660 msg4 = message.flow_mod()
661 msg4.out_port = ofp.OFPP_NONE
662 msg4.command = ofp.OFPFC_DELETE_STRICT
663 msg4.buffer_id = 0xffffffff
664 msg4.match = match
665
666 if priority != 0 :
667 msg4.priority = priority
668
669 rv = self.controller.message_send(msg4)
670 self.assertTrue(rv!= -1, "Error installing flow mod")
671 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
672
673
674
675def NonStrict_Delete(self,match,priority=0):
676# Issue Non_Strict Delete
677
678 #Create flow_mod message, command DELETE
679 msg6 = message.flow_mod()
680 msg6.out_port = ofp.OFPP_NONE
681 msg6.command = ofp.OFPFC_DELETE
682 msg6.buffer_id = 0xffffffff
683 msg6.match = match
684
685 if priority != 0 :
686 msg6.priority = priority
687
688 rv = self.controller.message_send(msg6)
689 self.assertTrue(rv != -1, "Error installing flow mod")
690 self.assertEqual(do_barrier(self.controller),0, "Barrier failed")
691
692
693###########################################################################################################################################################
694
695def SendPacket(obj, pkt, ingress_port, egress_port):
696#Send Packets on a specified ingress_port and verify if its recieved on correct egress_port.
697
698 obj.dataplane.send(ingress_port, str(pkt))
699 exp_pkt_arg = pkt
700 exp_port = egress_port
701
702 (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(timeout=2,
703 port_number=exp_port,
704 exp_pkt=exp_pkt_arg)
705 obj.assertTrue(rcv_pkt is not None,
706 "Packet not received on port " + str(egress_port))
707 obj.assertEqual(rcv_port, egress_port,
708 "Packet received on port " + str(rcv_port) +
709 ", expected port " + str(egress_port))
710 obj.assertEqual(str(pkt), str(rcv_pkt),
711 'Response packet does not match send packet')
712
713
ShreyaPandita572e64b2012-09-28 14:41:06 -0400714def sw_supported_actions(parent,use_cache=False):
ShreyaPandita60e45542012-09-27 15:11:16 -0400715#Returns the switch's supported actions
716
717 cache_supported_actions = None
718 if cache_supported_actions is None or not use_cache:
719 request = message.features_request()
720 (reply, pkt) = parent.controller.transact(request)
721 parent.assertTrue(reply is not None, "Did not get response to ftr req")
722 cache_supported_actions = reply.actions
723 return cache_supported_actions
724
ShreyaPandita66de26f2012-10-26 14:44:24 -0400725##############################################################################################################################################################
726