blob: e1cbeef801ed7ed1e891e6eff84c065e6be09f04 [file] [log] [blame]
timlindbergef8d55d2013-09-27 12:50:13 -07001#!/usr/bin/env python
Jeremy Songsterae01bba2016-07-11 15:39:17 -07002"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003Copyright 2015 Open Networking Foundation (ONF)
Jeremy Songsterae01bba2016-07-11 15:39:17 -07004
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>
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07008
9 TestON is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 2 of the License, or
12 (at your option) any later version.
13
14 TestON is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with TestON. If not, see <http://www.gnu.org/licenses/>.
Jeremy Songsterae01bba2016-07-11 15:39:17 -070021"""
timlindbergef8d55d2013-09-27 12:50:13 -070022
23import time
24import pexpect
kelvin-onlabbbe46482015-01-16 10:44:28 -080025import sys
timlindbergef8d55d2013-09-27 12:50:13 -070026import json
timlindbergef8d55d2013-09-27 12:50:13 -070027from drivers.common.clidriver import CLI
28
timlindbergef8d55d2013-09-27 12:50:13 -070029
kelvin-onlabbbe46482015-01-16 10:44:28 -080030class QuaggaCliDriver( CLI ):
31
32 def __init__( self ):
Devin Limdc78e202017-06-09 18:30:07 -070033 super( QuaggaCliDriver, self ).__init__()
timlindbergef8d55d2013-09-27 12:50:13 -070034
pingping-linc6b86fa2014-12-01 16:18:10 -080035 # TODO: simplify this method
kelvin-onlabbbe46482015-01-16 10:44:28 -080036 def connect( self, **connectargs ):
timlindbergef8d55d2013-09-27 12:50:13 -070037 for key in connectargs:
kelvin-onlabbbe46482015-01-16 10:44:28 -080038 vars( self )[ key ] = connectargs[ key ]
pingping-lin763ee042015-05-20 17:45:30 -070039 self.name = self.options[ 'name' ]
40 self.handle = super( QuaggaCliDriver, self ).connect(
41 user_name=self.user_name,
42 ip_address="127.0.0.1",
43 port=self.port,
44 pwd=self.pwd )
45 if self.handle:
46 return self.handle
47 else:
48 main.log.info( "NO HANDLE" )
49 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -080050
pingping-lin763ee042015-05-20 17:45:30 -070051 def connectQuagga( self ):
kelvin-onlabbbe46482015-01-16 10:44:28 -080052 self.name = self.options[ 'name' ]
53 # self.handle = super( QuaggaCliDriver,self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080054 # user_name=self.user_name, ip_address=self.ip_address,port=self.port,
kelvin-onlabbbe46482015-01-16 10:44:28 -080055 # pwd=self.pwd )
pingping-lin4e7b0d32015-01-27 18:06:22 -080056 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080057 user_name=self.user_name,
58 ip_address="1.1.1.1",
59 port=self.port,
60 pwd=self.pwd )
pingping-lina600d9b2015-01-30 13:57:26 -080061 #main.log.info( "connect parameters:" + str( self.user_name ) + ";"
62 # + str( self.ip_address ) + ";" + str( self.port )
63 # + ";" + str(self.pwd ) )
timlindbergef8d55d2013-09-27 12:50:13 -070064
pingping-linc6b86fa2014-12-01 16:18:10 -080065 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -080066 # self.handle.expect( "",timeout=10 )
Devin Limdc78e202017-06-09 18:30:07 -070067 # self.handle.expect( self.prompt,timeout=10 )
kelvin-onlabbbe46482015-01-16 10:44:28 -080068 self.handle.sendline( "telnet localhost 2605" )
69 # self.handle.expect( "Password:", timeout=5 )
70 self.handle.expect( "Password:" )
71 self.handle.sendline( "hello" )
72 # self.handle.expect( "bgpd", timeout=5 )
73 self.handle.expect( "bgpd" )
74 self.handle.sendline( "enable" )
75 # self.handle.expect( "bgpd#", timeout=5 )
76 self.handle.expect( "bgpd#" )
timlindbergef8d55d2013-09-27 12:50:13 -070077 return self.handle
kelvin-onlabbbe46482015-01-16 10:44:28 -080078 else:
79 main.log.info( "NO HANDLE" )
timlindbergef8d55d2013-09-27 12:50:13 -070080 return main.FALSE
81
pingping-linc1c696e2015-01-27 13:46:44 -080082 def loginQuagga( self, ip_address ):
kelvin-onlabbbe46482015-01-16 10:44:28 -080083 self.name = self.options[ 'name' ]
84 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080085 user_name=self.user_name, ip_address=ip_address,
kelvin-onlabbbe46482015-01-16 10:44:28 -080086 port=self.port, pwd=self.pwd )
pingping-linc1c696e2015-01-27 13:46:44 -080087 main.log.info( "connect parameters:" + str( self.user_name ) + ";"
pingping-lin4e7b0d32015-01-27 18:06:22 -080088 + str( self.ip_address ) + ";" + str( self.port )
89 + ";" + str( self.pwd ) )
pingping-lin8b306ac2014-11-17 18:13:51 -080090
91 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -080092 # self.handle.expect( "" )
Devin Limdc78e202017-06-09 18:30:07 -070093 # self.handle.expect( self.prompt )
kelvin-onlabbbe46482015-01-16 10:44:28 -080094 self.handle.sendline( "telnet localhost 2605" )
95 # self.handle.expect( "Password:", timeout=5 )
96 self.handle.expect( "Password:" )
97 self.handle.sendline( "hello" )
98 # self.handle.expect( "bgpd", timeout=5 )
99 self.handle.expect( "bgpd" )
100 self.handle.sendline( "enable" )
101 # self.handle.expect( "bgpd#", timeout=5 )
102 self.handle.expect( "bgpd#" )
pingping-linc1c696e2015-01-27 13:46:44 -0800103 main.log.info( "I am in quagga on host " + str( ip_address ) )
pingping-lin8b306ac2014-11-17 18:13:51 -0800104
105 return self.handle
106 else:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800107 main.log.info( "NO HANDLE" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800108 return main.FALSE
109
kelvin-onlabd3b64892015-01-20 13:26:24 -0800110 def enterConfig( self, asn ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800111 main.log.info( "I am in enter_config method!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700112 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800113 self.handle.sendline( "" )
114 self.handle.expect( "bgpd#" )
pingping-lin763ee042015-05-20 17:45:30 -0700115 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800116 main.log.warn( "Probably not currently in enable mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700117 self.disconnect()
118 return main.FALSE
kelvin-onlabbbe46482015-01-16 10:44:28 -0800119 self.handle.sendline( "configure terminal" )
120 self.handle.expect( "config", timeout=5 )
121 routerAS = "router bgp " + str( asn )
timlindbergef8d55d2013-09-27 12:50:13 -0700122 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800123 self.handle.sendline( routerAS )
124 self.handle.expect( "config-router", timeout=5 )
timlindbergef8d55d2013-09-27 12:50:13 -0700125 return main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -0700126 except Exception:
timlindbergef8d55d2013-09-27 12:50:13 -0700127 return main.FALSE
pingping-lin8b306ac2014-11-17 18:13:51 -0800128
kelvin-onlabd3b64892015-01-20 13:26:24 -0800129 def generatePrefixes( self, net, numRoutes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800130 main.log.info( "I am in generate_prefixes method!" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800131
pingping-lin4e7b0d32015-01-27 18:06:22 -0800132 # each IP prefix is composed by "net" + "." + m + "." + n + "." + x
pingping-lin8b306ac2014-11-17 18:13:51 -0800133 # the length of each IP prefix is 24
134 routes = []
kelvin-onlabd3b64892015-01-20 13:26:24 -0800135 routesGen = 0
pingping-lin8b306ac2014-11-17 18:13:51 -0800136 m = numRoutes / 256
137 n = numRoutes % 256
138
kelvin-onlabbbe46482015-01-16 10:44:28 -0800139 for i in range( 0, m ):
140 for j in range( 0, 256 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800141 network = str( net ) + "." + str( i ) + "." + str( j ) \
142 + ".0/24"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800143 routes.append( network )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800144 routesGen = routesGen + 1
pingping-lin8b306ac2014-11-17 18:13:51 -0800145
kelvin-onlabbbe46482015-01-16 10:44:28 -0800146 for j in range( 0, n ):
147 network = str( net ) + "." + str( m ) + "." + str( j ) + ".0/24"
148 routes.append( network )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800149 routesGen = routesGen + 1
pingping-lin8b306ac2014-11-17 18:13:51 -0800150
kelvin-onlabd3b64892015-01-20 13:26:24 -0800151 if routesGen == numRoutes:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800152 main.log.info( "Successfully generated " + str( numRoutes )
153 + " prefixes!" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800154 return routes
155 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800156
kelvin-onlabbbe46482015-01-16 10:44:28 -0800157 # This method generates a multiple to single point intent(
158 # MultiPointToSinglePointIntent ) for a given route
pingping-lin4e7b0d32015-01-27 18:06:22 -0800159 def generateExpectedSingleRouteIntent( self, prefix, nextHop, nextHopMac,
160 sdnipData ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800161
pingping-linc1c696e2015-01-27 13:46:44 -0800162 ingresses = []
pingping-lin6f6332e2014-11-19 19:13:58 -0800163 egress = ""
kelvin-onlabd3b64892015-01-20 13:26:24 -0800164 for peer in sdnipData[ 'bgpPeers' ]:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800165 if peer[ 'ipAddress' ] == nextHop:
pingping-linc1c696e2015-01-27 13:46:44 -0800166 egress = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800167 peer[ 'attachmentDpid' ] ).replace( ":", "" ) + ":" \
168 + str( peer[ 'attachmentPort' ] )
pingping-linc1c696e2015-01-27 13:46:44 -0800169 for peer in sdnipData[ 'bgpPeers' ]:
170 if not peer[ 'ipAddress' ] == nextHop:
171 ingress = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800172 peer[ 'attachmentDpid' ] ).replace( ":", "" ) + ":" \
173 + str( peer[ 'attachmentPort' ] )
pingping-linc1c696e2015-01-27 13:46:44 -0800174 if not ingress == egress and ingress not in ingresses:
175 ingresses.append( ingress )
176 # ingresses.append( "of:" + str( peer[ 'attachmentDpid' ]
177 # ).replace( ":", "" ) + ":" + str( peer[ 'attachmentPort'
178 # ] ) )
pingping-lin6f6332e2014-11-19 19:13:58 -0800179
pingping-linc6b86fa2014-12-01 16:18:10 -0800180 selector = "ETH_TYPE{ethType=800},IPV4_DST{ip=" + prefix + "}"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800181 treatment = "[ETH_DST{mac=" + str( nextHopMac ) + "}]"
pingping-lin6f6332e2014-11-19 19:13:58 -0800182
pingping-lin4e7b0d32015-01-27 18:06:22 -0800183 intent = egress + "/" + str( sorted( ingresses ) ) + "/" + \
184 selector + "/" + treatment
pingping-lin6f6332e2014-11-19 19:13:58 -0800185 return intent
186
pingping-lin4e7b0d32015-01-27 18:06:22 -0800187 def generateExpectedOnePeerRouteIntents( self, prefixes, nextHop,
188 nextHopMac, sdnipJsonFilePath ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800189 intents = []
kelvin-onlabd3b64892015-01-20 13:26:24 -0800190 sdnipJsonFile = open( sdnipJsonFilePath ).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800191
kelvin-onlabd3b64892015-01-20 13:26:24 -0800192 sdnipData = json.loads( sdnipJsonFile )
pingping-lin6f6332e2014-11-19 19:13:58 -0800193
194 for prefix in prefixes:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800195 intents.append(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800196 self.generateExpectedSingleRouteIntent(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800197 prefix, nextHop, nextHopMac, sdnipData ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800198 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800199
200 # TODO
201 # This method generates all expected route intents for all BGP peers
kelvin-onlabd3b64892015-01-20 13:26:24 -0800202 def generateExpectedRouteIntents( self ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800203 intents = []
204 return intents
205
206 # This method extracts all actual routes from ONOS CLI
pingping-linb2a86582015-02-02 16:18:59 -0800207 def extractActualRoutesOneDotZero( self, getRoutesResult ):
kelvin-onlabd3b64892015-01-20 13:26:24 -0800208 routesJsonObj = json.loads( getRoutesResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800209
kelvin-onlabd3b64892015-01-20 13:26:24 -0800210 allRoutesActual = []
pingping-lin763ee042015-05-20 17:45:30 -0700211 for route in routesJsonObj['routes4']:
212 if 'prefix' in route:
213 if route[ 'prefix' ] == '172.16.10.0/24':
214 continue
215 allRoutesActual.append(
216 route[ 'prefix' ] + "/" + route[ 'nextHop' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800217
kelvin-onlabd3b64892015-01-20 13:26:24 -0800218 return sorted( allRoutesActual )
pingping-linb2a86582015-02-02 16:18:59 -0800219
220 def extractActualRoutesMaster( self, getRoutesResult ):
pingping-lina600d9b2015-01-30 13:57:26 -0800221 routesJsonObj = json.loads( getRoutesResult )
222
223 allRoutesActual = []
224 for route in routesJsonObj['routes4']:
225 if route[ 'prefix' ] == '172.16.10.0/24':
226 continue
227 allRoutesActual.append(
228 route[ 'prefix' ] + "/" + route[ 'nextHop' ] )
229
230 return sorted( allRoutesActual )
pingping-lin6f6332e2014-11-19 19:13:58 -0800231
232 # This method extracts all actual route intents from ONOS CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800233 def extractActualRouteIntents( self, getIntentsResult ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800234 intents = []
235 # TODO: delete the line below when change to Mininet demo script
kelvin-onlabd3b64892015-01-20 13:26:24 -0800236 # getIntentsResult=open( "../tests/SdnIpTest/intents.json" ).read()
237 intentsJsonObj = json.loads( getIntentsResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800238
kelvin-onlabd3b64892015-01-20 13:26:24 -0800239 for intent in intentsJsonObj:
pingping-linf30cf272015-05-29 15:54:07 -0700240 #if intent[ 'appId' ] != "org.onosproject.sdnip":
241 # continue
pingping-lin4e7b0d32015-01-27 18:06:22 -0800242 if intent[ 'type' ] == "MultiPointToSinglePointIntent" \
243 and intent[ 'state' ] == 'INSTALLED':
244 egress = str( intent[ 'egress' ][ 'device' ] ) + ":" \
245 + str( intent[ 'egress' ][ 'port' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800246 ingress = []
kelvin-onlabbbe46482015-01-16 10:44:28 -0800247 for attachmentPoint in intent[ 'ingress' ]:
pingping-linc1c696e2015-01-27 13:46:44 -0800248 ingress.append(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800249 str( attachmentPoint[ 'device' ] ) + ":"
250 + str( attachmentPoint[ 'port' ] ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800251
kelvin-onlabbbe46482015-01-16 10:44:28 -0800252 selector = intent[ 'selector' ].replace(
253 "[", "" ).replace( "]", "" ).replace( " ", "" )
254 if str( selector ).startswith( "IPV4" ):
255 str1, str2 = str( selector ).split( "," )
pingping-linc6b86fa2014-12-01 16:18:10 -0800256 selector = str2 + "," + str1
257
pingping-lin4e7b0d32015-01-27 18:06:22 -0800258 intent = egress + "/" + str( sorted( ingress ) ) + "/" + \
259 selector + "/" + intent[ 'treatment' ]
kelvin-onlabbbe46482015-01-16 10:44:28 -0800260 intents.append( intent )
261 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800262
pingping-linf30cf272015-05-29 15:54:07 -0700263 # This method calculates the MultiPointToSinglePointIntent number installed
264 def extractActualRouteIntentNum( self, getIntentsResult ):
265 intentsJsonObj = json.loads( getIntentsResult )
266 num = 0
267 for intent in intentsJsonObj:
268 if intent[ 'type' ] == "MultiPointToSinglePointIntent" \
269 and intent[ 'state' ] == 'INSTALLED':
270 num = num + 1
271 return num
272
273 # This method calculates the PointToPointIntent number installed
274 def extractActualBgpIntentNum( self, getIntentsResult ):
275 intentsJsonObj = json.loads( getIntentsResult )
276 num = 0
277 for intent in intentsJsonObj:
278 if intent[ 'type' ] == "PointToPointIntent" \
279 and intent[ 'state' ] == 'INSTALLED':
280 num = num + 1
281 return num
282
pingping-lin6f6332e2014-11-19 19:13:58 -0800283 # This method extracts all actual BGP intents from ONOS CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800284 def extractActualBgpIntents( self, getIntentsResult ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800285 intents = []
286 # TODO: delete the line below when change to Mininet demo script
kelvin-onlabd3b64892015-01-20 13:26:24 -0800287 # getIntentsResult=open( "../tests/SdnIpTest/intents.json" ).read()
288 intentsJsonObj = json.loads( getIntentsResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800289
kelvin-onlabd3b64892015-01-20 13:26:24 -0800290 for intent in intentsJsonObj:
pingping-linf30cf272015-05-29 15:54:07 -0700291 #if intent[ 'appId' ] != "org.onosproject.sdnip":
292 # continue
pingping-lin4e7b0d32015-01-27 18:06:22 -0800293 if intent[ 'type' ] == "PointToPointIntent" \
294 and "protocol=6" in str( intent[ 'selector' ] ):
295 ingress = str( intent[ 'ingress' ][ 'device' ] ) + ":" \
296 + str( intent[ 'ingress' ][ 'port' ] )
297 egress = str( intent[ 'egress' ][ 'device' ] ) + ":" + \
298 str( intent[ 'egress' ][ 'port' ] )
299 selector = str( intent[ 'selector' ] ).replace( " ", "" )\
300 .replace( "[", "" ).replace( "]", "" ).split( "," )
301 intent = ingress + "/" + egress + "/" + \
302 str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800303 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800304
kelvin-onlabbbe46482015-01-16 10:44:28 -0800305 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800306
kelvin-onlabbbe46482015-01-16 10:44:28 -0800307 # This method generates a single point to single point intent(
308 # PointToPointIntent ) for BGP path
kelvin-onlabd3b64892015-01-20 13:26:24 -0800309 def generateExpectedBgpIntents( self, sdnipJsonFilePath ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800310 from operator import eq
311
kelvin-onlabd3b64892015-01-20 13:26:24 -0800312 sdnipJsonFile = open( sdnipJsonFilePath ).read()
313 sdnipData = json.loads( sdnipJsonFile )
pingping-lin6f6332e2014-11-19 19:13:58 -0800314
315 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800316 bgpPeerAttachmentPoint = ""
kelvin-onlabbbe46482015-01-16 10:44:28 -0800317 bgpSpeakerAttachmentPoint = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800318 sdnipData[ 'bgpSpeakers' ][ 0 ][ 'attachmentDpid' ] )\
319 .replace( ":", "" ) + ":" \
320 + str( sdnipData[ 'bgpSpeakers' ][ 0 ][ 'attachmentPort' ] )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800321 for peer in sdnipData[ 'bgpPeers' ]:
pingping-lin4e7b0d32015-01-27 18:06:22 -0800322 bgpPeerAttachmentPoint = "of:" \
323 + str( peer[ 'attachmentDpid' ] ).replace( ":", "" ) \
324 + ":" + str( peer[ 'attachmentPort' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800325 # find out the BGP speaker IP address for this BGP peer
pingping-linc6b86fa2014-12-01 16:18:10 -0800326 bgpSpeakerIpAddress = ""
pingping-lin4e7b0d32015-01-27 18:06:22 -0800327 for interfaceAddress in \
328 sdnipData[ 'bgpSpeakers' ][ 0 ][ 'interfaceAddresses' ]:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800329 # if eq( interfaceAddress[ 'interfaceDpid' ],sdnipData[
kelvin-onlabbbe46482015-01-16 10:44:28 -0800330 # 'bgpSpeakers' ][ 0 ][ 'attachmentDpid' ] ) and eq(
pingping-linc1c696e2015-01-27 13:46:44 -0800331 # interfaceAddress[ 'interfacePort' ], sdnipData[ 'bgpSpeakers'
332 # ][ 0 ][ 'attachmentPort' ] ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800333 if eq( interfaceAddress[ 'interfaceDpid' ],
334 peer[ 'attachmentDpid' ] ) \
335 and eq( interfaceAddress[ 'interfacePort' ],
336 peer[ 'attachmentPort' ] ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800337 bgpSpeakerIpAddress = interfaceAddress[ 'ipAddress' ]
pingping-lin6f6332e2014-11-19 19:13:58 -0800338 break
339 else:
340 continue
341
kelvin-onlabbbe46482015-01-16 10:44:28 -0800342 # from bgpSpeakerAttachmentPoint to bgpPeerAttachmentPoint
343 # direction
pingping-lin4e7b0d32015-01-27 18:06:22 -0800344 selectorStr = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," \
345 + "IPV4_DST{ip=" + peer[ 'ipAddress' ] + "/32}," \
346 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
347 TCP_DST{tcpPort=179}"
348 selector = selectorStr.replace( " ", "" ).replace("[", "" )\
349 .replace( "]", "" ).split( "," )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800350 intent = bgpSpeakerAttachmentPoint + "/" + \
351 bgpPeerAttachmentPoint + "/" + str( sorted( selector ) )
352 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800353
pingping-lin4e7b0d32015-01-27 18:06:22 -0800354 selectorStr = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," \
355 + "IPV4_DST{ip=" + peer[ 'ipAddress' ] + "/32}," \
356 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
357 TCP_SRC{tcpPort=179}"
358 selector = selectorStr.replace( " ", "" ).replace("[", "" )\
359 .replace( "]", "" ).split( "," )
360 intent = bgpSpeakerAttachmentPoint + "/" \
361 + bgpPeerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800362 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800363
kelvin-onlabbbe46482015-01-16 10:44:28 -0800364 # from bgpPeerAttachmentPoint to bgpSpeakerAttachmentPoint
365 # direction
pingping-lin4e7b0d32015-01-27 18:06:22 -0800366 selectorStr = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," \
367 + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," \
368 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
369 TCP_DST{tcpPort=179}"
370 selector = selectorStr.replace( " ", "" ).replace("[", "" )\
371 .replace( "]", "" ).split( "," )
372 intent = bgpPeerAttachmentPoint + "/" \
373 + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800374 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800375
pingping-lin4e7b0d32015-01-27 18:06:22 -0800376 selectorStr = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," \
377 + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," \
378 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
379 TCP_SRC{tcpPort=179}"
380 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
381 .replace( "]", "" ).split( "," )
382 intent = bgpPeerAttachmentPoint + "/" \
383 + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800384 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800385
kelvin-onlabbbe46482015-01-16 10:44:28 -0800386 return sorted( intents )
pingping-linc6b86fa2014-12-01 16:18:10 -0800387
kelvin-onlabd3b64892015-01-20 13:26:24 -0800388 def addRoutes( self, routes, routeRate ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800389 main.log.info( "I am in add_routes method!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800390
kelvin-onlabd3b64892015-01-20 13:26:24 -0800391 routesAdded = 0
pingping-lin8b306ac2014-11-17 18:13:51 -0800392 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800393 self.handle.sendline( "" )
394 # self.handle.expect( "config-router" )
395 self.handle.expect( "config-router", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700396 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800397 main.log.warn( "Probably not in config-router mode!" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800398 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800399 main.log.info( "Start to add routes" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800400
pingping-lin763ee042015-05-20 17:45:30 -0700401 chunk_size = 20
402
403 if len(routes) > chunk_size:
Jon Hall4ba53f02015-07-29 13:07:41 -0700404 num_iter = (int) (len(routes) / chunk_size)
pingping-lin763ee042015-05-20 17:45:30 -0700405 else:
406 num_iter = 1;
407
408 total = 0
409 for n in range( 0, num_iter + 1):
410 routeCmd = ""
411 if (len( routes ) - (n * chunk_size)) >= chunk_size:
412 m = (n + 1) * chunk_size
413 else:
414 m = len( routes )
415 for i in range( n * chunk_size, m ):
416 routeCmd = routeCmd + "network " + routes[ i ] + "\n"
417 total = total + 1
418
419 main.log.info(routeCmd)
pingping-lin8b306ac2014-11-17 18:13:51 -0800420 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800421 self.handle.sendline( routeCmd )
422 self.handle.expect( "bgpd", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700423 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800424 main.log.warn( "Failed to add route" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800425 self.disconnect()
Jon Hall4ba53f02015-07-29 13:07:41 -0700426
pingping-linc1c696e2015-01-27 13:46:44 -0800427 # waitTimer = 1.00 / routeRate
pingping-lin763ee042015-05-20 17:45:30 -0700428 main.log.info("Total routes so far " + ((str) (total)) + " wait for 0 sec")
429 #time.sleep( 1 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800430 if routesAdded == len( routes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800431 main.log.info( "Finished adding routes" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800432 return main.TRUE
433 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800434
kelvin-onlabd3b64892015-01-20 13:26:24 -0800435 def deleteRoutes( self, routes, routeRate ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800436 main.log.info( "I am in delete_routes method!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800437
kelvin-onlabd3b64892015-01-20 13:26:24 -0800438 routesAdded = 0
pingping-linc6b86fa2014-12-01 16:18:10 -0800439 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800440 self.handle.sendline( "" )
441 # self.handle.expect( "config-router" )
442 self.handle.expect( "config-router", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700443 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800444 main.log.warn( "Probably not in config-router mode!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800445 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800446 main.log.info( "Start to delete routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800447
kelvin-onlabbbe46482015-01-16 10:44:28 -0800448 for i in range( 0, len( routes ) ):
449 routeCmd = "no network " + routes[ i ]
pingping-linc6b86fa2014-12-01 16:18:10 -0800450 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800451 self.handle.sendline( routeCmd )
452 self.handle.expect( "bgpd", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700453 except Exception:
pingping-lin4e7b0d32015-01-27 18:06:22 -0800454 main.log.warn( "Failed to delete route" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800455 self.disconnect()
pingping-linc1c696e2015-01-27 13:46:44 -0800456 # waitTimer = 1.00 / routeRate
457 # time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800458 if routesAdded == len( routes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800459 main.log.info( "Finished deleting routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800460 return main.TRUE
461 return main.FALSE
462
pingping-linc1c696e2015-01-27 13:46:44 -0800463 def pingTest( self, ip_address, pingTestFile, pingTestResultFile ):
464 main.log.info( "Start the ping test on host:" + str( ip_address ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800465
kelvin-onlabbbe46482015-01-16 10:44:28 -0800466 self.name = self.options[ 'name' ]
467 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -0800468 user_name=self.user_name, ip_address=ip_address,
kelvin-onlabbbe46482015-01-16 10:44:28 -0800469 port=self.port, pwd=self.pwd )
pingping-linc1c696e2015-01-27 13:46:44 -0800470 main.log.info( "connect parameters:" + str( self.user_name ) + ";"
pingping-lin4e7b0d32015-01-27 18:06:22 -0800471 + str( self.ip_address ) + ";" + str( self.port )
472 + ";" + str( self.pwd ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800473
474 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800475 # self.handle.expect( "" )
Devin Limdc78e202017-06-09 18:30:07 -0700476 # self.handle.expect( self.prompt )
pingping-linc1c696e2015-01-27 13:46:44 -0800477 main.log.info( "I in host " + str( ip_address ) )
478 main.log.info( pingTestFile + " > " + pingTestResultFile + " &" )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800479 self.handle.sendline(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800480 pingTestFile +
kelvin-onlabbbe46482015-01-16 10:44:28 -0800481 " > " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800482 pingTestResultFile +
kelvin-onlabbbe46482015-01-16 10:44:28 -0800483 " &" )
Devin Limdc78e202017-06-09 18:30:07 -0700484 self.handle.expect( self.prompt, timeout=60 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800485 handle = self.handle.before
486
487 return handle
488 else:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800489 main.log.info( "NO HANDLE" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800490 return main.FALSE
491
pingping-lin763ee042015-05-20 17:45:30 -0700492
pingping-lin4e7b0d32015-01-27 18:06:22 -0800493 # Please use the generateRoutes plus addRoutes instead of this one!
kelvin-onlabd3b64892015-01-20 13:26:24 -0800494 def addRoute( self, net, numRoutes, routeRate ):
timlindbergef8d55d2013-09-27 12:50:13 -0700495 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800496 self.handle.sendline( "" )
497 self.handle.expect( "config-router" )
pingping-lin763ee042015-05-20 17:45:30 -0700498 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800499 main.log.warn( "Probably not in config-router mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700500 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800501 main.log.info( "Adding Routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800502 j = 0
503 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700504 while numRoutes > 255:
505 numRoutes = numRoutes - 255
506 j = j + 1
507 k = numRoutes % 254
kelvin-onlabd3b64892015-01-20 13:26:24 -0800508 routesAdded = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700509 if numRoutes > 255:
510 numRoutes = 255
kelvin-onlabbbe46482015-01-16 10:44:28 -0800511 for m in range( 1, j + 1 ):
512 for n in range( 1, numRoutes + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800513 network = str( net ) + "." + str( m ) + "." + str( n ) \
514 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700515 routeCmd = "network " + network
516 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800517 self.handle.sendline( routeCmd )
518 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700519 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800520 main.log.warn( "failed to add route" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800521 self.disconnect()
522 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800523 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800524 routesAdded = routesAdded + 1
kelvin-onlabbbe46482015-01-16 10:44:28 -0800525 for d in range( j + 1, j + 2 ):
526 for e in range( 1, k + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800527 network = str( net ) + "." + str( d ) + "." + str( e ) \
528 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700529 routeCmd = "network " + network
530 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800531 self.handle.sendline( routeCmd )
532 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700533 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800534 main.log.warn( "failed to add route" )
pingping-lin763ee042015-05-20 17:45:30 -0700535 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800536 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800537 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800538 routesAdded = routesAdded + 1
539 if routesAdded == numRoutes:
timlindbergef8d55d2013-09-27 12:50:13 -0700540 return main.TRUE
541 return main.FALSE
pingping-lin0904ad02015-01-30 15:18:14 -0800542
pingping-lin4e7b0d32015-01-27 18:06:22 -0800543 # Please use deleteRoutes method instead of this one!
kelvin-onlabd3b64892015-01-20 13:26:24 -0800544 def delRoute( self, net, numRoutes, routeRate ):
timlindbergef8d55d2013-09-27 12:50:13 -0700545 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800546 self.handle.sendline( "" )
547 self.handle.expect( "config-router" )
pingping-lin763ee042015-05-20 17:45:30 -0700548 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800549 main.log.warn( "Probably not in config-router mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700550 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800551 main.log.info( "Deleting Routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800552 j = 0
553 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700554 while numRoutes > 255:
555 numRoutes = numRoutes - 255
556 j = j + 1
557 k = numRoutes % 254
kelvin-onlabd3b64892015-01-20 13:26:24 -0800558 routesDeleted = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700559 if numRoutes > 255:
560 numRoutes = 255
kelvin-onlabbbe46482015-01-16 10:44:28 -0800561 for m in range( 1, j + 1 ):
562 for n in range( 1, numRoutes + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800563 network = str( net ) + "." + str( m ) + "." + str( n ) \
564 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700565 routeCmd = "no network " + network
566 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800567 self.handle.sendline( routeCmd )
568 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700569 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800570 main.log.warn( "Failed to delete route" )
timlindbergef8d55d2013-09-27 12:50:13 -0700571 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800572 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800573 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800574 routesDeleted = routesDeleted + 1
kelvin-onlabbbe46482015-01-16 10:44:28 -0800575 for d in range( j + 1, j + 2 ):
576 for e in range( 1, k + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800577 network = str( net ) + "." + str( d ) + "." + str( e ) \
578 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700579 routeCmd = "no network " + network
580 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800581 self.handle.sendline( routeCmd )
582 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700583 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800584 main.log.warn( "Failed to delete route" )
timlindbergef8d55d2013-09-27 12:50:13 -0700585 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800586 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800587 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800588 routesDeleted = routesDeleted + 1
589 if routesDeleted == numRoutes:
timlindbergef8d55d2013-09-27 12:50:13 -0700590 return main.TRUE
591 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800592
kelvin-onlabd3b64892015-01-20 13:26:24 -0800593 def checkRoutes( self, brand, ip, user, pw ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800594 def pronto( ip, user, passwd ):
timlindbergef8d55d2013-09-27 12:50:13 -0700595 print "Connecting to Pronto switch"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800596 child = pexpect.spawn( "telnet " + ip )
597 i = child.expect( [ "login:", "CLI#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700598 if i == 0:
pingping-linc1c696e2015-01-27 13:46:44 -0800599 print "user_name and password required. Passing login info."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800600 child.sendline( user )
601 child.expect( "Password:" )
602 child.sendline( passwd )
603 child.expect( "CLI#" )
timlindbergef8d55d2013-09-27 12:50:13 -0700604 print "Logged in, getting flowtable."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800605 child.sendline( "flowtable brief" )
606 for t in range( 9 ):
timlindbergef8d55d2013-09-27 12:50:13 -0700607 t2 = 9 - t
kelvin-onlabbbe46482015-01-16 10:44:28 -0800608 print "\r" + str( t2 )
609 sys.stdout.write( "\033[F" )
610 time.sleep( 1 )
timlindbergef8d55d2013-09-27 12:50:13 -0700611 print "Scanning flowtable"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800612 child.expect( "Flow table show" )
timlindbergef8d55d2013-09-27 12:50:13 -0700613 count = 0
kelvin-onlabbbe46482015-01-16 10:44:28 -0800614 while True:
pingping-lin0904ad02015-01-30 15:18:14 -0800615 i = child.expect( [ '17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}',
pingping-lin4e7b0d32015-01-27 18:06:22 -0800616 'CLI#', pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700617 if i == 0:
618 count = count + 1
619 elif i == 1:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800620 print "Pronto flows: " + str( count ) + "\nDone\n"
timlindbergef8d55d2013-09-27 12:50:13 -0700621 break
622 else:
623 break
kelvin-onlabbbe46482015-01-16 10:44:28 -0800624
625 def cisco( ip, user, passwd ):
timlindbergef8d55d2013-09-27 12:50:13 -0700626 print "Establishing Cisco switch connection"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800627 child = pexpect.spawn( "ssh " + user + "@" + ip )
628 i = child.expect( [ "Password:", "CLI#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700629 if i == 0:
630 print "Password required. Passing now."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800631 child.sendline( passwd )
632 child.expect( "#" )
timlindbergef8d55d2013-09-27 12:50:13 -0700633 print "Logged in. Retrieving flow table then counting flows."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800634 child.sendline( "show openflow switch all flows all" )
635 child.expect( "Logical Openflow Switch" )
timlindbergef8d55d2013-09-27 12:50:13 -0700636 print "Flow table retrieved. Counting flows"
637 count = 0
kelvin-onlabbbe46482015-01-16 10:44:28 -0800638 while True:
639 i = child.expect( [ "nw_src=17", "#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700640 if i == 0:
641 count = count + 1
642 elif i == 1:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800643 print "Cisco flows: " + str( count ) + "\nDone\n"
timlindbergef8d55d2013-09-27 12:50:13 -0700644 break
645 else:
646 break
647 if brand == "pronto" or brand == "PRONTO":
kelvin-onlabbbe46482015-01-16 10:44:28 -0800648 pronto( ip, user, passwd )
pingping-linc6b86fa2014-12-01 16:18:10 -0800649 # elif brand == "cisco" or brand == "CISCO":
kelvin-onlabbbe46482015-01-16 10:44:28 -0800650 # cisco( ip,user,passwd )
651
pingping-lin763ee042015-05-20 17:45:30 -0700652 def disable_bgp_peer( self, peer, peer_as ):
653 main.log.info( "I am in disconnect_peer_session method!" )
654
655 try:
656 self.handle.sendline( "" )
657 # self.handle.expect( "config-router" )
658 self.handle.expect( "config-router", timeout=5 )
659 except Exception:
660 main.log.warn( "Probably not in config-router mode!" )
661 self.disconnect()
662 main.log.info( "Start to disable peer" )
663
664 cmd = "no neighbor " + peer + " remote-as " + peer_as
665 try:
666 self.handle.sendline( cmd )
667 self.handle.expect( "bgpd", timeout=5 )
668 except Exception:
669 main.log.warn( "Failed to disable peer" )
670 self.disconnect()
671
672 def enable_bgp_peer( self, peer, peer_as ):
673 main.log.info( "I am in enable_bgp_peer method!" )
674
675 try:
676 self.handle.sendline( "" )
677 # self.handle.expect( "config-router" )
678 self.handle.expect( "config-router", timeout=5 )
679 except Exception:
680 main.log.warn( "Probably not in config-router mode!" )
681 self.disconnect()
682 main.log.info( "Start to disable peer" )
683
684 cmd = "neighbor " + peer + " remote-as " + peer_as
685 try:
686 self.handle.sendline( cmd )
687 self.handle.expect( "bgpd", timeout=5 )
688 except Exception:
689 main.log.warn( "Failed to enable peer" )
690 self.disconnect()
691
kelvin-onlabbbe46482015-01-16 10:44:28 -0800692 def disconnect( self ):
693 """
694 Called when Test is complete to disconnect the Quagga handle.
695 """
timlindbergef8d55d2013-09-27 12:50:13 -0700696 response = ''
697 try:
698 self.handle.close()
pingping-lin763ee042015-05-20 17:45:30 -0700699 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800700 main.log.error( "Connection failed to the host" )
timlindbergef8d55d2013-09-27 12:50:13 -0700701 response = main.FALSE
702 return response
pingping-linc1c696e2015-01-27 13:46:44 -0800703