Package TestON :: Package drivers :: Package common :: Package cli :: Package tool :: Module dpctlclidriver
[hide private]
[frames] | no frames]

Source Code for Module TestON.drivers.common.cli.tool.dpctlclidriver

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