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