timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 2 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 3 | Copyright 2015 Open Networking Foundation ( ONF ) |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 4 | |
| 5 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 6 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 7 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 8 | |
| 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 12 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 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 Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 21 | """ |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 22 | import time |
| 23 | import pexpect |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 24 | import sys |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 25 | import json |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 26 | from drivers.common.clidriver import CLI |
| 27 | |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 28 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 29 | class QuaggaCliDriver( CLI ): |
| 30 | |
| 31 | def __init__( self ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 32 | super( QuaggaCliDriver, self ).__init__() |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 33 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 34 | # TODO: simplify this method |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 35 | def connect( self, **connectargs ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 36 | for key in connectargs: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 37 | vars( self )[ key ] = connectargs[ key ] |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 38 | 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-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 49 | |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 50 | def connectQuagga( self ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 51 | self.name = self.options[ 'name' ] |
| 52 | # self.handle = super( QuaggaCliDriver,self ).connect( |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 53 | # user_name=self.user_name, ip_address=self.ip_address,port=self.port, |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 54 | # pwd=self.pwd ) |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 55 | self.handle = super( QuaggaCliDriver, self ).connect( |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 56 | user_name=self.user_name, |
| 57 | ip_address="1.1.1.1", |
| 58 | port=self.port, |
| 59 | pwd=self.pwd ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 60 | # main.log.info( "connect parameters:" + str( self.user_name ) + ";" |
pingping-lin | a600d9b | 2015-01-30 13:57:26 -0800 | [diff] [blame] | 61 | # + str( self.ip_address ) + ";" + str( self.port ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 62 | # + ";" + str( self.pwd ) ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 63 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 64 | if self.handle: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 65 | # self.handle.expect( "",timeout=10 ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 66 | # self.handle.expect( self.prompt,timeout=10 ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 67 | 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#" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 76 | return self.handle |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 77 | else: |
| 78 | main.log.info( "NO HANDLE" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 79 | return main.FALSE |
| 80 | |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 81 | def loginQuagga( self, ip_address ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 82 | self.name = self.options[ 'name' ] |
| 83 | self.handle = super( QuaggaCliDriver, self ).connect( |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 84 | user_name=self.user_name, ip_address=ip_address, |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 85 | port=self.port, pwd=self.pwd ) |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 86 | main.log.info( "connect parameters:" + str( self.user_name ) + ";" |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 87 | + str( self.ip_address ) + ";" + str( self.port ) |
| 88 | + ";" + str( self.pwd ) ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 89 | |
| 90 | if self.handle: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 91 | # self.handle.expect( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 92 | # self.handle.expect( self.prompt ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 93 | 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-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 102 | main.log.info( "I am in quagga on host " + str( ip_address ) ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 103 | |
| 104 | return self.handle |
| 105 | else: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 106 | main.log.info( "NO HANDLE" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 107 | return main.FALSE |
| 108 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 109 | def enterConfig( self, asn ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 110 | main.log.info( "I am in enter_config method!" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 111 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 112 | self.handle.sendline( "" ) |
| 113 | self.handle.expect( "bgpd#" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 114 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 115 | main.log.warn( "Probably not currently in enable mode!" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 116 | self.disconnect() |
| 117 | return main.FALSE |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 118 | self.handle.sendline( "configure terminal" ) |
| 119 | self.handle.expect( "config", timeout=5 ) |
| 120 | routerAS = "router bgp " + str( asn ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 121 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 122 | self.handle.sendline( routerAS ) |
| 123 | self.handle.expect( "config-router", timeout=5 ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 124 | return main.TRUE |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 125 | except Exception: |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 126 | return main.FALSE |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 127 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 128 | def generatePrefixes( self, net, numRoutes ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 129 | main.log.info( "I am in generate_prefixes method!" ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 130 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 131 | # each IP prefix is composed by "net" + "." + m + "." + n + "." + x |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 132 | # the length of each IP prefix is 24 |
| 133 | routes = [] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 134 | routesGen = 0 |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 135 | m = numRoutes / 256 |
| 136 | n = numRoutes % 256 |
| 137 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 138 | for i in range( 0, m ): |
| 139 | for j in range( 0, 256 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 140 | network = str( net ) + "." + str( i ) + "." + str( j ) \ |
| 141 | + ".0/24" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 142 | routes.append( network ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 143 | routesGen = routesGen + 1 |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 144 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 145 | for j in range( 0, n ): |
| 146 | network = str( net ) + "." + str( m ) + "." + str( j ) + ".0/24" |
| 147 | routes.append( network ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 148 | routesGen = routesGen + 1 |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 149 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 150 | if routesGen == numRoutes: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 151 | main.log.info( "Successfully generated " + str( numRoutes ) |
| 152 | + " prefixes!" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 153 | return routes |
| 154 | return main.FALSE |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 155 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 156 | # This method generates a multiple to single point intent( |
| 157 | # MultiPointToSinglePointIntent ) for a given route |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 158 | def generateExpectedSingleRouteIntent( self, prefix, nextHop, nextHopMac, |
| 159 | sdnipData ): |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 160 | |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 161 | ingresses = [] |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 162 | egress = "" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 163 | for peer in sdnipData[ 'bgpPeers' ]: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 164 | if peer[ 'ipAddress' ] == nextHop: |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 165 | egress = "of:" + str( |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 166 | peer[ 'attachmentDpid' ] ).replace( ":", "" ) + ":" \ |
| 167 | + str( peer[ 'attachmentPort' ] ) |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 168 | for peer in sdnipData[ 'bgpPeers' ]: |
| 169 | if not peer[ 'ipAddress' ] == nextHop: |
| 170 | ingress = "of:" + str( |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 171 | peer[ 'attachmentDpid' ] ).replace( ":", "" ) + ":" \ |
| 172 | + str( peer[ 'attachmentPort' ] ) |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 173 | 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-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 178 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 179 | selector = "ETH_TYPE{ethType=800},IPV4_DST{ip=" + prefix + "}" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 180 | treatment = "[ETH_DST{mac=" + str( nextHopMac ) + "}]" |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 181 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 182 | intent = egress + "/" + str( sorted( ingresses ) ) + "/" + \ |
| 183 | selector + "/" + treatment |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 184 | return intent |
| 185 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 186 | def generateExpectedOnePeerRouteIntents( self, prefixes, nextHop, |
| 187 | nextHopMac, sdnipJsonFilePath ): |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 188 | intents = [] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 189 | sdnipJsonFile = open( sdnipJsonFilePath ).read() |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 190 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 191 | sdnipData = json.loads( sdnipJsonFile ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 192 | |
| 193 | for prefix in prefixes: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 194 | intents.append( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 195 | self.generateExpectedSingleRouteIntent( |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 196 | prefix, nextHop, nextHopMac, sdnipData ) ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 197 | return sorted( intents ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 198 | |
| 199 | # TODO |
| 200 | # This method generates all expected route intents for all BGP peers |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 201 | def generateExpectedRouteIntents( self ): |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 202 | intents = [] |
| 203 | return intents |
| 204 | |
| 205 | # This method extracts all actual routes from ONOS CLI |
pingping-lin | b2a8658 | 2015-02-02 16:18:59 -0800 | [diff] [blame] | 206 | def extractActualRoutesOneDotZero( self, getRoutesResult ): |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 207 | routesJsonObj = json.loads( getRoutesResult ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 208 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 209 | allRoutesActual = [] |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 210 | for route in routesJsonObj[ 'routes4' ]: |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 211 | if 'prefix' in route: |
| 212 | if route[ 'prefix' ] == '172.16.10.0/24': |
| 213 | continue |
| 214 | allRoutesActual.append( |
| 215 | route[ 'prefix' ] + "/" + route[ 'nextHop' ] ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 216 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 217 | return sorted( allRoutesActual ) |
pingping-lin | b2a8658 | 2015-02-02 16:18:59 -0800 | [diff] [blame] | 218 | |
| 219 | def extractActualRoutesMaster( self, getRoutesResult ): |
pingping-lin | a600d9b | 2015-01-30 13:57:26 -0800 | [diff] [blame] | 220 | routesJsonObj = json.loads( getRoutesResult ) |
| 221 | |
| 222 | allRoutesActual = [] |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 223 | for route in routesJsonObj[ 'routes4' ]: |
pingping-lin | a600d9b | 2015-01-30 13:57:26 -0800 | [diff] [blame] | 224 | if route[ 'prefix' ] == '172.16.10.0/24': |
| 225 | continue |
| 226 | allRoutesActual.append( |
| 227 | route[ 'prefix' ] + "/" + route[ 'nextHop' ] ) |
| 228 | |
| 229 | return sorted( allRoutesActual ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 230 | |
| 231 | # This method extracts all actual route intents from ONOS CLI |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 232 | def extractActualRouteIntents( self, getIntentsResult ): |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 233 | intents = [] |
| 234 | # TODO: delete the line below when change to Mininet demo script |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 235 | # getIntentsResult=open( "../tests/SdnIpTest/intents.json" ).read() |
| 236 | intentsJsonObj = json.loads( getIntentsResult ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 237 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 238 | for intent in intentsJsonObj: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 239 | # if intent[ 'appId' ] != "org.onosproject.sdnip": |
pingping-lin | f30cf27 | 2015-05-29 15:54:07 -0700 | [diff] [blame] | 240 | # continue |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 241 | if intent[ 'type' ] == "MultiPointToSinglePointIntent" \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 242 | and intent[ 'state' ] == 'INSTALLED': |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 243 | egress = str( intent[ 'egress' ][ 'device' ] ) + ":" \ |
| 244 | + str( intent[ 'egress' ][ 'port' ] ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 245 | ingress = [] |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 246 | for attachmentPoint in intent[ 'ingress' ]: |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 247 | ingress.append( |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 248 | str( attachmentPoint[ 'device' ] ) + ":" |
| 249 | + str( attachmentPoint[ 'port' ] ) ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 250 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 251 | selector = intent[ 'selector' ].replace( |
| 252 | "[", "" ).replace( "]", "" ).replace( " ", "" ) |
| 253 | if str( selector ).startswith( "IPV4" ): |
| 254 | str1, str2 = str( selector ).split( "," ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 255 | selector = str2 + "," + str1 |
| 256 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 257 | intent = egress + "/" + str( sorted( ingress ) ) + "/" + \ |
| 258 | selector + "/" + intent[ 'treatment' ] |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 259 | intents.append( intent ) |
| 260 | return sorted( intents ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 261 | |
pingping-lin | f30cf27 | 2015-05-29 15:54:07 -0700 | [diff] [blame] | 262 | # 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 268 | and intent[ 'state' ] == 'INSTALLED': |
pingping-lin | f30cf27 | 2015-05-29 15:54:07 -0700 | [diff] [blame] | 269 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 278 | and intent[ 'state' ] == 'INSTALLED': |
pingping-lin | f30cf27 | 2015-05-29 15:54:07 -0700 | [diff] [blame] | 279 | num = num + 1 |
| 280 | return num |
| 281 | |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 282 | # This method extracts all actual BGP intents from ONOS CLI |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 283 | def extractActualBgpIntents( self, getIntentsResult ): |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 284 | intents = [] |
| 285 | # TODO: delete the line below when change to Mininet demo script |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 286 | # getIntentsResult=open( "../tests/SdnIpTest/intents.json" ).read() |
| 287 | intentsJsonObj = json.loads( getIntentsResult ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 288 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 289 | for intent in intentsJsonObj: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 290 | # if intent[ 'appId' ] != "org.onosproject.sdnip": |
pingping-lin | f30cf27 | 2015-05-29 15:54:07 -0700 | [diff] [blame] | 291 | # continue |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 292 | if intent[ 'type' ] == "PointToPointIntent" \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 293 | and "protocol=6" in str( intent[ 'selector' ] ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 294 | 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-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 302 | intents.append( intent ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 303 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 304 | return sorted( intents ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 305 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 306 | # This method generates a single point to single point intent( |
| 307 | # PointToPointIntent ) for BGP path |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 308 | def generateExpectedBgpIntents( self, sdnipJsonFilePath ): |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 309 | from operator import eq |
| 310 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 311 | sdnipJsonFile = open( sdnipJsonFilePath ).read() |
| 312 | sdnipData = json.loads( sdnipJsonFile ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 313 | |
| 314 | intents = [] |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 315 | bgpPeerAttachmentPoint = "" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 316 | bgpSpeakerAttachmentPoint = "of:" + str( |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 317 | sdnipData[ 'bgpSpeakers' ][ 0 ][ 'attachmentDpid' ] )\ |
| 318 | .replace( ":", "" ) + ":" \ |
| 319 | + str( sdnipData[ 'bgpSpeakers' ][ 0 ][ 'attachmentPort' ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 320 | for peer in sdnipData[ 'bgpPeers' ]: |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 321 | bgpPeerAttachmentPoint = "of:" \ |
| 322 | + str( peer[ 'attachmentDpid' ] ).replace( ":", "" ) \ |
| 323 | + ":" + str( peer[ 'attachmentPort' ] ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 324 | # find out the BGP speaker IP address for this BGP peer |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 325 | bgpSpeakerIpAddress = "" |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 326 | for interfaceAddress in \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 327 | sdnipData[ 'bgpSpeakers' ][ 0 ][ 'interfaceAddresses' ]: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 328 | # if eq( interfaceAddress[ 'interfaceDpid' ],sdnipData[ |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 329 | # 'bgpSpeakers' ][ 0 ][ 'attachmentDpid' ] ) and eq( |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 330 | # interfaceAddress[ 'interfacePort' ], sdnipData[ 'bgpSpeakers' |
| 331 | # ][ 0 ][ 'attachmentPort' ] ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 332 | if eq( interfaceAddress[ 'interfaceDpid' ], |
| 333 | peer[ 'attachmentDpid' ] ) \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 334 | and eq( interfaceAddress[ 'interfacePort' ], |
| 335 | peer[ 'attachmentPort' ] ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 336 | bgpSpeakerIpAddress = interfaceAddress[ 'ipAddress' ] |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 337 | break |
| 338 | else: |
| 339 | continue |
| 340 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 341 | # from bgpSpeakerAttachmentPoint to bgpPeerAttachmentPoint |
| 342 | # direction |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 343 | selectorStr = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," \ |
| 344 | + "IPV4_DST{ip=" + peer[ 'ipAddress' ] + "/32}," \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 345 | + "IP_PROTO{ protocol=6 }, ETH_TYPE{ ethType=800 }, \ |
| 346 | TCP_DST{ tcpPort=179 }" |
| 347 | selector = selectorStr.replace( " ", "" ).replace( "[", "" )\ |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 348 | .replace( "]", "" ).split( "," ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 349 | intent = bgpSpeakerAttachmentPoint + "/" + \ |
| 350 | bgpPeerAttachmentPoint + "/" + str( sorted( selector ) ) |
| 351 | intents.append( intent ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 352 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 353 | selectorStr = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," \ |
| 354 | + "IPV4_DST{ip=" + peer[ 'ipAddress' ] + "/32}," \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 355 | + "IP_PROTO{ protocol=6 }, ETH_TYPE{ ethType=800 }, \ |
| 356 | TCP_SRC{ tcpPort=179 }" |
| 357 | selector = selectorStr.replace( " ", "" ).replace( "[", "" )\ |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 358 | .replace( "]", "" ).split( "," ) |
| 359 | intent = bgpSpeakerAttachmentPoint + "/" \ |
| 360 | + bgpPeerAttachmentPoint + "/" + str( sorted( selector ) ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 361 | intents.append( intent ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 362 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 363 | # from bgpPeerAttachmentPoint to bgpSpeakerAttachmentPoint |
| 364 | # direction |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 365 | selectorStr = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," \ |
| 366 | + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 367 | + "IP_PROTO{ protocol=6 }, ETH_TYPE{ ethType=800 }, \ |
| 368 | TCP_DST{ tcpPort=179 }" |
| 369 | selector = selectorStr.replace( " ", "" ).replace( "[", "" )\ |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 370 | .replace( "]", "" ).split( "," ) |
| 371 | intent = bgpPeerAttachmentPoint + "/" \ |
| 372 | + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 373 | intents.append( intent ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 374 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 375 | selectorStr = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," \ |
| 376 | + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 377 | + "IP_PROTO{ protocol=6 }, ETH_TYPE{ ethType=800 }, \ |
| 378 | TCP_SRC{ tcpPort=179 }" |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 379 | selector = selectorStr.replace( " ", "" ).replace( "[", "" )\ |
| 380 | .replace( "]", "" ).split( "," ) |
| 381 | intent = bgpPeerAttachmentPoint + "/" \ |
| 382 | + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 383 | intents.append( intent ) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 384 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 385 | return sorted( intents ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 386 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 387 | def addRoutes( self, routes, routeRate ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 388 | main.log.info( "I am in add_routes method!" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 389 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 390 | routesAdded = 0 |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 391 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 392 | self.handle.sendline( "" ) |
| 393 | # self.handle.expect( "config-router" ) |
| 394 | self.handle.expect( "config-router", timeout=5 ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 395 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 396 | main.log.warn( "Probably not in config-router mode!" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 397 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 398 | main.log.info( "Start to add routes" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 399 | |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 400 | chunk_size = 20 |
| 401 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 402 | if len( routes ) > chunk_size: |
| 403 | num_iter = ( int )( len( routes ) / chunk_size ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 404 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 405 | num_iter = 1 |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 406 | |
| 407 | total = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 408 | for n in range( 0, num_iter + 1 ): |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 409 | routeCmd = "" |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 410 | if ( len( routes ) - ( n * chunk_size ) ) >= chunk_size: |
| 411 | m = ( n + 1 ) * chunk_size |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 412 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 418 | main.log.info( routeCmd ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 419 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 420 | self.handle.sendline( routeCmd ) |
| 421 | self.handle.expect( "bgpd", timeout=5 ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 422 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 423 | main.log.warn( "Failed to add route" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 424 | self.disconnect() |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 425 | |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 426 | # waitTimer = 1.00 / routeRate |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 427 | main.log.info( "Total routes so far " + ( ( str )( total ) ) + " wait for 0 sec" ) |
| 428 | # time.sleep( 1 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 429 | if routesAdded == len( routes ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 430 | main.log.info( "Finished adding routes" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 431 | return main.TRUE |
| 432 | return main.FALSE |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 433 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 434 | def deleteRoutes( self, routes, routeRate ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 435 | main.log.info( "I am in delete_routes method!" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 436 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 437 | routesAdded = 0 |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 438 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 439 | self.handle.sendline( "" ) |
| 440 | # self.handle.expect( "config-router" ) |
| 441 | self.handle.expect( "config-router", timeout=5 ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 442 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 443 | main.log.warn( "Probably not in config-router mode!" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 444 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 445 | main.log.info( "Start to delete routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 446 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 447 | for i in range( 0, len( routes ) ): |
| 448 | routeCmd = "no network " + routes[ i ] |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 449 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 450 | self.handle.sendline( routeCmd ) |
| 451 | self.handle.expect( "bgpd", timeout=5 ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 452 | except Exception: |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 453 | main.log.warn( "Failed to delete route" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 454 | self.disconnect() |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 455 | # waitTimer = 1.00 / routeRate |
| 456 | # time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 457 | if routesAdded == len( routes ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 458 | main.log.info( "Finished deleting routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 459 | return main.TRUE |
| 460 | return main.FALSE |
| 461 | |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 462 | def pingTest( self, ip_address, pingTestFile, pingTestResultFile ): |
| 463 | main.log.info( "Start the ping test on host:" + str( ip_address ) ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 464 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 465 | self.name = self.options[ 'name' ] |
| 466 | self.handle = super( QuaggaCliDriver, self ).connect( |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 467 | user_name=self.user_name, ip_address=ip_address, |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 468 | port=self.port, pwd=self.pwd ) |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 469 | main.log.info( "connect parameters:" + str( self.user_name ) + ";" |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 470 | + str( self.ip_address ) + ";" + str( self.port ) |
| 471 | + ";" + str( self.pwd ) ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 472 | |
| 473 | if self.handle: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 474 | # self.handle.expect( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 475 | # self.handle.expect( self.prompt ) |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 476 | main.log.info( "I in host " + str( ip_address ) ) |
| 477 | main.log.info( pingTestFile + " > " + pingTestResultFile + " &" ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 478 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 479 | pingTestFile + |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 480 | " > " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 481 | pingTestResultFile + |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 482 | " &" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 483 | self.handle.expect( self.prompt, timeout=60 ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 484 | handle = self.handle.before |
| 485 | |
| 486 | return handle |
| 487 | else: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 488 | main.log.info( "NO HANDLE" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 489 | return main.FALSE |
| 490 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 491 | # Please use the generateRoutes plus addRoutes instead of this one! |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 492 | def addRoute( self, net, numRoutes, routeRate ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 493 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 494 | self.handle.sendline( "" ) |
| 495 | self.handle.expect( "config-router" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 496 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 497 | main.log.warn( "Probably not in config-router mode!" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 498 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 499 | main.log.info( "Adding Routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 500 | j = 0 |
| 501 | k = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 502 | while numRoutes > 255: |
| 503 | numRoutes = numRoutes - 255 |
| 504 | j = j + 1 |
| 505 | k = numRoutes % 254 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 506 | routesAdded = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 507 | if numRoutes > 255: |
| 508 | numRoutes = 255 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 509 | for m in range( 1, j + 1 ): |
| 510 | for n in range( 1, numRoutes + 1 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 511 | network = str( net ) + "." + str( m ) + "." + str( n ) \ |
| 512 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 513 | routeCmd = "network " + network |
| 514 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 515 | self.handle.sendline( routeCmd ) |
| 516 | self.handle.expect( "bgpd" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 517 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 518 | main.log.warn( "failed to add route" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 519 | self.disconnect() |
| 520 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 521 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 522 | routesAdded = routesAdded + 1 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 523 | for d in range( j + 1, j + 2 ): |
| 524 | for e in range( 1, k + 1 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 525 | network = str( net ) + "." + str( d ) + "." + str( e ) \ |
| 526 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 527 | routeCmd = "network " + network |
| 528 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 529 | self.handle.sendline( routeCmd ) |
| 530 | self.handle.expect( "bgpd" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 531 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 532 | main.log.warn( "failed to add route" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 533 | self.disconnect() |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 534 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 535 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 536 | routesAdded = routesAdded + 1 |
| 537 | if routesAdded == numRoutes: |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 538 | return main.TRUE |
| 539 | return main.FALSE |
pingping-lin | 0904ad0 | 2015-01-30 15:18:14 -0800 | [diff] [blame] | 540 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 541 | # Please use deleteRoutes method instead of this one! |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 542 | def delRoute( self, net, numRoutes, routeRate ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 543 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 544 | self.handle.sendline( "" ) |
| 545 | self.handle.expect( "config-router" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 546 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 547 | main.log.warn( "Probably not in config-router mode!" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 548 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 549 | main.log.info( "Deleting Routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 550 | j = 0 |
| 551 | k = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 552 | while numRoutes > 255: |
| 553 | numRoutes = numRoutes - 255 |
| 554 | j = j + 1 |
| 555 | k = numRoutes % 254 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 556 | routesDeleted = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 557 | if numRoutes > 255: |
| 558 | numRoutes = 255 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 559 | for m in range( 1, j + 1 ): |
| 560 | for n in range( 1, numRoutes + 1 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 561 | network = str( net ) + "." + str( m ) + "." + str( n ) \ |
| 562 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 563 | routeCmd = "no network " + network |
| 564 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 565 | self.handle.sendline( routeCmd ) |
| 566 | self.handle.expect( "bgpd" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 567 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 568 | main.log.warn( "Failed to delete route" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 569 | self.disconnect() |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 570 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 571 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 572 | routesDeleted = routesDeleted + 1 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 573 | for d in range( j + 1, j + 2 ): |
| 574 | for e in range( 1, k + 1 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 575 | network = str( net ) + "." + str( d ) + "." + str( e ) \ |
| 576 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 577 | routeCmd = "no network " + network |
| 578 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 579 | self.handle.sendline( routeCmd ) |
| 580 | self.handle.expect( "bgpd" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 581 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 582 | main.log.warn( "Failed to delete route" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 583 | self.disconnect() |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 584 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 585 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 586 | routesDeleted = routesDeleted + 1 |
| 587 | if routesDeleted == numRoutes: |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 588 | return main.TRUE |
| 589 | return main.FALSE |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 590 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 591 | def checkRoutes( self, brand, ip, user, pw ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 592 | def pronto( ip, user, passwd ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 593 | print "Connecting to Pronto switch" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 594 | child = pexpect.spawn( "telnet " + ip ) |
| 595 | i = child.expect( [ "login:", "CLI#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 596 | if i == 0: |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 597 | print "user_name and password required. Passing login info." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 598 | child.sendline( user ) |
| 599 | child.expect( "Password:" ) |
| 600 | child.sendline( passwd ) |
| 601 | child.expect( "CLI#" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 602 | print "Logged in, getting flowtable." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 603 | child.sendline( "flowtable brief" ) |
| 604 | for t in range( 9 ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 605 | t2 = 9 - t |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 606 | print "\r" + str( t2 ) |
| 607 | sys.stdout.write( "\033[F" ) |
| 608 | time.sleep( 1 ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 609 | print "Scanning flowtable" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 610 | child.expect( "Flow table show" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 611 | count = 0 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 612 | while True: |
pingping-lin | 0904ad0 | 2015-01-30 15:18:14 -0800 | [diff] [blame] | 613 | i = child.expect( [ '17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}', |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 614 | 'CLI#', pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 615 | if i == 0: |
| 616 | count = count + 1 |
| 617 | elif i == 1: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 618 | print "Pronto flows: " + str( count ) + "\nDone\n" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 619 | break |
| 620 | else: |
| 621 | break |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 622 | |
| 623 | def cisco( ip, user, passwd ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 624 | print "Establishing Cisco switch connection" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 625 | child = pexpect.spawn( "ssh " + user + "@" + ip ) |
| 626 | i = child.expect( [ "Password:", "CLI#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 627 | if i == 0: |
| 628 | print "Password required. Passing now." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 629 | child.sendline( passwd ) |
| 630 | child.expect( "#" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 631 | print "Logged in. Retrieving flow table then counting flows." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 632 | child.sendline( "show openflow switch all flows all" ) |
| 633 | child.expect( "Logical Openflow Switch" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 634 | print "Flow table retrieved. Counting flows" |
| 635 | count = 0 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 636 | while True: |
| 637 | i = child.expect( [ "nw_src=17", "#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 638 | if i == 0: |
| 639 | count = count + 1 |
| 640 | elif i == 1: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 641 | print "Cisco flows: " + str( count ) + "\nDone\n" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 642 | break |
| 643 | else: |
| 644 | break |
| 645 | if brand == "pronto" or brand == "PRONTO": |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 646 | pronto( ip, user, passwd ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 647 | # elif brand == "cisco" or brand == "CISCO": |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 648 | # cisco( ip,user,passwd ) |
| 649 | |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 650 | 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-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 690 | def disconnect( self ): |
| 691 | """ |
| 692 | Called when Test is complete to disconnect the Quagga handle. |
| 693 | """ |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 694 | response = '' |
| 695 | try: |
| 696 | self.handle.close() |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 697 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 698 | main.log.error( "Connection failed to the host" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 699 | response = main.FALSE |
| 700 | return response |