blob: acb08319b3395deae42af46565326e52320157e7 [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))
316 self.handle.sendline(ping_test_file + ">" + ping_test_result_file + "&")
317 self.handle.expect("\$", timeout=60)
318 handle = self.handle.before
319
320 return handle
321 else:
322 main.log.info("NO HANDLE")
323 return main.FALSE
324
325
pingping-lin6f6332e2014-11-19 19:13:58 -0800326 # Please use the generate_routes plus add_routes instead of this one
timlindbergef8d55d2013-09-27 12:50:13 -0700327 def add_route(self, net, numRoutes, routeRate):
328 try:
329 self.handle.sendline("")
330 self.handle.expect("config-router")
331 except:
332 main.log.warn("Probably not in config-router mode!")
333 self.disconnect()
pingping-lin36fbe802014-11-25 16:01:14 -0800334 main.log.info("Adding Routes")
pingping-linc6b86fa2014-12-01 16:18:10 -0800335 j = 0
336 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700337 while numRoutes > 255:
338 numRoutes = numRoutes - 255
339 j = j + 1
340 k = numRoutes % 254
341 routes_added = 0
342 if numRoutes > 255:
343 numRoutes = 255
pingping-linc6b86fa2014-12-01 16:18:10 -0800344 for m in range(1, j + 1):
345 for n in range(1, numRoutes + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700346 network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
347 routeCmd = "network " + network
348 try:
349 self.handle.sendline(routeCmd)
350 self.handle.expect("bgpd")
351 except:
352 main.log.warn("failed to add route")
pingping-linc6b86fa2014-12-01 16:18:10 -0800353 self.disconnect()
354 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700355 time.sleep(waitTimer)
356 routes_added = routes_added + 1
pingping-linc6b86fa2014-12-01 16:18:10 -0800357 for d in range(j + 1, j + 2):
358 for e in range(1, k + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700359 network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
360 routeCmd = "network " + network
361 try:
362 self.handle.sendline(routeCmd)
363 self.handle.expect("bgpd")
364 except:
365 main.log.warn("failed to add route")
366 self.disconnect
pingping-linc6b86fa2014-12-01 16:18:10 -0800367 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700368 time.sleep(waitTimer)
369 routes_added = routes_added + 1
370 if routes_added == numRoutes:
371 return main.TRUE
372 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800373
timlindbergef8d55d2013-09-27 12:50:13 -0700374 def del_route(self, net, numRoutes, routeRate):
375 try:
376 self.handle.sendline("")
377 self.handle.expect("config-router")
378 except:
379 main.log.warn("Probably not in config-router mode!")
380 self.disconnect()
pingping-lin36fbe802014-11-25 16:01:14 -0800381 main.log.info("Deleting Routes")
pingping-linc6b86fa2014-12-01 16:18:10 -0800382 j = 0
383 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700384 while numRoutes > 255:
385 numRoutes = numRoutes - 255
386 j = j + 1
387 k = numRoutes % 254
388 routes_deleted = 0
389 if numRoutes > 255:
390 numRoutes = 255
pingping-linc6b86fa2014-12-01 16:18:10 -0800391 for m in range(1, j + 1):
392 for n in range(1, numRoutes + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700393 network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
394 routeCmd = "no network " + network
395 try:
396 self.handle.sendline(routeCmd)
397 self.handle.expect("bgpd")
398 except:
399 main.log.warn("Failed to delete route")
400 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800401 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700402 time.sleep(waitTimer)
403 routes_deleted = routes_deleted + 1
pingping-linc6b86fa2014-12-01 16:18:10 -0800404 for d in range(j + 1, j + 2):
405 for e in range(1, k + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700406 network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
407 routeCmd = "no network " + network
408 try:
409 self.handle.sendline(routeCmd)
410 self.handle.expect("bgpd")
411 except:
412 main.log.warn("Failed to delete route")
413 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800414 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700415 time.sleep(waitTimer)
416 routes_deleted = routes_deleted + 1
417 if routes_deleted == numRoutes:
418 return main.TRUE
419 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800420
timlindbergef8d55d2013-09-27 12:50:13 -0700421 def check_routes(self, brand, ip, user, pw):
422 def pronto(ip, user, passwd):
423 print "Connecting to Pronto switch"
424 child = pexpect.spawn("telnet " + ip)
pingping-linc6b86fa2014-12-01 16:18:10 -0800425 i = child.expect(["login:", "CLI#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700426 if i == 0:
427 print "Username and password required. Passing login info."
428 child.sendline(user)
429 child.expect("Password:")
430 child.sendline(passwd)
431 child.expect("CLI#")
432 print "Logged in, getting flowtable."
433 child.sendline("flowtable brief")
434 for t in range (9):
435 t2 = 9 - t
436 print "\r" + str(t2)
437 sys.stdout.write("\033[F")
438 time.sleep(1)
439 print "Scanning flowtable"
440 child.expect("Flow table show")
441 count = 0
442 while 1:
pingping-linc6b86fa2014-12-01 16:18:10 -0800443 i = child.expect(['17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}', 'CLI#', pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700444 if i == 0:
445 count = count + 1
446 elif i == 1:
447 print "Pronto flows: " + str(count) + "\nDone\n"
448 break
449 else:
450 break
pingping-linc6b86fa2014-12-01 16:18:10 -0800451 def cisco(ip, user, passwd):
timlindbergef8d55d2013-09-27 12:50:13 -0700452 print "Establishing Cisco switch connection"
pingping-linc6b86fa2014-12-01 16:18:10 -0800453 child = pexpect.spawn("ssh " + user + "@" + ip)
454 i = child.expect(["Password:", "CLI#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700455 if i == 0:
456 print "Password required. Passing now."
457 child.sendline(passwd)
458 child.expect("#")
459 print "Logged in. Retrieving flow table then counting flows."
460 child.sendline("show openflow switch all flows all")
461 child.expect("Logical Openflow Switch")
462 print "Flow table retrieved. Counting flows"
463 count = 0
464 while 1:
pingping-linc6b86fa2014-12-01 16:18:10 -0800465 i = child.expect(["nw_src=17", "#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700466 if i == 0:
467 count = count + 1
468 elif i == 1:
469 print "Cisco flows: " + str(count) + "\nDone\n"
470 break
471 else:
472 break
473 if brand == "pronto" or brand == "PRONTO":
pingping-linc6b86fa2014-12-01 16:18:10 -0800474 pronto(ip, user, passwd)
475 # elif brand == "cisco" or brand == "CISCO":
476 # cisco(ip,user,passwd)
timlindbergef8d55d2013-09-27 12:50:13 -0700477 def disconnect(self):
478 '''
479 Called when Test is complete to disconnect the Quagga handle.
480 '''
481 response = ''
482 try:
483 self.handle.close()
484 except:
485 main.log.error("Connection failed to the host")
486 response = main.FALSE
487 return response