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