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