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