blob: 892eef9759a88ed3a2516a61e2b14486e36becaf [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
adminbae64d82013-08-01 10:50:15 -070038from common.apidriver import API
39import logging
40
kelvin8ec71442015-01-15 16:57:00 -080041sys.path.append( path + "/lib/flowvisor-test/tests" )
42sys.path.append( path + "/lib/flowvisor-test/src/python/" )
adminbae64d82013-08-01 10:50:15 -070043
44import templatetest
45import testutils
46import oftest.cstruct as ofp
47import oftest.message as message
48import oftest.parse as parse
49import oftest.action as action
50import oftest.error as error
51import socket
52import __builtin__
53
54config_default = {
kelvin8ec71442015-01-15 16:57:00 -080055 "param": None,
56 "fv_cmd": "/home/openflow/flowvisor/scripts/flowvisor.sh",
57 "platform": "local",
58 "controller_host": "127.0.0.1",
Charles Chan029be652015-08-24 01:46:10 +080059 "controller_port": 6653,
kelvin8ec71442015-01-15 16:57:00 -080060 "timeout": 3,
61 "port_count": 4,
62 "base_of_port": 1,
63 "base_if_index": 1,
64 "test_spec": "all",
65 "test_dir": ".",
66 "log_file": "/home/openflow/fvt.log",
67 "list": False,
68 "debug": "debug",
69 "dbg_level": logging.DEBUG,
70 "port_map": {},
71 "test_params": "None"
adminbae64d82013-08-01 10:50:15 -070072}
73
kelvin8ec71442015-01-15 16:57:00 -080074
75def test_set_init( config ):
adminbae64d82013-08-01 10:50:15 -070076 """
77 Set up function for basic test classes
kelvin8ec71442015-01-15 16:57:00 -080078 config: The configuration dictionary; see fvt
adminbae64d82013-08-01 10:50:15 -070079 """
80 global basic_port_map
81 global basic_fv_cmd
82 global basic_logger
83 global basic_timeout
84 global basic_config
85 global baisc_logger
86
kelvin8ec71442015-01-15 16:57:00 -080087 basic_fv_cmd = config[ "fv_cmd" ]
88 basic_timeout = config[ "timeout" ]
89 basic_port_map = config[ "port_map" ]
adminbae64d82013-08-01 10:50:15 -070090 basic_config = config
91
adminbae64d82013-08-01 10:50:15 -070092
kelvin8ec71442015-01-15 16:57:00 -080093class FvtApiDriver( API, templatetest.TemplateTest ):
94
95 def __init__( self ):
96 super( API, self ).__init__()
adminbae64d82013-08-01 10:50:15 -070097 print 'init'
adminbae64d82013-08-01 10:50:15 -070098
kelvin8ec71442015-01-15 16:57:00 -080099 def connect( self, **connectargs ):
adminbae64d82013-08-01 10:50:15 -0700100 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -0800101 vars( self )[ key ] = connectargs[ key ]
adminbae64d82013-08-01 10:50:15 -0700102
kelvin8ec71442015-01-15 16:57:00 -0800103 self.name = self.options[ 'name' ]
104 connect_result = super( API, self ).connect()
105 self.logFileName = main.logdir + "/" + self.name + ".session"
106 config_default[ "log_file" ] = self.logFileName
107 test_set_init( config_default )
108 __builtin__.basic_logger = vars( main )[ self.name + 'log' ]
109 __builtin__.basic_logger.info( "Calling my test setup" )
110 self.setUp( basic_logger )
111
112 ( self.fv, self.sv, sv_ret, ctl_ret, sw_ret ) = testutils.setUpTestEnv(
113 self, fv_cmd=basic_fv_cmd )
114
115 self.chkSetUpCondition( self.fv, sv_ret, ctl_ret, sw_ret )
adminbae64d82013-08-01 10:50:15 -0700116 return main.TRUE
117
kelvin8ec71442015-01-15 16:57:00 -0800118 def simplePacket( self, dl_src ):
119 dl_src = vars( testutils )[ dl_src ]
120 return testutils.simplePacket( dl_src=dl_src )
121
122 def genPacketIn( self, in_port, pkt ):
123 return testutils.genPacketIn( in_port=in_port, pkt=pkt )
124
125 def ofmsgSndCmp( self, snd_list, exp_list, xid_ignore=True, hdr_only=True ):
126 return testutils.ofmsgSndCmp( self, snd_list, exp_list, xid_ignore, hdr_only )
127
128 def setRule( self, sv, rule, num_try ):
129 return testutils.setRule( self, sv, rule, num_try )
130
131 def chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites ):
132 return testutils.chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites )
133
134 def chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count ):
135 return testutils.chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count )
136
137 def chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count ):
138 return testutils.chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count )
139
140 def recvStats( self, swId, typ ):
141 return testutils.recvStats( self, swId, typ )
142
143 def ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only ):
144 return testutils.ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only )
145
146 def genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt ):
147 return testutils.genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt )
148
149 def genFlowModFlush( self ):
adminbae64d82013-08-01 10:50:15 -0700150 return testutils.genFlowModFlush()
kelvin8ec71442015-01-15 16:57:00 -0800151
152 def genPhyPort( self, name, addr, port_no ):
153 return testutils.genPhyPort( name, addr, port_no )
154
155 def disconnect( self, handle ):
adminbae64d82013-08-01 10:50:15 -0700156 response = ''
kelvin8ec71442015-01-15 16:57:00 -0800157 """
adminbae64d82013-08-01 10:50:15 -0700158 if self.handle:
159 self.handle = handle
kelvin8ec71442015-01-15 16:57:00 -0800160 response = self.execute( cmd="exit",prompt="(.*)",timeout=120 )
adminbae64d82013-08-01 10:50:15 -0700161 else :
kelvin8ec71442015-01-15 16:57:00 -0800162 main.log.error( "Connection failed to the host" )
adminbae64d82013-08-01 10:50:15 -0700163 response = main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800164 """
165 return response
166
167 def setUp( self, basic_logger ):
adminbae64d82013-08-01 10:50:15 -0700168 self.logger = basic_logger
kelvin8ec71442015-01-15 16:57:00 -0800169 # basic_logger.info( "** START TEST CASE " + str( self ) )
adminbae64d82013-08-01 10:50:15 -0700170 if basic_timeout == 0:
171 self.timeout = None
172 else:
173 self.timeout = basic_timeout
174 self.fv = None
175 self.sv = None
176 self.controllers = []
177 self.switches = []
kelvin8ec71442015-01-15 16:57:00 -0800178
179 def close_log_handles( self ):
180 self.tearDown()
181 vars( main )[ self.name + 'log' ].removeHandler( self.log_handler )
182 # if self.logfile_handler:
adminbae64d82013-08-01 10:50:15 -0700183 # self.logfile_handler.close()
kelvin8ec71442015-01-15 16:57:00 -0800184
adminbae64d82013-08-01 10:50:15 -0700185 return main.TRUE
186