blob: 721ae6a611eeca35acd06db1559a1a94ef82a492 [file] [log] [blame]
timlindbergef8d55d2013-09-27 12:50:13 -07001#!/usr/bin/env python
Jeremy Songsterae01bba2016-07-11 15:39:17 -07002"""
3Modified 2015 by ON.Lab
4
5Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
8"""
timlindbergef8d55d2013-09-27 12:50:13 -07009
10import time
11import pexpect
kelvin-onlabbbe46482015-01-16 10:44:28 -080012import sys
timlindbergef8d55d2013-09-27 12:50:13 -070013import json
timlindbergef8d55d2013-09-27 12:50:13 -070014from drivers.common.clidriver import CLI
15
timlindbergef8d55d2013-09-27 12:50:13 -070016
kelvin-onlabbbe46482015-01-16 10:44:28 -080017class QuaggaCliDriver( CLI ):
18
19 def __init__( self ):
20 super( CLI, self ).__init__()
timlindbergef8d55d2013-09-27 12:50:13 -070021
pingping-linc6b86fa2014-12-01 16:18:10 -080022 # TODO: simplify this method
kelvin-onlabbbe46482015-01-16 10:44:28 -080023 def connect( self, **connectargs ):
timlindbergef8d55d2013-09-27 12:50:13 -070024 for key in connectargs:
kelvin-onlabbbe46482015-01-16 10:44:28 -080025 vars( self )[ key ] = connectargs[ key ]
pingping-lin763ee042015-05-20 17:45:30 -070026 self.name = self.options[ 'name' ]
27 self.handle = super( QuaggaCliDriver, self ).connect(
28 user_name=self.user_name,
29 ip_address="127.0.0.1",
30 port=self.port,
31 pwd=self.pwd )
32 if self.handle:
33 return self.handle
34 else:
35 main.log.info( "NO HANDLE" )
36 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -080037
pingping-lin763ee042015-05-20 17:45:30 -070038 def connectQuagga( self ):
kelvin-onlabbbe46482015-01-16 10:44:28 -080039 self.name = self.options[ 'name' ]
40 # self.handle = super( QuaggaCliDriver,self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080041 # user_name=self.user_name, ip_address=self.ip_address,port=self.port,
kelvin-onlabbbe46482015-01-16 10:44:28 -080042 # pwd=self.pwd )
pingping-lin4e7b0d32015-01-27 18:06:22 -080043 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080044 user_name=self.user_name,
45 ip_address="1.1.1.1",
46 port=self.port,
47 pwd=self.pwd )
pingping-lina600d9b2015-01-30 13:57:26 -080048 #main.log.info( "connect parameters:" + str( self.user_name ) + ";"
49 # + str( self.ip_address ) + ";" + str( self.port )
50 # + ";" + str(self.pwd ) )
timlindbergef8d55d2013-09-27 12:50:13 -070051
pingping-linc6b86fa2014-12-01 16:18:10 -080052 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -080053 # self.handle.expect( "",timeout=10 )
54 # self.handle.expect( "\$",timeout=10 )
55 self.handle.sendline( "telnet localhost 2605" )
56 # self.handle.expect( "Password:", timeout=5 )
57 self.handle.expect( "Password:" )
58 self.handle.sendline( "hello" )
59 # self.handle.expect( "bgpd", timeout=5 )
60 self.handle.expect( "bgpd" )
61 self.handle.sendline( "enable" )
62 # self.handle.expect( "bgpd#", timeout=5 )
63 self.handle.expect( "bgpd#" )
timlindbergef8d55d2013-09-27 12:50:13 -070064 return self.handle
kelvin-onlabbbe46482015-01-16 10:44:28 -080065 else:
66 main.log.info( "NO HANDLE" )
timlindbergef8d55d2013-09-27 12:50:13 -070067 return main.FALSE
68
pingping-linc1c696e2015-01-27 13:46:44 -080069 def loginQuagga( self, ip_address ):
kelvin-onlabbbe46482015-01-16 10:44:28 -080070 self.name = self.options[ 'name' ]
71 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080072 user_name=self.user_name, ip_address=ip_address,
kelvin-onlabbbe46482015-01-16 10:44:28 -080073 port=self.port, pwd=self.pwd )
pingping-linc1c696e2015-01-27 13:46:44 -080074 main.log.info( "connect parameters:" + str( self.user_name ) + ";"
pingping-lin4e7b0d32015-01-27 18:06:22 -080075 + str( self.ip_address ) + ";" + str( self.port )
76 + ";" + str( self.pwd ) )
pingping-lin8b306ac2014-11-17 18:13:51 -080077
78 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -080079 # self.handle.expect( "" )
80 # self.handle.expect( "\$" )
81 self.handle.sendline( "telnet localhost 2605" )
82 # self.handle.expect( "Password:", timeout=5 )
83 self.handle.expect( "Password:" )
84 self.handle.sendline( "hello" )
85 # self.handle.expect( "bgpd", timeout=5 )
86 self.handle.expect( "bgpd" )
87 self.handle.sendline( "enable" )
88 # self.handle.expect( "bgpd#", timeout=5 )
89 self.handle.expect( "bgpd#" )
pingping-linc1c696e2015-01-27 13:46:44 -080090 main.log.info( "I am in quagga on host " + str( ip_address ) )
pingping-lin8b306ac2014-11-17 18:13:51 -080091
92 return self.handle
93 else:
kelvin-onlabbbe46482015-01-16 10:44:28 -080094 main.log.info( "NO HANDLE" )
pingping-lin8b306ac2014-11-17 18:13:51 -080095 return main.FALSE
96
kelvin-onlabd3b64892015-01-20 13:26:24 -080097 def enterConfig( self, asn ):
kelvin-onlabbbe46482015-01-16 10:44:28 -080098 main.log.info( "I am in enter_config method!" )
timlindbergef8d55d2013-09-27 12:50:13 -070099 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800100 self.handle.sendline( "" )
101 self.handle.expect( "bgpd#" )
pingping-lin763ee042015-05-20 17:45:30 -0700102 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800103 main.log.warn( "Probably not currently in enable mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700104 self.disconnect()
105 return main.FALSE
kelvin-onlabbbe46482015-01-16 10:44:28 -0800106 self.handle.sendline( "configure terminal" )
107 self.handle.expect( "config", timeout=5 )
108 routerAS = "router bgp " + str( asn )
timlindbergef8d55d2013-09-27 12:50:13 -0700109 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800110 self.handle.sendline( routerAS )
111 self.handle.expect( "config-router", timeout=5 )
timlindbergef8d55d2013-09-27 12:50:13 -0700112 return main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -0700113 except Exception:
timlindbergef8d55d2013-09-27 12:50:13 -0700114 return main.FALSE
pingping-lin8b306ac2014-11-17 18:13:51 -0800115
kelvin-onlabd3b64892015-01-20 13:26:24 -0800116 def generatePrefixes( self, net, numRoutes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800117 main.log.info( "I am in generate_prefixes method!" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800118
pingping-lin4e7b0d32015-01-27 18:06:22 -0800119 # each IP prefix is composed by "net" + "." + m + "." + n + "." + x
pingping-lin8b306ac2014-11-17 18:13:51 -0800120 # the length of each IP prefix is 24
121 routes = []
kelvin-onlabd3b64892015-01-20 13:26:24 -0800122 routesGen = 0
pingping-lin8b306ac2014-11-17 18:13:51 -0800123 m = numRoutes / 256
124 n = numRoutes % 256
125
kelvin-onlabbbe46482015-01-16 10:44:28 -0800126 for i in range( 0, m ):
127 for j in range( 0, 256 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800128 network = str( net ) + "." + str( i ) + "." + str( j ) \
129 + ".0/24"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800130 routes.append( network )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800131 routesGen = routesGen + 1
pingping-lin8b306ac2014-11-17 18:13:51 -0800132
kelvin-onlabbbe46482015-01-16 10:44:28 -0800133 for j in range( 0, n ):
134 network = str( net ) + "." + str( m ) + "." + str( j ) + ".0/24"
135 routes.append( network )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800136 routesGen = routesGen + 1
pingping-lin8b306ac2014-11-17 18:13:51 -0800137
kelvin-onlabd3b64892015-01-20 13:26:24 -0800138 if routesGen == numRoutes:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800139 main.log.info( "Successfully generated " + str( numRoutes )
140 + " prefixes!" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800141 return routes
142 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800143
kelvin-onlabbbe46482015-01-16 10:44:28 -0800144 # This method generates a multiple to single point intent(
145 # MultiPointToSinglePointIntent ) for a given route
pingping-lin4e7b0d32015-01-27 18:06:22 -0800146 def generateExpectedSingleRouteIntent( self, prefix, nextHop, nextHopMac,
147 sdnipData ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800148
pingping-linc1c696e2015-01-27 13:46:44 -0800149 ingresses = []
pingping-lin6f6332e2014-11-19 19:13:58 -0800150 egress = ""
kelvin-onlabd3b64892015-01-20 13:26:24 -0800151 for peer in sdnipData[ 'bgpPeers' ]:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800152 if peer[ 'ipAddress' ] == nextHop:
pingping-linc1c696e2015-01-27 13:46:44 -0800153 egress = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800154 peer[ 'attachmentDpid' ] ).replace( ":", "" ) + ":" \
155 + str( peer[ 'attachmentPort' ] )
pingping-linc1c696e2015-01-27 13:46:44 -0800156 for peer in sdnipData[ 'bgpPeers' ]:
157 if not peer[ 'ipAddress' ] == nextHop:
158 ingress = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800159 peer[ 'attachmentDpid' ] ).replace( ":", "" ) + ":" \
160 + str( peer[ 'attachmentPort' ] )
pingping-linc1c696e2015-01-27 13:46:44 -0800161 if not ingress == egress and ingress not in ingresses:
162 ingresses.append( ingress )
163 # ingresses.append( "of:" + str( peer[ 'attachmentDpid' ]
164 # ).replace( ":", "" ) + ":" + str( peer[ 'attachmentPort'
165 # ] ) )
pingping-lin6f6332e2014-11-19 19:13:58 -0800166
pingping-linc6b86fa2014-12-01 16:18:10 -0800167 selector = "ETH_TYPE{ethType=800},IPV4_DST{ip=" + prefix + "}"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800168 treatment = "[ETH_DST{mac=" + str( nextHopMac ) + "}]"
pingping-lin6f6332e2014-11-19 19:13:58 -0800169
pingping-lin4e7b0d32015-01-27 18:06:22 -0800170 intent = egress + "/" + str( sorted( ingresses ) ) + "/" + \
171 selector + "/" + treatment
pingping-lin6f6332e2014-11-19 19:13:58 -0800172 return intent
173
pingping-lin4e7b0d32015-01-27 18:06:22 -0800174 def generateExpectedOnePeerRouteIntents( self, prefixes, nextHop,
175 nextHopMac, sdnipJsonFilePath ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800176 intents = []
kelvin-onlabd3b64892015-01-20 13:26:24 -0800177 sdnipJsonFile = open( sdnipJsonFilePath ).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800178
kelvin-onlabd3b64892015-01-20 13:26:24 -0800179 sdnipData = json.loads( sdnipJsonFile )
pingping-lin6f6332e2014-11-19 19:13:58 -0800180
181 for prefix in prefixes:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800182 intents.append(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800183 self.generateExpectedSingleRouteIntent(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800184 prefix, nextHop, nextHopMac, sdnipData ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800185 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800186
187 # TODO
188 # This method generates all expected route intents for all BGP peers
kelvin-onlabd3b64892015-01-20 13:26:24 -0800189 def generateExpectedRouteIntents( self ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800190 intents = []
191 return intents
192
193 # This method extracts all actual routes from ONOS CLI
pingping-linb2a86582015-02-02 16:18:59 -0800194 def extractActualRoutesOneDotZero( self, getRoutesResult ):
kelvin-onlabd3b64892015-01-20 13:26:24 -0800195 routesJsonObj = json.loads( getRoutesResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800196
kelvin-onlabd3b64892015-01-20 13:26:24 -0800197 allRoutesActual = []
pingping-lin763ee042015-05-20 17:45:30 -0700198 for route in routesJsonObj['routes4']:
199 if 'prefix' in route:
200 if route[ 'prefix' ] == '172.16.10.0/24':
201 continue
202 allRoutesActual.append(
203 route[ 'prefix' ] + "/" + route[ 'nextHop' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800204
kelvin-onlabd3b64892015-01-20 13:26:24 -0800205 return sorted( allRoutesActual )
pingping-linb2a86582015-02-02 16:18:59 -0800206
207 def extractActualRoutesMaster( self, getRoutesResult ):
pingping-lina600d9b2015-01-30 13:57:26 -0800208 routesJsonObj = json.loads( getRoutesResult )
209
210 allRoutesActual = []
211 for route in routesJsonObj['routes4']:
212 if route[ 'prefix' ] == '172.16.10.0/24':
213 continue
214 allRoutesActual.append(
215 route[ 'prefix' ] + "/" + route[ 'nextHop' ] )
216
217 return sorted( allRoutesActual )
pingping-lin6f6332e2014-11-19 19:13:58 -0800218
219 # This method extracts all actual route intents from ONOS CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800220 def extractActualRouteIntents( self, getIntentsResult ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800221 intents = []
222 # TODO: delete the line below when change to Mininet demo script
kelvin-onlabd3b64892015-01-20 13:26:24 -0800223 # getIntentsResult=open( "../tests/SdnIpTest/intents.json" ).read()
224 intentsJsonObj = json.loads( getIntentsResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800225
kelvin-onlabd3b64892015-01-20 13:26:24 -0800226 for intent in intentsJsonObj:
pingping-linf30cf272015-05-29 15:54:07 -0700227 #if intent[ 'appId' ] != "org.onosproject.sdnip":
228 # continue
pingping-lin4e7b0d32015-01-27 18:06:22 -0800229 if intent[ 'type' ] == "MultiPointToSinglePointIntent" \
230 and intent[ 'state' ] == 'INSTALLED':
231 egress = str( intent[ 'egress' ][ 'device' ] ) + ":" \
232 + str( intent[ 'egress' ][ 'port' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800233 ingress = []
kelvin-onlabbbe46482015-01-16 10:44:28 -0800234 for attachmentPoint in intent[ 'ingress' ]:
pingping-linc1c696e2015-01-27 13:46:44 -0800235 ingress.append(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800236 str( attachmentPoint[ 'device' ] ) + ":"
237 + str( attachmentPoint[ 'port' ] ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800238
kelvin-onlabbbe46482015-01-16 10:44:28 -0800239 selector = intent[ 'selector' ].replace(
240 "[", "" ).replace( "]", "" ).replace( " ", "" )
241 if str( selector ).startswith( "IPV4" ):
242 str1, str2 = str( selector ).split( "," )
pingping-linc6b86fa2014-12-01 16:18:10 -0800243 selector = str2 + "," + str1
244
pingping-lin4e7b0d32015-01-27 18:06:22 -0800245 intent = egress + "/" + str( sorted( ingress ) ) + "/" + \
246 selector + "/" + intent[ 'treatment' ]
kelvin-onlabbbe46482015-01-16 10:44:28 -0800247 intents.append( intent )
248 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800249
pingping-linf30cf272015-05-29 15:54:07 -0700250 # This method calculates the MultiPointToSinglePointIntent number installed
251 def extractActualRouteIntentNum( self, getIntentsResult ):
252 intentsJsonObj = json.loads( getIntentsResult )
253 num = 0
254 for intent in intentsJsonObj:
255 if intent[ 'type' ] == "MultiPointToSinglePointIntent" \
256 and intent[ 'state' ] == 'INSTALLED':
257 num = num + 1
258 return num
259
260 # This method calculates the PointToPointIntent number installed
261 def extractActualBgpIntentNum( self, getIntentsResult ):
262 intentsJsonObj = json.loads( getIntentsResult )
263 num = 0
264 for intent in intentsJsonObj:
265 if intent[ 'type' ] == "PointToPointIntent" \
266 and intent[ 'state' ] == 'INSTALLED':
267 num = num + 1
268 return num
269
pingping-lin6f6332e2014-11-19 19:13:58 -0800270 # This method extracts all actual BGP intents from ONOS CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800271 def extractActualBgpIntents( self, getIntentsResult ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800272 intents = []
273 # TODO: delete the line below when change to Mininet demo script
kelvin-onlabd3b64892015-01-20 13:26:24 -0800274 # getIntentsResult=open( "../tests/SdnIpTest/intents.json" ).read()
275 intentsJsonObj = json.loads( getIntentsResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800276
kelvin-onlabd3b64892015-01-20 13:26:24 -0800277 for intent in intentsJsonObj:
pingping-linf30cf272015-05-29 15:54:07 -0700278 #if intent[ 'appId' ] != "org.onosproject.sdnip":
279 # continue
pingping-lin4e7b0d32015-01-27 18:06:22 -0800280 if intent[ 'type' ] == "PointToPointIntent" \
281 and "protocol=6" in str( intent[ 'selector' ] ):
282 ingress = str( intent[ 'ingress' ][ 'device' ] ) + ":" \
283 + str( intent[ 'ingress' ][ 'port' ] )
284 egress = str( intent[ 'egress' ][ 'device' ] ) + ":" + \
285 str( intent[ 'egress' ][ 'port' ] )
286 selector = str( intent[ 'selector' ] ).replace( " ", "" )\
287 .replace( "[", "" ).replace( "]", "" ).split( "," )
288 intent = ingress + "/" + egress + "/" + \
289 str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800290 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800291
kelvin-onlabbbe46482015-01-16 10:44:28 -0800292 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800293
kelvin-onlabbbe46482015-01-16 10:44:28 -0800294 # This method generates a single point to single point intent(
295 # PointToPointIntent ) for BGP path
kelvin-onlabd3b64892015-01-20 13:26:24 -0800296 def generateExpectedBgpIntents( self, sdnipJsonFilePath ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800297 from operator import eq
298
kelvin-onlabd3b64892015-01-20 13:26:24 -0800299 sdnipJsonFile = open( sdnipJsonFilePath ).read()
300 sdnipData = json.loads( sdnipJsonFile )
pingping-lin6f6332e2014-11-19 19:13:58 -0800301
302 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800303 bgpPeerAttachmentPoint = ""
kelvin-onlabbbe46482015-01-16 10:44:28 -0800304 bgpSpeakerAttachmentPoint = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800305 sdnipData[ 'bgpSpeakers' ][ 0 ][ 'attachmentDpid' ] )\
306 .replace( ":", "" ) + ":" \
307 + str( sdnipData[ 'bgpSpeakers' ][ 0 ][ 'attachmentPort' ] )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800308 for peer in sdnipData[ 'bgpPeers' ]:
pingping-lin4e7b0d32015-01-27 18:06:22 -0800309 bgpPeerAttachmentPoint = "of:" \
310 + str( peer[ 'attachmentDpid' ] ).replace( ":", "" ) \
311 + ":" + str( peer[ 'attachmentPort' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800312 # find out the BGP speaker IP address for this BGP peer
pingping-linc6b86fa2014-12-01 16:18:10 -0800313 bgpSpeakerIpAddress = ""
pingping-lin4e7b0d32015-01-27 18:06:22 -0800314 for interfaceAddress in \
315 sdnipData[ 'bgpSpeakers' ][ 0 ][ 'interfaceAddresses' ]:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800316 # if eq( interfaceAddress[ 'interfaceDpid' ],sdnipData[
kelvin-onlabbbe46482015-01-16 10:44:28 -0800317 # 'bgpSpeakers' ][ 0 ][ 'attachmentDpid' ] ) and eq(
pingping-linc1c696e2015-01-27 13:46:44 -0800318 # interfaceAddress[ 'interfacePort' ], sdnipData[ 'bgpSpeakers'
319 # ][ 0 ][ 'attachmentPort' ] ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800320 if eq( interfaceAddress[ 'interfaceDpid' ],
321 peer[ 'attachmentDpid' ] ) \
322 and eq( interfaceAddress[ 'interfacePort' ],
323 peer[ 'attachmentPort' ] ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800324 bgpSpeakerIpAddress = interfaceAddress[ 'ipAddress' ]
pingping-lin6f6332e2014-11-19 19:13:58 -0800325 break
326 else:
327 continue
328
kelvin-onlabbbe46482015-01-16 10:44:28 -0800329 # from bgpSpeakerAttachmentPoint to bgpPeerAttachmentPoint
330 # direction
pingping-lin4e7b0d32015-01-27 18:06:22 -0800331 selectorStr = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," \
332 + "IPV4_DST{ip=" + peer[ 'ipAddress' ] + "/32}," \
333 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
334 TCP_DST{tcpPort=179}"
335 selector = selectorStr.replace( " ", "" ).replace("[", "" )\
336 .replace( "]", "" ).split( "," )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800337 intent = bgpSpeakerAttachmentPoint + "/" + \
338 bgpPeerAttachmentPoint + "/" + str( sorted( selector ) )
339 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800340
pingping-lin4e7b0d32015-01-27 18:06:22 -0800341 selectorStr = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," \
342 + "IPV4_DST{ip=" + peer[ 'ipAddress' ] + "/32}," \
343 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
344 TCP_SRC{tcpPort=179}"
345 selector = selectorStr.replace( " ", "" ).replace("[", "" )\
346 .replace( "]", "" ).split( "," )
347 intent = bgpSpeakerAttachmentPoint + "/" \
348 + bgpPeerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800349 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800350
kelvin-onlabbbe46482015-01-16 10:44:28 -0800351 # from bgpPeerAttachmentPoint to bgpSpeakerAttachmentPoint
352 # direction
pingping-lin4e7b0d32015-01-27 18:06:22 -0800353 selectorStr = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," \
354 + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," \
355 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
356 TCP_DST{tcpPort=179}"
357 selector = selectorStr.replace( " ", "" ).replace("[", "" )\
358 .replace( "]", "" ).split( "," )
359 intent = bgpPeerAttachmentPoint + "/" \
360 + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800361 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800362
pingping-lin4e7b0d32015-01-27 18:06:22 -0800363 selectorStr = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," \
364 + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," \
365 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
366 TCP_SRC{tcpPort=179}"
367 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
368 .replace( "]", "" ).split( "," )
369 intent = bgpPeerAttachmentPoint + "/" \
370 + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800371 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800372
kelvin-onlabbbe46482015-01-16 10:44:28 -0800373 return sorted( intents )
pingping-linc6b86fa2014-12-01 16:18:10 -0800374
kelvin-onlabd3b64892015-01-20 13:26:24 -0800375 def addRoutes( self, routes, routeRate ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800376 main.log.info( "I am in add_routes method!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800377
kelvin-onlabd3b64892015-01-20 13:26:24 -0800378 routesAdded = 0
pingping-lin8b306ac2014-11-17 18:13:51 -0800379 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800380 self.handle.sendline( "" )
381 # self.handle.expect( "config-router" )
382 self.handle.expect( "config-router", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700383 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800384 main.log.warn( "Probably not in config-router mode!" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800385 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800386 main.log.info( "Start to add routes" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800387
pingping-lin763ee042015-05-20 17:45:30 -0700388 chunk_size = 20
389
390 if len(routes) > chunk_size:
Jon Hall4ba53f02015-07-29 13:07:41 -0700391 num_iter = (int) (len(routes) / chunk_size)
pingping-lin763ee042015-05-20 17:45:30 -0700392 else:
393 num_iter = 1;
394
395 total = 0
396 for n in range( 0, num_iter + 1):
397 routeCmd = ""
398 if (len( routes ) - (n * chunk_size)) >= chunk_size:
399 m = (n + 1) * chunk_size
400 else:
401 m = len( routes )
402 for i in range( n * chunk_size, m ):
403 routeCmd = routeCmd + "network " + routes[ i ] + "\n"
404 total = total + 1
405
406 main.log.info(routeCmd)
pingping-lin8b306ac2014-11-17 18:13:51 -0800407 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800408 self.handle.sendline( routeCmd )
409 self.handle.expect( "bgpd", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700410 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800411 main.log.warn( "Failed to add route" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800412 self.disconnect()
Jon Hall4ba53f02015-07-29 13:07:41 -0700413
pingping-linc1c696e2015-01-27 13:46:44 -0800414 # waitTimer = 1.00 / routeRate
pingping-lin763ee042015-05-20 17:45:30 -0700415 main.log.info("Total routes so far " + ((str) (total)) + " wait for 0 sec")
416 #time.sleep( 1 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800417 if routesAdded == len( routes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800418 main.log.info( "Finished adding routes" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800419 return main.TRUE
420 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800421
kelvin-onlabd3b64892015-01-20 13:26:24 -0800422 def deleteRoutes( self, routes, routeRate ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800423 main.log.info( "I am in delete_routes method!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800424
kelvin-onlabd3b64892015-01-20 13:26:24 -0800425 routesAdded = 0
pingping-linc6b86fa2014-12-01 16:18:10 -0800426 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800427 self.handle.sendline( "" )
428 # self.handle.expect( "config-router" )
429 self.handle.expect( "config-router", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700430 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800431 main.log.warn( "Probably not in config-router mode!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800432 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800433 main.log.info( "Start to delete routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800434
kelvin-onlabbbe46482015-01-16 10:44:28 -0800435 for i in range( 0, len( routes ) ):
436 routeCmd = "no network " + routes[ i ]
pingping-linc6b86fa2014-12-01 16:18:10 -0800437 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800438 self.handle.sendline( routeCmd )
439 self.handle.expect( "bgpd", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700440 except Exception:
pingping-lin4e7b0d32015-01-27 18:06:22 -0800441 main.log.warn( "Failed to delete route" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800442 self.disconnect()
pingping-linc1c696e2015-01-27 13:46:44 -0800443 # waitTimer = 1.00 / routeRate
444 # time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800445 if routesAdded == len( routes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800446 main.log.info( "Finished deleting routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800447 return main.TRUE
448 return main.FALSE
449
pingping-linc1c696e2015-01-27 13:46:44 -0800450 def pingTest( self, ip_address, pingTestFile, pingTestResultFile ):
451 main.log.info( "Start the ping test on host:" + str( ip_address ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800452
kelvin-onlabbbe46482015-01-16 10:44:28 -0800453 self.name = self.options[ 'name' ]
454 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -0800455 user_name=self.user_name, ip_address=ip_address,
kelvin-onlabbbe46482015-01-16 10:44:28 -0800456 port=self.port, pwd=self.pwd )
pingping-linc1c696e2015-01-27 13:46:44 -0800457 main.log.info( "connect parameters:" + str( self.user_name ) + ";"
pingping-lin4e7b0d32015-01-27 18:06:22 -0800458 + str( self.ip_address ) + ";" + str( self.port )
459 + ";" + str( self.pwd ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800460
461 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800462 # self.handle.expect( "" )
463 # self.handle.expect( "\$" )
pingping-linc1c696e2015-01-27 13:46:44 -0800464 main.log.info( "I in host " + str( ip_address ) )
465 main.log.info( pingTestFile + " > " + pingTestResultFile + " &" )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800466 self.handle.sendline(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800467 pingTestFile +
kelvin-onlabbbe46482015-01-16 10:44:28 -0800468 " > " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800469 pingTestResultFile +
kelvin-onlabbbe46482015-01-16 10:44:28 -0800470 " &" )
471 self.handle.expect( "\$", timeout=60 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800472 handle = self.handle.before
473
474 return handle
475 else:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800476 main.log.info( "NO HANDLE" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800477 return main.FALSE
478
pingping-lin763ee042015-05-20 17:45:30 -0700479
pingping-lin4e7b0d32015-01-27 18:06:22 -0800480 # Please use the generateRoutes plus addRoutes instead of this one!
kelvin-onlabd3b64892015-01-20 13:26:24 -0800481 def addRoute( self, net, numRoutes, routeRate ):
timlindbergef8d55d2013-09-27 12:50:13 -0700482 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800483 self.handle.sendline( "" )
484 self.handle.expect( "config-router" )
pingping-lin763ee042015-05-20 17:45:30 -0700485 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800486 main.log.warn( "Probably not in config-router mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700487 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800488 main.log.info( "Adding Routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800489 j = 0
490 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700491 while numRoutes > 255:
492 numRoutes = numRoutes - 255
493 j = j + 1
494 k = numRoutes % 254
kelvin-onlabd3b64892015-01-20 13:26:24 -0800495 routesAdded = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700496 if numRoutes > 255:
497 numRoutes = 255
kelvin-onlabbbe46482015-01-16 10:44:28 -0800498 for m in range( 1, j + 1 ):
499 for n in range( 1, numRoutes + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800500 network = str( net ) + "." + str( m ) + "." + str( n ) \
501 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700502 routeCmd = "network " + network
503 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800504 self.handle.sendline( routeCmd )
505 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700506 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800507 main.log.warn( "failed to add route" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800508 self.disconnect()
509 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800510 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800511 routesAdded = routesAdded + 1
kelvin-onlabbbe46482015-01-16 10:44:28 -0800512 for d in range( j + 1, j + 2 ):
513 for e in range( 1, k + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800514 network = str( net ) + "." + str( d ) + "." + str( e ) \
515 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700516 routeCmd = "network " + network
517 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800518 self.handle.sendline( routeCmd )
519 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700520 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800521 main.log.warn( "failed to add route" )
pingping-lin763ee042015-05-20 17:45:30 -0700522 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800523 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800524 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800525 routesAdded = routesAdded + 1
526 if routesAdded == numRoutes:
timlindbergef8d55d2013-09-27 12:50:13 -0700527 return main.TRUE
528 return main.FALSE
pingping-lin0904ad02015-01-30 15:18:14 -0800529
pingping-lin4e7b0d32015-01-27 18:06:22 -0800530 # Please use deleteRoutes method instead of this one!
kelvin-onlabd3b64892015-01-20 13:26:24 -0800531 def delRoute( self, net, numRoutes, routeRate ):
timlindbergef8d55d2013-09-27 12:50:13 -0700532 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800533 self.handle.sendline( "" )
534 self.handle.expect( "config-router" )
pingping-lin763ee042015-05-20 17:45:30 -0700535 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800536 main.log.warn( "Probably not in config-router mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700537 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800538 main.log.info( "Deleting Routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800539 j = 0
540 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700541 while numRoutes > 255:
542 numRoutes = numRoutes - 255
543 j = j + 1
544 k = numRoutes % 254
kelvin-onlabd3b64892015-01-20 13:26:24 -0800545 routesDeleted = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700546 if numRoutes > 255:
547 numRoutes = 255
kelvin-onlabbbe46482015-01-16 10:44:28 -0800548 for m in range( 1, j + 1 ):
549 for n in range( 1, numRoutes + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800550 network = str( net ) + "." + str( m ) + "." + str( n ) \
551 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700552 routeCmd = "no network " + network
553 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800554 self.handle.sendline( routeCmd )
555 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700556 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800557 main.log.warn( "Failed to delete route" )
timlindbergef8d55d2013-09-27 12:50:13 -0700558 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800559 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800560 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800561 routesDeleted = routesDeleted + 1
kelvin-onlabbbe46482015-01-16 10:44:28 -0800562 for d in range( j + 1, j + 2 ):
563 for e in range( 1, k + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800564 network = str( net ) + "." + str( d ) + "." + str( e ) \
565 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700566 routeCmd = "no network " + network
567 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800568 self.handle.sendline( routeCmd )
569 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700570 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800571 main.log.warn( "Failed to delete route" )
timlindbergef8d55d2013-09-27 12:50:13 -0700572 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800573 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800574 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800575 routesDeleted = routesDeleted + 1
576 if routesDeleted == numRoutes:
timlindbergef8d55d2013-09-27 12:50:13 -0700577 return main.TRUE
578 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800579
kelvin-onlabd3b64892015-01-20 13:26:24 -0800580 def checkRoutes( self, brand, ip, user, pw ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800581 def pronto( ip, user, passwd ):
timlindbergef8d55d2013-09-27 12:50:13 -0700582 print "Connecting to Pronto switch"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800583 child = pexpect.spawn( "telnet " + ip )
584 i = child.expect( [ "login:", "CLI#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700585 if i == 0:
pingping-linc1c696e2015-01-27 13:46:44 -0800586 print "user_name and password required. Passing login info."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800587 child.sendline( user )
588 child.expect( "Password:" )
589 child.sendline( passwd )
590 child.expect( "CLI#" )
timlindbergef8d55d2013-09-27 12:50:13 -0700591 print "Logged in, getting flowtable."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800592 child.sendline( "flowtable brief" )
593 for t in range( 9 ):
timlindbergef8d55d2013-09-27 12:50:13 -0700594 t2 = 9 - t
kelvin-onlabbbe46482015-01-16 10:44:28 -0800595 print "\r" + str( t2 )
596 sys.stdout.write( "\033[F" )
597 time.sleep( 1 )
timlindbergef8d55d2013-09-27 12:50:13 -0700598 print "Scanning flowtable"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800599 child.expect( "Flow table show" )
timlindbergef8d55d2013-09-27 12:50:13 -0700600 count = 0
kelvin-onlabbbe46482015-01-16 10:44:28 -0800601 while True:
pingping-lin0904ad02015-01-30 15:18:14 -0800602 i = child.expect( [ '17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}',
pingping-lin4e7b0d32015-01-27 18:06:22 -0800603 'CLI#', pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700604 if i == 0:
605 count = count + 1
606 elif i == 1:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800607 print "Pronto flows: " + str( count ) + "\nDone\n"
timlindbergef8d55d2013-09-27 12:50:13 -0700608 break
609 else:
610 break
kelvin-onlabbbe46482015-01-16 10:44:28 -0800611
612 def cisco( ip, user, passwd ):
timlindbergef8d55d2013-09-27 12:50:13 -0700613 print "Establishing Cisco switch connection"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800614 child = pexpect.spawn( "ssh " + user + "@" + ip )
615 i = child.expect( [ "Password:", "CLI#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700616 if i == 0:
617 print "Password required. Passing now."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800618 child.sendline( passwd )
619 child.expect( "#" )
timlindbergef8d55d2013-09-27 12:50:13 -0700620 print "Logged in. Retrieving flow table then counting flows."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800621 child.sendline( "show openflow switch all flows all" )
622 child.expect( "Logical Openflow Switch" )
timlindbergef8d55d2013-09-27 12:50:13 -0700623 print "Flow table retrieved. Counting flows"
624 count = 0
kelvin-onlabbbe46482015-01-16 10:44:28 -0800625 while True:
626 i = child.expect( [ "nw_src=17", "#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700627 if i == 0:
628 count = count + 1
629 elif i == 1:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800630 print "Cisco flows: " + str( count ) + "\nDone\n"
timlindbergef8d55d2013-09-27 12:50:13 -0700631 break
632 else:
633 break
634 if brand == "pronto" or brand == "PRONTO":
kelvin-onlabbbe46482015-01-16 10:44:28 -0800635 pronto( ip, user, passwd )
pingping-linc6b86fa2014-12-01 16:18:10 -0800636 # elif brand == "cisco" or brand == "CISCO":
kelvin-onlabbbe46482015-01-16 10:44:28 -0800637 # cisco( ip,user,passwd )
638
pingping-lin763ee042015-05-20 17:45:30 -0700639 def disable_bgp_peer( self, peer, peer_as ):
640 main.log.info( "I am in disconnect_peer_session method!" )
641
642 try:
643 self.handle.sendline( "" )
644 # self.handle.expect( "config-router" )
645 self.handle.expect( "config-router", timeout=5 )
646 except Exception:
647 main.log.warn( "Probably not in config-router mode!" )
648 self.disconnect()
649 main.log.info( "Start to disable peer" )
650
651 cmd = "no neighbor " + peer + " remote-as " + peer_as
652 try:
653 self.handle.sendline( cmd )
654 self.handle.expect( "bgpd", timeout=5 )
655 except Exception:
656 main.log.warn( "Failed to disable peer" )
657 self.disconnect()
658
659 def enable_bgp_peer( self, peer, peer_as ):
660 main.log.info( "I am in enable_bgp_peer method!" )
661
662 try:
663 self.handle.sendline( "" )
664 # self.handle.expect( "config-router" )
665 self.handle.expect( "config-router", timeout=5 )
666 except Exception:
667 main.log.warn( "Probably not in config-router mode!" )
668 self.disconnect()
669 main.log.info( "Start to disable peer" )
670
671 cmd = "neighbor " + peer + " remote-as " + peer_as
672 try:
673 self.handle.sendline( cmd )
674 self.handle.expect( "bgpd", timeout=5 )
675 except Exception:
676 main.log.warn( "Failed to enable peer" )
677 self.disconnect()
678
kelvin-onlabbbe46482015-01-16 10:44:28 -0800679 def disconnect( self ):
680 """
681 Called when Test is complete to disconnect the Quagga handle.
682 """
timlindbergef8d55d2013-09-27 12:50:13 -0700683 response = ''
684 try:
685 self.handle.close()
pingping-lin763ee042015-05-20 17:45:30 -0700686 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800687 main.log.error( "Connection failed to the host" )
timlindbergef8d55d2013-09-27 12:50:13 -0700688 response = main.FALSE
689 return response
pingping-linc1c696e2015-01-27 13:46:44 -0800690