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 | b27ce4c | 2017-07-17 12:41:28 -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 |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | TestON is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 21 | """ |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 22 | |
| 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 ) |
pingping-lin | a600d9b | 2015-01-30 13:57:26 -0800 | [diff] [blame] | 61 | #main.log.info( "connect parameters:" + str( self.user_name ) + ";" |
| 62 | # + str( self.ip_address ) + ";" + str( self.port ) |
| 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 = [] |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 211 | for route in routesJsonObj['routes4']: |
| 212 | if 'prefix' in route: |
| 213 | if route[ 'prefix' ] == '172.16.10.0/24': |
| 214 | continue |
| 215 | allRoutesActual.append( |
| 216 | route[ 'prefix' ] + "/" + route[ 'nextHop' ] ) |
pingping-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 = [] |
| 224 | for route in routesJsonObj['routes4']: |
| 225 | if route[ 'prefix' ] == '172.16.10.0/24': |
| 226 | continue |
| 227 | allRoutesActual.append( |
| 228 | route[ 'prefix' ] + "/" + route[ 'nextHop' ] ) |
| 229 | |
| 230 | return sorted( allRoutesActual ) |
pingping-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: |
pingping-lin | f30cf27 | 2015-05-29 15:54:07 -0700 | [diff] [blame] | 240 | #if intent[ 'appId' ] != "org.onosproject.sdnip": |
| 241 | # continue |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 242 | if intent[ 'type' ] == "MultiPointToSinglePointIntent" \ |
| 243 | and intent[ 'state' ] == 'INSTALLED': |
| 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" \ |
| 269 | and intent[ 'state' ] == 'INSTALLED': |
| 270 | num = num + 1 |
| 271 | return num |
| 272 | |
| 273 | # This method calculates the PointToPointIntent number installed |
| 274 | def extractActualBgpIntentNum( self, getIntentsResult ): |
| 275 | intentsJsonObj = json.loads( getIntentsResult ) |
| 276 | num = 0 |
| 277 | for intent in intentsJsonObj: |
| 278 | if intent[ 'type' ] == "PointToPointIntent" \ |
| 279 | and intent[ 'state' ] == 'INSTALLED': |
| 280 | num = num + 1 |
| 281 | return num |
| 282 | |
pingping-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: |
pingping-lin | f30cf27 | 2015-05-29 15:54:07 -0700 | [diff] [blame] | 291 | #if intent[ 'appId' ] != "org.onosproject.sdnip": |
| 292 | # continue |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 293 | if intent[ 'type' ] == "PointToPointIntent" \ |
| 294 | and "protocol=6" in str( intent[ 'selector' ] ): |
| 295 | ingress = str( intent[ 'ingress' ][ 'device' ] ) + ":" \ |
| 296 | + str( intent[ 'ingress' ][ 'port' ] ) |
| 297 | egress = str( intent[ 'egress' ][ 'device' ] ) + ":" + \ |
| 298 | str( intent[ 'egress' ][ 'port' ] ) |
| 299 | selector = str( intent[ 'selector' ] ).replace( " ", "" )\ |
| 300 | .replace( "[", "" ).replace( "]", "" ).split( "," ) |
| 301 | intent = ingress + "/" + egress + "/" + \ |
| 302 | str( sorted( selector ) ) |
kelvin-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 \ |
| 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' ] ) \ |
| 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}," \ |
| 346 | + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \ |
| 347 | TCP_DST{tcpPort=179}" |
| 348 | selector = selectorStr.replace( " ", "" ).replace("[", "" )\ |
| 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}," \ |
| 356 | + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \ |
| 357 | TCP_SRC{tcpPort=179}" |
| 358 | selector = selectorStr.replace( " ", "" ).replace("[", "" )\ |
| 359 | .replace( "]", "" ).split( "," ) |
| 360 | intent = bgpSpeakerAttachmentPoint + "/" \ |
| 361 | + bgpPeerAttachmentPoint + "/" + str( sorted( selector ) ) |
kelvin-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}," \ |
| 368 | + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \ |
| 369 | TCP_DST{tcpPort=179}" |
| 370 | selector = selectorStr.replace( " ", "" ).replace("[", "" )\ |
| 371 | .replace( "]", "" ).split( "," ) |
| 372 | intent = bgpPeerAttachmentPoint + "/" \ |
| 373 | + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) ) |
kelvin-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}," \ |
| 378 | + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, \ |
| 379 | TCP_SRC{tcpPort=179}" |
| 380 | selector = selectorStr.replace( " ", "" ).replace( "[", "" )\ |
| 381 | .replace( "]", "" ).split( "," ) |
| 382 | intent = bgpPeerAttachmentPoint + "/" \ |
| 383 | + bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) ) |
kelvin-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 | |
| 403 | if len(routes) > chunk_size: |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 404 | num_iter = (int) (len(routes) / chunk_size) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 405 | else: |
| 406 | num_iter = 1; |
| 407 | |
| 408 | total = 0 |
| 409 | for n in range( 0, num_iter + 1): |
| 410 | routeCmd = "" |
| 411 | if (len( routes ) - (n * chunk_size)) >= chunk_size: |
| 412 | m = (n + 1) * chunk_size |
| 413 | else: |
| 414 | m = len( routes ) |
| 415 | for i in range( n * chunk_size, m ): |
| 416 | routeCmd = routeCmd + "network " + routes[ i ] + "\n" |
| 417 | total = total + 1 |
| 418 | |
| 419 | main.log.info(routeCmd) |
pingping-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 |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -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 | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 492 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 493 | # Please use the generateRoutes plus addRoutes instead of this one! |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 494 | def addRoute( self, net, numRoutes, routeRate ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 495 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 496 | self.handle.sendline( "" ) |
| 497 | self.handle.expect( "config-router" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 498 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 499 | main.log.warn( "Probably not in config-router mode!" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 500 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 501 | main.log.info( "Adding Routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 502 | j = 0 |
| 503 | k = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 504 | while numRoutes > 255: |
| 505 | numRoutes = numRoutes - 255 |
| 506 | j = j + 1 |
| 507 | k = numRoutes % 254 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 508 | routesAdded = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 509 | if numRoutes > 255: |
| 510 | numRoutes = 255 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 511 | for m in range( 1, j + 1 ): |
| 512 | for n in range( 1, numRoutes + 1 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 513 | network = str( net ) + "." + str( m ) + "." + str( n ) \ |
| 514 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 515 | routeCmd = "network " + network |
| 516 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 517 | self.handle.sendline( routeCmd ) |
| 518 | self.handle.expect( "bgpd" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 519 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 520 | main.log.warn( "failed to add route" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 521 | self.disconnect() |
| 522 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 523 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 524 | routesAdded = routesAdded + 1 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 525 | for d in range( j + 1, j + 2 ): |
| 526 | for e in range( 1, k + 1 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 527 | network = str( net ) + "." + str( d ) + "." + str( e ) \ |
| 528 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 529 | routeCmd = "network " + network |
| 530 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 531 | self.handle.sendline( routeCmd ) |
| 532 | self.handle.expect( "bgpd" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 533 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 534 | main.log.warn( "failed to add route" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 535 | self.disconnect() |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 536 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 537 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 538 | routesAdded = routesAdded + 1 |
| 539 | if routesAdded == numRoutes: |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 540 | return main.TRUE |
| 541 | return main.FALSE |
pingping-lin | 0904ad0 | 2015-01-30 15:18:14 -0800 | [diff] [blame] | 542 | |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 543 | # Please use deleteRoutes method instead of this one! |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 544 | def delRoute( self, net, numRoutes, routeRate ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 545 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 546 | self.handle.sendline( "" ) |
| 547 | self.handle.expect( "config-router" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 548 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 549 | main.log.warn( "Probably not in config-router mode!" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 550 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 551 | main.log.info( "Deleting Routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 552 | j = 0 |
| 553 | k = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 554 | while numRoutes > 255: |
| 555 | numRoutes = numRoutes - 255 |
| 556 | j = j + 1 |
| 557 | k = numRoutes % 254 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 558 | routesDeleted = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 559 | if numRoutes > 255: |
| 560 | numRoutes = 255 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 561 | for m in range( 1, j + 1 ): |
| 562 | for n in range( 1, numRoutes + 1 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 563 | network = str( net ) + "." + str( m ) + "." + str( n ) \ |
| 564 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 565 | routeCmd = "no network " + network |
| 566 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 567 | self.handle.sendline( routeCmd ) |
| 568 | self.handle.expect( "bgpd" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 569 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 570 | main.log.warn( "Failed to delete route" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 571 | self.disconnect() |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 572 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 573 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 574 | routesDeleted = routesDeleted + 1 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 575 | for d in range( j + 1, j + 2 ): |
| 576 | for e in range( 1, k + 1 ): |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 577 | network = str( net ) + "." + str( d ) + "." + str( e ) \ |
| 578 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 579 | routeCmd = "no network " + network |
| 580 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 581 | self.handle.sendline( routeCmd ) |
| 582 | self.handle.expect( "bgpd" ) |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 583 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 584 | main.log.warn( "Failed to delete route" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 585 | self.disconnect() |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 586 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 587 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 588 | routesDeleted = routesDeleted + 1 |
| 589 | if routesDeleted == numRoutes: |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 590 | return main.TRUE |
| 591 | return main.FALSE |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 592 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 593 | def checkRoutes( self, brand, ip, user, pw ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 594 | def pronto( ip, user, passwd ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 595 | print "Connecting to Pronto switch" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 596 | child = pexpect.spawn( "telnet " + ip ) |
| 597 | i = child.expect( [ "login:", "CLI#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 598 | if i == 0: |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 599 | print "user_name and password required. Passing login info." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 600 | child.sendline( user ) |
| 601 | child.expect( "Password:" ) |
| 602 | child.sendline( passwd ) |
| 603 | child.expect( "CLI#" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 604 | print "Logged in, getting flowtable." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 605 | child.sendline( "flowtable brief" ) |
| 606 | for t in range( 9 ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 607 | t2 = 9 - t |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 608 | print "\r" + str( t2 ) |
| 609 | sys.stdout.write( "\033[F" ) |
| 610 | time.sleep( 1 ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 611 | print "Scanning flowtable" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 612 | child.expect( "Flow table show" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 613 | count = 0 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 614 | while True: |
pingping-lin | 0904ad0 | 2015-01-30 15:18:14 -0800 | [diff] [blame] | 615 | i = child.expect( [ '17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}', |
pingping-lin | 4e7b0d3 | 2015-01-27 18:06:22 -0800 | [diff] [blame] | 616 | 'CLI#', pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 617 | if i == 0: |
| 618 | count = count + 1 |
| 619 | elif i == 1: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 620 | print "Pronto flows: " + str( count ) + "\nDone\n" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 621 | break |
| 622 | else: |
| 623 | break |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 624 | |
| 625 | def cisco( ip, user, passwd ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 626 | print "Establishing Cisco switch connection" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 627 | child = pexpect.spawn( "ssh " + user + "@" + ip ) |
| 628 | i = child.expect( [ "Password:", "CLI#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 629 | if i == 0: |
| 630 | print "Password required. Passing now." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 631 | child.sendline( passwd ) |
| 632 | child.expect( "#" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 633 | print "Logged in. Retrieving flow table then counting flows." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 634 | child.sendline( "show openflow switch all flows all" ) |
| 635 | child.expect( "Logical Openflow Switch" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 636 | print "Flow table retrieved. Counting flows" |
| 637 | count = 0 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 638 | while True: |
| 639 | i = child.expect( [ "nw_src=17", "#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 640 | if i == 0: |
| 641 | count = count + 1 |
| 642 | elif i == 1: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 643 | print "Cisco flows: " + str( count ) + "\nDone\n" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 644 | break |
| 645 | else: |
| 646 | break |
| 647 | if brand == "pronto" or brand == "PRONTO": |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 648 | pronto( ip, user, passwd ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 649 | # elif brand == "cisco" or brand == "CISCO": |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 650 | # cisco( ip,user,passwd ) |
| 651 | |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 652 | def disable_bgp_peer( self, peer, peer_as ): |
| 653 | main.log.info( "I am in disconnect_peer_session method!" ) |
| 654 | |
| 655 | try: |
| 656 | self.handle.sendline( "" ) |
| 657 | # self.handle.expect( "config-router" ) |
| 658 | self.handle.expect( "config-router", timeout=5 ) |
| 659 | except Exception: |
| 660 | main.log.warn( "Probably not in config-router mode!" ) |
| 661 | self.disconnect() |
| 662 | main.log.info( "Start to disable peer" ) |
| 663 | |
| 664 | cmd = "no neighbor " + peer + " remote-as " + peer_as |
| 665 | try: |
| 666 | self.handle.sendline( cmd ) |
| 667 | self.handle.expect( "bgpd", timeout=5 ) |
| 668 | except Exception: |
| 669 | main.log.warn( "Failed to disable peer" ) |
| 670 | self.disconnect() |
| 671 | |
| 672 | def enable_bgp_peer( self, peer, peer_as ): |
| 673 | main.log.info( "I am in enable_bgp_peer method!" ) |
| 674 | |
| 675 | try: |
| 676 | self.handle.sendline( "" ) |
| 677 | # self.handle.expect( "config-router" ) |
| 678 | self.handle.expect( "config-router", timeout=5 ) |
| 679 | except Exception: |
| 680 | main.log.warn( "Probably not in config-router mode!" ) |
| 681 | self.disconnect() |
| 682 | main.log.info( "Start to disable peer" ) |
| 683 | |
| 684 | cmd = "neighbor " + peer + " remote-as " + peer_as |
| 685 | try: |
| 686 | self.handle.sendline( cmd ) |
| 687 | self.handle.expect( "bgpd", timeout=5 ) |
| 688 | except Exception: |
| 689 | main.log.warn( "Failed to enable peer" ) |
| 690 | self.disconnect() |
| 691 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 692 | def disconnect( self ): |
| 693 | """ |
| 694 | Called when Test is complete to disconnect the Quagga handle. |
| 695 | """ |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 696 | response = '' |
| 697 | try: |
| 698 | self.handle.close() |
pingping-lin | 763ee04 | 2015-05-20 17:45:30 -0700 | [diff] [blame] | 699 | except Exception: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 700 | main.log.error( "Connection failed to the host" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 701 | response = main.FALSE |
| 702 | return response |
pingping-lin | c1c696e | 2015-01-27 13:46:44 -0800 | [diff] [blame] | 703 | |