blob: 27ce71f093206a1b3479db05714fe9fbcc9ecfc4 [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)
pingping-linbc230942014-12-03 18:36:27 -080025 main.log.info("quagga handle" + str(self.handle) )
26 main.log.info("where is this timeout from?")
pingping-lin8b306ac2014-11-17 18:13:51 -080027 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 -070028
pingping-linc6b86fa2014-12-01 16:18:10 -080029 if self.handle:
pingping-linbc230942014-12-03 18:36:27 -080030 #self.handle.expect("",timeout=10)
31 #self.handle.expect("\$",timeout=10)
32 #main.log.info(self.handle.before)
33 #main.log.info(self.handle.after)
timlindbergef8d55d2013-09-27 12:50:13 -070034 self.handle.sendline("telnet localhost 2605")
pingping-linbc230942014-12-03 18:36:27 -080035 #self.handle.expect("Password:", timeout=5)
36 self.handle.expect("Password:")
37 main.log.info("TEST1")
timlindbergef8d55d2013-09-27 12:50:13 -070038 self.handle.sendline("hello")
pingping-linbc230942014-12-03 18:36:27 -080039 #self.handle.expect("bgpd", timeout=5)
40 self.handle.expect("bgpd")
41 main.log.info("TEST2")
timlindbergef8d55d2013-09-27 12:50:13 -070042 self.handle.sendline("enable")
pingping-linbc230942014-12-03 18:36:27 -080043 #self.handle.expect("bgpd#", timeout=5)
44 self.handle.expect("bgpd#")
45 main.log.info("TEST3")
timlindbergef8d55d2013-09-27 12:50:13 -070046 return self.handle
47 else :
48 main.log.info("NO HANDLE")
49 return main.FALSE
50
pingping-lin8b306ac2014-11-17 18:13:51 -080051 def loginQuagga(self, ip_address):
pingping-lin8b306ac2014-11-17 18:13:51 -080052 self.name = self.options['name']
53 self.handle = super(QuaggaCliDriver, self).connect(
54 user_name=self.user_name, ip_address=ip_address,
55 port=self.port, pwd=self.pwd)
56 main.log.info("connect parameters:" + str(self.user_name) + ";"
57 + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
58
59 if self.handle:
pingping-linbc230942014-12-03 18:36:27 -080060 #self.handle.expect("")
61 #self.handle.expect("\$")
pingping-lin8b306ac2014-11-17 18:13:51 -080062 self.handle.sendline("telnet localhost 2605")
63 self.handle.expect("Password:", timeout=5)
64 self.handle.sendline("hello")
65 self.handle.expect("bgpd", timeout=5)
66 self.handle.sendline("enable")
67 self.handle.expect("bgpd#", timeout=5)
pingping-lin36fbe802014-11-25 16:01:14 -080068 main.log.info("I in quagga on host " + str(ip_address))
pingping-lin8b306ac2014-11-17 18:13:51 -080069
70 return self.handle
71 else:
72 main.log.info("NO HANDLE")
73 return main.FALSE
74
timlindbergef8d55d2013-09-27 12:50:13 -070075 def enter_config(self, asn):
pingping-lin8b306ac2014-11-17 18:13:51 -080076 main.log.info("I am in enter_config method!")
timlindbergef8d55d2013-09-27 12:50:13 -070077 try:
78 self.handle.sendline("")
79 self.handle.expect("bgpd#")
80 except:
81 main.log.warn("Probably not currently in enable mode!")
82 self.disconnect()
83 return main.FALSE
84 self.handle.sendline("configure terminal")
pingping-linc6b86fa2014-12-01 16:18:10 -080085 self.handle.expect("config", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070086 routerAS = "router bgp " + str(asn)
87 try:
88 self.handle.sendline(routerAS)
pingping-linc6b86fa2014-12-01 16:18:10 -080089 self.handle.expect("config-router", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070090 return main.TRUE
91 except:
92 return main.FALSE
pingping-lin8b306ac2014-11-17 18:13:51 -080093
pingping-lin6f6332e2014-11-19 19:13:58 -080094 def generate_prefixes(self, net, numRoutes):
95 main.log.info("I am in generate_prefixes method!")
96
97 # each IP prefix will be composed by "net" + "." + m + "." + n + "." + x
pingping-lin8b306ac2014-11-17 18:13:51 -080098 # the length of each IP prefix is 24
99 routes = []
100 routes_gen = 0
101 m = numRoutes / 256
102 n = numRoutes % 256
103
104 for i in range(0, m):
105 for j in range(0, 256):
106 network = str(net) + "." + str(i) + "." + str(j) + ".0/24"
107 routes.append(network)
108 routes_gen = routes_gen + 1
109
110 for j in range(0, n):
111 network = str(net) + "." + str(m) + "." + str(j) + ".0/24"
112 routes.append(network)
113 routes_gen = routes_gen + 1
114
115 if routes_gen == numRoutes:
116 main.log.info("Successfully generated " + str(numRoutes)
pingping-lin6f6332e2014-11-19 19:13:58 -0800117 + " prefixes!")
pingping-lin8b306ac2014-11-17 18:13:51 -0800118 return routes
119 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800120
121 # This method generates a multiple to single point intent(MultiPointToSinglePointIntent) for a given route
122 def generate_expected_singleRouteIntent(self, prefix, nextHop, nextHopMac, sdnip_data):
123
124 ingress = []
125 egress = ""
126 for peer in sdnip_data['bgpPeers']:
127 if peer['ipAddress'] == nextHop:
128 egress = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
129 else:
pingping-linc6b86fa2014-12-01 16:18:10 -0800130 ingress.append("of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort']))
pingping-lin6f6332e2014-11-19 19:13:58 -0800131
pingping-linc6b86fa2014-12-01 16:18:10 -0800132 selector = "ETH_TYPE{ethType=800},IPV4_DST{ip=" + prefix + "}"
pingping-lin6f6332e2014-11-19 19:13:58 -0800133 treatment = "[ETH_DST{mac=" + str(nextHopMac) + "}]"
134
135 intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + treatment
136 return intent
137
138 def generate_expected_onePeerRouteIntents(self, prefixes, nextHop, nextHopMac, sdnip_json_file_path):
139 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800140 sdnip_json_file = open(sdnip_json_file_path).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800141
142 sdnip_data = json.loads(sdnip_json_file)
143
144 for prefix in prefixes:
145 intents.append(self.generate_expected_singleRouteIntent(prefix, nextHop, nextHopMac, sdnip_data))
146 return sorted(intents)
147
148 # TODO
149 # This method generates all expected route intents for all BGP peers
150 def generate_expected_routeIntents(self):
151 intents = []
152 return intents
153
154 # This method extracts all actual routes from ONOS CLI
155 def extract_actual_routes(self, get_routes_result):
156 routes_json_obj = json.loads(get_routes_result)
157
158 allRoutes_actual = []
159 for route in routes_json_obj:
160 if route['prefix'] == '172.16.10.0/24':
161 continue
162 allRoutes_actual.append(route['prefix'] + "/" + route['nextHop'])
163
164 return sorted(allRoutes_actual)
165
166 # This method extracts all actual route intents from ONOS CLI
167 def extract_actual_routeIntents(self, get_intents_result):
168 intents = []
169 # TODO: delete the line below when change to Mininet demo script
pingping-lin36fbe802014-11-25 16:01:14 -0800170 # get_intents_result=open("../tests/SdnIpTest/intents.json").read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800171 intents_json_obj = json.loads(get_intents_result)
172
173 for intent in intents_json_obj:
174 if intent['appId'] != "org.onlab.onos.sdnip" :
175 continue
pingping-linc6b86fa2014-12-01 16:18:10 -0800176 if intent['type'] == "MultiPointToSinglePointIntent" and intent['state'] == 'INSTALLED':
177 egress = str(intent['egress']['device']) + ":" + str(intent['egress']['port'])
pingping-lin6f6332e2014-11-19 19:13:58 -0800178 ingress = []
179 for attachmentPoint in intent['ingress']:
180 ingress.append(str(attachmentPoint['device']) + ":" + str(attachmentPoint['port']))
pingping-linc6b86fa2014-12-01 16:18:10 -0800181
182 selector = intent['selector'].replace("[" , "").replace("]" , "").replace(" ", "")
183 if str(selector).startswith("IPV4"):
184 str1, str2 = str(selector).split(",")
185 selector = str2 + "," + str1
186
187 intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + intent['treatment']
pingping-lin6f6332e2014-11-19 19:13:58 -0800188 intents.append(intent)
189 return sorted(intents)
190
191 # This method extracts all actual BGP intents from ONOS CLI
192 def extract_actual_bgpIntents(self, get_intents_result):
193 intents = []
194 # TODO: delete the line below when change to Mininet demo script
pingping-lin36fbe802014-11-25 16:01:14 -0800195 # get_intents_result=open("../tests/SdnIpTest/intents.json").read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800196 intents_json_obj = json.loads(get_intents_result)
197
198 for intent in intents_json_obj:
199 if intent['appId'] != "org.onlab.onos.sdnip":
200 continue
201 if intent['type'] == "PointToPointIntent" and "protocol=6" in str(intent['selector']):
202 ingress = str(intent['ingress']['device']) + ":" + str(intent['ingress']['port'])
203 egress = str(intent['egress']['device']) + ":" + str(intent['egress']['port'])
204 selector = str(intent['selector']).replace(" ", "").replace("[", "").replace("]", "").split(",")
205 intent = ingress + "/" + egress + "/" + str(sorted(selector))
206 intents.append(intent)
207
208 return sorted(intents)
209
210 # This method generates a single point to single point intent(PointToPointIntent) for BGP path
211 def generate_expected_bgpIntents(self, sdnip_json_file_path):
212 from operator import eq
213
pingping-linc6b86fa2014-12-01 16:18:10 -0800214 sdnip_json_file = open(sdnip_json_file_path).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800215 sdnip_data = json.loads(sdnip_json_file)
216
217 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800218 bgpPeerAttachmentPoint = ""
pingping-lin6f6332e2014-11-19 19:13:58 -0800219 bgpSpeakerAttachmentPoint = "of:" + str(sdnip_data['bgpSpeakers'][0]['attachmentDpid']).replace(":", "") + ":" + str(sdnip_data['bgpSpeakers'][0]['attachmentPort'])
220 for peer in sdnip_data['bgpPeers']:
221 bgpPeerAttachmentPoint = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
222 # find out the BGP speaker IP address for this BGP peer
pingping-linc6b86fa2014-12-01 16:18:10 -0800223 bgpSpeakerIpAddress = ""
pingping-lin6f6332e2014-11-19 19:13:58 -0800224 for interfaceAddress in sdnip_data['bgpSpeakers'][0]['interfaceAddresses']:
pingping-linc6b86fa2014-12-01 16:18:10 -0800225 # if eq(interfaceAddress['interfaceDpid'],sdnip_data['bgpSpeakers'][0]['attachmentDpid']) and eq(interfaceAddress['interfacePort'], sdnip_data['bgpSpeakers'][0]['attachmentPort']):
226 if eq(interfaceAddress['interfaceDpid'], peer['attachmentDpid']) and eq(interfaceAddress['interfacePort'], peer['attachmentPort']):
227 bgpSpeakerIpAddress = interfaceAddress['ipAddress']
pingping-lin6f6332e2014-11-19 19:13:58 -0800228 break
229 else:
230 continue
231
232 # from bgpSpeakerAttachmentPoint to bgpPeerAttachmentPoint direction
pingping-linc6b86fa2014-12-01 16:18:10 -0800233 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 -0800234 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
235 intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
236 intents.append(intent)
237
pingping-linc6b86fa2014-12-01 16:18:10 -0800238 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 -0800239 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
240 intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
241 intents.append(intent)
242
243 # from bgpPeerAttachmentPoint to bgpSpeakerAttachmentPoint direction
pingping-linc6b86fa2014-12-01 16:18:10 -0800244 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 -0800245 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
246 intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + str(sorted(selector))
247 intents.append(intent)
248
249 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}"
250 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
251 intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + str(sorted(selector))
252 intents.append(intent)
253
254 return sorted(intents)
pingping-linc6b86fa2014-12-01 16:18:10 -0800255
pingping-lin8b306ac2014-11-17 18:13:51 -0800256 def add_routes(self, routes, routeRate):
257 main.log.info("I am in add_routes method!")
pingping-linc6b86fa2014-12-01 16:18:10 -0800258
pingping-lin8b306ac2014-11-17 18:13:51 -0800259 routes_added = 0
260 try:
261 self.handle.sendline("")
pingping-linc6b86fa2014-12-01 16:18:10 -0800262 # self.handle.expect("config-router")
pingping-lin8b306ac2014-11-17 18:13:51 -0800263 self.handle.expect("config-router", timeout=5)
264 except:
265 main.log.warn("Probably not in config-router mode!")
266 self.disconnect()
267 main.log.info("Start to add routes")
268
269 for i in range(0, len(routes)):
270 routeCmd = "network " + routes[i]
271 try:
272 self.handle.sendline(routeCmd)
273 self.handle.expect("bgpd", timeout=5)
274 except:
275 main.log.warn("Failed to add route")
276 self.disconnect()
277 waitTimer = 1.00 / routeRate
278 time.sleep(waitTimer)
279 if routes_added == len(routes):
280 main.log.info("Finished adding routes")
281 return main.TRUE
282 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800283
284 def delete_routes(self, routes, routeRate):
285 main.log.info("I am in delete_routes method!")
286
287 routes_added = 0
288 try:
289 self.handle.sendline("")
290 # self.handle.expect("config-router")
291 self.handle.expect("config-router", timeout=5)
292 except:
293 main.log.warn("Probably not in config-router mode!")
294 self.disconnect()
295 main.log.info("Start to delete routes")
296
297 for i in range(0, len(routes)):
298 routeCmd = "no network " + routes[i]
299 try:
300 self.handle.sendline(routeCmd)
301 self.handle.expect("bgpd", timeout=5)
302 except:
303 main.log.warn("Failed to add route")
304 self.disconnect()
305 waitTimer = 1.00 / routeRate
306 time.sleep(waitTimer)
307 if routes_added == len(routes):
308 main.log.info("Finished deleting routes")
309 return main.TRUE
310 return main.FALSE
311
312 def ping_test(self, ip_address, ping_test_file, ping_test_result_file):
pingping-lindd3b0e42014-12-02 11:46:54 -0800313 main.log.info("Start the ping test on host:" + str(ip_address))
pingping-linc6b86fa2014-12-01 16:18:10 -0800314
315 self.name = self.options['name']
316 self.handle = super(QuaggaCliDriver, self).connect(
317 user_name=self.user_name, ip_address=ip_address,
318 port=self.port, pwd=self.pwd)
319 main.log.info("connect parameters:" + str(self.user_name) + ";"
320 + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
321
322 if self.handle:
323 self.handle.expect("")
324 self.handle.expect("\$")
325 main.log.info("I in host " + str(ip_address))
pingping-lin01355a62014-12-02 20:58:14 -0800326 main.log.info(ping_test_file + " > " + ping_test_result_file + " &")
327 self.handle.sendline(ping_test_file + " > " + ping_test_result_file + " &")
pingping-linc6b86fa2014-12-01 16:18:10 -0800328 self.handle.expect("\$", timeout=60)
329 handle = self.handle.before
330
331 return handle
332 else:
333 main.log.info("NO HANDLE")
334 return main.FALSE
335
336
pingping-lin6f6332e2014-11-19 19:13:58 -0800337 # Please use the generate_routes plus add_routes instead of this one
timlindbergef8d55d2013-09-27 12:50:13 -0700338 def add_route(self, net, numRoutes, routeRate):
339 try:
340 self.handle.sendline("")
341 self.handle.expect("config-router")
342 except:
343 main.log.warn("Probably not in config-router mode!")
344 self.disconnect()
pingping-lin36fbe802014-11-25 16:01:14 -0800345 main.log.info("Adding Routes")
pingping-linc6b86fa2014-12-01 16:18:10 -0800346 j = 0
347 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700348 while numRoutes > 255:
349 numRoutes = numRoutes - 255
350 j = j + 1
351 k = numRoutes % 254
352 routes_added = 0
353 if numRoutes > 255:
354 numRoutes = 255
pingping-linc6b86fa2014-12-01 16:18:10 -0800355 for m in range(1, j + 1):
356 for n in range(1, numRoutes + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700357 network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
358 routeCmd = "network " + network
359 try:
360 self.handle.sendline(routeCmd)
361 self.handle.expect("bgpd")
362 except:
363 main.log.warn("failed to add route")
pingping-linc6b86fa2014-12-01 16:18:10 -0800364 self.disconnect()
365 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700366 time.sleep(waitTimer)
367 routes_added = routes_added + 1
pingping-linc6b86fa2014-12-01 16:18:10 -0800368 for d in range(j + 1, j + 2):
369 for e in range(1, k + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700370 network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
371 routeCmd = "network " + network
372 try:
373 self.handle.sendline(routeCmd)
374 self.handle.expect("bgpd")
375 except:
376 main.log.warn("failed to add route")
377 self.disconnect
pingping-linc6b86fa2014-12-01 16:18:10 -0800378 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700379 time.sleep(waitTimer)
380 routes_added = routes_added + 1
381 if routes_added == numRoutes:
382 return main.TRUE
383 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800384
timlindbergef8d55d2013-09-27 12:50:13 -0700385 def del_route(self, net, numRoutes, routeRate):
386 try:
387 self.handle.sendline("")
388 self.handle.expect("config-router")
389 except:
390 main.log.warn("Probably not in config-router mode!")
391 self.disconnect()
pingping-lin36fbe802014-11-25 16:01:14 -0800392 main.log.info("Deleting Routes")
pingping-linc6b86fa2014-12-01 16:18:10 -0800393 j = 0
394 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700395 while numRoutes > 255:
396 numRoutes = numRoutes - 255
397 j = j + 1
398 k = numRoutes % 254
399 routes_deleted = 0
400 if numRoutes > 255:
401 numRoutes = 255
pingping-linc6b86fa2014-12-01 16:18:10 -0800402 for m in range(1, j + 1):
403 for n in range(1, numRoutes + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700404 network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
405 routeCmd = "no network " + network
406 try:
407 self.handle.sendline(routeCmd)
408 self.handle.expect("bgpd")
409 except:
410 main.log.warn("Failed to delete route")
411 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800412 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700413 time.sleep(waitTimer)
414 routes_deleted = routes_deleted + 1
pingping-linc6b86fa2014-12-01 16:18:10 -0800415 for d in range(j + 1, j + 2):
416 for e in range(1, k + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700417 network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
418 routeCmd = "no network " + network
419 try:
420 self.handle.sendline(routeCmd)
421 self.handle.expect("bgpd")
422 except:
423 main.log.warn("Failed to delete route")
424 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800425 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700426 time.sleep(waitTimer)
427 routes_deleted = routes_deleted + 1
428 if routes_deleted == numRoutes:
429 return main.TRUE
430 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800431
timlindbergef8d55d2013-09-27 12:50:13 -0700432 def check_routes(self, brand, ip, user, pw):
433 def pronto(ip, user, passwd):
434 print "Connecting to Pronto switch"
435 child = pexpect.spawn("telnet " + ip)
pingping-linc6b86fa2014-12-01 16:18:10 -0800436 i = child.expect(["login:", "CLI#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700437 if i == 0:
438 print "Username and password required. Passing login info."
439 child.sendline(user)
440 child.expect("Password:")
441 child.sendline(passwd)
442 child.expect("CLI#")
443 print "Logged in, getting flowtable."
444 child.sendline("flowtable brief")
445 for t in range (9):
446 t2 = 9 - t
447 print "\r" + str(t2)
448 sys.stdout.write("\033[F")
449 time.sleep(1)
450 print "Scanning flowtable"
451 child.expect("Flow table show")
452 count = 0
453 while 1:
pingping-linc6b86fa2014-12-01 16:18:10 -0800454 i = child.expect(['17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}', 'CLI#', pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700455 if i == 0:
456 count = count + 1
457 elif i == 1:
458 print "Pronto flows: " + str(count) + "\nDone\n"
459 break
460 else:
461 break
pingping-linc6b86fa2014-12-01 16:18:10 -0800462 def cisco(ip, user, passwd):
timlindbergef8d55d2013-09-27 12:50:13 -0700463 print "Establishing Cisco switch connection"
pingping-linc6b86fa2014-12-01 16:18:10 -0800464 child = pexpect.spawn("ssh " + user + "@" + ip)
465 i = child.expect(["Password:", "CLI#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700466 if i == 0:
467 print "Password required. Passing now."
468 child.sendline(passwd)
469 child.expect("#")
470 print "Logged in. Retrieving flow table then counting flows."
471 child.sendline("show openflow switch all flows all")
472 child.expect("Logical Openflow Switch")
473 print "Flow table retrieved. Counting flows"
474 count = 0
475 while 1:
pingping-linc6b86fa2014-12-01 16:18:10 -0800476 i = child.expect(["nw_src=17", "#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700477 if i == 0:
478 count = count + 1
479 elif i == 1:
480 print "Cisco flows: " + str(count) + "\nDone\n"
481 break
482 else:
483 break
484 if brand == "pronto" or brand == "PRONTO":
pingping-linc6b86fa2014-12-01 16:18:10 -0800485 pronto(ip, user, passwd)
486 # elif brand == "cisco" or brand == "CISCO":
487 # cisco(ip,user,passwd)
timlindbergef8d55d2013-09-27 12:50:13 -0700488 def disconnect(self):
489 '''
490 Called when Test is complete to disconnect the Quagga handle.
491 '''
492 response = ''
493 try:
494 self.handle.close()
495 except:
496 main.log.error("Connection failed to the host")
497 response = main.FALSE
498 return response