blob: 01905c2bc2265cc0f8d05b8f911e44bdf50c50be [file] [log] [blame]
timlindbergef8d55d2013-09-27 12:50:13 -07001#!/usr/bin/env python
Jeremy Songsterae01bba2016-07-11 15:39:17 -07002"""
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00003Copyright 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 Ronquillo4d5f1d02017-10-13 20:23:57 +000012 (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"""
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000022
timlindbergef8d55d2013-09-27 12:50:13 -070023import 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 )
Jeremy Ronquillo82705492017-10-18 14:19:55 -070061 # main.log.info( "connect parameters:" + str( self.user_name ) + ";"
pingping-lina600d9b2015-01-30 13:57:26 -080062 # + str( self.ip_address ) + ";" + str( self.port )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000063 # + ";" + 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 = []
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700211 for route in routesJsonObj[ 'routes4' ]:
pingping-lin763ee042015-05-20 17:45:30 -0700212 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 = []
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700224 for route in routesJsonObj[ 'routes4' ]:
pingping-lina600d9b2015-01-30 13:57:26 -0800225 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:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700240 # if intent[ 'appId' ] != "org.onosproject.sdnip":
pingping-linf30cf272015-05-29 15:54:07 -0700241 # continue
pingping-lin4e7b0d32015-01-27 18:06:22 -0800242 if intent[ 'type' ] == "MultiPointToSinglePointIntent" \
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700243 and intent[ 'state' ] == 'INSTALLED':
pingping-lin4e7b0d32015-01-27 18:06:22 -0800244 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" \
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700269 and intent[ 'state' ] == 'INSTALLED':
pingping-linf30cf272015-05-29 15:54:07 -0700270 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" \
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700279 and intent[ 'state' ] == 'INSTALLED':
pingping-linf30cf272015-05-29 15:54:07 -0700280 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:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700291 # if intent[ 'appId' ] != "org.onosproject.sdnip":
pingping-linf30cf272015-05-29 15:54:07 -0700292 # continue
pingping-lin4e7b0d32015-01-27 18:06:22 -0800293 if intent[ 'type' ] == "PointToPointIntent" \
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700294 and "protocol=6" in str( intent[ 'selector' ] ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800295 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 \
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700328 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' ] ) \
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700335 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}," \
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000346 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
347 TCP_DST{tcpPort=179}"
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700348 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
pingping-lin4e7b0d32015-01-27 18:06:22 -0800349 .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}," \
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000356 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
357 TCP_SRC{tcpPort=179}"
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700358 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
pingping-lin4e7b0d32015-01-27 18:06:22 -0800359 .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}," \
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000368 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
369 TCP_DST{tcpPort=179}"
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700370 selector = selectorStr.replace( " ", "" ).replace( "[", "" )\
pingping-lin4e7b0d32015-01-27 18:06:22 -0800371 .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}," \
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000378 + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \
379 TCP_SRC{tcpPort=179}"
pingping-lin4e7b0d32015-01-27 18:06:22 -0800380 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
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700403 if len( routes ) > chunk_size:
404 num_iter = ( int )( len( routes ) / chunk_size )
pingping-lin763ee042015-05-20 17:45:30 -0700405 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700406 num_iter = 1
pingping-lin763ee042015-05-20 17:45:30 -0700407
408 total = 0
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700409 for n in range( 0, num_iter + 1 ):
pingping-lin763ee042015-05-20 17:45:30 -0700410 routeCmd = ""
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700411 if ( len( routes ) - ( n * chunk_size ) ) >= chunk_size:
412 m = ( n + 1 ) * chunk_size
pingping-lin763ee042015-05-20 17:45:30 -0700413 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
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700419 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
Jeremy Ronquillo82705492017-10-18 14:19:55 -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-lin4e7b0d32015-01-27 18:06:22 -0800492 # Please use the generateRoutes plus addRoutes instead of this one!
kelvin-onlabd3b64892015-01-20 13:26:24 -0800493 def addRoute( self, net, numRoutes, routeRate ):
timlindbergef8d55d2013-09-27 12:50:13 -0700494 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800495 self.handle.sendline( "" )
496 self.handle.expect( "config-router" )
pingping-lin763ee042015-05-20 17:45:30 -0700497 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800498 main.log.warn( "Probably not in config-router mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700499 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800500 main.log.info( "Adding Routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800501 j = 0
502 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700503 while numRoutes > 255:
504 numRoutes = numRoutes - 255
505 j = j + 1
506 k = numRoutes % 254
kelvin-onlabd3b64892015-01-20 13:26:24 -0800507 routesAdded = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700508 if numRoutes > 255:
509 numRoutes = 255
kelvin-onlabbbe46482015-01-16 10:44:28 -0800510 for m in range( 1, j + 1 ):
511 for n in range( 1, numRoutes + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800512 network = str( net ) + "." + str( m ) + "." + str( n ) \
513 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700514 routeCmd = "network " + network
515 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800516 self.handle.sendline( routeCmd )
517 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700518 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800519 main.log.warn( "failed to add route" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800520 self.disconnect()
521 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800522 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800523 routesAdded = routesAdded + 1
kelvin-onlabbbe46482015-01-16 10:44:28 -0800524 for d in range( j + 1, j + 2 ):
525 for e in range( 1, k + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800526 network = str( net ) + "." + str( d ) + "." + str( e ) \
527 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700528 routeCmd = "network " + network
529 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800530 self.handle.sendline( routeCmd )
531 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700532 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800533 main.log.warn( "failed to add route" )
pingping-lin763ee042015-05-20 17:45:30 -0700534 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800535 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800536 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800537 routesAdded = routesAdded + 1
538 if routesAdded == numRoutes:
timlindbergef8d55d2013-09-27 12:50:13 -0700539 return main.TRUE
540 return main.FALSE
pingping-lin0904ad02015-01-30 15:18:14 -0800541
pingping-lin4e7b0d32015-01-27 18:06:22 -0800542 # Please use deleteRoutes method instead of this one!
kelvin-onlabd3b64892015-01-20 13:26:24 -0800543 def delRoute( self, net, numRoutes, routeRate ):
timlindbergef8d55d2013-09-27 12:50:13 -0700544 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800545 self.handle.sendline( "" )
546 self.handle.expect( "config-router" )
pingping-lin763ee042015-05-20 17:45:30 -0700547 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800548 main.log.warn( "Probably not in config-router mode!" )
timlindbergef8d55d2013-09-27 12:50:13 -0700549 self.disconnect()
kelvin-onlabbbe46482015-01-16 10:44:28 -0800550 main.log.info( "Deleting Routes" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800551 j = 0
552 k = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700553 while numRoutes > 255:
554 numRoutes = numRoutes - 255
555 j = j + 1
556 k = numRoutes % 254
kelvin-onlabd3b64892015-01-20 13:26:24 -0800557 routesDeleted = 0
timlindbergef8d55d2013-09-27 12:50:13 -0700558 if numRoutes > 255:
559 numRoutes = 255
kelvin-onlabbbe46482015-01-16 10:44:28 -0800560 for m in range( 1, j + 1 ):
561 for n in range( 1, numRoutes + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800562 network = str( net ) + "." + str( m ) + "." + str( n ) \
563 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700564 routeCmd = "no network " + network
565 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800566 self.handle.sendline( routeCmd )
567 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700568 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800569 main.log.warn( "Failed to delete route" )
timlindbergef8d55d2013-09-27 12:50:13 -0700570 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800571 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800572 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800573 routesDeleted = routesDeleted + 1
kelvin-onlabbbe46482015-01-16 10:44:28 -0800574 for d in range( j + 1, j + 2 ):
575 for e in range( 1, k + 1 ):
pingping-lin4e7b0d32015-01-27 18:06:22 -0800576 network = str( net ) + "." + str( d ) + "." + str( e ) \
577 + ".0/24"
timlindbergef8d55d2013-09-27 12:50:13 -0700578 routeCmd = "no network " + network
579 try:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800580 self.handle.sendline( routeCmd )
581 self.handle.expect( "bgpd" )
pingping-lin763ee042015-05-20 17:45:30 -0700582 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800583 main.log.warn( "Failed to delete route" )
timlindbergef8d55d2013-09-27 12:50:13 -0700584 self.disconnect()
pingping-linc6b86fa2014-12-01 16:18:10 -0800585 waitTimer = 1.00 / routeRate
kelvin-onlabbbe46482015-01-16 10:44:28 -0800586 time.sleep( waitTimer )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800587 routesDeleted = routesDeleted + 1
588 if routesDeleted == numRoutes:
timlindbergef8d55d2013-09-27 12:50:13 -0700589 return main.TRUE
590 return main.FALSE
pingping-linc6b86fa2014-12-01 16:18:10 -0800591
kelvin-onlabd3b64892015-01-20 13:26:24 -0800592 def checkRoutes( self, brand, ip, user, pw ):
kelvin-onlabbbe46482015-01-16 10:44:28 -0800593 def pronto( ip, user, passwd ):
timlindbergef8d55d2013-09-27 12:50:13 -0700594 print "Connecting to Pronto switch"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800595 child = pexpect.spawn( "telnet " + ip )
596 i = child.expect( [ "login:", "CLI#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700597 if i == 0:
pingping-linc1c696e2015-01-27 13:46:44 -0800598 print "user_name and password required. Passing login info."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800599 child.sendline( user )
600 child.expect( "Password:" )
601 child.sendline( passwd )
602 child.expect( "CLI#" )
timlindbergef8d55d2013-09-27 12:50:13 -0700603 print "Logged in, getting flowtable."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800604 child.sendline( "flowtable brief" )
605 for t in range( 9 ):
timlindbergef8d55d2013-09-27 12:50:13 -0700606 t2 = 9 - t
kelvin-onlabbbe46482015-01-16 10:44:28 -0800607 print "\r" + str( t2 )
608 sys.stdout.write( "\033[F" )
609 time.sleep( 1 )
timlindbergef8d55d2013-09-27 12:50:13 -0700610 print "Scanning flowtable"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800611 child.expect( "Flow table show" )
timlindbergef8d55d2013-09-27 12:50:13 -0700612 count = 0
kelvin-onlabbbe46482015-01-16 10:44:28 -0800613 while True:
pingping-lin0904ad02015-01-30 15:18:14 -0800614 i = child.expect( [ '17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}',
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700615 'CLI#', pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700616 if i == 0:
617 count = count + 1
618 elif i == 1:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800619 print "Pronto flows: " + str( count ) + "\nDone\n"
timlindbergef8d55d2013-09-27 12:50:13 -0700620 break
621 else:
622 break
kelvin-onlabbbe46482015-01-16 10:44:28 -0800623
624 def cisco( ip, user, passwd ):
timlindbergef8d55d2013-09-27 12:50:13 -0700625 print "Establishing Cisco switch connection"
kelvin-onlabbbe46482015-01-16 10:44:28 -0800626 child = pexpect.spawn( "ssh " + user + "@" + ip )
627 i = child.expect( [ "Password:", "CLI#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700628 if i == 0:
629 print "Password required. Passing now."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800630 child.sendline( passwd )
631 child.expect( "#" )
timlindbergef8d55d2013-09-27 12:50:13 -0700632 print "Logged in. Retrieving flow table then counting flows."
kelvin-onlabbbe46482015-01-16 10:44:28 -0800633 child.sendline( "show openflow switch all flows all" )
634 child.expect( "Logical Openflow Switch" )
timlindbergef8d55d2013-09-27 12:50:13 -0700635 print "Flow table retrieved. Counting flows"
636 count = 0
kelvin-onlabbbe46482015-01-16 10:44:28 -0800637 while True:
638 i = child.expect( [ "nw_src=17", "#", pexpect.TIMEOUT ] )
timlindbergef8d55d2013-09-27 12:50:13 -0700639 if i == 0:
640 count = count + 1
641 elif i == 1:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800642 print "Cisco flows: " + str( count ) + "\nDone\n"
timlindbergef8d55d2013-09-27 12:50:13 -0700643 break
644 else:
645 break
646 if brand == "pronto" or brand == "PRONTO":
kelvin-onlabbbe46482015-01-16 10:44:28 -0800647 pronto( ip, user, passwd )
pingping-linc6b86fa2014-12-01 16:18:10 -0800648 # elif brand == "cisco" or brand == "CISCO":
kelvin-onlabbbe46482015-01-16 10:44:28 -0800649 # cisco( ip,user,passwd )
650
pingping-lin763ee042015-05-20 17:45:30 -0700651 def disable_bgp_peer( self, peer, peer_as ):
652 main.log.info( "I am in disconnect_peer_session method!" )
653
654 try:
655 self.handle.sendline( "" )
656 # self.handle.expect( "config-router" )
657 self.handle.expect( "config-router", timeout=5 )
658 except Exception:
659 main.log.warn( "Probably not in config-router mode!" )
660 self.disconnect()
661 main.log.info( "Start to disable peer" )
662
663 cmd = "no neighbor " + peer + " remote-as " + peer_as
664 try:
665 self.handle.sendline( cmd )
666 self.handle.expect( "bgpd", timeout=5 )
667 except Exception:
668 main.log.warn( "Failed to disable peer" )
669 self.disconnect()
670
671 def enable_bgp_peer( self, peer, peer_as ):
672 main.log.info( "I am in enable_bgp_peer method!" )
673
674 try:
675 self.handle.sendline( "" )
676 # self.handle.expect( "config-router" )
677 self.handle.expect( "config-router", timeout=5 )
678 except Exception:
679 main.log.warn( "Probably not in config-router mode!" )
680 self.disconnect()
681 main.log.info( "Start to disable peer" )
682
683 cmd = "neighbor " + peer + " remote-as " + peer_as
684 try:
685 self.handle.sendline( cmd )
686 self.handle.expect( "bgpd", timeout=5 )
687 except Exception:
688 main.log.warn( "Failed to enable peer" )
689 self.disconnect()
690
kelvin-onlabbbe46482015-01-16 10:44:28 -0800691 def disconnect( self ):
692 """
693 Called when Test is complete to disconnect the Quagga handle.
694 """
timlindbergef8d55d2013-09-27 12:50:13 -0700695 response = ''
696 try:
697 self.handle.close()
pingping-lin763ee042015-05-20 17:45:30 -0700698 except Exception:
kelvin-onlabbbe46482015-01-16 10:44:28 -0800699 main.log.error( "Connection failed to the host" )
timlindbergef8d55d2013-09-27 12:50:13 -0700700 response = main.FALSE
701 return response