blob: 8314941bc9c209f9c7ff356cc4bd3f2639aeb26d [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:
pingping-linbc230942014-12-03 18:36:27 -080028 #self.handle.expect("",timeout=10)
29 #self.handle.expect("\$",timeout=10)
timlindbergef8d55d2013-09-27 12:50:13 -070030 self.handle.sendline("telnet localhost 2605")
pingping-linbc230942014-12-03 18:36:27 -080031 #self.handle.expect("Password:", timeout=5)
32 self.handle.expect("Password:")
timlindbergef8d55d2013-09-27 12:50:13 -070033 self.handle.sendline("hello")
pingping-linbc230942014-12-03 18:36:27 -080034 #self.handle.expect("bgpd", timeout=5)
35 self.handle.expect("bgpd")
timlindbergef8d55d2013-09-27 12:50:13 -070036 self.handle.sendline("enable")
pingping-linbc230942014-12-03 18:36:27 -080037 #self.handle.expect("bgpd#", timeout=5)
38 self.handle.expect("bgpd#")
timlindbergef8d55d2013-09-27 12:50:13 -070039 return self.handle
40 else :
41 main.log.info("NO HANDLE")
42 return main.FALSE
43
pingping-lin8b306ac2014-11-17 18:13:51 -080044 def loginQuagga(self, ip_address):
pingping-lin8b306ac2014-11-17 18:13:51 -080045 self.name = self.options['name']
46 self.handle = super(QuaggaCliDriver, self).connect(
47 user_name=self.user_name, ip_address=ip_address,
48 port=self.port, pwd=self.pwd)
49 main.log.info("connect parameters:" + str(self.user_name) + ";"
50 + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
51
52 if self.handle:
pingping-linbc230942014-12-03 18:36:27 -080053 #self.handle.expect("")
54 #self.handle.expect("\$")
pingping-lin8b306ac2014-11-17 18:13:51 -080055 self.handle.sendline("telnet localhost 2605")
pingping-lind3139ac2014-12-04 14:21:26 -080056 #self.handle.expect("Password:", timeout=5)
57 self.handle.expect("Password:")
pingping-lin8b306ac2014-11-17 18:13:51 -080058 self.handle.sendline("hello")
pingping-lind3139ac2014-12-04 14:21:26 -080059 #self.handle.expect("bgpd", timeout=5)
60 self.handle.expect("bgpd")
pingping-lin8b306ac2014-11-17 18:13:51 -080061 self.handle.sendline("enable")
pingping-lind3139ac2014-12-04 14:21:26 -080062 #self.handle.expect("bgpd#", timeout=5)
63 self.handle.expect("bgpd#")
pingping-lin36fbe802014-11-25 16:01:14 -080064 main.log.info("I in quagga on host " + str(ip_address))
pingping-lin8b306ac2014-11-17 18:13:51 -080065
66 return self.handle
67 else:
68 main.log.info("NO HANDLE")
69 return main.FALSE
70
timlindbergef8d55d2013-09-27 12:50:13 -070071 def enter_config(self, asn):
pingping-lin8b306ac2014-11-17 18:13:51 -080072 main.log.info("I am in enter_config method!")
timlindbergef8d55d2013-09-27 12:50:13 -070073 try:
74 self.handle.sendline("")
75 self.handle.expect("bgpd#")
76 except:
77 main.log.warn("Probably not currently in enable mode!")
78 self.disconnect()
79 return main.FALSE
80 self.handle.sendline("configure terminal")
pingping-linc6b86fa2014-12-01 16:18:10 -080081 self.handle.expect("config", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070082 routerAS = "router bgp " + str(asn)
83 try:
84 self.handle.sendline(routerAS)
pingping-linc6b86fa2014-12-01 16:18:10 -080085 self.handle.expect("config-router", timeout=5)
timlindbergef8d55d2013-09-27 12:50:13 -070086 return main.TRUE
87 except:
88 return main.FALSE
pingping-lin8b306ac2014-11-17 18:13:51 -080089
pingping-lin6f6332e2014-11-19 19:13:58 -080090 def generate_prefixes(self, net, numRoutes):
91 main.log.info("I am in generate_prefixes method!")
92
93 # each IP prefix will be composed by "net" + "." + m + "." + n + "." + x
pingping-lin8b306ac2014-11-17 18:13:51 -080094 # the length of each IP prefix is 24
95 routes = []
96 routes_gen = 0
97 m = numRoutes / 256
98 n = numRoutes % 256
99
100 for i in range(0, m):
101 for j in range(0, 256):
102 network = str(net) + "." + str(i) + "." + str(j) + ".0/24"
103 routes.append(network)
104 routes_gen = routes_gen + 1
105
106 for j in range(0, n):
107 network = str(net) + "." + str(m) + "." + str(j) + ".0/24"
108 routes.append(network)
109 routes_gen = routes_gen + 1
110
111 if routes_gen == numRoutes:
112 main.log.info("Successfully generated " + str(numRoutes)
pingping-lin6f6332e2014-11-19 19:13:58 -0800113 + " prefixes!")
pingping-lin8b306ac2014-11-17 18:13:51 -0800114 return routes
115 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800116
117 # This method generates a multiple to single point intent(MultiPointToSinglePointIntent) for a given route
118 def generate_expected_singleRouteIntent(self, prefix, nextHop, nextHopMac, sdnip_data):
119
120 ingress = []
121 egress = ""
122 for peer in sdnip_data['bgpPeers']:
123 if peer['ipAddress'] == nextHop:
124 egress = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
125 else:
pingping-linc6b86fa2014-12-01 16:18:10 -0800126 ingress.append("of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort']))
pingping-lin6f6332e2014-11-19 19:13:58 -0800127
pingping-linc6b86fa2014-12-01 16:18:10 -0800128 selector = "ETH_TYPE{ethType=800},IPV4_DST{ip=" + prefix + "}"
pingping-lin6f6332e2014-11-19 19:13:58 -0800129 treatment = "[ETH_DST{mac=" + str(nextHopMac) + "}]"
130
131 intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + treatment
132 return intent
133
134 def generate_expected_onePeerRouteIntents(self, prefixes, nextHop, nextHopMac, sdnip_json_file_path):
135 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800136 sdnip_json_file = open(sdnip_json_file_path).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800137
138 sdnip_data = json.loads(sdnip_json_file)
139
140 for prefix in prefixes:
141 intents.append(self.generate_expected_singleRouteIntent(prefix, nextHop, nextHopMac, sdnip_data))
142 return sorted(intents)
143
144 # TODO
145 # This method generates all expected route intents for all BGP peers
146 def generate_expected_routeIntents(self):
147 intents = []
148 return intents
149
150 # This method extracts all actual routes from ONOS CLI
151 def extract_actual_routes(self, get_routes_result):
152 routes_json_obj = json.loads(get_routes_result)
153
154 allRoutes_actual = []
155 for route in routes_json_obj:
156 if route['prefix'] == '172.16.10.0/24':
157 continue
158 allRoutes_actual.append(route['prefix'] + "/" + route['nextHop'])
159
160 return sorted(allRoutes_actual)
161
162 # This method extracts all actual route intents from ONOS CLI
163 def extract_actual_routeIntents(self, get_intents_result):
164 intents = []
165 # TODO: delete the line below when change to Mininet demo script
pingping-lin36fbe802014-11-25 16:01:14 -0800166 # get_intents_result=open("../tests/SdnIpTest/intents.json").read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800167 intents_json_obj = json.loads(get_intents_result)
168
169 for intent in intents_json_obj:
pingping-lin78fe4462014-12-04 17:34:48 -0800170 if intent['appId'] != "org.onosproject.sdnip" :
pingping-lin6f6332e2014-11-19 19:13:58 -0800171 continue
pingping-linc6b86fa2014-12-01 16:18:10 -0800172 if intent['type'] == "MultiPointToSinglePointIntent" and intent['state'] == 'INSTALLED':
173 egress = str(intent['egress']['device']) + ":" + str(intent['egress']['port'])
pingping-lin6f6332e2014-11-19 19:13:58 -0800174 ingress = []
175 for attachmentPoint in intent['ingress']:
176 ingress.append(str(attachmentPoint['device']) + ":" + str(attachmentPoint['port']))
pingping-linc6b86fa2014-12-01 16:18:10 -0800177
178 selector = intent['selector'].replace("[" , "").replace("]" , "").replace(" ", "")
179 if str(selector).startswith("IPV4"):
180 str1, str2 = str(selector).split(",")
181 selector = str2 + "," + str1
182
183 intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + intent['treatment']
pingping-lin6f6332e2014-11-19 19:13:58 -0800184 intents.append(intent)
185 return sorted(intents)
186
187 # This method extracts all actual BGP intents from ONOS CLI
188 def extract_actual_bgpIntents(self, get_intents_result):
189 intents = []
190 # TODO: delete the line below when change to Mininet demo script
pingping-lin36fbe802014-11-25 16:01:14 -0800191 # get_intents_result=open("../tests/SdnIpTest/intents.json").read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800192 intents_json_obj = json.loads(get_intents_result)
193
194 for intent in intents_json_obj:
pingping-lin78fe4462014-12-04 17:34:48 -0800195 if intent['appId'] != "org.onosproject.sdnip":
pingping-lin6f6332e2014-11-19 19:13:58 -0800196 continue
197 if intent['type'] == "PointToPointIntent" and "protocol=6" in str(intent['selector']):
198 ingress = str(intent['ingress']['device']) + ":" + str(intent['ingress']['port'])
199 egress = str(intent['egress']['device']) + ":" + str(intent['egress']['port'])
200 selector = str(intent['selector']).replace(" ", "").replace("[", "").replace("]", "").split(",")
201 intent = ingress + "/" + egress + "/" + str(sorted(selector))
202 intents.append(intent)
203
204 return sorted(intents)
205
206 # This method generates a single point to single point intent(PointToPointIntent) for BGP path
207 def generate_expected_bgpIntents(self, sdnip_json_file_path):
208 from operator import eq
209
pingping-linc6b86fa2014-12-01 16:18:10 -0800210 sdnip_json_file = open(sdnip_json_file_path).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800211 sdnip_data = json.loads(sdnip_json_file)
212
213 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800214 bgpPeerAttachmentPoint = ""
pingping-lin6f6332e2014-11-19 19:13:58 -0800215 bgpSpeakerAttachmentPoint = "of:" + str(sdnip_data['bgpSpeakers'][0]['attachmentDpid']).replace(":", "") + ":" + str(sdnip_data['bgpSpeakers'][0]['attachmentPort'])
216 for peer in sdnip_data['bgpPeers']:
217 bgpPeerAttachmentPoint = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
218 # find out the BGP speaker IP address for this BGP peer
pingping-linc6b86fa2014-12-01 16:18:10 -0800219 bgpSpeakerIpAddress = ""
pingping-lin6f6332e2014-11-19 19:13:58 -0800220 for interfaceAddress in sdnip_data['bgpSpeakers'][0]['interfaceAddresses']:
pingping-linc6b86fa2014-12-01 16:18:10 -0800221 # if eq(interfaceAddress['interfaceDpid'],sdnip_data['bgpSpeakers'][0]['attachmentDpid']) and eq(interfaceAddress['interfacePort'], sdnip_data['bgpSpeakers'][0]['attachmentPort']):
222 if eq(interfaceAddress['interfaceDpid'], peer['attachmentDpid']) and eq(interfaceAddress['interfacePort'], peer['attachmentPort']):
223 bgpSpeakerIpAddress = interfaceAddress['ipAddress']
pingping-lin6f6332e2014-11-19 19:13:58 -0800224 break
225 else:
226 continue
227
228 # from bgpSpeakerAttachmentPoint to bgpPeerAttachmentPoint direction
pingping-linc6b86fa2014-12-01 16:18:10 -0800229 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 -0800230 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
231 intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
232 intents.append(intent)
233
pingping-linc6b86fa2014-12-01 16:18:10 -0800234 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 -0800235 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
236 intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
237 intents.append(intent)
238
239 # from bgpPeerAttachmentPoint to bgpSpeakerAttachmentPoint direction
pingping-linc6b86fa2014-12-01 16:18:10 -0800240 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 -0800241 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
242 intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + str(sorted(selector))
243 intents.append(intent)
244
245 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}"
246 selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
247 intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + str(sorted(selector))
248 intents.append(intent)
249
250 return sorted(intents)
pingping-linc6b86fa2014-12-01 16:18:10 -0800251
pingping-lin8b306ac2014-11-17 18:13:51 -0800252 def add_routes(self, routes, routeRate):
253 main.log.info("I am in add_routes method!")
pingping-linc6b86fa2014-12-01 16:18:10 -0800254
pingping-lin8b306ac2014-11-17 18:13:51 -0800255 routes_added = 0
256 try:
257 self.handle.sendline("")
pingping-linc6b86fa2014-12-01 16:18:10 -0800258 # self.handle.expect("config-router")
pingping-lin8b306ac2014-11-17 18:13:51 -0800259 self.handle.expect("config-router", timeout=5)
260 except:
261 main.log.warn("Probably not in config-router mode!")
262 self.disconnect()
263 main.log.info("Start to add routes")
264
265 for i in range(0, len(routes)):
266 routeCmd = "network " + routes[i]
267 try:
268 self.handle.sendline(routeCmd)
269 self.handle.expect("bgpd", timeout=5)
270 except:
271 main.log.warn("Failed to add route")
272 self.disconnect()
273 waitTimer = 1.00 / routeRate
274 time.sleep(waitTimer)
275 if routes_added == len(routes):
276 main.log.info("Finished adding routes")
277 return main.TRUE
278 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800279
280 def delete_routes(self, routes, routeRate):
281 main.log.info("I am in delete_routes method!")
282
283 routes_added = 0
284 try:
285 self.handle.sendline("")
286 # self.handle.expect("config-router")
287 self.handle.expect("config-router", timeout=5)
288 except:
289 main.log.warn("Probably not in config-router mode!")
290 self.disconnect()
291 main.log.info("Start to delete routes")
292
293 for i in range(0, len(routes)):
294 routeCmd = "no network " + routes[i]
295 try:
296 self.handle.sendline(routeCmd)
297 self.handle.expect("bgpd", timeout=5)
298 except:
299 main.log.warn("Failed to add route")
300 self.disconnect()
301 waitTimer = 1.00 / routeRate
302 time.sleep(waitTimer)
303 if routes_added == len(routes):
304 main.log.info("Finished deleting routes")
305 return main.TRUE
306 return main.FALSE
307
308 def ping_test(self, ip_address, ping_test_file, ping_test_result_file):
pingping-lindd3b0e42014-12-02 11:46:54 -0800309 main.log.info("Start the ping test on host:" + str(ip_address))
pingping-linc6b86fa2014-12-01 16:18:10 -0800310
311 self.name = self.options['name']
312 self.handle = super(QuaggaCliDriver, self).connect(
313 user_name=self.user_name, ip_address=ip_address,
314 port=self.port, pwd=self.pwd)
315 main.log.info("connect parameters:" + str(self.user_name) + ";"
316 + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
317
318 if self.handle:
pingping-lind3139ac2014-12-04 14:21:26 -0800319 #self.handle.expect("")
320 #self.handle.expect("\$")
pingping-linc6b86fa2014-12-01 16:18:10 -0800321 main.log.info("I in host " + str(ip_address))
pingping-lin01355a62014-12-02 20:58:14 -0800322 main.log.info(ping_test_file + " > " + ping_test_result_file + " &")
323 self.handle.sendline(ping_test_file + " > " + ping_test_result_file + " &")
pingping-linc6b86fa2014-12-01 16:18:10 -0800324 self.handle.expect("\$", timeout=60)
325 handle = self.handle.before
326
327 return handle
328 else:
329 main.log.info("NO HANDLE")
330 return main.FALSE
331
332
pingping-lin6f6332e2014-11-19 19:13:58 -0800333 # Please use the generate_routes plus add_routes instead of this one
timlindbergef8d55d2013-09-27 12:50:13 -0700334 def add_route(self, net, numRoutes, routeRate):
335 try:
336 self.handle.sendline("")
337 self.handle.expect("config-router")
338 except:
339 main.log.warn("Probably not in config-router mode!")
340 self.disconnect()
pingping-lin36fbe802014-11-25 16:01:14 -0800341 main.log.info("Adding Routes")
pingping-linc6b86fa2014-12-01 16:18:10 -0800342 j = 0
343 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700344 while numRoutes > 255:
345 numRoutes = numRoutes - 255
346 j = j + 1
347 k = numRoutes % 254
348 routes_added = 0
349 if numRoutes > 255:
350 numRoutes = 255
pingping-linc6b86fa2014-12-01 16:18:10 -0800351 for m in range(1, j + 1):
352 for n in range(1, numRoutes + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700353 network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
354 routeCmd = "network " + network
355 try:
356 self.handle.sendline(routeCmd)
357 self.handle.expect("bgpd")
358 except:
359 main.log.warn("failed to add route")
pingping-linc6b86fa2014-12-01 16:18:10 -0800360 self.disconnect()
361 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700362 time.sleep(waitTimer)
363 routes_added = routes_added + 1
pingping-linc6b86fa2014-12-01 16:18:10 -0800364 for d in range(j + 1, j + 2):
365 for e in range(1, k + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700366 network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
367 routeCmd = "network " + network
368 try:
369 self.handle.sendline(routeCmd)
370 self.handle.expect("bgpd")
371 except:
372 main.log.warn("failed to add route")
373 self.disconnect
pingping-linc6b86fa2014-12-01 16:18:10 -0800374 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700375 time.sleep(waitTimer)
376 routes_added = routes_added + 1
377 if routes_added == numRoutes:
378 return main.TRUE
379 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800380
timlindbergef8d55d2013-09-27 12:50:13 -0700381 def del_route(self, net, numRoutes, routeRate):
382 try:
383 self.handle.sendline("")
384 self.handle.expect("config-router")
385 except:
386 main.log.warn("Probably not in config-router mode!")
387 self.disconnect()
pingping-lin36fbe802014-11-25 16:01:14 -0800388 main.log.info("Deleting Routes")
pingping-linc6b86fa2014-12-01 16:18:10 -0800389 j = 0
390 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700391 while numRoutes > 255:
392 numRoutes = numRoutes - 255
393 j = j + 1
394 k = numRoutes % 254
395 routes_deleted = 0
396 if numRoutes > 255:
397 numRoutes = 255
pingping-linc6b86fa2014-12-01 16:18:10 -0800398 for m in range(1, j + 1):
399 for n in range(1, numRoutes + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700400 network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
401 routeCmd = "no network " + network
402 try:
403 self.handle.sendline(routeCmd)
404 self.handle.expect("bgpd")
405 except:
406 main.log.warn("Failed to delete route")
407 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800408 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700409 time.sleep(waitTimer)
410 routes_deleted = routes_deleted + 1
pingping-linc6b86fa2014-12-01 16:18:10 -0800411 for d in range(j + 1, j + 2):
412 for e in range(1, k + 1):
timlindbergef8d55d2013-09-27 12:50:13 -0700413 network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
414 routeCmd = "no network " + network
415 try:
416 self.handle.sendline(routeCmd)
417 self.handle.expect("bgpd")
418 except:
419 main.log.warn("Failed to delete route")
420 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800421 waitTimer = 1.00 / routeRate
timlindbergef8d55d2013-09-27 12:50:13 -0700422 time.sleep(waitTimer)
423 routes_deleted = routes_deleted + 1
424 if routes_deleted == numRoutes:
425 return main.TRUE
426 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800427
timlindbergef8d55d2013-09-27 12:50:13 -0700428 def check_routes(self, brand, ip, user, pw):
429 def pronto(ip, user, passwd):
430 print "Connecting to Pronto switch"
431 child = pexpect.spawn("telnet " + ip)
pingping-linc6b86fa2014-12-01 16:18:10 -0800432 i = child.expect(["login:", "CLI#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700433 if i == 0:
434 print "Username and password required. Passing login info."
435 child.sendline(user)
436 child.expect("Password:")
437 child.sendline(passwd)
438 child.expect("CLI#")
439 print "Logged in, getting flowtable."
440 child.sendline("flowtable brief")
441 for t in range (9):
442 t2 = 9 - t
443 print "\r" + str(t2)
444 sys.stdout.write("\033[F")
445 time.sleep(1)
446 print "Scanning flowtable"
447 child.expect("Flow table show")
448 count = 0
449 while 1:
pingping-linc6b86fa2014-12-01 16:18:10 -0800450 i = child.expect(['17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}', 'CLI#', pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700451 if i == 0:
452 count = count + 1
453 elif i == 1:
454 print "Pronto flows: " + str(count) + "\nDone\n"
455 break
456 else:
457 break
pingping-linc6b86fa2014-12-01 16:18:10 -0800458 def cisco(ip, user, passwd):
timlindbergef8d55d2013-09-27 12:50:13 -0700459 print "Establishing Cisco switch connection"
pingping-linc6b86fa2014-12-01 16:18:10 -0800460 child = pexpect.spawn("ssh " + user + "@" + ip)
461 i = child.expect(["Password:", "CLI#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700462 if i == 0:
463 print "Password required. Passing now."
464 child.sendline(passwd)
465 child.expect("#")
466 print "Logged in. Retrieving flow table then counting flows."
467 child.sendline("show openflow switch all flows all")
468 child.expect("Logical Openflow Switch")
469 print "Flow table retrieved. Counting flows"
470 count = 0
471 while 1:
pingping-linc6b86fa2014-12-01 16:18:10 -0800472 i = child.expect(["nw_src=17", "#", pexpect.TIMEOUT])
timlindbergef8d55d2013-09-27 12:50:13 -0700473 if i == 0:
474 count = count + 1
475 elif i == 1:
476 print "Cisco flows: " + str(count) + "\nDone\n"
477 break
478 else:
479 break
480 if brand == "pronto" or brand == "PRONTO":
pingping-linc6b86fa2014-12-01 16:18:10 -0800481 pronto(ip, user, passwd)
482 # elif brand == "cisco" or brand == "CISCO":
483 # cisco(ip,user,passwd)
timlindbergef8d55d2013-09-27 12:50:13 -0700484 def disconnect(self):
485 '''
486 Called when Test is complete to disconnect the Quagga handle.
487 '''
488 response = ''
489 try:
490 self.handle.close()
491 except:
492 main.log.error("Connection failed to the host")
493 response = main.FALSE
494 return response