blob: 3ad5bba2e7a7c56a609aee31f0e95520c3f7a316 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#/usr/bin/env python
2'''
3Created on 26-Nov-2012
4
5@author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
6
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
11 (at your option) any later version.
12
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
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
22
23DPCTL driver class provides the basic functions of DPCTL controller
24'''
25import pexpect
26import struct, fcntl, os, sys, signal
27import sys
28from drivers.common.cli.toolsdriver import Tools
29import pydoc
30from drivers.common.clidriver import CLI
31import re
32import os
33import sys
34
35class DpctlCliDriver(Tools):
36 '''
37 DpctlCliDriver driver class provides the basic functions of DPCTL controller
38 '''
39 def __init__(self):
40 super(DpctlCliDriver, self).__init__()
41 self.handle = self
42 self.wrapped = sys.modules[__name__]
43
44 def connect(self,**connectargs):
45
46 for key in connectargs:
47 vars(self)[key] = connectargs[key]
48
49 self.name = self.options['name']
50
51 self.handle = super(DpctlCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
52 if self.handle :
53 main.log.info("Connected to the host")
54 return main.TRUE
55 else :
56 main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
57 return main.FALSE
58
59 def addFlow(self,**flowParameters):
60 '''
61 addFlow create a new flow entry into flow table using "dpctl"
62 '''
63 args = utilities.parse_args(["TCPIP","TCPPORT","INPORT","ACTION","TIMEOUT"],**flowParameters)
64 cmd = "dpctl add-flow tcp:"
65 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
66 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
67 timeOut = args["TIMEOUT"] if args["TIMEOUT"] != None else 120
68 cmd = cmd + tcpIP + ":" + tcpPort + " in_port=" + str(args["INPORT"]) + ",idle_timeout=" + str(args["TIMEOUT"]) +",actions=" + args["ACTION"]
69 response = self.execute(cmd=cmd,prompt="\~\$",timeout=60 )
70 if utilities.assert_matches(expect="openflow",actual=response,onpass="Flow Added Successfully",onfail="Adding Flow Failed!!!"):
71 return main.TRUE
72 else :
73 return main.FALSE
74
75 def showFlow(self,**flowParameters):
76 '''
77 showFlow dumps the flow entries of flow table using "dpctl"
78 '''
79 args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
80 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
81 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
82 command = "dpctl show tcp:" + str(tcpIP) + ":" + str(tcpPort)
83 response = self.execute(cmd=command,prompt="get_config_reply",timeout=240)
84 if utilities.assert_matches(expect='features_reply',actual=response,onpass="Show flow executed",onfail="Show flow execution Failed"):
85 main.last_result = main.TRUE
86 return main.TRUE
87 else :
88 main.last_result = main.FALSE
89 return main.FALSE
90
91 def dumpFlow(self,**flowParameters):
92 '''
93 dumpFlow gives installed flow information
94 '''
95 args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
96 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
97 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
98 command = "dpctl dump-flows tcp:" + str(tcpIP) + ":" + str(tcpPort)
99 response = self.execute(cmd=command,prompt="type=",timeout=240)
100 if utilities.assert_matches(expect='stats_reply',actual=response,onpass="Dump flow executed",onfail="Dump flow execution Failed"):
101 main.last_result = main.TRUE
102 return main.TRUE
103 else :
104 main.last_result = main.FALSE
105 return main.FALSE
106
107
108 def dumpTables(self,**flowParameters):
109 '''
110 dumpTables gives statistics for each of the flow tables used by datapath switch.
111 '''
112 args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
113 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
114 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
115 command = "dpctl dump-tables tcp:" + str(tcpIP) + ":" + str(tcpPort)
116 response = self.execute(cmd=command,prompt="matched",timeout=240)
117 if utilities.assert_matches(expect='lookup=3',actual=response,onpass="Dump Tables executed",onfail="Dump Tables execution Failed"):
118 main.last_result = main.TRUE
119 return main.TRUE
120 else :
121 main.last_result = main.FALSE
122 return main.FALSE
123
124 def dumpPorts(self,**flowParameters):
125 '''
126 dumpPorts gives ports information
127 '''
128 args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
129 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
130 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
131 command = "dpctl dump-ports tcp:" + str(tcpIP) + ":" + str(tcpPort)
132 response = self.execute(cmd=command,prompt="rx pkts",timeout=240)
133 if utilities.assert_matches(expect='ports',actual=response,onpass="Dump Ports executed",onfail="Dump Ports execution Failed"):
134 main.last_result = main.TRUE
135 return main.TRUE
136 else :
137 main.last_result = main.FALSE
138 return main.FALSE
139
140
141 def dumpAggregate(self,**flowParameters):
142 '''
143 dumpAggregate gives installed flow information.ggregate statistics for flows in datapath WITCH's tables that match flows.
144 If flows is omitted, the statistics are aggregated across all flows in the datapath's flow tables
145 '''
146 args = utilities.parse_args(["TCPIP","TCPPORT","FLOW"],**flowParameters)
147 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
148 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
149 flow = args["FLOW"] if args["FLOW"] != None else ""
150 command = "dpctl dump-aggregate tcp:" + str(tcpIP) + ":" + str(tcpPort) + " " + str (flow)
151 response = self.execute(cmd=command,prompt="flow_count=",timeout=240)
152 if utilities.assert_matches(expect='stats_reply',actual=response,onpass="Dump Aggregate executed",onfail="Dump Aggregate execution Failed"):
153 main.last_result = main.TRUE
154 return main.TRUE
155 else :
156 main.last_result = main.FALSE
157 return main.FALSE
158
159 def delFlow(self,**flowParameters):
160 '''
161 delFlow Deletes entries from the datapath switch's tables that match flow
162 '''
163 args = utilities.parse_args(["TCPIP","TCPPORT","FLOW"],**flowParameters)
164 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
165 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
166 flow = args["FLOW"] if args["FLOW"] != None else ""
167 command = "dpctl del-flows tcp:" + str(tcpIP) + ":" + str(tcpPort) + " " +str(flow)
168 response = self.execute(cmd=command,prompt="ETH-Tutorial",timeout=240)
169 if utilities.assert_matches(expect='@',actual=response,onpass="Delete flow executed",onfail="Delete flow execution Failed"):
170 main.last_result = main.TRUE
171 return main.TRUE
172 else :
173 main.last_result = main.FALSE
174 return main.FALSE
175
176 def show(self,**flowParameters):
177 '''
178 show gives information on datapath switch including information on its flow tables and ports.
179 '''
180 args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
181 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
182 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
183 command = "dpctl show tcp:" + str(tcpIP) + ":" + str(tcpPort)
184 response = self.execute(cmd=command,prompt="miss_send_len=",timeout=240)
185 if utilities.assert_matches(expect='get_config_reply',actual=response,onpass="show command executed",onfail="show command execution Failed"):
186 main.last_result = main.TRUE
187 return main.TRUE
188 else :
189 main.last_result = main.FALSE
190 return main.FALSE
191
192 def showStatus(self,**flowParameters):
193 '''
194 showStatus gives a series of key-value pairs that report the status of switch.
195 If key is specified, only the key-value pairs whose key names begin with key are printed.
196 '''
197 args = utilities.parse_args(["TCPIP","TCPPORT","KEY"],**flowParameters)
198 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
199 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
200 key = args["KEY"] if args["KEY"] != None else ""
201 command = "dpctl status tcp:" + str(tcpIP) + ":" + str(tcpPort) + " " + key
202 response = self.execute(cmd=command,prompt="(.*)",timeout=240)
203 if utilities.assert_matches(expect='(.*)',actual=response,onpass="show command executed",onfail="show command execution Failed"):
204 main.last_result = main.TRUE
205 return main.TRUE
206 else :
207 main.last_result = main.FALSE
208 return main.FALSE
209
210 def desc_set(self,**flowParameters):
211 '''
212 desc_set Sets the switch description (as returned in ofp_desc_stats) to string (max length is DESC_STR_LEN)
213 '''
214 args = utilities.parse_args(["TCPIP","TCPPORT","STRING"],**flowParameters)
215 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
216 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
217 string = " " + args["STRING"] if args["STRING"] != None else " DESC_STR_LEN"
218 command = "dpctl desc tcp:" + str(tcpIP) + ":" + str(tcpPort) + str(string)
219 response = self.execute(cmd=command,prompt="ETH-Tutorial",timeout=240)
220 if utilities.assert_matches(expect='@',actual=response,onpass="desc command executed",onfail="desc command execution Failed"):
221 main.last_result = main.TRUE
222 return main.TRUE
223 else :
224 main.last_result = main.FALSE
225 return main.FALSE
226
227 def dumpDesc(self,**flowParameters):
228 '''
229 dumpDesc Sets the switch description (as returned in ofp_desc_stats) to string (max length is DESC_STR_LEN)
230 '''
231 args = utilities.parse_args(["TCPIP","TCPPORT","STRING"],**flowParameters)
232 tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
233 tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
234 command = "dpctl dump-desc tcp:" + str(tcpIP) + ":" + str(tcpPort)
235 response = self.execute(cmd=command,prompt="Serial Num:",timeout=240)
236 if utilities.assert_matches(expect='stats_reply',actual=response,onpass="desc command executed",onfail="desc command execution Failed"):
237 main.last_result = main.TRUE
238 return main.TRUE
239 else :
240 main.last_result = main.FALSE
241 return main.FALSE
242
243if __name__ != "__main__":
244 import sys
245 sys.modules[__name__] = DpctlCliDriver()