blob: 8203166e41a11062e022449194b044d029108255 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
kelvin8ec71442015-01-15 16:57:00 -08002"""
adminbae64d82013-08-01 10:50:15 -07003Created on 26-Oct-2012
4
kelvin8ec71442015-01-15 16:57:00 -08005author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com )
adminbae64d82013-08-01 10:50:15 -07006
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
kelvin8ec71442015-01-15 16:57:00 -080011 ( at your option ) any later version.
adminbae64d82013-08-01 10:50:15 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
kelvin8ec71442015-01-15 16:57:00 -080019 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070020
21
22fvtapidriver is the basic driver which will handle the fvtapidriver functions
kelvin8ec71442015-01-15 16:57:00 -080023"""
24"""
adminbae64d82013-08-01 10:50:15 -070025There are two changes required in flowvisor-test framework :
26
271. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None'
282. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json"
29
kelvin8ec71442015-01-15 16:57:00 -080030"""
adminbae64d82013-08-01 10:50:15 -070031import pexpect
32import struct
33import fcntl
34import os
35import signal
36import re
37import sys
kelvin8ec71442015-01-15 16:57:00 -080038sys.path.append( "../" )
adminbae64d82013-08-01 10:50:15 -070039from common.apidriver import API
40import logging
41
kelvin8ec71442015-01-15 16:57:00 -080042sys.path.append( path + "/lib/flowvisor-test/tests" )
43sys.path.append( path + "/lib/flowvisor-test/src/python/" )
adminbae64d82013-08-01 10:50:15 -070044
45import templatetest
46import testutils
47import oftest.cstruct as ofp
48import oftest.message as message
49import oftest.parse as parse
50import oftest.action as action
51import oftest.error as error
52import socket
53import __builtin__
54
55config_default = {
kelvin8ec71442015-01-15 16:57:00 -080056 "param": None,
57 "fv_cmd": "/home/openflow/flowvisor/scripts/flowvisor.sh",
58 "platform": "local",
59 "controller_host": "127.0.0.1",
60 "controller_port": 6633,
61 "timeout": 3,
62 "port_count": 4,
63 "base_of_port": 1,
64 "base_if_index": 1,
65 "test_spec": "all",
66 "test_dir": ".",
67 "log_file": "/home/openflow/fvt.log",
68 "list": False,
69 "debug": "debug",
70 "dbg_level": logging.DEBUG,
71 "port_map": {},
72 "test_params": "None"
adminbae64d82013-08-01 10:50:15 -070073}
74
kelvin8ec71442015-01-15 16:57:00 -080075
76def test_set_init( config ):
adminbae64d82013-08-01 10:50:15 -070077 """
78 Set up function for basic test classes
kelvin8ec71442015-01-15 16:57:00 -080079 config: The configuration dictionary; see fvt
adminbae64d82013-08-01 10:50:15 -070080 """
81 global basic_port_map
82 global basic_fv_cmd
83 global basic_logger
84 global basic_timeout
85 global basic_config
86 global baisc_logger
87
kelvin8ec71442015-01-15 16:57:00 -080088 basic_fv_cmd = config[ "fv_cmd" ]
89 basic_timeout = config[ "timeout" ]
90 basic_port_map = config[ "port_map" ]
adminbae64d82013-08-01 10:50:15 -070091 basic_config = config
92
adminbae64d82013-08-01 10:50:15 -070093
kelvin8ec71442015-01-15 16:57:00 -080094class FvtApiDriver( API, templatetest.TemplateTest ):
95
96 def __init__( self ):
97 super( API, self ).__init__()
adminbae64d82013-08-01 10:50:15 -070098 print 'init'
adminbae64d82013-08-01 10:50:15 -070099
kelvin8ec71442015-01-15 16:57:00 -0800100 def connect( self, **connectargs ):
adminbae64d82013-08-01 10:50:15 -0700101 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -0800102 vars( self )[ key ] = connectargs[ key ]
adminbae64d82013-08-01 10:50:15 -0700103
kelvin8ec71442015-01-15 16:57:00 -0800104 self.name = self.options[ 'name' ]
105 connect_result = super( API, self ).connect()
106 self.logFileName = main.logdir + "/" + self.name + ".session"
107 config_default[ "log_file" ] = self.logFileName
108 test_set_init( config_default )
109 __builtin__.basic_logger = vars( main )[ self.name + 'log' ]
110 __builtin__.basic_logger.info( "Calling my test setup" )
111 self.setUp( basic_logger )
112
113 ( self.fv, self.sv, sv_ret, ctl_ret, sw_ret ) = testutils.setUpTestEnv(
114 self, fv_cmd=basic_fv_cmd )
115
116 self.chkSetUpCondition( self.fv, sv_ret, ctl_ret, sw_ret )
adminbae64d82013-08-01 10:50:15 -0700117 return main.TRUE
118
kelvin8ec71442015-01-15 16:57:00 -0800119 def simplePacket( self, dl_src ):
120 dl_src = vars( testutils )[ dl_src ]
121 return testutils.simplePacket( dl_src=dl_src )
122
123 def genPacketIn( self, in_port, pkt ):
124 return testutils.genPacketIn( in_port=in_port, pkt=pkt )
125
126 def ofmsgSndCmp( self, snd_list, exp_list, xid_ignore=True, hdr_only=True ):
127 return testutils.ofmsgSndCmp( self, snd_list, exp_list, xid_ignore, hdr_only )
128
129 def setRule( self, sv, rule, num_try ):
130 return testutils.setRule( self, sv, rule, num_try )
131
132 def chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites ):
133 return testutils.chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites )
134
135 def chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count ):
136 return testutils.chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count )
137
138 def chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count ):
139 return testutils.chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count )
140
141 def recvStats( self, swId, typ ):
142 return testutils.recvStats( self, swId, typ )
143
144 def ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only ):
145 return testutils.ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only )
146
147 def genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt ):
148 return testutils.genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt )
149
150 def genFlowModFlush( self ):
adminbae64d82013-08-01 10:50:15 -0700151 return testutils.genFlowModFlush()
kelvin8ec71442015-01-15 16:57:00 -0800152
153 def genPhyPort( self, name, addr, port_no ):
154 return testutils.genPhyPort( name, addr, port_no )
155
156 def disconnect( self, handle ):
adminbae64d82013-08-01 10:50:15 -0700157 response = ''
kelvin8ec71442015-01-15 16:57:00 -0800158 """
adminbae64d82013-08-01 10:50:15 -0700159 if self.handle:
160 self.handle = handle
kelvin8ec71442015-01-15 16:57:00 -0800161 response = self.execute( cmd="exit",prompt="(.*)",timeout=120 )
adminbae64d82013-08-01 10:50:15 -0700162 else :
kelvin8ec71442015-01-15 16:57:00 -0800163 main.log.error( "Connection failed to the host" )
adminbae64d82013-08-01 10:50:15 -0700164 response = main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800165 """
166 return response
167
168 def setUp( self, basic_logger ):
adminbae64d82013-08-01 10:50:15 -0700169 self.logger = basic_logger
kelvin8ec71442015-01-15 16:57:00 -0800170 # basic_logger.info( "** START TEST CASE " + str( self ) )
adminbae64d82013-08-01 10:50:15 -0700171 if basic_timeout == 0:
172 self.timeout = None
173 else:
174 self.timeout = basic_timeout
175 self.fv = None
176 self.sv = None
177 self.controllers = []
178 self.switches = []
kelvin8ec71442015-01-15 16:57:00 -0800179
180 def close_log_handles( self ):
181 self.tearDown()
182 vars( main )[ self.name + 'log' ].removeHandler( self.log_handler )
183 # if self.logfile_handler:
adminbae64d82013-08-01 10:50:15 -0700184 # self.logfile_handler.close()
kelvin8ec71442015-01-15 16:57:00 -0800185
adminbae64d82013-08-01 10:50:15 -0700186 return main.TRUE
187