blob: e0f793be0397b1d01ebbf0cd804cd3e618c877a0 [file] [log] [blame]
timlindbergef8d55d2013-09-27 12:50:13 -07001#!/usr/bin/env python
2
3import time
4import pexpect
5import struct, fcntl, os, sys, signal
6import sys
7import re
8import json
9sys.path.append("../")
10from drivers.common.clidriver import CLI
11
12class QuaggaCliDriver(CLI):
13
14 def __init__(self):
15 super(CLI, self).__init__()
16
pingping-linc6b86fa2014-12-01 16:18:10 -080017 # TODO: simplify this method
timlindbergef8d55d2013-09-27 12:50:13 -070018 def connect(self, **connectargs):
19 for key in connectargs:
20 vars(self)[key] = connectargs[key]
pingping-linc6b86fa2014-12-01 16:18:10 -080021
timlindbergef8d55d2013-09-27 12:50:13 -070022 self.name = self.options['name']
pingping-linc6b86fa2014-12-01 16:18:10 -080023 # self.handle = super(QuaggaCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
pingping-lin8b306ac2014-11-17 18:13:51 -080024 self.handle = super(QuaggaCliDriver, self).connect(user_name=self.user_name, ip_address="1.1.1.1", port=self.port, pwd=self.pwd)
25 main.log.info("connect parameters:" + str(self.user_name) + ";" + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
timlindbergef8d55d2013-09-27 12:50:13 -070026
pingping-linc6b86fa2014-12-01 16:18:10 -080027 if self.handle:
timlindbergef8d55d2013-09-27 12:50:13 -070028 self.handle.expect("")
29 self.handle.expect("\$")
30 self.handle.sendline("telnet localhost 2605")
pingping-linc6b86fa2014-12-01 16:18:10 -080031 self.handle.expect("Password:", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070032 self.handle.sendline("hello")
pingping-linc6b86fa2014-12-01 16:18:10 -080033 self.handle.expect("bgpd", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070034 self.handle.sendline("enable")
pingping-linc6b86fa2014-12-01 16:18:10 -080035 self.handle.expect("bgpd#", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070036 return self.handle
37 else :
38 main.log.info("NO HANDLE")
39 return main.FALSE
40
pingping-lin8b306ac2014-11-17 18:13:51 -080041 def loginQuagga(self, ip_address):
pingping-lin8b306ac2014-11-17 18:13:51 -080042 self.name = self.options['name']
43 self.handle = super(QuaggaCliDriver, self).connect(
44 user_name=self.user_name, ip_address=ip_address,
45 port=self.port, pwd=self.pwd)
46 main.log.info("connect parameters:" + str(self.user_name) + ";"
47 + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
48
49 if self.handle:
50 self.handle.expect("")
51 self.handle.expect("\$")
52 self.handle.sendline("telnet localhost 2605")
53 self.handle.expect("Password:", timeout=5)
54 self.handle.sendline("hello")
55 self.handle.expect("bgpd", timeout=5)
56 self.handle.sendline("enable")
57 self.handle.expect("bgpd#", timeout=5)
pingping-lin36fbe802014-11-25 16:01:14 -080058 main.log.info("I in quagga on host " + str(ip_address))
pingping-lin8b306ac2014-11-17 18:13:51 -080059
60 return self.handle
61 else:
62 main.log.info("NO HANDLE")
63 return main.FALSE
64
timlindbergef8d55d2013-09-27 12:50:13 -070065 def enter_config(self, asn):
pingping-lin8b306ac2014-11-17 18:13:51 -080066 main.log.info("I am in enter_config method!")
timlindbergef8d55d2013-09-27 12:50:13 -070067 try:
68 self.handle.sendline("")
69 self.handle.expect("bgpd#")
70 except:
71 main.log.warn("Probably not currently in enable mode!")
72 self.disconnect()
73 return main.FALSE
74 self.handle.sendline("configure terminal")
pingping-linc6b86fa2014-12-01 16:18:10 -080075 self.handle.expect("config", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070076 routerAS = "router bgp " + str(asn)
77 try:
78 self.handle.sendline(routerAS)
pingping-linc6b86fa2014-12-01 16:18:10 -080079 self.handle.expect("config-router", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070080 return main.TRUE
81 except:
82 return main.FALSE
pingping-lin8b306ac2014-11-17 18:13:51 -080083
pingping-lin6f6332e2014-11-19 19:13:58 -080084 def generate_prefixes(self, net, numRoutes):
85 main.log.info("I am in generate_prefixes method!")
86
87 # each IP prefix will be composed by "net" + "." + m + "." + n + "." + x
pingping-lin8b306ac2014-11-17 18:13:51 -080088 # the length of each IP prefix is 24
89 routes = []
90 routes_gen = 0
91 m = numRoutes / 256
92 n = numRoutes % 256
93
94 for i in range(0, m):
95 for j in range(0, 256):
96 network = str(net) + "." + str(i) + "." + str(j) + ".0/24"
97 routes.append(network)
98 routes_gen = routes_gen + 1
99
100 for j in range(0, n):
101 network = str(net) + "." + str(m) + "." + str(j) + ".0/24"
102 routes.append(network)
103 routes_gen = routes_gen + 1
104
105 if routes_gen == numRoutes:
106 main.log.info("Successfully generated " + str(numRoutes)
pingping-lin6f6332e2014-11-19 19:13:58 -0800107 + " prefixes!")
pingping-lin8b306ac2014-11-17 18:13:51 -0800108 return routes
109 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800110
111 # This method generates a multiple to single point intent(MultiPointToSinglePointIntent) for a given route
112 def generate_expected_singleRouteIntent(self, prefix, nextHop, nextHopMac, sdnip_data):
113
114 ingress = []
115 egress = ""
116 for peer in sdnip_data['bgpPeers']:
117 if peer['ipAddress'] == nextHop:
118 egress = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
119 else:
pingping-linc6b86fa2014-12-01 16:18:10 -0800120 ingress.append("of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort']))
pingping-lin6f6332e2014-11-19 19:13:58 -0800121
pingping-linc6b86fa2014-12-01 16:18:10 -0800122 selector = "ETH_TYPE{ethType=800},IPV4_DST{ip=" + prefix + "}"
pingping-lin6f6332e2014-11-19 19:13:58 -0800123 treatment = "[ETH_DST{mac=" + str(nextHopMac) + "}]"
124
125 intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + treatment
126 return intent
127
128 def generate_expected_onePeerRouteIntents(self, prefixes, nextHop, nextHopMac, sdnip_json_file_path):
129 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800130 sdnip_json_file = open(sdnip_json_file_path).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800131
132 sdnip_data = json.loads(sdnip_json_file)
133
134 for prefix in prefixes:
135 intents.append(self.generate_expected_singleRouteIntent(prefix, nextHop, nextHopMac, sdnip_data))
136 return sorted(intents)
137
138 # TODO
139 # This method generates all expected route intents for all BGP peers
140 def generate_expected_routeIntents(self):
141 intents = []
142 return intents
143
144 # This method extracts all actual routes from ONOS CLI
145 def extract_actual_routes(self, get_routes_result):
146 routes_json_obj = json.loads(get_routes_result)
147
148 allRoutes_actual = []
149 for route in routes_json_obj:
150 if route['prefix'] == '172.16.10.0/24':
151 continue
152 allRoutes_actual.append(route['prefix'] + "/" + route['nextHop'])
153
154 return sorted(allRoutes_actual)
155
156 # This method extracts all actual route intents from ONOS CLI
157 def extract_actual_routeIntents(self, get_intents_result):
158 intents = []
159 # TODO: delete the line below when change to Mininet demo script
pingping-lin36fbe802014-11-25 16:01:14 -0800160 # get_intents_result=open("../tests/SdnIpTest/intents.json").read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800161 intents_json_obj = json.loads(get_intents_result)
162
163 for intent in intents_json_obj:
164 if intent['appId'] != "org.onlab.onos.sdnip" :
165 continue
pingping-linc6b86fa2014-12-01 16:18:10 -0800166 if intent['type'] == "MultiPointToSinglePointIntent" and intent['state'] == 'INSTALLED':
167 egress = str(intent['egress']['device']) + ":" + str(intent['egress']['port'])
pingping-lin6f6332e2014-11-19 19:13:58 -0800168 ingress = []
169 for attachmentPoint in intent['ingress']:
170 ingress.append(str(attachmentPoint['device']) + ":" + str(attachmentPoint['port']))
pingping-linc6b86fa2014-12-01 16:18:10 -0800171
172 selector = intent['selector'].replace("[" , "").replace("]" , "").replace(" ", "")
173 if str(selector).startswith("IPV4"):
174 str1, str2 = str(selector).split(",")
175 selector = str2 + "," + str1
176
177 intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + intent['treatment']
pingping-lin6f6332e2014-11-19 19:13:58 -0800178 intents.append(intent)
179 return sorted(intents)
180
181 # This method extracts all actual BGP intents from ONOS CLI
182 def extract_actual_bgpIntents(self, get_intents_result):
183 intents = []
184 # TODO: delete the line below when change to Mininet demo script
pingping-lin36fbe802014-11-25 16:01:14 -0800185 # get_intents_result=open("../tests/SdnIpTest/intents.json").read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800186 intents_json_obj = json.loads(get_intents_result)
187
188 for intent in intents_json_obj:
189 if intent['appId'] != "org.onlab.onos.sdnip":
190 continue
191 if intent['type'] == "PointToPointIntent" and "protocol=6" in str(intent['selector']):
192 ingress = str(intent['ingress']['device']) + ":" + str(intent['ingress']['port'])
193 egress = str(intent['egress']['device']) + ":" + str(intent['egress']['port'])
194 selector = str(intent['selector']).replace(" ", "").replace("[", "").replace("]", "").split(",")
195 intent = ingress + "/" + egress + "/" + str(sorted(selector))
196 intents.append(intent)
197
198 return sorted(intents)
199
200 # This method generates a single point to single point intent(PointToPointIntent) for BGP path
201 def generate_expected_bgpIntents(self, sdnip_json_file_path):
202 from operator import eq
203
pingping-linc6b86fa2014-12-01 16:18:10 -0800204 sdnip_json_file = open(sdnip_json_file_path).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800205 sdnip_data = json.loads(sdnip_json_file)
206
207 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800208 bgpPeerAttachmentPoint = ""
pingping-lin6f6332e2014-11-19 19:13:58 -0800209 bgpSpeakerAttachmentPoint = "of:" + str(sdnip_data['bgpSpeakers'][0]['attachmentDpid']).replace(":", "") + ":" + str(sdnip_data['bgpSpeakers'][0]['attachmentPort'])
210 for peer in sdnip_data['bgpPeers']:
211 bgpPeerAttachmentPoint = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
212 # find out the BGP speaker IP address for this BGP peer
pingping-linc6b86fa2014-12-01 16:18:10 -0800213 bgpSpeakerIpAddress = ""
pingping-lin6f6332e2014-11-19 19:13:58 -0800214 for interfaceAddress in sdnip_data['bgpSpeakers'][0]['interfaceAddresses']:
pingping-linc6b86fa2014-12-01 16:18:10 -0800215 # if eq(interfaceAddress['interfaceDpid'],sdnip_data['bgpSpeakers'][0]['attachmentDpid']) and eq(interfaceAddress['interfacePort'], sdnip_data['bgpSpeakers'][0]['attachmentPort']):
216 if eq(interfaceAddress['interfaceDpid'], peer['attachmentDpid']) and eq(interfaceAddress['interfacePort'], peer['attachmentPort']):
217 bgpSpeakerIpAddress = interfaceAddress['ipAddress']
pingping-lin6f6332e2014-11-19 19:13:58 -0800218 break
219 else:
220 continue
221
222 # from bgpSpeakerAttachmentPoint to bgpPeerAttachmentPoint direction
pingping-linc6b86fa2014-12-01 16:18:10 -0800223 selector_str = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," + "IPV4_DST{ip=" + peer['ipAddress'] + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_DST{tcpPort=179}"
pingping-lin6f6332e2014-11-19 19:13:58 -0800224 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
225 intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
226 intents.append(intent)
227
pingping-linc6b86fa2014-12-01 16:18:10 -0800228 selector_str = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," + "IPV4_DST{ip=" + peer['ipAddress'] + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_SRC{tcpPort=179}"
pingping-lin6f6332e2014-11-19 19:13:58 -0800229 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
230 intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
231 intents.append(intent)
232
233 # from bgpPeerAttachmentPoint to bgpSpeakerAttachmentPoint direction
pingping-linc6b86fa2014-12-01 16:18:10 -0800234 selector_str = "IPV4_SRC{ip=" + peer['ipAddress'] + "/32}," + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_DST{tcpPort=179}"
pingping-lin6f6332e2014-11-19 19:13:58 -0800235 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
236 intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + str(sorted(selector))
237 intents.append(intent)
238
239 selector_str = "IPV4_SRC{ip=" + peer['ipAddress'] + "/32}," + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_SRC{tcpPort=179}"
240 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
241 intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + str(sorted(selector))
242 intents.append(intent)
243
244 return sorted(intents)
pingping-linc6b86fa2014-12-01 16:18:10 -0800245
pingping-lin8b306ac2014-11-17 18:13:51 -0800246 def add_routes(self, routes, routeRate):
247 main.log.info("I am in add_routes method!")
pingping-linc6b86fa2014-12-01 16:18:10 -0800248
pingping-lin8b306ac2014-11-17 18:13:51 -0800249 routes_added = 0
250 try:
251 self.handle.sendline("")
pingping-linc6b86fa2014-12-01 16:18:10 -0800252 # self.handle.expect("config-router")
pingping-lin8b306ac2014-11-17 18:13:51 -0800253 self.handle.expect("config-router", timeout=5)
254 except:
255 main.log.warn("Probably not in config-router mode!")
256 self.disconnect()
257 main.log.info("Start to add routes")
258
259 for i in range(0, len(routes)):
260 routeCmd = "network " + routes[i]
261 try:
262 self.handle.sendline(routeCmd)
263 self.handle.expect("bgpd", timeout=5)
264 except:
265 main.log.warn("Failed to add route")
266 self.disconnect()
267 waitTimer = 1.00 / routeRate
268 time.sleep(waitTimer)
269 if routes_added == len(routes):
270 main.log.info("Finished adding routes")
271 return main.TRUE
272 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800273
274 def delete_routes(self, routes, routeRate):
275 main.log.info("I am in delete_routes method!")
276
277 routes_added = 0
278 try:
279 self.handle.sendline("")
280 # self.handle.expect("config-router")
281 self.handle.expect("config-router", timeout=5)
282 except:
283 main.log.warn("Probably not in config-router mode!")
284 self.disconnect()
285 main.log.info("Start to delete routes")
286
287 for i in range(0, len(routes)):
288 routeCmd = "no network " + routes[i]
289 try:
290 self.handle.sendline(routeCmd)
291 self.handle.expect("bgpd", timeout=5)
292 except:
293 main.log.warn("Failed to add route")
294 self.disconnect()
295 waitTimer = 1.00 / routeRate
296 time.sleep(waitTimer)
297 if routes_added == len(routes):
298 main.log.info("Finished deleting routes")
299 return main.TRUE
300 return main.FALSE
301
302 def ping_test(self, ip_address, ping_test_file, ping_test_result_file):
pingping-lindd3b0e42014-12-02 11:46:54 -0800303 main.log.info("Start the ping test on host:" + str(ip_address))
pingping-linc6b86fa2014-12-01 16:18:10 -0800304
305 self.name = self.options['name']
306 self.handle = super(QuaggaCliDriver, self).connect(
307 user_name=self.user_name, ip_address=ip_address,
308 port=self.port, pwd=self.pwd)
309 main.log.info("connect parameters:" + str(self.user_name) + ";"
310 + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
311
312 if self.handle:
313 self.handle.expect("")
314 self.handle.expect("\$")
315 main.log.info("I in host " + str(ip_address))
pingping-lin01355a62014-12-02 20:58:14 -0800316 main.log.info(ping_test_file + " > " + ping_test_result_file + " &")
317 self.handle.sendline(ping_test_file + " > " + ping_test_result_file + " &")
pingping-linc6b86fa2014-12-01 16:18:10 -0800318 self.handle.expect("\$", timeout=60)
319 handle = self.handle.before
320
321 return handle
322 else:
323 main.log.info("NO HANDLE")
324 return main.FALSE
325
326
pingping-lin6f6332e2014-11-19 19:13:58 -0800327 # Please use the generate_routes plus add_routes instead of this one
timlindbergef8d55d2013-09-27 12:50:13 -0700328 def add_route(self, net, numRoutes, routeRate):
329 try:
330 self.handle.sendline("")
331 self.handle.expect("config-router")
332 except:
333 main.log.warn("Probably not in config-router mode!")
334 self.disconnect()
pingping-lin36fbe802014-11-25 16:01:14 -0800335 main.log.info("Adding Routes")
pingping-linc6b86fa2014-12-01 16:18:10 -0800336 j = 0
337 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700338 while numRoutes > 255:
339 numRoutes = numRoutes - 255
340 j = j + 1
341 k = numRoutes % 254
342 routes_added = 0
343 if numRoutes > 255:
344 numRoutes = 255
pingping-linc6b86fa2014-12-01 16:18:10 -0800345 for m in range(1, j + 1):
346 for n in range(1, numRoutes + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700347 network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
348 routeCmd = "network " + network
349 try:
350 self.handle.sendline(routeCmd)
351 self.handle.expect("bgpd")
352 except:
353 main.log.warn("failed to add route")
pingping-linc6b86fa2014-12-01 16:18:10 -0800354 self.disconnect()
355 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700356 time.sleep(waitTimer)
357 routes_added = routes_added + 1
pingping-linc6b86fa2014-12-01 16:18:10 -0800358 for d in range(j + 1, j + 2):
359 for e in range(1, k + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700360 network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
361 routeCmd = "network " + network
362 try:
363 self.handle.sendline(routeCmd)
364 self.handle.expect("bgpd")
365 except:
366 main.log.warn("failed to add route")
367 self.disconnect
pingping-linc6b86fa2014-12-01 16:18:10 -0800368 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700369 time.sleep(waitTimer)
370 routes_added = routes_added + 1
371 if routes_added == numRoutes:
372 return main.TRUE
373 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800374
timlindbergef8d55d2013-09-27 12:50:13 -0700375 def del_route(self, net, numRoutes, routeRate):
376 try:
377 self.handle.sendline("")
378 self.handle.expect("config-router")
379 except:
380 main.log.warn("Probably not in config-router mode!")
381 self.disconnect()
pingping-lin36fbe802014-11-25 16:01:14 -0800382 main.log.info("Deleting Routes")
pingping-linc6b86fa2014-12-01 16:18:10 -0800383 j = 0
384 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700385 while numRoutes > 255:
386 numRoutes = numRoutes - 255
387 j = j + 1
388 k = numRoutes % 254
389 routes_deleted = 0
390 if numRoutes > 255:
391 numRoutes = 255
pingping-linc6b86fa2014-12-01 16:18:10 -0800392 for m in range(1, j + 1):
393 for n in range(1, numRoutes + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700394 network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
395 routeCmd = "no network " + network
396 try:
397 self.handle.sendline(routeCmd)
398 self.handle.expect("bgpd")
399 except:
400 main.log.warn("Failed to delete route")
401 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800402 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700403 time.sleep(waitTimer)
404 routes_deleted = routes_deleted + 1
pingping-linc6b86fa2014-12-01 16:18:10 -0800405 for d in range(j + 1, j + 2):
406 for e in range(1, k + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700407 network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
408 routeCmd = "no network " + network
409 try:
410 self.handle.sendline(routeCmd)
411 self.handle.expect("bgpd")
412 except:
413 main.log.warn("Failed to delete route")
414 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800415 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700416 time.sleep(waitTimer)
417 routes_deleted = routes_deleted + 1
418 if routes_deleted == numRoutes:
419 return main.TRUE
420 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800421
timlindbergef8d55d2013-09-27 12:50:13 -0700422 def check_routes(self, brand, ip, user, pw):
423 def pronto(ip, user, passwd):
424 print "Connecting to Pronto switch"
425 child = pexpect.spawn("telnet " + ip)
pingping-linc6b86fa2014-12-01 16:18:10 -0800426 i = child.expect(["login:", "CLI#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700427 if i == 0:
428 print "Username and password required. Passing login info."
429 child.sendline(user)
430 child.expect("Password:")
431 child.sendline(passwd)
432 child.expect("CLI#")
433 print "Logged in, getting flowtable."
434 child.sendline("flowtable brief")
435 for t in range (9):
436 t2 = 9 - t
437 print "\r" + str(t2)
438 sys.stdout.write("\033[F")
439 time.sleep(1)
440 print "Scanning flowtable"
441 child.expect("Flow table show")
442 count = 0
443 while 1:
pingping-linc6b86fa2014-12-01 16:18:10 -0800444 i = child.expect(['17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}', 'CLI#', pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700445 if i == 0:
446 count = count + 1
447 elif i == 1:
448 print "Pronto flows: " + str(count) + "\nDone\n"
449 break
450 else:
451 break
pingping-linc6b86fa2014-12-01 16:18:10 -0800452 def cisco(ip, user, passwd):
timlindbergef8d55d2013-09-27 12:50:13 -0700453 print "Establishing Cisco switch connection"
pingping-linc6b86fa2014-12-01 16:18:10 -0800454 child = pexpect.spawn("ssh " + user + "@" + ip)
455 i = child.expect(["Password:", "CLI#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700456 if i == 0:
457 print "Password required. Passing now."
458 child.sendline(passwd)
459 child.expect("#")
460 print "Logged in. Retrieving flow table then counting flows."
461 child.sendline("show openflow switch all flows all")
462 child.expect("Logical Openflow Switch")
463 print "Flow table retrieved. Counting flows"
464 count = 0
465 while 1:
pingping-linc6b86fa2014-12-01 16:18:10 -0800466 i = child.expect(["nw_src=17", "#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700467 if i == 0:
468 count = count + 1
469 elif i == 1:
470 print "Cisco flows: " + str(count) + "\nDone\n"
471 break
472 else:
473 break
474 if brand == "pronto" or brand == "PRONTO":
pingping-linc6b86fa2014-12-01 16:18:10 -0800475 pronto(ip, user, passwd)
476 # elif brand == "cisco" or brand == "CISCO":
477 # cisco(ip,user,passwd)
timlindbergef8d55d2013-09-27 12:50:13 -0700478 def disconnect(self):
479 '''
480 Called when Test is complete to disconnect the Quagga handle.
481 '''
482 response = ''
483 try:
484 self.handle.close()
485 except:
486 main.log.error("Connection failed to the host")
487 response = main.FALSE
488 return response