blob: 02c6af3941beac6470c8d206ea363d72988ca09d [file] [log] [blame]
timlindbergef8d55d2013-09-27 12:50:13 -07001#!/usr/bin/env python
Jeremy Songsterae01bba2016-07-11 15:39:17 -07002"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070012 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070013
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 -070022import time
23import pexpect
kelvin-onlabbbe46482015-01-16 10:44:28 -080024import sys
timlindbergef8d55d2013-09-27 12:50:13 -070025import json
timlindbergef8d55d2013-09-27 12:50:13 -070026from drivers.common.clidriver import CLI
27
timlindbergef8d55d2013-09-27 12:50:13 -070028
kelvin-onlabbbe46482015-01-16 10:44:28 -080029class QuaggaCliDriver( CLI ):
30
31 def __init__( self ):
Devin Limdc78e202017-06-09 18:30:07 -070032 super( QuaggaCliDriver, self ).__init__()
timlindbergef8d55d2013-09-27 12:50:13 -070033
pingping-linc6b86fa2014-12-01 16:18:10 -080034 # TODO: simplify this method
kelvin-onlabbbe46482015-01-16 10:44:28 -080035 def connect( self, **connectargs ):
timlindbergef8d55d2013-09-27 12:50:13 -070036 for key in connectargs:
kelvin-onlabbbe46482015-01-16 10:44:28 -080037 vars( self )[ key ] = connectargs[ key ]
pingping-lin763ee042015-05-20 17:45:30 -070038 self.name = self.options[ 'name' ]
39 self.handle = super( QuaggaCliDriver, self ).connect(
40 user_name=self.user_name,
41 ip_address="127.0.0.1",
42 port=self.port,
43 pwd=self.pwd )
44 if self.handle:
45 return self.handle
46 else:
47 main.log.info( "NO HANDLE" )
48 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -080049
pingping-lin763ee042015-05-20 17:45:30 -070050 def connectQuagga( self ):
kelvin-onlabbbe46482015-01-16 10:44:28 -080051 self.name = self.options[ 'name' ]
52 # self.handle = super( QuaggaCliDriver,self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080053 # user_name=self.user_name, ip_address=self.ip_address,port=self.port,
kelvin-onlabbbe46482015-01-16 10:44:28 -080054 # pwd=self.pwd )
pingping-lin4e7b0d32015-01-27 18:06:22 -080055 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080056 user_name=self.user_name,
57 ip_address="1.1.1.1",
58 port=self.port,
59 pwd=self.pwd )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070060 # main.log.info( "connect parameters:" + str( self.user_name ) + ";"
pingping-lina600d9b2015-01-30 13:57:26 -080061 # + str( self.ip_address ) + ";" + str( self.port )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070062 # + ";" + str( self.pwd ) )
timlindbergef8d55d2013-09-27 12:50:13 -070063
pingping-linc6b86fa2014-12-01 16:18:10 -080064 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -080065 # self.handle.expect( "",timeout=10 )
Devin Limdc78e202017-06-09 18:30:07 -070066 # self.handle.expect( self.prompt,timeout=10 )
kelvin-onlabbbe46482015-01-16 10:44:28 -080067 self.handle.sendline( "telnet localhost 2605" )
68 # self.handle.expect( "Password:", timeout=5 )
69 self.handle.expect( "Password:" )
70 self.handle.sendline( "hello" )
71 # self.handle.expect( "bgpd", timeout=5 )
72 self.handle.expect( "bgpd" )
73 self.handle.sendline( "enable" )
74 # self.handle.expect( "bgpd#", timeout=5 )
75 self.handle.expect( "bgpd#" )
timlindbergef8d55d2013-09-27 12:50:13 -070076 return self.handle
kelvin-onlabbbe46482015-01-16 10:44:28 -080077 else:
78 main.log.info( "NO HANDLE" )
timlindbergef8d55d2013-09-27 12:50:13 -070079 return main.FALSE
80
pingping-linc1c696e2015-01-27 13:46:44 -080081 def loginQuagga( self, ip_address ):
kelvin-onlabbbe46482015-01-16 10:44:28 -080082 self.name = self.options[ 'name' ]
83 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -080084 user_name=self.user_name, ip_address=ip_address,
kelvin-onlabbbe46482015-01-16 10:44:28 -080085 port=self.port, pwd=self.pwd )
pingping-linc1c696e2015-01-27 13:46:44 -080086 main.log.info( "connect parameters:" + str( self.user_name ) + ";"
pingping-lin4e7b0d32015-01-27 18:06:22 -080087 + str( self.ip_address ) + ";" + str( self.port )
88 + ";" + str( self.pwd ) )
pingping-lin8b306ac2014-11-17 18:13:51 -080089
90 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -080091 # self.handle.expect( "" )
Devin Limdc78e202017-06-09 18:30:07 -070092 # self.handle.expect( self.prompt )
kelvin-onlabbbe46482015-01-16 10:44:28 -080093 self.handle.sendline( "telnet localhost 2605" )
94 # self.handle.expect( "Password:", timeout=5 )
95 self.handle.expect( "Password:" )
96 self.handle.sendline( "hello" )
97 # self.handle.expect( "bgpd", timeout=5 )
98 self.handle.expect( "bgpd" )
99 self.handle.sendline( "enable" )
100 # self.handle.expect( "bgpd#", timeout=5 )
101 self.handle.expect( "bgpd#" )
pingping-linc1c696e2015-01-27 13:46:44 -0800102 main.log.info( "I am in quagga on host " + str( ip_address ) )
pingping-lin8b306ac2014-11-17 18:13:51 -0800103
104 return self.handle
105 else:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800106 main.log.info( "NO HANDLE" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800107 return main.FALSE
108
kelvin-onlabd3b64892015-01-20 13:26:24 -0800109 def enterConfig( self, asn ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800110 main.log.info( "I am in enter_config method!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700111 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800112 self.handle.sendline( "" )
113 self.handle.expect( "bgpd#" )
pingping-lin763ee042015-05-20 17:45:30 -0700114 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800115 main.log.warn( "Probably not currently in enable mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700116 self.disconnect()
117 return main.FALSE
kelvin-onlabbbe46482015-01-16 10:44:28 -0800118 self.handle.sendline( "configure terminal" )
119 self.handle.expect( "config", timeout=5 )
120 routerAS = "router bgp " + str( asn )
timlindbergef8d55d2013-09-27 12:50:13 -0700121 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800122 self.handle.sendline( routerAS )
123 self.handle.expect( "config-router", timeout=5 )
timlindbergef8d55d2013-09-27 12:50:13 -0700124 return main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -0700125 except Exception:
timlindbergef8d55d2013-09-27 12:50:13 -0700126 return main.FALSE
pingping-lin8b306ac2014-11-17 18:13:51 -0800127
kelvin-onlabd3b64892015-01-20 13:26:24 -0800128 def generatePrefixes( self, net, numRoutes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800129 main.log.info( "I am in generate_prefixes method!" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800130
pingping-lin4e7b0d32015-01-27 18:06:22 -0800131 # each IP prefix is composed by "net" + "." + m + "." + n + "." + x
pingping-lin8b306ac2014-11-17 18:13:51 -0800132 # the length of each IP prefix is 24
133 routes = []
kelvin-onlabd3b64892015-01-20 13:26:24 -0800134 routesGen = 0
pingping-lin8b306ac2014-11-17 18:13:51 -0800135 m = numRoutes / 256
136 n = numRoutes % 256
137
kelvin-onlabbbe46482015-01-16 10:44:28 -0800138 for i in range( 0, m ):
139 for j in range( 0, 256 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800140 network = str( net ) + "." + str( i ) + "." + str( j ) \
141 + ".0/24"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800142 routes.append( network )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800143 routesGen = routesGen + 1
pingping-lin8b306ac2014-11-17 18:13:51 -0800144
kelvin-onlabbbe46482015-01-16 10:44:28 -0800145 for j in range( 0, n ):
146 network = str( net ) + "." + str( m ) + "." + str( j ) + ".0/24"
147 routes.append( network )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800148 routesGen = routesGen + 1
pingping-lin8b306ac2014-11-17 18:13:51 -0800149
kelvin-onlabd3b64892015-01-20 13:26:24 -0800150 if routesGen == numRoutes:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800151 main.log.info( "Successfully generated " + str( numRoutes )
152 + " prefixes!" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800153 return routes
154 return main.FALSE
pingping-lin6f6332e2014-11-19 19:13:58 -0800155
kelvin-onlabbbe46482015-01-16 10:44:28 -0800156 # This method generates a multiple to single point intent(
157 # MultiPointToSinglePointIntent ) for a given route
pingping-lin4e7b0d32015-01-27 18:06:22 -0800158 def generateExpectedSingleRouteIntent( self, prefix, nextHop, nextHopMac,
159 sdnipData ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800160
pingping-linc1c696e2015-01-27 13:46:44 -0800161 ingresses = []
pingping-lin6f6332e2014-11-19 19:13:58 -0800162 egress = ""
kelvin-onlabd3b64892015-01-20 13:26:24 -0800163 for peer in sdnipData[ 'bgpPeers' ]:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800164 if peer[ 'ipAddress' ] == nextHop:
pingping-linc1c696e2015-01-27 13:46:44 -0800165 egress = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800166 peer[ 'attachmentDpid' ] ).replace( ":", "" ) + ":" \
167 + str( peer[ 'attachmentPort' ] )
pingping-linc1c696e2015-01-27 13:46:44 -0800168 for peer in sdnipData[ 'bgpPeers' ]:
169 if not peer[ 'ipAddress' ] == nextHop:
170 ingress = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800171 peer[ 'attachmentDpid' ] ).replace( ":", "" ) + ":" \
172 + str( peer[ 'attachmentPort' ] )
pingping-linc1c696e2015-01-27 13:46:44 -0800173 if not ingress == egress and ingress not in ingresses:
174 ingresses.append( ingress )
175 # ingresses.append( "of:" + str( peer[ 'attachmentDpid' ]
176 # ).replace( ":", "" ) + ":" + str( peer[ 'attachmentPort'
177 # ] ) )
pingping-lin6f6332e2014-11-19 19:13:58 -0800178
pingping-linc6b86fa2014-12-01 16:18:10 -0800179 selector = "ETH_TYPE{ethType=800},IPV4_DST{ip=" + prefix + "}"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800180 treatment = "[ETH_DST{mac=" + str( nextHopMac ) + "}]"
pingping-lin6f6332e2014-11-19 19:13:58 -0800181
pingping-lin4e7b0d32015-01-27 18:06:22 -0800182 intent = egress + "/" + str( sorted( ingresses ) ) + "/" + \
183 selector + "/" + treatment
pingping-lin6f6332e2014-11-19 19:13:58 -0800184 return intent
185
pingping-lin4e7b0d32015-01-27 18:06:22 -0800186 def generateExpectedOnePeerRouteIntents( self, prefixes, nextHop,
187 nextHopMac, sdnipJsonFilePath ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800188 intents = []
kelvin-onlabd3b64892015-01-20 13:26:24 -0800189 sdnipJsonFile = open( sdnipJsonFilePath ).read()
pingping-lin6f6332e2014-11-19 19:13:58 -0800190
kelvin-onlabd3b64892015-01-20 13:26:24 -0800191 sdnipData = json.loads( sdnipJsonFile )
pingping-lin6f6332e2014-11-19 19:13:58 -0800192
193 for prefix in prefixes:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800194 intents.append(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800195 self.generateExpectedSingleRouteIntent(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800196 prefix, nextHop, nextHopMac, sdnipData ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800197 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800198
199 # TODO
200 # This method generates all expected route intents for all BGP peers
kelvin-onlabd3b64892015-01-20 13:26:24 -0800201 def generateExpectedRouteIntents( self ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800202 intents = []
203 return intents
204
205 # This method extracts all actual routes from ONOS CLI
pingping-linb2a86582015-02-02 16:18:59 -0800206 def extractActualRoutesOneDotZero( self, getRoutesResult ):
kelvin-onlabd3b64892015-01-20 13:26:24 -0800207 routesJsonObj = json.loads( getRoutesResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800208
kelvin-onlabd3b64892015-01-20 13:26:24 -0800209 allRoutesActual = []
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700210 for route in routesJsonObj[ 'routes4' ]:
pingping-lin763ee042015-05-20 17:45:30 -0700211 if 'prefix' in route:
212 if route[ 'prefix' ] == '172.16.10.0/24':
213 continue
214 allRoutesActual.append(
215 route[ 'prefix' ] + "/" + route[ 'nextHop' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800216
kelvin-onlabd3b64892015-01-20 13:26:24 -0800217 return sorted( allRoutesActual )
pingping-linb2a86582015-02-02 16:18:59 -0800218
219 def extractActualRoutesMaster( self, getRoutesResult ):
pingping-lina600d9b2015-01-30 13:57:26 -0800220 routesJsonObj = json.loads( getRoutesResult )
221
222 allRoutesActual = []
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700223 for route in routesJsonObj[ 'routes4' ]:
pingping-lina600d9b2015-01-30 13:57:26 -0800224 if route[ 'prefix' ] == '172.16.10.0/24':
225 continue
226 allRoutesActual.append(
227 route[ 'prefix' ] + "/" + route[ 'nextHop' ] )
228
229 return sorted( allRoutesActual )
pingping-lin6f6332e2014-11-19 19:13:58 -0800230
231 # This method extracts all actual route intents from ONOS CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800232 def extractActualRouteIntents( self, getIntentsResult ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800233 intents = []
234 # TODO: delete the line below when change to Mininet demo script
kelvin-onlabd3b64892015-01-20 13:26:24 -0800235 # getIntentsResult=open( "../tests/SdnIpTest/intents.json" ).read()
236 intentsJsonObj = json.loads( getIntentsResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800237
kelvin-onlabd3b64892015-01-20 13:26:24 -0800238 for intent in intentsJsonObj:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700239 # if intent[ 'appId' ] != "org.onosproject.sdnip":
pingping-linf30cf272015-05-29 15:54:07 -0700240 # continue
pingping-lin4e7b0d32015-01-27 18:06:22 -0800241 if intent[ 'type' ] == "MultiPointToSinglePointIntent" \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700242 and intent[ 'state' ] == 'INSTALLED':
pingping-lin4e7b0d32015-01-27 18:06:22 -0800243 egress = str( intent[ 'egress' ][ 'device' ] ) + ":" \
244 + str( intent[ 'egress' ][ 'port' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800245 ingress = []
kelvin-onlabbbe46482015-01-16 10:44:28 -0800246 for attachmentPoint in intent[ 'ingress' ]:
pingping-linc1c696e2015-01-27 13:46:44 -0800247 ingress.append(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800248 str( attachmentPoint[ 'device' ] ) + ":"
249 + str( attachmentPoint[ 'port' ] ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800250
kelvin-onlabbbe46482015-01-16 10:44:28 -0800251 selector = intent[ 'selector' ].replace(
252 "[", "" ).replace( "]", "" ).replace( " ", "" )
253 if str( selector ).startswith( "IPV4" ):
254 str1, str2 = str( selector ).split( "," )
pingping-linc6b86fa2014-12-01 16:18:10 -0800255 selector = str2 + "," + str1
256
pingping-lin4e7b0d32015-01-27 18:06:22 -0800257 intent = egress + "/" + str( sorted( ingress ) ) + "/" + \
258 selector + "/" + intent[ 'treatment' ]
kelvin-onlabbbe46482015-01-16 10:44:28 -0800259 intents.append( intent )
260 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800261
pingping-linf30cf272015-05-29 15:54:07 -0700262 # This method calculates the MultiPointToSinglePointIntent number installed
263 def extractActualRouteIntentNum( self, getIntentsResult ):
264 intentsJsonObj = json.loads( getIntentsResult )
265 num = 0
266 for intent in intentsJsonObj:
267 if intent[ 'type' ] == "MultiPointToSinglePointIntent" \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700268 and intent[ 'state' ] == 'INSTALLED':
pingping-linf30cf272015-05-29 15:54:07 -0700269 num = num + 1
270 return num
271
272 # This method calculates the PointToPointIntent number installed
273 def extractActualBgpIntentNum( self, getIntentsResult ):
274 intentsJsonObj = json.loads( getIntentsResult )
275 num = 0
276 for intent in intentsJsonObj:
277 if intent[ 'type' ] == "PointToPointIntent" \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700278 and intent[ 'state' ] == 'INSTALLED':
pingping-linf30cf272015-05-29 15:54:07 -0700279 num = num + 1
280 return num
281
pingping-lin6f6332e2014-11-19 19:13:58 -0800282 # This method extracts all actual BGP intents from ONOS CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800283 def extractActualBgpIntents( self, getIntentsResult ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800284 intents = []
285 # TODO: delete the line below when change to Mininet demo script
kelvin-onlabd3b64892015-01-20 13:26:24 -0800286 # getIntentsResult=open( "../tests/SdnIpTest/intents.json" ).read()
287 intentsJsonObj = json.loads( getIntentsResult )
pingping-lin6f6332e2014-11-19 19:13:58 -0800288
kelvin-onlabd3b64892015-01-20 13:26:24 -0800289 for intent in intentsJsonObj:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700290 # if intent[ 'appId' ] != "org.onosproject.sdnip":
pingping-linf30cf272015-05-29 15:54:07 -0700291 # continue
pingping-lin4e7b0d32015-01-27 18:06:22 -0800292 if intent[ 'type' ] == "PointToPointIntent" \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700293 and "protocol=6" in str( intent[ 'selector' ] ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800294 ingress = str( intent[ 'ingress' ][ 'device' ] ) + ":" \
295 + str( intent[ 'ingress' ][ 'port' ] )
296 egress = str( intent[ 'egress' ][ 'device' ] ) + ":" + \
297 str( intent[ 'egress' ][ 'port' ] )
298 selector = str( intent[ 'selector' ] ).replace( " ", "" )\
299 .replace( "[", "" ).replace( "]", "" ).split( "," )
300 intent = ingress + "/" + egress + "/" + \
301 str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800302 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800303
kelvin-onlabbbe46482015-01-16 10:44:28 -0800304 return sorted( intents )
pingping-lin6f6332e2014-11-19 19:13:58 -0800305
kelvin-onlabbbe46482015-01-16 10:44:28 -0800306 # This method generates a single point to single point intent(
307 # PointToPointIntent ) for BGP path
kelvin-onlabd3b64892015-01-20 13:26:24 -0800308 def generateExpectedBgpIntents( self, sdnipJsonFilePath ):
pingping-lin6f6332e2014-11-19 19:13:58 -0800309 from operator import eq
310
kelvin-onlabd3b64892015-01-20 13:26:24 -0800311 sdnipJsonFile = open( sdnipJsonFilePath ).read()
312 sdnipData = json.loads( sdnipJsonFile )
pingping-lin6f6332e2014-11-19 19:13:58 -0800313
314 intents = []
pingping-linc6b86fa2014-12-01 16:18:10 -0800315 bgpPeerAttachmentPoint = ""
kelvin-onlabbbe46482015-01-16 10:44:28 -0800316 bgpSpeakerAttachmentPoint = "of:" + str(
pingping-lin4e7b0d32015-01-27 18:06:22 -0800317 sdnipData[ 'bgpSpeakers' ][ 0 ][ 'attachmentDpid' ] )\
318 .replace( ":", "" ) + ":" \
319 + str( sdnipData[ 'bgpSpeakers' ][ 0 ][ 'attachmentPort' ] )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800320 for peer in sdnipData[ 'bgpPeers' ]:
pingping-lin4e7b0d32015-01-27 18:06:22 -0800321 bgpPeerAttachmentPoint = "of:" \
322 + str( peer[ 'attachmentDpid' ] ).replace( ":", "" ) \
323 + ":" + str( peer[ 'attachmentPort' ] )
pingping-lin6f6332e2014-11-19 19:13:58 -0800324 # find out the BGP speaker IP address for this BGP peer
pingping-linc6b86fa2014-12-01 16:18:10 -0800325 bgpSpeakerIpAddress = ""
pingping-lin4e7b0d32015-01-27 18:06:22 -0800326 for interfaceAddress in \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700327 sdnipData[ 'bgpSpeakers' ][ 0 ][ 'interfaceAddresses' ]:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800328 # if eq( interfaceAddress[ 'interfaceDpid' ],sdnipData[
kelvin-onlabbbe46482015-01-16 10:44:28 -0800329 # 'bgpSpeakers' ][ 0 ][ 'attachmentDpid' ] ) and eq(
pingping-linc1c696e2015-01-27 13:46:44 -0800330 # interfaceAddress[ 'interfacePort' ], sdnipData[ 'bgpSpeakers'
331 # ][ 0 ][ 'attachmentPort' ] ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800332 if eq( interfaceAddress[ 'interfaceDpid' ],
333 peer[ 'attachmentDpid' ] ) \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700334 and eq( interfaceAddress[ 'interfacePort' ],
335 peer[ 'attachmentPort' ] ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800336 bgpSpeakerIpAddress = interfaceAddress[ 'ipAddress' ]
pingping-lin6f6332e2014-11-19 19:13:58 -0800337 break
338 else:
339 continue
340
kelvin-onlabbbe46482015-01-16 10:44:28 -0800341 # from bgpSpeakerAttachmentPoint to bgpPeerAttachmentPoint
342 # direction
pingping-lin4e7b0d32015-01-27 18:06:22 -0800343 selectorStr = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," \
344 + "IPV4_DST{ip=" + peer[ 'ipAddress' ] + "/32}," \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700345 + "IP_PROTO{ protocol=6 }, ETH_TYPE{ ethType=800 }, \
346 TCP_DST{ tcpPort=179 }"
347 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
pingping-lin4e7b0d32015-01-27 18:06:22 -0800348 .replace( "]", "" ).split( "," )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800349 intent = bgpSpeakerAttachmentPoint + "/" + \
350 bgpPeerAttachmentPoint + "/" + str( sorted( selector ) )
351 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800352
pingping-lin4e7b0d32015-01-27 18:06:22 -0800353 selectorStr = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," \
354 + "IPV4_DST{ip=" + peer[ 'ipAddress' ] + "/32}," \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700355 + "IP_PROTO{ protocol=6 }, ETH_TYPE{ ethType=800 }, \
356 TCP_SRC{ tcpPort=179 }"
357 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
pingping-lin4e7b0d32015-01-27 18:06:22 -0800358 .replace( "]", "" ).split( "," )
359 intent = bgpSpeakerAttachmentPoint + "/" \
360 + bgpPeerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800361 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800362
kelvin-onlabbbe46482015-01-16 10:44:28 -0800363 # from bgpPeerAttachmentPoint to bgpSpeakerAttachmentPoint
364 # direction
pingping-lin4e7b0d32015-01-27 18:06:22 -0800365 selectorStr = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," \
366 + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700367 + "IP_PROTO{ protocol=6 }, ETH_TYPE{ ethType=800 }, \
368 TCP_DST{ tcpPort=179 }"
369 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
pingping-lin4e7b0d32015-01-27 18:06:22 -0800370 .replace( "]", "" ).split( "," )
371 intent = bgpPeerAttachmentPoint + "/" \
372 + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800373 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800374
pingping-lin4e7b0d32015-01-27 18:06:22 -0800375 selectorStr = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," \
376 + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700377 + "IP_PROTO{ protocol=6 }, ETH_TYPE{ ethType=800 }, \
378 TCP_SRC{ tcpPort=179 }"
pingping-lin4e7b0d32015-01-27 18:06:22 -0800379 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
380 .replace( "]", "" ).split( "," )
381 intent = bgpPeerAttachmentPoint + "/" \
382 + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800383 intents.append( intent )
pingping-lin6f6332e2014-11-19 19:13:58 -0800384
kelvin-onlabbbe46482015-01-16 10:44:28 -0800385 return sorted( intents )
pingping-linc6b86fa2014-12-01 16:18:10 -0800386
kelvin-onlabd3b64892015-01-20 13:26:24 -0800387 def addRoutes( self, routes, routeRate ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800388 main.log.info( "I am in add_routes method!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800389
kelvin-onlabd3b64892015-01-20 13:26:24 -0800390 routesAdded = 0
pingping-lin8b306ac2014-11-17 18:13:51 -0800391 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800392 self.handle.sendline( "" )
393 # self.handle.expect( "config-router" )
394 self.handle.expect( "config-router", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700395 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800396 main.log.warn( "Probably not in config-router mode!" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800397 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800398 main.log.info( "Start to add routes" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800399
pingping-lin763ee042015-05-20 17:45:30 -0700400 chunk_size = 20
401
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700402 if len( routes ) > chunk_size:
403 num_iter = ( int )( len( routes ) / chunk_size )
pingping-lin763ee042015-05-20 17:45:30 -0700404 else:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700405 num_iter = 1
pingping-lin763ee042015-05-20 17:45:30 -0700406
407 total = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700408 for n in range( 0, num_iter + 1 ):
pingping-lin763ee042015-05-20 17:45:30 -0700409 routeCmd = ""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700410 if ( len( routes ) - ( n * chunk_size ) ) >= chunk_size:
411 m = ( n + 1 ) * chunk_size
pingping-lin763ee042015-05-20 17:45:30 -0700412 else:
413 m = len( routes )
414 for i in range( n * chunk_size, m ):
415 routeCmd = routeCmd + "network " + routes[ i ] + "\n"
416 total = total + 1
417
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700418 main.log.info( routeCmd )
pingping-lin8b306ac2014-11-17 18:13:51 -0800419 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800420 self.handle.sendline( routeCmd )
421 self.handle.expect( "bgpd", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700422 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800423 main.log.warn( "Failed to add route" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800424 self.disconnect()
Jon Hall4ba53f02015-07-29 13:07:41 -0700425
pingping-linc1c696e2015-01-27 13:46:44 -0800426 # waitTimer = 1.00 / routeRate
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700427 main.log.info( "Total routes so far " + ( ( str )( total ) ) + " wait for 0 sec" )
428 # time.sleep( 1 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800429 if routesAdded == len( routes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800430 main.log.info( "Finished adding routes" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800431 return main.TRUE
432 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800433
kelvin-onlabd3b64892015-01-20 13:26:24 -0800434 def deleteRoutes( self, routes, routeRate ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800435 main.log.info( "I am in delete_routes method!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800436
kelvin-onlabd3b64892015-01-20 13:26:24 -0800437 routesAdded = 0
pingping-linc6b86fa2014-12-01 16:18:10 -0800438 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800439 self.handle.sendline( "" )
440 # self.handle.expect( "config-router" )
441 self.handle.expect( "config-router", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700442 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800443 main.log.warn( "Probably not in config-router mode!" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800444 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800445 main.log.info( "Start to delete routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800446
kelvin-onlabbbe46482015-01-16 10:44:28 -0800447 for i in range( 0, len( routes ) ):
448 routeCmd = "no network " + routes[ i ]
pingping-linc6b86fa2014-12-01 16:18:10 -0800449 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800450 self.handle.sendline( routeCmd )
451 self.handle.expect( "bgpd", timeout=5 )
pingping-lin763ee042015-05-20 17:45:30 -0700452 except Exception:
pingping-lin4e7b0d32015-01-27 18:06:22 -0800453 main.log.warn( "Failed to delete route" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800454 self.disconnect()
pingping-linc1c696e2015-01-27 13:46:44 -0800455 # waitTimer = 1.00 / routeRate
456 # time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800457 if routesAdded == len( routes ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800458 main.log.info( "Finished deleting routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800459 return main.TRUE
460 return main.FALSE
461
pingping-linc1c696e2015-01-27 13:46:44 -0800462 def pingTest( self, ip_address, pingTestFile, pingTestResultFile ):
463 main.log.info( "Start the ping test on host:" + str( ip_address ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800464
kelvin-onlabbbe46482015-01-16 10:44:28 -0800465 self.name = self.options[ 'name' ]
466 self.handle = super( QuaggaCliDriver, self ).connect(
pingping-linc1c696e2015-01-27 13:46:44 -0800467 user_name=self.user_name, ip_address=ip_address,
kelvin-onlabbbe46482015-01-16 10:44:28 -0800468 port=self.port, pwd=self.pwd )
pingping-linc1c696e2015-01-27 13:46:44 -0800469 main.log.info( "connect parameters:" + str( self.user_name ) + ";"
pingping-lin4e7b0d32015-01-27 18:06:22 -0800470 + str( self.ip_address ) + ";" + str( self.port )
471 + ";" + str( self.pwd ) )
pingping-linc6b86fa2014-12-01 16:18:10 -0800472
473 if self.handle:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800474 # self.handle.expect( "" )
Devin Limdc78e202017-06-09 18:30:07 -0700475 # self.handle.expect( self.prompt )
pingping-linc1c696e2015-01-27 13:46:44 -0800476 main.log.info( "I in host " + str( ip_address ) )
477 main.log.info( pingTestFile + " > " + pingTestResultFile + " &" )
kelvin-onlabbbe46482015-01-16 10:44:28 -0800478 self.handle.sendline(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800479 pingTestFile +
kelvin-onlabbbe46482015-01-16 10:44:28 -0800480 " > " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800481 pingTestResultFile +
kelvin-onlabbbe46482015-01-16 10:44:28 -0800482 " &" )
Devin Limdc78e202017-06-09 18:30:07 -0700483 self.handle.expect( self.prompt, timeout=60 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800484 handle = self.handle.before
485
486 return handle
487 else:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800488 main.log.info( "NO HANDLE" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800489 return main.FALSE
490
pingping-lin4e7b0d32015-01-27 18:06:22 -0800491 # Please use the generateRoutes plus addRoutes instead of this one!
kelvin-onlabd3b64892015-01-20 13:26:24 -0800492 def addRoute( self, net, numRoutes, routeRate ):
timlindbergef8d55d2013-09-27 12:50:13 -0700493 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800494 self.handle.sendline( "" )
495 self.handle.expect( "config-router" )
pingping-lin763ee042015-05-20 17:45:30 -0700496 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800497 main.log.warn( "Probably not in config-router mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700498 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800499 main.log.info( "Adding Routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800500 j = 0
501 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700502 while numRoutes > 255:
503 numRoutes = numRoutes - 255
504 j = j + 1
505 k = numRoutes % 254
kelvin-onlabd3b64892015-01-20 13:26:24 -0800506 routesAdded = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700507 if numRoutes > 255:
508 numRoutes = 255
kelvin-onlabbbe46482015-01-16 10:44:28 -0800509 for m in range( 1, j + 1 ):
510 for n in range( 1, numRoutes + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800511 network = str( net ) + "." + str( m ) + "." + str( n ) \
512 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700513 routeCmd = "network " + network
514 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800515 self.handle.sendline( routeCmd )
516 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700517 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800518 main.log.warn( "failed to add route" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800519 self.disconnect()
520 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800521 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800522 routesAdded = routesAdded + 1
kelvin-onlabbbe46482015-01-16 10:44:28 -0800523 for d in range( j + 1, j + 2 ):
524 for e in range( 1, k + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800525 network = str( net ) + "." + str( d ) + "." + str( e ) \
526 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700527 routeCmd = "network " + network
528 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800529 self.handle.sendline( routeCmd )
530 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700531 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800532 main.log.warn( "failed to add route" )
pingping-lin763ee042015-05-20 17:45:30 -0700533 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800534 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800535 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800536 routesAdded = routesAdded + 1
537 if routesAdded == numRoutes:
timlindbergef8d55d2013-09-27 12:50:13 -0700538 return main.TRUE
539 return main.FALSE
pingping-lin0904ad02015-01-30 15:18:14 -0800540
pingping-lin4e7b0d32015-01-27 18:06:22 -0800541 # Please use deleteRoutes method instead of this one!
kelvin-onlabd3b64892015-01-20 13:26:24 -0800542 def delRoute( self, net, numRoutes, routeRate ):
timlindbergef8d55d2013-09-27 12:50:13 -0700543 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800544 self.handle.sendline( "" )
545 self.handle.expect( "config-router" )
pingping-lin763ee042015-05-20 17:45:30 -0700546 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800547 main.log.warn( "Probably not in config-router mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700548 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800549 main.log.info( "Deleting Routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800550 j = 0
551 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700552 while numRoutes > 255:
553 numRoutes = numRoutes - 255
554 j = j + 1
555 k = numRoutes % 254
kelvin-onlabd3b64892015-01-20 13:26:24 -0800556 routesDeleted = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700557 if numRoutes > 255:
558 numRoutes = 255
kelvin-onlabbbe46482015-01-16 10:44:28 -0800559 for m in range( 1, j + 1 ):
560 for n in range( 1, numRoutes + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800561 network = str( net ) + "." + str( m ) + "." + str( n ) \
562 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700563 routeCmd = "no network " + network
564 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800565 self.handle.sendline( routeCmd )
566 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700567 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800568 main.log.warn( "Failed to delete route" )
timlindbergef8d55d2013-09-27 12:50:13 -0700569 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800570 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800571 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800572 routesDeleted = routesDeleted + 1
kelvin-onlabbbe46482015-01-16 10:44:28 -0800573 for d in range( j + 1, j + 2 ):
574 for e in range( 1, k + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800575 network = str( net ) + "." + str( d ) + "." + str( e ) \
576 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700577 routeCmd = "no network " + network
578 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800579 self.handle.sendline( routeCmd )
580 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700581 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800582 main.log.warn( "Failed to delete route" )
timlindbergef8d55d2013-09-27 12:50:13 -0700583 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800584 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800585 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800586 routesDeleted = routesDeleted + 1
587 if routesDeleted == numRoutes:
timlindbergef8d55d2013-09-27 12:50:13 -0700588 return main.TRUE
589 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800590
kelvin-onlabd3b64892015-01-20 13:26:24 -0800591 def checkRoutes( self, brand, ip, user, pw ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800592 def pronto( ip, user, passwd ):
timlindbergef8d55d2013-09-27 12:50:13 -0700593 print "Connecting to Pronto switch"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800594 child = pexpect.spawn( "telnet " + ip )
595 i = child.expect( [ "login:", "CLI#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700596 if i == 0:
pingping-linc1c696e2015-01-27 13:46:44 -0800597 print "user_name and password required. Passing login info."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800598 child.sendline( user )
599 child.expect( "Password:" )
600 child.sendline( passwd )
601 child.expect( "CLI#" )
timlindbergef8d55d2013-09-27 12:50:13 -0700602 print "Logged in, getting flowtable."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800603 child.sendline( "flowtable brief" )
604 for t in range( 9 ):
timlindbergef8d55d2013-09-27 12:50:13 -0700605 t2 = 9 - t
kelvin-onlabbbe46482015-01-16 10:44:28 -0800606 print "\r" + str( t2 )
607 sys.stdout.write( "\033[F" )
608 time.sleep( 1 )
timlindbergef8d55d2013-09-27 12:50:13 -0700609 print "Scanning flowtable"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800610 child.expect( "Flow table show" )
timlindbergef8d55d2013-09-27 12:50:13 -0700611 count = 0
kelvin-onlabbbe46482015-01-16 10:44:28 -0800612 while True:
pingping-lin0904ad02015-01-30 15:18:14 -0800613 i = child.expect( [ '17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}',
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700614 'CLI#', pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700615 if i == 0:
616 count = count + 1
617 elif i == 1:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800618 print "Pronto flows: " + str( count ) + "\nDone\n"
timlindbergef8d55d2013-09-27 12:50:13 -0700619 break
620 else:
621 break
kelvin-onlabbbe46482015-01-16 10:44:28 -0800622
623 def cisco( ip, user, passwd ):
timlindbergef8d55d2013-09-27 12:50:13 -0700624 print "Establishing Cisco switch connection"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800625 child = pexpect.spawn( "ssh " + user + "@" + ip )
626 i = child.expect( [ "Password:", "CLI#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700627 if i == 0:
628 print "Password required. Passing now."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800629 child.sendline( passwd )
630 child.expect( "#" )
timlindbergef8d55d2013-09-27 12:50:13 -0700631 print "Logged in. Retrieving flow table then counting flows."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800632 child.sendline( "show openflow switch all flows all" )
633 child.expect( "Logical Openflow Switch" )
timlindbergef8d55d2013-09-27 12:50:13 -0700634 print "Flow table retrieved. Counting flows"
635 count = 0
kelvin-onlabbbe46482015-01-16 10:44:28 -0800636 while True:
637 i = child.expect( [ "nw_src=17", "#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700638 if i == 0:
639 count = count + 1
640 elif i == 1:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800641 print "Cisco flows: " + str( count ) + "\nDone\n"
timlindbergef8d55d2013-09-27 12:50:13 -0700642 break
643 else:
644 break
645 if brand == "pronto" or brand == "PRONTO":
kelvin-onlabbbe46482015-01-16 10:44:28 -0800646 pronto( ip, user, passwd )
pingping-linc6b86fa2014-12-01 16:18:10 -0800647 # elif brand == "cisco" or brand == "CISCO":
kelvin-onlabbbe46482015-01-16 10:44:28 -0800648 # cisco( ip,user,passwd )
649
pingping-lin763ee042015-05-20 17:45:30 -0700650 def disable_bgp_peer( self, peer, peer_as ):
651 main.log.info( "I am in disconnect_peer_session method!" )
652
653 try:
654 self.handle.sendline( "" )
655 # self.handle.expect( "config-router" )
656 self.handle.expect( "config-router", timeout=5 )
657 except Exception:
658 main.log.warn( "Probably not in config-router mode!" )
659 self.disconnect()
660 main.log.info( "Start to disable peer" )
661
662 cmd = "no neighbor " + peer + " remote-as " + peer_as
663 try:
664 self.handle.sendline( cmd )
665 self.handle.expect( "bgpd", timeout=5 )
666 except Exception:
667 main.log.warn( "Failed to disable peer" )
668 self.disconnect()
669
670 def enable_bgp_peer( self, peer, peer_as ):
671 main.log.info( "I am in enable_bgp_peer method!" )
672
673 try:
674 self.handle.sendline( "" )
675 # self.handle.expect( "config-router" )
676 self.handle.expect( "config-router", timeout=5 )
677 except Exception:
678 main.log.warn( "Probably not in config-router mode!" )
679 self.disconnect()
680 main.log.info( "Start to disable peer" )
681
682 cmd = "neighbor " + peer + " remote-as " + peer_as
683 try:
684 self.handle.sendline( cmd )
685 self.handle.expect( "bgpd", timeout=5 )
686 except Exception:
687 main.log.warn( "Failed to enable peer" )
688 self.disconnect()
689
kelvin-onlabbbe46482015-01-16 10:44:28 -0800690 def disconnect( self ):
691 """
692 Called when Test is complete to disconnect the Quagga handle.
693 """
timlindbergef8d55d2013-09-27 12:50:13 -0700694 response = ''
695 try:
696 self.handle.close()
pingping-lin763ee042015-05-20 17:45:30 -0700697 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800698 main.log.error( "Connection failed to the host" )
timlindbergef8d55d2013-09-27 12:50:13 -0700699 response = main.FALSE
700 return response