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