blob: 388c86cc09f86cfd8df39c73bdfc8bcae62555a8 [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
ShreyaPandita4ebbac32012-11-02 13:40:44 -040022def exact_match(self,of_ports,priority=0):
ShreyaPandita60e45542012-09-27 15:11:16 -040023# Generate ExactMatch flow .
24
ShreyaPandita4ebbac32012-11-02 13:40:44 -040025 #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
ShreyaPandita60e45542012-09-27 15:11:16 -040039
ShreyaPandita4ebbac32012-11-02 13:40:44 -040040 act = action.action_output()
41 act.port = of_ports[1]
42 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita60e45542012-09-27 15:11:16 -040043
ShreyaPandita4ebbac32012-11-02 13:40:44 -040044 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")
ShreyaPandita60e45542012-09-27 15:11:16 -040047
ShreyaPandita4ebbac32012-11-02 13:40:44 -040048 return (pkt_exactflow,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -040049
ShreyaPandita4ebbac32012-11-02 13:40:44 -040050def exact_match_with_prio(self,of_ports,priority=0):
51 # Generate ExactMatch with action output to port 2
ShreyaPandita66de26f2012-10-26 14:44:24 -040052
ShreyaPandita4ebbac32012-11-02 13:40:44 -040053 #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
ShreyaPandita66de26f2012-10-26 14:44:24 -040067
ShreyaPandita4ebbac32012-11-02 13:40:44 -040068 act = action.action_output()
69 act.port = of_ports[2]
70 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -040071
ShreyaPandita4ebbac32012-11-02 13:40:44 -040072 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")
ShreyaPandita66de26f2012-10-26 14:44:24 -040075
ShreyaPandita4ebbac32012-11-02 13:40:44 -040076 return (pkt_exactflow,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -040077
ShreyaPandita60e45542012-09-27 15:11:16 -040078
ShreyaPandita4ebbac32012-11-02 13:40:44 -040079def match_all_except_source_address(self,of_ports,priority=0):
ShreyaPandita60e45542012-09-27 15:11:16 -040080# Generate Match_All_Except_Source_Address flow
81
ShreyaPandita4ebbac32012-11-02 13:40:44 -040082 #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
ShreyaPandita60e45542012-09-27 15:11:16 -040096
ShreyaPandita4ebbac32012-11-02 13:40:44 -040097 act1 = action.action_output()
98 act1.port = of_ports[1]
99 self.assertTrue(msg1.actions.add(act1), "could not add action")
ShreyaPandita60e45542012-09-27 15:11:16 -0400100
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400101 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")
ShreyaPandita60e45542012-09-27 15:11:16 -0400104
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400105 return (pkt_wildcardsrc,match1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400106
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400107def match_wthernet_src_address(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400108 #Generate Match_Ethernet_SrC_Address flow
109
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400110 #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")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400114
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400115 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_SRC
ShreyaPandita60e45542012-09-27 15:11:16 -0400116
ShreyaPandita4ebbac32012-11-02 13:40:44 -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
ShreyaPandita66de26f2012-10-26 14:44:24 -0400124
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400125 act = action.action_output()
126 act.port = of_ports[1]
127 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400128
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400129 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")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400132
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400133 return (pkt_MatchSrc,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400134
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400135def match_ethernet_dst_address(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400136 #Generate Match_Ethernet_Dst_Address flow
137
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400138 #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")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400142
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400143 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
ShreyaPandita66de26f2012-10-26 14:44:24 -0400151
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400152 act = action.action_output()
153 act.port = of_ports[1]
154 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400155
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400156 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")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400159
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400160 return (pkt_matchdst,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400161
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400162def wildcard_all(self,of_ports,priority=0):
ShreyaPandita60e45542012-09-27 15:11:16 -0400163# Generate a Wildcard_All Flow
164
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400165 #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]
ShreyaPandita60e45542012-09-27 15:11:16 -0400171
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400172 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
ShreyaPandita60e45542012-09-27 15:11:16 -0400182
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400183 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")
ShreyaPandita60e45542012-09-27 15:11:16 -0400186
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400187 return (pkt_wildcard,match2)
ShreyaPandita60e45542012-09-27 15:11:16 -0400188
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400189def wildcard_all_except_ingress(self,of_ports,priority=0):
ShreyaPandita60e45542012-09-27 15:11:16 -0400190# Generate Wildcard_All_Except_Ingress_port flow
191
192
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400193 #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]
ShreyaPandita60e45542012-09-27 15:11:16 -0400199
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400200 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
ShreyaPandita60e45542012-09-27 15:11:16 -0400209
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400210 act3 = action.action_output()
211 act3.port = of_ports[1]
212 self.assertTrue(msg3.actions.add(act3), "could not add action")
ShreyaPandita60e45542012-09-27 15:11:16 -0400213
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400214 if priority != 0 :
215 msg3.priority = priority
ShreyaPandita60e45542012-09-27 15:11:16 -0400216
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400217 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")
ShreyaPandita60e45542012-09-27 15:11:16 -0400220
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400221 return (pkt_matchingress,match3)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400222
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400223def wildcard_all_except_ingress1(self,of_ports,priority=0):
ShreyaPanditada75f752012-10-26 16:26:35 -0400224# Generate Wildcard_All_Except_Ingress_port flow with action output to port egress_port 2
225
226
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400227 #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]
ShreyaPanditada75f752012-10-26 16:26:35 -0400233
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400234 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
ShreyaPanditada75f752012-10-26 16:26:35 -0400243
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400244 act3 = action.action_output()
245 act3.port = of_ports[2]
246 self.assertTrue(msg3.actions.add(act3), "could not add action")
247 if priority != 0 :
248 msg3.priority = priority
ShreyaPanditada75f752012-10-26 16:26:35 -0400249
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400250 rv = self.controller.message_send(msg3)
251 self.assertTrue(rv != -1, "Error installing flow mod")
252 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPanditada75f752012-10-26 16:26:35 -0400253
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400254 return (pkt_matchingress,match3)
ShreyaPanditada75f752012-10-26 16:26:35 -0400255
256
257
258
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400259def match_vlan_id(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400260 #Generate Match_Vlan_Id
261
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400262 #Create a simple tcp packet and generate match on ethernet dst address flow
263 pkt_matchvlanid = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1)
264 match = parse.packet_to_flow_match(pkt_matchvlanid)
265 self.assertTrue(match is not None, "Could not generate flow match from pkt")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400266
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400267 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN
268 msg = message.flow_mod()
269 msg.out_port = ofp.OFPP_NONE
270 msg.command = ofp.OFPFC_ADD
271 msg.buffer_id = 0xffffffff
272 msg.match = match
273 if priority != 0 :
274 msg.priority = priority
ShreyaPandita66de26f2012-10-26 14:44:24 -0400275
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400276 act = action.action_output()
277 act.port = of_ports[1]
278 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400279
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400280 rv = self.controller.message_send(msg)
281 self.assertTrue(rv != -1, "Error installing flow mod")
282 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400283
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400284 return (pkt_matchvlanid,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400285
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400286def match_vlan_pcp(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400287 #Generate Match_Vlan_Id
288
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400289 #Create a simple tcp packet and generate match on ethernet dst address flow
290 pkt_matchvlanpcp = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=10)
291 match = parse.packet_to_flow_match(pkt_matchvlanpcp)
292 self.assertTrue(match is not None, "Could not generate flow match from pkt")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400293
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400294 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN_PCP
295 msg = message.flow_mod()
296 msg.out_port = ofp.OFPP_NONE
297 msg.command = ofp.OFPFC_ADD
298 msg.buffer_id = 0xffffffff
299 msg.match = match
300 if priority != 0 :
301 msg.priority = priority
ShreyaPandita66de26f2012-10-26 14:44:24 -0400302
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400303 act = action.action_output()
304 act.port = of_ports[1]
305 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400306
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400307 rv = self.controller.message_send(msg)
308 self.assertTrue(rv != -1, "Error installing flow mod")
309 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400310
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400311 return (pkt_matchvlanpcp,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400312
313
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400314def match_mul_l2(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400315 #Generate Match_Mul_L2 flow
316
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400317 #Create a simple eth packet and generate match on ethernet protocol flow
318 pkt_mulL2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02')
319 match = parse.packet_to_flow_match(pkt_mulL2)
320 self.assertTrue(match is not None, "Could not generate flow match from pkt")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400321
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400322 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC
323 msg = message.flow_mod()
324 msg.out_port = ofp.OFPP_NONE
325 msg.command = ofp.OFPFC_ADD
326 msg.buffer_id = 0xffffffff
327 msg.match = match
328 if priority != 0 :
329 msg.priority = priority
ShreyaPandita66de26f2012-10-26 14:44:24 -0400330
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400331 act = action.action_output()
332 act.port = of_ports[1]
333 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400334
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400335 rv = self.controller.message_send(msg)
336 self.assertTrue(rv != -1, "Error installing flow mod")
337 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400338
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400339 return (pkt_mulL2,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400340
341
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400342def match_mul_L4(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400343 #Generate Match_Mul_L4 flow
344
345 #Create a simple tcp packet and generate match on tcp protocol flow
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400346 pkt_mulL4 = simple_tcp_packet(tcp_sport=111,tcp_dport=112)
347 match = parse.packet_to_flow_match(pkt_mulL4)
348 self.assertTrue(match is not None, "Could not generate flow match from pkt")
349 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC ^ofp.OFPFW_TP_DST
350 msg = message.flow_mod()
351 msg.out_port = ofp.OFPP_NONE
352 msg.command = ofp.OFPFC_ADD
353 msg.buffer_id = 0xffffffff
354 msg.match = match
355 if priority != 0 :
356 msg.priority = priority
ShreyaPandita66de26f2012-10-26 14:44:24 -0400357
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400358 act = action.action_output()
359 act.port = of_ports[1]
360 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400361
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400362 rv = self.controller.message_send(msg)
363 self.assertTrue(rv != -1, "Error installing flow mod")
364 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400365
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400366 return (pkt_mulL4,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400367
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400368def match_ip_tos(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400369 #Generate a Match on IP Type of service flow
370
371 #Create a simple tcp packet and generate match on Type of service
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400372 pkt_iptos = simple_tcp_packet(ip_tos=3)
373 match = parse.packet_to_flow_match(pkt_iptos)
374 self.assertTrue(match is not None, "Could not generate flow match from pkt")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400375
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400376 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_NW_TOS
377 msg = message.flow_mod()
378 msg.out_port = ofp.OFPP_NONE
379 msg.command = ofp.OFPFC_ADD
380 msg.buffer_id = 0xffffffff
381 msg.match = match
382 if priority != 0 :
383 msg.priority = priority
384 act = action.action_output()
385 act.port = of_ports[1]
386 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400387
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400388 rv = self.controller.message_send(msg)
389 self.assertTrue(rv != -1, "Error installing flow mod")
390 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400391
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400392 return (pkt_iptos,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400393
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400394def match_tcp_src(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400395 #Generate Match_Tcp_Src
396
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400397 #Create a simple tcp packet and generate match on tcp source port flow
398 pkt_matchtSrc = simple_tcp_packet(tcp_sport=111)
399 match = parse.packet_to_flow_match(pkt_matchtSrc)
400 self.assertTrue(match is not None, "Could not generate flow match from pkt")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400401
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400402 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC
403 msg = message.flow_mod()
404 msg.out_port = ofp.OFPP_NONE
405 msg.command = ofp.OFPFC_ADD
406 msg.buffer_id = 0xffffffff
407 msg.match = match
408 if priority != 0 :
409 msg.priority = priority
ShreyaPandita66de26f2012-10-26 14:44:24 -0400410
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400411 act = action.action_output()
412 act.port = of_ports[1]
413 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400414
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400415 rv = self.controller.message_send(msg)
416 self.assertTrue(rv != -1, "Error installing flow mod")
417 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400418
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400419 return (pkt_matchtSrc,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400420
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400421def match_tcp_dst(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400422 #Generate Match_Tcp_Dst
423
424 #Create a simple tcp packet and generate match on tcp destination port flow
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400425 pkt_Matchtdst = simple_tcp_packet(tcp_dport=112)
426 match = parse.packet_to_flow_match(pkt_matchtdst)
427 self.assertTrue(match is not None, "Could not generate flow match from pkt")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400428
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400429 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_DST
430 msg = message.flow_mod()
431 msg.out_port = ofp.OFPP_NONE
432 msg.command = ofp.OFPFC_ADD
433 msg.buffer_id = 0xffffffff
434 msg.match = match
435 if priority != 0 :
436 msg.priority = priority
437 act = action.action_output()
438 act.port = of_ports[1]
439 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400440
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400441 rv = self.controller.message_send(msg)
442 self.assertTrue(rv != -1, "Error installing flow mod")
443 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400444
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400445 return (pkt_matchtdst,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400446
447
448
449
450
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400451def match_ethernet_type(self,of_ports,priority=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400452 #Generate a Match_Ethernet_Type flow
453
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400454 #Create a simple tcp packet and generate match on ethernet type flow
455 pkt_matchtype = simple_eth_packet(dl_type=0x88cc)
456 match = parse.packet_to_flow_match(pkt_matchtype)
457 self.assertTrue(match is not None, "Could not generate flow match from pkt")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400458
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400459 match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE
460 msg = message.flow_mod()
461 msg.out_port = ofp.OFPP_NONE
462 msg.command = ofp.OFPFC_ADD
463 msg.buffer_id = 0xffffffff
464 msg.match = match
465 if priority != 0 :
466 msg.priority = priority
ShreyaPandita66de26f2012-10-26 14:44:24 -0400467
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400468 act = action.action_output()
469 act.port = of_ports[1]
470 self.assertTrue(msg.actions.add(act), "could not add action")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400471
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400472 rv = self.controller.message_send(msg)
473 self.assertTrue(rv != -1, "Error installing flow mod")
474 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400475
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400476 return (pkt_matchtype,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400477
478
ShreyaPandita60e45542012-09-27 15:11:16 -0400479
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400480def strict_modify_flow_action(self,egress_port,match,priority=0):
ShreyaPandita60e45542012-09-27 15:11:16 -0400481# Strict Modify the flow Action
482
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400483 #Create a flow_mod message , command MODIFY_STRICT
484 msg5 = message.flow_mod()
485 msg5.match = match
486 msg5.cookie = random.randint(0,9007199254740992)
487 msg5.command = ofp.OFPFC_MODIFY_STRICT
488 msg5.buffer_id = 0xffffffff
489 act5 = action.action_output()
490 act5.port = egress_port
491 self.assertTrue(msg5.actions.add(act5), "could not add action")
ShreyaPandita60e45542012-09-27 15:11:16 -0400492
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400493 if priority != 0 :
494 msg5.priority = priority
ShreyaPandita60e45542012-09-27 15:11:16 -0400495
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400496 # Send the flow with action A'
497 rv = self.controller.message_send (msg5)
498 self.assertTrue(rv != -1, "Error installing flow mod")
499 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita60e45542012-09-27 15:11:16 -0400500
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400501def modify_flow_action(self,of_ports,match,priority=0):
ShreyaPandita60e45542012-09-27 15:11:16 -0400502# Modify the flow action
503
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400504 #Create a flow_mod message , command MODIFY
505 msg8 = message.flow_mod()
506 msg8.match = match
507 msg8.cookie = random.randint(0,9007199254740992)
508 msg8.command = ofp.OFPFC_MODIFY
509 #out_port will be ignored for flow adds and flow modify (here for test-case Add_Modify_With_Outport)
510 msg8.out_port = of_ports[3]
511 msg8.buffer_id = 0xffffffff
512 act8 = action.action_output()
513 act8.port = of_ports[2]
514 self.assertTrue(msg8.actions.add(act8), "could not add action")
ShreyaPandita60e45542012-09-27 15:11:16 -0400515
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400516 if priority != 0 :
517 msg8.priority = priority
ShreyaPandita60e45542012-09-27 15:11:16 -0400518
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400519 # Send the flow with action A'
520 rv = self.controller.message_send (msg8)
521 self.assertTrue(rv != -1, "Error installing flow mod")
522 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita60e45542012-09-27 15:11:16 -0400523
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400524def enqueue(self,ingress_port,egress_port,egress_queue_id):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400525#Generate a flow with enqueue action i.e output to a queue configured on a egress_port
526
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400527 pkt = simple_tcp_packet()
528 match = packet_to_flow_match(self, pkt)
529 match.wildcards &= ~ofp.OFPFW_IN_PORT
530 self.assertTrue(match is not None,
531 "Could not generate flow match from pkt")
532
533 match.in_port = ingress_port
534 request = message.flow_mod()
535 request.match = match
536 request.buffer_id = 0xffffffff
537 act = action.action_enqueue()
538 act.port = egress_port
539 act.queue_id = egress_queue_id
540 self.assertTrue(request.actions.add(act), "Could not add action")
541
542 logging.info("Inserting flow")
543 rv = self.controller.message_send(request)
544 self.assertTrue(rv != -1, "Error installing flow mod")
545 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
546 return (pkt,match)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400547
548
549
ShreyaPandita60e45542012-09-27 15:11:16 -0400550
551########################### Verify Stats Functions ###########################################################################################
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400552def get_flowstats(self,match):
553 # Generate flow_stats request
554
555 stat_req = message.flow_stats_request()
556 stat_req.match = match
557 stat_req.table_id = 0xff
558 stat_req.out_port = ofp.OFPP_NONE
559
560 logging.info("Sending stats request")
561 response, pkt = self.controller.transact(stat_req,
562 timeout=5)
563 self.assertTrue(response is not None,"No response to stats request")
ShreyaPandita60e45542012-09-27 15:11:16 -0400564
ShreyaPandita66de26f2012-10-26 14:44:24 -0400565
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400566def get_portstats(self,port_num):
567
568# Return all the port counters in the form a tuple
569 port_stats_req = message.port_stats_request()
570 port_stats_req.port_no = port_num
571 response,pkt = self.controller.transact(port_stats_req)
572 self.assertTrue(response is not None,"No response received for port stats request")
573 rx_pkts=0
574 tx_pkts=0
575 rx_byts=0
576 tx_byts=0
577 rx_drp =0
578 tx_drp = 0
579 rx_err=0
580 tx_err =0
581 rx_fr_err=0
582 rx_ovr_err=0
583 rx_crc_err=0
584 collisions = 0
585 tx_err=0
586
587
588 for obj in response.stats:
589 rx_pkts += obj.rx_packets
590 tx_pkts += obj.tx_packets
591 rx_byts += obj.rx_bytes
592 tx_byts += obj.tx_bytes
593 rx_drp += obj.rx_dropped
594 tx_drp += obj.tx_dropped
595 rx_err += obj.rx_errors
596 rx_fr_err += obj.rx_frame_err
597 rx_ovr_err += obj.rx_over_err
598 rx_crc_err += obj.rx_crc_err
599 collisions+= obj.collisions
600 tx_err += obj.tx_errors
601
602 return (rx_pkts,tx_pkts,rx_byts,tx_byts,rx_drp,tx_drp,rx_err,tx_err,rx_fr_err,rx_ovr_err,rx_crc_err,collisions,tx_err)
603
604def get_queuestats(self,port_num,queue_id):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400605#Generate Queue Stats request
606
607 request = message.queue_stats_request()
608 request.port_no = port_num
609 request.queue_id = queue_id
610 (queue_stats, p) = self.controller.transact(request)
611 self.assertNotEqual(queue_stats, None, "Queue stats request failed")
612
613 return (queue_stats,p)
614
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400615def get_tablestats(self):
616# Send Table_Stats request (retrieve current table counters )
617
618 stat_req = message.table_stats_request()
619 response, pkt = self.controller.transact(stat_req,
620 timeout=5)
621 self.assertTrue(response is not None,
622 "No response to stats request")
623 current_lookedup = 0
624 current_matched = 0
625 current_active = 0
626
627 for obj in response.stats:
628 current_lookedup += obj.lookup_count
629 current_matched += obj.matched_count
630 current_active += obj.active_count
631
632 return (current_lookedup,current_matched,current_active)
633
634
635
636def verify_tablestats(self,expect_lookup=0,expect_match=0,expect_active=0):
637
638 stat_req = message.table_stats_request()
639
640 all_packets_lookedup = 0
641 all_packets_matched = 0
642 all_entries_active = 0
643 lookedup = 0
644 matched = 0
645 active = 0
ShreyaPandita60e45542012-09-27 15:11:16 -0400646
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400647 for i in range(0,60):
ShreyaPandita60e45542012-09-27 15:11:16 -0400648
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400649 logging.info("Sending stats request")
650 # TODO: move REPLY_MORE handling to controller.transact?
ShreyaPandita66de26f2012-10-26 14:44:24 -0400651 response, pkt = self.controller.transact(stat_req,
652 timeout=5)
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400653 self.assertTrue(response is not None,"No response to stats request")
ShreyaPandita60e45542012-09-27 15:11:16 -0400654
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400655 for item in response.stats:
656 lookedup += item.lookup_count
657 matched += item.matched_count
658 active += item.active_count
659
660 logging.info("Packets Looked up " + str(lookedup) + " packets")
661 if expect_lookup != 0 :
662 if lookedup == expect_lookup:
663 all_packets_lookedup = 1
664
665 logging.info("Packets matched " + str(matched) + "packets")
666 if expect_match != 0 :
667 if matched == expect_match:
668 all_packets_matched = 1
669
670 logging.info("Active flow entries" + str(active) + "flows")
671 if active != 0 :
672 if active == expect_active:
673 all_entries_active = 1
674
675 if all_packets_lookedup == 1 and expect_lookup!= 0 :
676 break
677 if all_packets_matched== 1 and expect_match !=0 :
678 break
679 if all_entries_active ==1 and expect_active != 0 :
680 break
681
682 sleep(1)
683
684 if expect_lookup != 0 :
685 self.assertTrue(all_packets_matched, "lookup counter is not incremented properly")
686 if expect_match != 0 :
687 self.assertTrue(all_packets_matched, "matched counter is not incremented properly")
688 if expect_active != 0 :
689 self.assertTrue(all_entries_active, "active counter is not incremented properly")
690
691
692def verify_flowstats(self,match,byte_count=0,packet_count=0):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400693 # Verify flow counters : byte_count and packet_count
ShreyaPandita60e45542012-09-27 15:11:16 -0400694
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400695 stat_req = message.flow_stats_request()
696 stat_req.match = match
697 stat_req.table_id = 0xff
698 stat_req.out_port = ofp.OFPP_NONE
699
700 all_packets_rx = 0
701 all_bytes_rx = 0
702 packet_counter = 0
703 byte_counter = 0
704
705 for i in range(0,60):
706 logging.info("Sending stats request")
707 # TODO: move REPLY_MORE handling to controller.transact?
ShreyaPandita66de26f2012-10-26 14:44:24 -0400708 response, pkt = self.controller.transact(stat_req,
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400709 timeout=5)
710 self.assertTrue(response is not None,"No response to stats request")
711
712 for item in response.stats:
713 packet_counter += item.packet_count
714 byte_counter += item.byte_count
715
716 logging.info("Recieved" + str(item.packet_count) + " packets")
717 if packet_count != 0 :
718 if packet_count == packet_counter:
719 all_packets_rx = 1
720
721 logging.info("Received " + str(item.byte_count) + "bytes")
722 if byte_count != 0 :
723 if byte_counter == byte_count:
724 all_bytes_rx = 1
725
726 if all_packets_rx == 1 and packet_count != 0 :
727 break
728 if all_bytes_rx == 1 and byte_count !=0 :
729 break
730 sleep(1)
731
732 if packet_count != 0 :
733 self.assertTrue(all_packets_rx,"packet_count counter is not incremented correctly")
734
735 if byte_count != 0 :
736 self.assertTrue(all_bytes_rx,"byte_count counter is not incremented correctly")
737
738
739def verify_portstats(self, port,tx_packets=0,rx_packets=0,rx_byte=0,tx_byte=0):
740
741
742 stat_req = message.port_stats_request()
743 stat_req.port_no = port
744 all_packets_received = 0
745 all_packets_sent = 0
746 all_bytes_recieved = 0
747 all_bytes_sent = 0
748 sentp = recvp = 0
749 sentb = recvb = 0
750
751 for i in range(0,60):
752 logging.info("Sending stats request")
753 response, pkt = self.controller.transact(stat_req,
754 timeout=5)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400755 self.assertTrue(response is not None,
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400756 "No response to stats request")
757 self.assertTrue(len(response.stats) == 1,
758 "Did not receive port stats reply")
759 for item in response.stats:
760 sentp += item.tx_packets
761 recvp += item.rx_packets
762 sentb += item.tx_bytes
763 recvb += item.rx_bytes
764
765 logging.info("Sent " + str(sentp) + " packets")
766 if tx_packets != 0:
767 if item.tx_packets == tx_packets:
768 all_packets_sent = 1
769
770 logging.info("Received " + str(recvp) + " packets")
771 if rx_packets !=0 :
772 if item.rx_packets == rx_packets:
773 all_packets_received = 1
ShreyaPandita60e45542012-09-27 15:11:16 -0400774
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400775 logging.info("Received " + str(recvb) + "bytes")
776 if rx_byte !=0 :
777 if item.rx_bytes == rx_byte:
778 all_bytes_received = 1
779
780 logging.info("Sent" + str(sentb) + "bytes")
781 if tx_byte !=0 :
782 if item.tx_bytes == tx_byte:
783 all_bytes_sent = 1
784
785 if rx_packets !=0 and all_packets_received == 1:
786 break
787 if tx_packets !=0 and all_packets_sent == 1:
788 break
789 if rx_byte !=0 and all_bytes_received == 1:
790 break
791 if tx_byte !=0 and all_bytes_sent == 1:
792 break
793
794 sleep(1)
795
796 if (rx_packets !=0):
797 self.assertTrue(all_packets_received == 1 ,"rx_packets counter is not incremented correctly")
798 if (tx_packets !=0):
799 self.assertTrue(all_packets_sent == 1,"tx_packets counter is not incremented correctly")
800 if (rx_byte !=0):
801 self.assertTrue(all_bytes_received == 1 ,"rx_bytes counter is not incremented correctly")
802 if (tx_byte !=0):
803 self.assertTrue(all_bytes_sent == 1,"tx_bytes counter is not incremented correctly")
ShreyaPandita60e45542012-09-27 15:11:16 -0400804
ShreyaPandita60e45542012-09-27 15:11:16 -0400805
ShreyaPandita60e45542012-09-27 15:11:16 -0400806
807############################## Various delete commands #############################################################################################
808
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400809def strict_delete(self,match,priority=0):
ShreyaPandita60e45542012-09-27 15:11:16 -0400810# Issue Strict Delete
811
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400812 #Create flow_mod message, command DELETE_STRICT
813 msg4 = message.flow_mod()
814 msg4.out_port = ofp.OFPP_NONE
815 msg4.command = ofp.OFPFC_DELETE_STRICT
816 msg4.buffer_id = 0xffffffff
817 msg4.match = match
ShreyaPandita60e45542012-09-27 15:11:16 -0400818
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400819 if priority != 0 :
820 msg4.priority = priority
821 rv = self.controller.message_send(msg4)
822 self.assertTrue(rv!= -1, "Error installing flow mod")
823 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
ShreyaPandita60e45542012-09-27 15:11:16 -0400824
825
826
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400827def nonstrict_delete(self,match,priority=0):
ShreyaPandita60e45542012-09-27 15:11:16 -0400828# Issue Non_Strict Delete
829
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400830 #Create flow_mod message, command DELETE
831 msg6 = message.flow_mod()
832 msg6.out_port = ofp.OFPP_NONE
833 msg6.command = ofp.OFPFC_DELETE
834 msg6.buffer_id = 0xffffffff
835 msg6.match = match
ShreyaPandita60e45542012-09-27 15:11:16 -0400836
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400837 if priority != 0 :
838 msg6.priority = priority
ShreyaPandita60e45542012-09-27 15:11:16 -0400839
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400840 rv = self.controller.message_send(msg6)
841 self.assertTrue(rv != -1, "Error installing flow mod")
842 self.assertEqual(do_barrier(self.controller),0, "Barrier failed")
ShreyaPandita60e45542012-09-27 15:11:16 -0400843
844
845###########################################################################################################################################################
846
ShreyaPandita4ebbac32012-11-02 13:40:44 -0400847def send_packet(obj, pkt, ingress_port, egress_port):
ShreyaPandita60e45542012-09-27 15:11:16 -0400848#Send Packets on a specified ingress_port and verify if its recieved on correct egress_port.
849
850 obj.dataplane.send(ingress_port, str(pkt))
851 exp_pkt_arg = pkt
852 exp_port = egress_port
853
854 (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(timeout=2,
855 port_number=exp_port,
856 exp_pkt=exp_pkt_arg)
857 obj.assertTrue(rcv_pkt is not None,
858 "Packet not received on port " + str(egress_port))
859 obj.assertEqual(rcv_port, egress_port,
860 "Packet received on port " + str(rcv_port) +
861 ", expected port " + str(egress_port))
862 obj.assertEqual(str(pkt), str(rcv_pkt),
863 'Response packet does not match send packet')
864
865
ShreyaPandita572e64b2012-09-28 14:41:06 -0400866def sw_supported_actions(parent,use_cache=False):
ShreyaPandita60e45542012-09-27 15:11:16 -0400867#Returns the switch's supported actions
868
869 cache_supported_actions = None
870 if cache_supported_actions is None or not use_cache:
871 request = message.features_request()
872 (reply, pkt) = parent.controller.transact(request)
873 parent.assertTrue(reply is not None, "Did not get response to ftr req")
874 cache_supported_actions = reply.actions
875 return cache_supported_actions
876
ShreyaPandita66de26f2012-10-26 14:44:24 -0400877##############################################################################################################################################################
878