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