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 | |
sanghoshin | 7050200 | 2015-03-11 10:21:14 -0700 | [diff] [blame^] | 357 | chunk_size = 20 |
| 358 | |
| 359 | if len(routes) > chunk_size: |
| 360 | num_iter = (int) (len(routes) / chunk_size) |
| 361 | else: |
| 362 | num_iter = 1; |
| 363 | |
| 364 | total = 0 |
| 365 | for n in range( 0, num_iter + 1): |
| 366 | routeCmd = "" |
| 367 | if (len( routes ) - (n * chunk_size)) >= chunk_size: |
| 368 | m = (n + 1) * chunk_size |
| 369 | else: |
| 370 | m = len( routes ) |
| 371 | for i in range( n * chunk_size, m ): |
| 372 | routeCmd = routeCmd + "network " + routes[ i ] + "\n" |
| 373 | total = total + 1 |
| 374 | |
| 375 | main.log.info(routeCmd) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 376 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 377 | self.handle.sendline( routeCmd ) |
| 378 | self.handle.expect( "bgpd", timeout=5 ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 379 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 380 | main.log.warn( "Failed to add route" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 381 | self.disconnect() |
sanghoshin | 7050200 | 2015-03-11 10:21:14 -0700 | [diff] [blame^] | 382 | |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 383 | # waitTimer = 1.00 / routeRate |
sanghoshin | 7050200 | 2015-03-11 10:21:14 -0700 | [diff] [blame^] | 384 | main.log.info("Total routes so far " + ((str) (total)) + " wait for 0 sec") |
| 385 | #time.sleep( 1 ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 386 | if routesAdded == len( routes ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 387 | main.log.info( "Finished adding routes" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 388 | return main.TRUE |
| 389 | return main.FALSE |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 390 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 391 | def deleteRoutes( self, routes, routeRate ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 392 | main.log.info( "I am in delete_routes method!" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 393 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 394 | routesAdded = 0 |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 395 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 396 | self.handle.sendline( "" ) |
| 397 | # self.handle.expect( "config-router" ) |
| 398 | self.handle.expect( "config-router", timeout=5 ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 399 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 400 | main.log.warn( "Probably not in config-router mode!" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 401 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 402 | main.log.info( "Start to delete routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 403 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 404 | for i in range( 0, len( routes ) ): |
| 405 | routeCmd = "no network " + routes[ i ] |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 406 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 407 | self.handle.sendline( routeCmd ) |
| 408 | self.handle.expect( "bgpd", timeout=5 ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 409 | except: |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 410 | main.log.warn( "Failed to delete route" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 411 | self.disconnect() |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 412 | # waitTimer = 1.00 / routeRate |
| 413 | # time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 414 | if routesAdded == len( routes ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 415 | main.log.info( "Finished deleting routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 416 | return main.TRUE |
| 417 | return main.FALSE |
| 418 | |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 419 | def pingTest( self, ip_address, pingTestFile, pingTestResultFile ): |
| 420 | main.log.info( "Start the ping test on host:" + str( ip_address ) ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 421 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 422 | self.name = self.options[ 'name' ] |
| 423 | self.handle = super( QuaggaCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 424 | user_name=self.user_name, ip_address=ip_address, |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 425 | port=self.port, pwd=self.pwd ) |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 426 | main.log.info( "connect parameters:" + str( self.user_name ) + ";" |
| 427 | + str( self.ip_address ) + ";" + str( self.port ) |
| 428 | + ";" + str( self.pwd ) ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 429 | |
| 430 | if self.handle: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 431 | # self.handle.expect( "" ) |
| 432 | # self.handle.expect( "\$" ) |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 433 | main.log.info( "I in host " + str( ip_address ) ) |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 434 | main.log.info( pingTestFile + " > " + pingTestResultFile + " &" ) |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 435 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 436 | pingTestFile + |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 437 | " > " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 438 | pingTestResultFile + |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 439 | " &" ) |
| 440 | self.handle.expect( "\$", timeout=60 ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 441 | handle = self.handle.before |
| 442 | |
| 443 | return handle |
| 444 | else: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 445 | main.log.info( "NO HANDLE" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 446 | return main.FALSE |
| 447 | |
sanghoshin | 29e6a47 | 2015-02-27 12:55:06 -0800 | [diff] [blame] | 448 | |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 449 | # Please use the generateRoutes plus addRoutes instead of this one! |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 450 | def addRoute( self, net, numRoutes, routeRate ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 451 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 452 | self.handle.sendline( "" ) |
| 453 | self.handle.expect( "config-router" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 454 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 455 | main.log.warn( "Probably not in config-router mode!" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 456 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 457 | main.log.info( "Adding Routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 458 | j = 0 |
| 459 | k = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 460 | while numRoutes > 255: |
| 461 | numRoutes = numRoutes - 255 |
| 462 | j = j + 1 |
| 463 | k = numRoutes % 254 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 464 | routesAdded = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 465 | if numRoutes > 255: |
| 466 | numRoutes = 255 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 467 | for m in range( 1, j + 1 ): |
| 468 | for n in range( 1, numRoutes + 1 ): |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 469 | network = str( net ) + "." + str( m ) + "." + str( n ) \ |
| 470 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 471 | routeCmd = "network " + network |
| 472 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 473 | self.handle.sendline( routeCmd ) |
| 474 | self.handle.expect( "bgpd" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 475 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 476 | main.log.warn( "failed to add route" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 477 | self.disconnect() |
| 478 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 479 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 480 | routesAdded = routesAdded + 1 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 481 | for d in range( j + 1, j + 2 ): |
| 482 | for e in range( 1, k + 1 ): |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 483 | network = str( net ) + "." + str( d ) + "." + str( e ) \ |
| 484 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 485 | routeCmd = "network " + network |
| 486 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 487 | self.handle.sendline( routeCmd ) |
| 488 | self.handle.expect( "bgpd" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 489 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 490 | main.log.warn( "failed to add route" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 491 | self.disconnect |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 492 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 493 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 494 | routesAdded = routesAdded + 1 |
| 495 | if routesAdded == numRoutes: |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 496 | return main.TRUE |
| 497 | return main.FALSE |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 498 | |
| 499 | # Please use deleteRoutes method instead of this one! |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 500 | def delRoute( self, net, numRoutes, routeRate ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 501 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 502 | self.handle.sendline( "" ) |
| 503 | self.handle.expect( "config-router" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 504 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 505 | main.log.warn( "Probably not in config-router mode!" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 506 | self.disconnect() |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 507 | main.log.info( "Deleting Routes" ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 508 | j = 0 |
| 509 | k = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 510 | while numRoutes > 255: |
| 511 | numRoutes = numRoutes - 255 |
| 512 | j = j + 1 |
| 513 | k = numRoutes % 254 |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 514 | routesDeleted = 0 |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 515 | if numRoutes > 255: |
| 516 | numRoutes = 255 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 517 | for m in range( 1, j + 1 ): |
| 518 | for n in range( 1, numRoutes + 1 ): |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 519 | network = str( net ) + "." + str( m ) + "." + str( n ) \ |
| 520 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 521 | routeCmd = "no network " + network |
| 522 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 523 | self.handle.sendline( routeCmd ) |
| 524 | self.handle.expect( "bgpd" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 525 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 526 | main.log.warn( "Failed to delete route" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 527 | self.disconnect() |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 528 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 529 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 530 | routesDeleted = routesDeleted + 1 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 531 | for d in range( j + 1, j + 2 ): |
| 532 | for e in range( 1, k + 1 ): |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 533 | network = str( net ) + "." + str( d ) + "." + str( e ) \ |
| 534 | + ".0/24" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 535 | routeCmd = "no network " + network |
| 536 | try: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 537 | self.handle.sendline( routeCmd ) |
| 538 | self.handle.expect( "bgpd" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 539 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 540 | main.log.warn( "Failed to delete route" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 541 | self.disconnect() |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 542 | waitTimer = 1.00 / routeRate |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 543 | time.sleep( waitTimer ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 544 | routesDeleted = routesDeleted + 1 |
| 545 | if routesDeleted == numRoutes: |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 546 | return main.TRUE |
| 547 | return main.FALSE |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 548 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 549 | def checkRoutes( self, brand, ip, user, pw ): |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 550 | def pronto( ip, user, passwd ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 551 | print "Connecting to Pronto switch" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 552 | child = pexpect.spawn( "telnet " + ip ) |
| 553 | i = child.expect( [ "login:", "CLI#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 554 | if i == 0: |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 555 | print "user_name and password required. Passing login info." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 556 | child.sendline( user ) |
| 557 | child.expect( "Password:" ) |
| 558 | child.sendline( passwd ) |
| 559 | child.expect( "CLI#" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 560 | print "Logged in, getting flowtable." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 561 | child.sendline( "flowtable brief" ) |
| 562 | for t in range( 9 ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 563 | t2 = 9 - t |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 564 | print "\r" + str( t2 ) |
| 565 | sys.stdout.write( "\033[F" ) |
| 566 | time.sleep( 1 ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 567 | print "Scanning flowtable" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 568 | child.expect( "Flow table show" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 569 | count = 0 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 570 | while True: |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 571 | i = child.expect( [ '17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}', |
| 572 | 'CLI#', pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 573 | if i == 0: |
| 574 | count = count + 1 |
| 575 | elif i == 1: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 576 | print "Pronto flows: " + str( count ) + "\nDone\n" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 577 | break |
| 578 | else: |
| 579 | break |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 580 | |
| 581 | def cisco( ip, user, passwd ): |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 582 | print "Establishing Cisco switch connection" |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 583 | child = pexpect.spawn( "ssh " + user + "@" + ip ) |
| 584 | i = child.expect( [ "Password:", "CLI#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 585 | if i == 0: |
| 586 | print "Password required. Passing now." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 587 | child.sendline( passwd ) |
| 588 | child.expect( "#" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 589 | print "Logged in. Retrieving flow table then counting flows." |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 590 | child.sendline( "show openflow switch all flows all" ) |
| 591 | child.expect( "Logical Openflow Switch" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 592 | print "Flow table retrieved. Counting flows" |
| 593 | count = 0 |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 594 | while True: |
| 595 | i = child.expect( [ "nw_src=17", "#", pexpect.TIMEOUT ] ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 596 | if i == 0: |
| 597 | count = count + 1 |
| 598 | elif i == 1: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 599 | print "Cisco flows: " + str( count ) + "\nDone\n" |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 600 | break |
| 601 | else: |
| 602 | break |
| 603 | if brand == "pronto" or brand == "PRONTO": |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 604 | pronto( ip, user, passwd ) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 605 | # elif brand == "cisco" or brand == "CISCO": |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 606 | # cisco( ip,user,passwd ) |
| 607 | |
Srikanth Vavilapalli | 68a1a2b | 2015-02-27 10:29:14 -0800 | [diff] [blame] | 608 | def disable_bgp_peer( self, peer, peer_as ): |
| 609 | main.log.info( "I am in disconnect_peer_session method!" ) |
| 610 | |
| 611 | try: |
| 612 | self.handle.sendline( "" ) |
| 613 | # self.handle.expect( "config-router" ) |
| 614 | self.handle.expect( "config-router", timeout=5 ) |
| 615 | except: |
| 616 | main.log.warn( "Probably not in config-router mode!" ) |
| 617 | self.disconnect() |
| 618 | main.log.info( "Start to disable peer" ) |
| 619 | |
| 620 | cmd = "no neighbor " + peer + " remote-as " + peer_as |
| 621 | try: |
| 622 | self.handle.sendline( cmd ) |
| 623 | self.handle.expect( "bgpd", timeout=5 ) |
| 624 | except: |
| 625 | main.log.warn( "Failed to disable peer" ) |
| 626 | self.disconnect() |
| 627 | |
Srikanth Vavilapalli | 43f3a1d | 2015-03-04 11:09:44 -0800 | [diff] [blame] | 628 | def enable_bgp_peer( self, peer, peer_as ): |
| 629 | main.log.info( "I am in enable_bgp_peer method!" ) |
| 630 | |
| 631 | try: |
| 632 | self.handle.sendline( "" ) |
| 633 | # self.handle.expect( "config-router" ) |
| 634 | self.handle.expect( "config-router", timeout=5 ) |
| 635 | except: |
| 636 | main.log.warn( "Probably not in config-router mode!" ) |
| 637 | self.disconnect() |
| 638 | main.log.info( "Start to disable peer" ) |
| 639 | |
| 640 | cmd = "neighbor " + peer + " remote-as " + peer_as |
| 641 | try: |
| 642 | self.handle.sendline( cmd ) |
| 643 | self.handle.expect( "bgpd", timeout=5 ) |
| 644 | except: |
| 645 | main.log.warn( "Failed to enable peer" ) |
| 646 | self.disconnect() |
| 647 | |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 648 | def disconnect( self ): |
| 649 | """ |
| 650 | Called when Test is complete to disconnect the Quagga handle. |
| 651 | """ |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 652 | response = '' |
| 653 | try: |
| 654 | self.handle.close() |
| 655 | except: |
kelvin-onlab | bbe4648 | 2015-01-16 10:44:28 -0800 | [diff] [blame] | 656 | main.log.error( "Connection failed to the host" ) |
timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 657 | response = main.FALSE |
| 658 | return response |
kelvin-onlab | 2c4342a | 2015-01-28 15:59:53 -0800 | [diff] [blame] | 659 | |