1
2 '''
3 Created on 26-Oct-2012
4
5 @author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
6
7 MininetCliDriver is the basic driver which will handle the Mininet functions
8 '''
9
10 import pexpect
11 import struct
12 import fcntl
13 import os
14 import signal
15 import re
16 import sys
17 import core.teston
18 sys.path.append("../")
19 from drivers.common.cli.emulatordriver import Emulator
20 from drivers.common.clidriver import CLI
21
23 '''
24 MininetCliDriver is the basic driver which will handle the Mininet functions
25 '''
27 super(Emulator, self).__init__()
28 self.handle = self
29 self.wrapped = sys.modules[__name__]
30
32
33
34 for key in connectargs:
35 vars(self)[key] = connectargs[key]
36
37 self.name = self.options['name']
38 copy = super(MininetCliDriver, self).secureCopy(self.user_name, self.ip_address,'/home/openflow/mininet/INSTALL', self.pwd,path+'/lib/Mininet/')
39 self.handle = super(MininetCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
40
41 self.ssh_handle = self.handle
42
43
44 if self.handle :
45
46 main.log.info("Clearing any residual state or processes")
47 result = self.execute(cmd="sudo mn -c",timeout=30,prompt="password")
48 pattern = '[sudo]'
49 if utilities.assert_matches(expect=pattern,actual=result,onpass="password is being asked",onfail="password is not being asked"):
50 resultPass = self.execute(cmd="openflow",prompt="openflow",timeout=120)
51
52 else :
53 main.log.info("password is not being asked")
54 pass
55
56 cmdString = "sudo mn --topo "+self.options['topo']+","+self.options['topocount']+" --mac --switch "+self.options['switch']+" --controller "+self.options['controller']
57 resultCommand = self.execute(cmd=cmdString,prompt='mininet',timeout=120)
58
59 patterns = "Starting CLI:"
60 if utilities.assert_matches(expect=patterns,actual=resultCommand,onpass="Network is being launched",onfail="Network launching is being failed "):
61 return main.TRUE
62 else:
63 return main.FALSE
64
65 else :
66 main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
67 main.log.error("Failed to connect to the Mininet")
68 return main.FALSE
69
71 '''
72 Verifies the reachability of the hosts using pingall command.
73 '''
74 if self.handle :
75 main.log.info("Checking reachabilty to the hosts using pingall")
76 response = self.execute(cmd="pingall",prompt="mininet>",timeout=120)
77 pattern = 'Results\:\s0\%\sdropped\s\(0\/\d+\slost\)\s*$'
78 if utilities.assert_matches(expect=pattern,actual=response,onpass="All hosts are reaching",onfail="Unable to reach all the hosts"):
79 return main.TRUE
80 else:
81 return main.FALSE
82 else :
83 main.log.error("Connection failed to the host")
84 return main.FALSE
85
87
88 args = utilities.parse_args(["SRC","TARGET","CONTROLLER"],**pingParams)
89 command = args["SRC"] + " ping -" + args["CONTROLLER"] + " " +args ["TARGET"]
90 response = self.execute(cmd=command,prompt="mininet",timeout=120 )
91 if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Host is not reachable"):
92 main.log.info("PING SUCCESS WITH NO PACKET LOSS")
93 main.last_result = main.TRUE
94 return main.TRUE
95 else :
96 main.log.error("PACKET LOST, HOST IS NOT REACHABLE")
97 main.last_result = main.FALSE
98 return main.FALSE
99
100
102 '''
103 Verifies the host's ip configured or not.
104 '''
105 if self.handle :
106 main.log.info("Pinging host "+host)
107 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=120)
108
109 pattern = "inet\s(addr|Mask):([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2})"
110 if utilities.assert_matches(expect=pattern,actual=response,onpass="Host Ip configured properly",onfail="Host IP didn't found") :
111 return main.TRUE
112 else:
113 return main.FALSE
114 else :
115 main.log.error("Connection failed to the host")
116
118 main.log.info("Dump node info")
119 self.execute(cmd = 'dump',prompt = 'mininet>',timeout = 10)
120 return main.TRUE
121
123 main.log.info("List interfaces")
124 self.execute(cmd = 'intfs',prompt = 'mininet>',timeout = 10)
125 return main.TRUE
126
128 main.log.info("List network connections")
129 self.execute(cmd = 'net',prompt = 'mininet>',timeout = 10)
130 return main.TRUE
131
133 main.log.info("Simple iperf TCP test between two (optionally specified) hosts")
134 self.execute(cmd = 'iperf',prompt = 'mininet>',timeout = 10)
135 return main.TRUE
136
138 main.log.info("Simple iperf TCP test between two (optionally specified) hosts")
139 self.execute(cmd = 'iperfudp',prompt = 'mininet>',timeout = 10)
140 return main.TRUE
141
143 main.log.info("List all nodes.")
144 self.execute(cmd = 'nodes',prompt = 'mininet>',timeout = 10)
145 return main.TRUE
146
148 main.log.infoe("Ping between first two hosts")
149 self.execute(cmd = 'pingpair',prompt = 'mininet>',timeout = 20)
150
151 if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Hosts not reachable"):
152 main.log.info("Ping between two hosts SUCCESS")
153 main.last_result = main.TRUE
154 return main.TRUE
155 else :
156 main.log.error("PACKET LOST, HOSTS NOT REACHABLE")
157 main.last_result = main.FALSE
158 return main.FALSE
159
160 - def link(self,**linkargs):
161 '''
162 Bring link(s) between two nodes up or down
163 '''
164 main.log.info('Bring link(s) between two nodes up or down')
165 args = utilities.parse_args(["END1","END2","OPTION"],**linkargs)
166 end1 = args["END1"] if args["END1"] != None else ""
167 end2 = args["END2"] if args["END2"] != None else ""
168 option = args["OPTION"] if args["OPTION"] != None else ""
169 command = "link "+str(end1) + " " + str(end2)+ " " + str(option)
170 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
171 return main.TRUE
172
173
174 - def dpctl(self,**dpctlargs):
175 '''
176 Run dpctl command on all switches.
177 '''
178 main.log.info('Run dpctl command on all switches')
179 args = utilities.parse_args(["CMD","ARGS"],**dpctlargs)
180 cmd = args["CMD"] if args["CMD"] != None else ""
181 cmdargs = args["ARGS"] if args["ARGS"] != None else ""
182 command = "dpctl "+cmd + " " + str(cmdargs)
183 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
184 return main.TRUE
185
186
188 file_input = path+'/lib/Mininet/INSTALL'
189 version = super(Mininet, self).get_version()
190 pattern = 'Mininet\s\w\.\w\.\w\w*'
191 for line in open(file_input,'r').readlines():
192 result = re.match(pattern, line)
193 if result:
194 version = result.group(0)
195
196
197 return version
198
200
201 response = ''
202 if self.handle:
203 self.handle = handle
204 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
205 else :
206 main.log.error("Connection failed to the host")
207 response = main.FALSE
208 return response
209
210 if __name__ != "__main__":
211 import sys
212 sys.modules[__name__] = MininetCliDriver()
213