blob: 1e5f839a32d24e42f4a42dd36af6b49b92969988 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#/usr/bin/env python
kelvin8ec71442015-01-15 16:57:00 -08002"""
adminbae64d82013-08-01 10:50:15 -07003Created on 26-Nov-2012
kelvin8ec71442015-01-15 16:57:00 -08004
5author:: Raghav Kashyap( raghavkashyap@paxterrasolutions.com )
adminbae64d82013-08-01 10:50:15 -07006
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
kelvin8ec71442015-01-15 16:57:00 -080011 ( at your option ) any later version.
adminbae64d82013-08-01 10:50:15 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
kelvin8ec71442015-01-15 16:57:00 -080019 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070020
21
22
23DPCTL driver class provides the basic functions of DPCTL controller
kelvin8ec71442015-01-15 16:57:00 -080024"""
adminbae64d82013-08-01 10:50:15 -070025import sys
26from drivers.common.cli.toolsdriver import Tools
adminbae64d82013-08-01 10:50:15 -070027
kelvin8ec71442015-01-15 16:57:00 -080028
29class DpctlCliDriver( Tools ):
30
31 """
adminbae64d82013-08-01 10:50:15 -070032 DpctlCliDriver driver class provides the basic functions of DPCTL controller
kelvin8ec71442015-01-15 16:57:00 -080033 """
34 def __init__( self ):
35 super( DpctlCliDriver, self ).__init__()
adminbae64d82013-08-01 10:50:15 -070036 self.handle = self
kelvin8ec71442015-01-15 16:57:00 -080037 self.wrapped = sys.modules[ __name__ ]
38
39 def connect( self, **connectargs ):
40
adminbae64d82013-08-01 10:50:15 -070041 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080042 vars( self )[ key ] = connectargs[ key ]
adminbae64d82013-08-01 10:50:15 -070043
kelvin8ec71442015-01-15 16:57:00 -080044 self.name = self.options[ 'name' ]
45
Jon Hallfd8ce432015-07-21 13:07:53 -070046 self.handle = super(
kelvin8ec71442015-01-15 16:57:00 -080047 DpctlCliDriver, self ).connect( user_name=self.user_name,
48 ip_address=self.ip_address,
49 port=None,
50 pwd=self.pwd )
51 if self.handle:
52 main.log.info( "Connected to the host" )
53 return main.TRUE
54 else:
55 main.log.error(
56 "Connection failed to the host " +
57 self.user_name +
58 "@" +
59 self.ip_address )
60 return main.FALSE
61
62 def addFlow( self, **flowParameters ):
63 """
adminbae64d82013-08-01 10:50:15 -070064 addFlow create a new flow entry into flow table using "dpctl"
kelvin8ec71442015-01-15 16:57:00 -080065 """
66 args = utilities.parse_args( [
67 "TCPIP",
68 "TCPPORT",
69 "INPORT",
70 "ACTION",
71 "TIMEOUT" ],
72 **flowParameters )
73
adminbae64d82013-08-01 10:50:15 -070074 cmd = "dpctl add-flow tcp:"
kelvin8ec71442015-01-15 16:57:00 -080075 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
76 tcpPort = args[ "TCPPORT" ] if args[
77 "TCPPORT" ] is not None else "6634"
78 timeOut = args[ "TIMEOUT" ] if args[ "TIMEOUT" ] is not None else 120
79 cmd = cmd + tcpIP + ":" + tcpPort + " in_port=" + \
80 str( args[ "INPORT" ] ) + ",idle_timeout=" + str(
81 args[ "TIMEOUT" ] ) + ",actions=" + args[ "ACTION" ]
82 response = self.execute( cmd=cmd, prompt="\~\$", timeout=60 )
83 if utilities.assert_matches( expect="openflow", actual=response, onpass="Flow Added Successfully", onfail="Adding Flow Failed!!!" ):
adminbae64d82013-08-01 10:50:15 -070084 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -080085 else:
adminbae64d82013-08-01 10:50:15 -070086 return main.FALSE
87
kelvin8ec71442015-01-15 16:57:00 -080088 def showFlow( self, **flowParameters ):
89 """
adminbae64d82013-08-01 10:50:15 -070090 showFlow dumps the flow entries of flow table using "dpctl"
kelvin8ec71442015-01-15 16:57:00 -080091 """
92 args = utilities.parse_args( [ "TCPIP", "TCPPORT" ], **flowParameters )
93 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
94 tcpPort = args[ "TCPPORT" ] if args[
95 "TCPPORT" ] is not None else "6634"
96 command = "dpctl show tcp:" + str( tcpIP ) + ":" + str( tcpPort )
97 response = self.execute(
98 cmd=command,
99 prompt="get_config_reply",
100 timeout=240 )
101 if utilities.assert_matches( expect='features_reply', actual=response, onpass="Show flow executed", onfail="Show flow execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700102 main.last_result = main.TRUE
103 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800104 else:
adminbae64d82013-08-01 10:50:15 -0700105 main.last_result = main.FALSE
106 return main.FALSE
107
kelvin8ec71442015-01-15 16:57:00 -0800108 def dumpFlow( self, **flowParameters ):
109 """
adminbae64d82013-08-01 10:50:15 -0700110 dumpFlow gives installed flow information
kelvin8ec71442015-01-15 16:57:00 -0800111 """
112 args = utilities.parse_args( [ "TCPIP", "TCPPORT" ], **flowParameters )
113 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
114 tcpPort = args[ "TCPPORT" ] if args[
115 "TCPPORT" ] is not None else "6634"
116 command = "dpctl dump-flows tcp:" + str( tcpIP ) + ":" + str( tcpPort )
117 response = self.execute( cmd=command, prompt="type=", timeout=240 )
118 if utilities.assert_matches( expect='stats_reply', actual=response, onpass="Dump flow executed", onfail="Dump flow execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700119 main.last_result = main.TRUE
120 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800121 else:
adminbae64d82013-08-01 10:50:15 -0700122 main.last_result = main.FALSE
123 return main.FALSE
124
kelvin8ec71442015-01-15 16:57:00 -0800125 def dumpTables( self, **flowParameters ):
126 """
adminbae64d82013-08-01 10:50:15 -0700127 dumpTables gives statistics for each of the flow tables used by datapath switch.
kelvin8ec71442015-01-15 16:57:00 -0800128 """
129 args = utilities.parse_args( [ "TCPIP", "TCPPORT" ], **flowParameters )
130 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
131 tcpPort = args[ "TCPPORT" ] if args[
132 "TCPPORT" ] is not None else "6634"
133 command = "dpctl dump-tables tcp:" + \
134 str( tcpIP ) + ":" + str( tcpPort )
135 response = self.execute( cmd=command, prompt="matched", timeout=240 )
136 if utilities.assert_matches( expect='lookup=3', actual=response, onpass="Dump Tables executed", onfail="Dump Tables execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700137 main.last_result = main.TRUE
138 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800139 else:
adminbae64d82013-08-01 10:50:15 -0700140 main.last_result = main.FALSE
141 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800142
143 def dumpPorts( self, **flowParameters ):
144 """
adminbae64d82013-08-01 10:50:15 -0700145 dumpPorts gives ports information
kelvin8ec71442015-01-15 16:57:00 -0800146 """
147 args = utilities.parse_args( [ "TCPIP", "TCPPORT" ], **flowParameters )
148 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
149 tcpPort = args[ "TCPPORT" ] if args[
150 "TCPPORT" ] is not None else "6634"
151 command = "dpctl dump-ports tcp:" + str( tcpIP ) + ":" + str( tcpPort )
152 response = self.execute( cmd=command, prompt="rx pkts", timeout=240 )
153 if utilities.assert_matches( expect='ports', actual=response, onpass="Dump Ports executed", onfail="Dump Ports execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700154 main.last_result = main.TRUE
155 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800156 else:
adminbae64d82013-08-01 10:50:15 -0700157 main.last_result = main.FALSE
158 return main.FALSE
159
kelvin8ec71442015-01-15 16:57:00 -0800160 def dumpAggregate( self, **flowParameters ):
161 """
adminbae64d82013-08-01 10:50:15 -0700162 dumpAggregate gives installed flow information.ggregate statistics for flows in datapath WITCH's tables that match flows.
163 If flows is omitted, the statistics are aggregated across all flows in the datapath's flow tables
kelvin8ec71442015-01-15 16:57:00 -0800164 """
165 args = utilities.parse_args(
166 [ "TCPIP", "TCPPORT", "FLOW" ], **flowParameters )
167 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
168 tcpPort = args[ "TCPPORT" ] if args[
169 "TCPPORT" ] is not None else "6634"
170 flow = args[ "FLOW" ] if args[ "FLOW" ] is not None else ""
171 command = "dpctl dump-aggregate tcp:" + \
172 str( tcpIP ) + ":" + str( tcpPort ) + " " + str( flow )
173 response = self.execute(
174 cmd=command,
175 prompt="flow_count=",
176 timeout=240 )
177 if utilities.assert_matches( expect='stats_reply', actual=response, onpass="Dump Aggregate executed", onfail="Dump Aggregate execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700178 main.last_result = main.TRUE
179 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800180 else:
adminbae64d82013-08-01 10:50:15 -0700181 main.last_result = main.FALSE
182 return main.FALSE
183
kelvin8ec71442015-01-15 16:57:00 -0800184 def delFlow( self, **flowParameters ):
185 """
adminbae64d82013-08-01 10:50:15 -0700186 delFlow Deletes entries from the datapath switch's tables that match flow
kelvin8ec71442015-01-15 16:57:00 -0800187 """
188 args = utilities.parse_args(
189 [ "TCPIP", "TCPPORT", "FLOW" ], **flowParameters )
190 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
191 tcpPort = args[ "TCPPORT" ] if args[
192 "TCPPORT" ] is not None else "6634"
193 flow = args[ "FLOW" ] if args[ "FLOW" ] is not None else ""
194 command = "dpctl del-flows tcp:" + \
195 str( tcpIP ) + ":" + str( tcpPort ) + " " + str( flow )
196 response = self.execute(
197 cmd=command,
198 prompt="ETH-Tutorial",
199 timeout=240 )
200 if utilities.assert_matches( expect='@', actual=response, onpass="Delete flow executed", onfail="Delete flow execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700201 main.last_result = main.TRUE
202 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800203 else:
adminbae64d82013-08-01 10:50:15 -0700204 main.last_result = main.FALSE
205 return main.FALSE
206
kelvin8ec71442015-01-15 16:57:00 -0800207 def show( self, **flowParameters ):
208 """
adminbae64d82013-08-01 10:50:15 -0700209 show gives information on datapath switch including information on its flow tables and ports.
kelvin8ec71442015-01-15 16:57:00 -0800210 """
211 args = utilities.parse_args( [ "TCPIP", "TCPPORT" ], **flowParameters )
212 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
213 tcpPort = args[ "TCPPORT" ] if args[
214 "TCPPORT" ] is not None else "6634"
215 command = "dpctl show tcp:" + str( tcpIP ) + ":" + str( tcpPort )
216 response = self.execute(
217 cmd=command,
218 prompt="miss_send_len=",
219 timeout=240 )
220 if utilities.assert_matches( expect='get_config_reply', actual=response, onpass="show command executed", onfail="show command execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700221 main.last_result = main.TRUE
222 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800223 else:
adminbae64d82013-08-01 10:50:15 -0700224 main.last_result = main.FALSE
225 return main.FALSE
226
kelvin8ec71442015-01-15 16:57:00 -0800227 def showStatus( self, **flowParameters ):
228 """
229 showStatus gives a series of key-value pairs that report the status of switch.
230 If key is specified, only the key-value pairs whose key names begin with key are printed.
231 """
232 args = utilities.parse_args(
233 [ "TCPIP", "TCPPORT", "KEY" ], **flowParameters )
234 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
235 tcpPort = args[ "TCPPORT" ] if args[
236 "TCPPORT" ] is not None else "6634"
237 key = args[ "KEY" ] if args[ "KEY" ] is not None else ""
238 command = "dpctl status tcp:" + \
239 str( tcpIP ) + ":" + str( tcpPort ) + " " + key
240 response = self.execute( cmd=command, prompt="(.*)", timeout=240 )
241 if utilities.assert_matches( expect='(.*)', actual=response, onpass="show command executed", onfail="show command execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700242 main.last_result = main.TRUE
243 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800244 else:
adminbae64d82013-08-01 10:50:15 -0700245 main.last_result = main.FALSE
246 return main.FALSE
247
kelvin8ec71442015-01-15 16:57:00 -0800248 def desc_set( self, **flowParameters ):
249 """
250 desc_set Sets the switch description ( as returned in ofp_desc_stats ) to string ( max length is DESC_STR_LEN )
251 """
252 args = utilities.parse_args( [
253 "TCPIP",
254 "TCPPORT",
255 "STRING" ],
256 **flowParameters )
257
258 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
259 tcpPort = args[ "TCPPORT" ] if args[
260 "TCPPORT" ] is not None else "6634"
261 string = " " + args[ "STRING" ] if args[
262 "STRING" ] is not None else " DESC_STR_LEN"
263 command = "dpctl desc tcp:" + \
264 str( tcpIP ) + ":" + str( tcpPort ) + str( string )
265 response = self.execute(
266 cmd=command,
267 prompt="ETH-Tutorial",
268 timeout=240 )
269 if utilities.assert_matches( expect='@', actual=response, onpass="desc command executed", onfail="desc command execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700270 main.last_result = main.TRUE
271 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800272 else:
adminbae64d82013-08-01 10:50:15 -0700273 main.last_result = main.FALSE
274 return main.FALSE
275
kelvin8ec71442015-01-15 16:57:00 -0800276 def dumpDesc( self, **flowParameters ):
277 """
278 dumpDesc Sets the switch description ( as returned in ofp_desc_stats ) to string ( max length is DESC_STR_LEN )
279 """
280 args = utilities.parse_args( [
281 "TCPIP",
282 "TCPPORT",
283 "STRING" ],
284 **flowParameters )
285
286 tcpIP = args[ "TCPIP" ] if args[ "TCPIP" ] is not None else "127.0.0.1"
287 tcpPort = args[ "TCPPORT" ] if args[
288 "TCPPORT" ] is not None else "6634"
289 command = "dpctl dump-desc tcp:" + str( tcpIP ) + ":" + str( tcpPort )
290 response = self.execute(
291 cmd=command,
292 prompt="Serial Num:",
293 timeout=240 )
294 if utilities.assert_matches( expect='stats_reply', actual=response, onpass="desc command executed", onfail="desc command execution Failed" ):
adminbae64d82013-08-01 10:50:15 -0700295 main.last_result = main.TRUE
296 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800297 else:
adminbae64d82013-08-01 10:50:15 -0700298 main.last_result = main.FALSE
299 return main.FALSE
300
301if __name__ != "__main__":
302 import sys
kelvin8ec71442015-01-15 16:57:00 -0800303 sys.modules[ __name__ ] = DpctlCliDriver()
304