blob: de7a7c3fc374c06acc081fb7636a6d7052126f4e [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
kelvin-onlabedcff052015-01-16 12:53:55 -08002"""
adminbae64d82013-08-01 10:50:15 -07003Created on 26-Oct-2012
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07004Copyright 2012 Open Networking Foundation (ONF)
Jeremy Songsterae01bba2016-07-11 15:39:17 -07005
6Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
7the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
8or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
kelvin-onlabedcff052015-01-16 12:53:55 -08009
10author:: Raghav Kashyap( raghavkashyap@paxterrasolutions.com )
adminbae64d82013-08-01 10:50:15 -070011
adminbae64d82013-08-01 10:50:15 -070012 TestON is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 2 of the License, or
kelvin-onlabedcff052015-01-16 12:53:55 -080015 ( at your option ) any later version.
adminbae64d82013-08-01 10:50:15 -070016
17 TestON is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
kelvin-onlabedcff052015-01-16 12:53:55 -080023 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070024
25
26pox driver provides the basic functions of POX controller
kelvin-onlabedcff052015-01-16 12:53:55 -080027"""
adminbae64d82013-08-01 10:50:15 -070028import pexpect
kelvin-onlabedcff052015-01-16 12:53:55 -080029import struct
30import fcntl
31import os
kelvin-onlabedcff052015-01-16 12:53:55 -080032import signal
adminbae64d82013-08-01 10:50:15 -070033import sys
34from drivers.common.cli.emulatordriver import Emulator
35
adminbae64d82013-08-01 10:50:15 -070036
kelvin-onlabedcff052015-01-16 12:53:55 -080037class PoxCliDriver( Emulator ):
38
39 """
40 PoxCliDriver driver provides the basic functions of POX controller
41 """
42 def __init__( self ):
Devin Limdc78e202017-06-09 18:30:07 -070043 super( PoxCliDriver, self ).__init__()
kelvin-onlabedcff052015-01-16 12:53:55 -080044 self.handle = self
45 self.wrapped = sys.modules[ __name__ ]
46
47 def connect( self, **connectargs ):
48 #,user_name, ip_address, pwd,options ):
49 """
50 this subroutine is to launch pox controller . It must have arguments as :
adminbae64d82013-08-01 10:50:15 -070051 user_name = host name ,
52 ip_address = ip address of the host ,
53 pwd = password of host ,
54 options = it is a topology hash which will consists the component's details for the test run
55
56 *** host is here a virtual mahine or system where pox framework hierarchy exists
kelvin-onlabedcff052015-01-16 12:53:55 -080057 """
adminbae64d82013-08-01 10:50:15 -070058 for key in connectargs:
kelvin-onlabedcff052015-01-16 12:53:55 -080059 vars( self )[ key ] = connectargs[ key ]
60
61 self.name = self.options[ 'name' ]
62
adminbae64d82013-08-01 10:50:15 -070063 poxLibPath = 'default'
kelvin-onlabd9e23de2015-08-06 10:34:44 -070064
kelvin-onlabedcff052015-01-16 12:53:55 -080065 self.handle = super(
66 PoxCliDriver,
67 self ).connect(
68 user_name=self.user_name,
69 ip_address=self.ip_address,
70 port=None,
71 pwd=self.pwd )
72
adminbae64d82013-08-01 10:50:15 -070073 if self.handle:
kelvin-onlabedcff052015-01-16 12:53:55 -080074 self.handle.expect( "openflow" )
75 command = self.getcmd( self.options )
76 # print command
77 main.log.info( "Entering into POX hierarchy" )
78 if self.options[ 'pox_lib_location' ] != 'default':
79 self.execute(
80 cmd="cd " +
81 self.options[ 'pox_lib_location' ],
Devin Limdc78e202017-06-09 18:30:07 -070082 prompt="/pox" + self.prompt,
kelvin-onlabedcff052015-01-16 12:53:55 -080083 timeout=120 )
84 else:
85 self.execute(
86 cmd="cd ~/TestON/lib/pox/",
Devin Limdc78e202017-06-09 18:30:07 -070087 prompt="/pox" + self.prompt,
kelvin-onlabedcff052015-01-16 12:53:55 -080088 timeout=120 )
89 # launching pox with components
90 main.log.info( "launching POX controller with given components" )
91 self.execute( cmd=command, prompt="DEBUG:", timeout=120 )
adminbae64d82013-08-01 10:50:15 -070092 return main.TRUE
kelvin-onlabedcff052015-01-16 12:53:55 -080093 else:
94 main.log.error(
95 "Connection failed to the host " +
96 self.user_name +
97 "@" +
98 self.ip_address )
99 main.log.error( "Failed to connect to the POX controller" )
adminbae64d82013-08-01 10:50:15 -0700100 return main.FALSE
kelvin-onlabedcff052015-01-16 12:53:55 -0800101
102 def disconnect( self, handle ):
adminbae64d82013-08-01 10:50:15 -0700103 if self.handle:
Devin Limdc78e202017-06-09 18:30:07 -0700104 self.execute( cmd="exit()", prompt="/pox" + self.prompt, timeout=120 )
kelvin-onlabedcff052015-01-16 12:53:55 -0800105 else:
106 main.log.error( "Connection failed to the host" )
adminbae64d82013-08-01 10:50:15 -0700107
kelvin-onlabedcff052015-01-16 12:53:55 -0800108 def get_version( self ):
109 file_input = path + '/lib/pox/core.py'
110 version = super( PoxCliDriver, self ).get_version()
adminbae64d82013-08-01 10:50:15 -0700111 pattern = '\s*self\.version(.*)'
112 import re
kelvin-onlabedcff052015-01-16 12:53:55 -0800113 for line in open( file_input, 'r' ).readlines():
114 result = re.match( pattern, line )
adminbae64d82013-08-01 10:50:15 -0700115 if result:
kelvin-onlabedcff052015-01-16 12:53:55 -0800116 version = result.group( 0 )
117 version = re.sub(
118 "\s*self\.version\s*=\s*|\(|\)",
119 '',
120 version )
121 version = re.sub( ",", '.', version )
122 version = "POX " + version
adminbae64d82013-08-01 10:50:15 -0700123
kelvin-onlabedcff052015-01-16 12:53:55 -0800124 return version
125
126 def getcmd( self, options ):
127 command = "./pox.py "
adminbae64d82013-08-01 10:50:15 -0700128 for item in options.keys():
kelvin-onlabedcff052015-01-16 12:53:55 -0800129 if isinstance( options[ item ], dict ):
adminbae64d82013-08-01 10:50:15 -0700130 command = command + item
kelvin-onlabedcff052015-01-16 12:53:55 -0800131 for items in options[ item ].keys():
132 if options[ item ][ items ] == "None":
adminbae64d82013-08-01 10:50:15 -0700133 command = command + " --" + items + " "
kelvin-onlabedcff052015-01-16 12:53:55 -0800134 else:
135 command = command + " --" + items + \
136 "=" + options[ item ][ items ] + " "
adminbae64d82013-08-01 10:50:15 -0700137 else:
138 if item == 'pox_lib_location':
kelvin-onlabedcff052015-01-16 12:53:55 -0800139 poxLibPath = options[ item ]
adminbae64d82013-08-01 10:50:15 -0700140 elif item == 'type' or item == 'name':
141 pass
kelvin-onlabedcff052015-01-16 12:53:55 -0800142 else:
adminbae64d82013-08-01 10:50:15 -0700143 command = command + item
144
kelvin-onlabedcff052015-01-16 12:53:55 -0800145 return command
adminbae64d82013-08-01 10:50:15 -0700146
adminbae64d82013-08-01 10:50:15 -0700147
148if __name__ != "__main__":
149 import sys
150
kelvin-onlabedcff052015-01-16 12:53:55 -0800151 sys.modules[ __name__ ] = PoxCliDriver()