blob: 1a716559a09dc444838236fe39206135a5635923 [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
Jeremy Songsterae01bba2016-07-11 15:39:17 -07004Modified 2015 by ON.Lab
5
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>
adminbae64d82013-08-01 10:50:15 -07009
kelvin8ec71442015-01-15 16:57:00 -080010author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com )
adminbae64d82013-08-01 10:50:15 -070011
12
13 TestON is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 2 of the License, or
kelvin8ec71442015-01-15 16:57:00 -080016 ( at your option ) any later version.
adminbae64d82013-08-01 10:50:15 -070017
18 TestON is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
kelvin8ec71442015-01-15 16:57:00 -080024 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070025
26
27fvtapidriver is the basic driver which will handle the fvtapidriver functions
kelvin8ec71442015-01-15 16:57:00 -080028"""
29"""
adminbae64d82013-08-01 10:50:15 -070030There are two changes required in flowvisor-test framework :
31
321. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None'
332. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json"
34
kelvin8ec71442015-01-15 16:57:00 -080035"""
adminbae64d82013-08-01 10:50:15 -070036import pexpect
37import struct
38import fcntl
39import os
40import signal
41import re
42import sys
adminbae64d82013-08-01 10:50:15 -070043from common.apidriver import API
44import logging
45
kelvin8ec71442015-01-15 16:57:00 -080046sys.path.append( path + "/lib/flowvisor-test/tests" )
47sys.path.append( path + "/lib/flowvisor-test/src/python/" )
adminbae64d82013-08-01 10:50:15 -070048
49import templatetest
50import testutils
51import oftest.cstruct as ofp
52import oftest.message as message
53import oftest.parse as parse
54import oftest.action as action
55import oftest.error as error
56import socket
57import __builtin__
58
59config_default = {
kelvin8ec71442015-01-15 16:57:00 -080060 "param": None,
61 "fv_cmd": "/home/openflow/flowvisor/scripts/flowvisor.sh",
62 "platform": "local",
63 "controller_host": "127.0.0.1",
Charles Chan029be652015-08-24 01:46:10 +080064 "controller_port": 6653,
kelvin8ec71442015-01-15 16:57:00 -080065 "timeout": 3,
66 "port_count": 4,
67 "base_of_port": 1,
68 "base_if_index": 1,
69 "test_spec": "all",
70 "test_dir": ".",
71 "log_file": "/home/openflow/fvt.log",
72 "list": False,
73 "debug": "debug",
74 "dbg_level": logging.DEBUG,
75 "port_map": {},
76 "test_params": "None"
adminbae64d82013-08-01 10:50:15 -070077}
78
kelvin8ec71442015-01-15 16:57:00 -080079
80def test_set_init( config ):
adminbae64d82013-08-01 10:50:15 -070081 """
82 Set up function for basic test classes
kelvin8ec71442015-01-15 16:57:00 -080083 config: The configuration dictionary; see fvt
adminbae64d82013-08-01 10:50:15 -070084 """
85 global basic_port_map
86 global basic_fv_cmd
87 global basic_logger
88 global basic_timeout
89 global basic_config
90 global baisc_logger
91
kelvin8ec71442015-01-15 16:57:00 -080092 basic_fv_cmd = config[ "fv_cmd" ]
93 basic_timeout = config[ "timeout" ]
94 basic_port_map = config[ "port_map" ]
adminbae64d82013-08-01 10:50:15 -070095 basic_config = config
96
adminbae64d82013-08-01 10:50:15 -070097
kelvin8ec71442015-01-15 16:57:00 -080098class FvtApiDriver( API, templatetest.TemplateTest ):
99
100 def __init__( self ):
Devin Limdc78e202017-06-09 18:30:07 -0700101 super( FvtApiDriver, self ).__init__()
adminbae64d82013-08-01 10:50:15 -0700102 print 'init'
adminbae64d82013-08-01 10:50:15 -0700103
kelvin8ec71442015-01-15 16:57:00 -0800104 def connect( self, **connectargs ):
adminbae64d82013-08-01 10:50:15 -0700105 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -0800106 vars( self )[ key ] = connectargs[ key ]
adminbae64d82013-08-01 10:50:15 -0700107
kelvin8ec71442015-01-15 16:57:00 -0800108 self.name = self.options[ 'name' ]
109 connect_result = super( API, self ).connect()
110 self.logFileName = main.logdir + "/" + self.name + ".session"
111 config_default[ "log_file" ] = self.logFileName
112 test_set_init( config_default )
113 __builtin__.basic_logger = vars( main )[ self.name + 'log' ]
114 __builtin__.basic_logger.info( "Calling my test setup" )
115 self.setUp( basic_logger )
116
117 ( self.fv, self.sv, sv_ret, ctl_ret, sw_ret ) = testutils.setUpTestEnv(
118 self, fv_cmd=basic_fv_cmd )
119
120 self.chkSetUpCondition( self.fv, sv_ret, ctl_ret, sw_ret )
adminbae64d82013-08-01 10:50:15 -0700121 return main.TRUE
122
kelvin8ec71442015-01-15 16:57:00 -0800123 def simplePacket( self, dl_src ):
124 dl_src = vars( testutils )[ dl_src ]
125 return testutils.simplePacket( dl_src=dl_src )
126
127 def genPacketIn( self, in_port, pkt ):
128 return testutils.genPacketIn( in_port=in_port, pkt=pkt )
129
130 def ofmsgSndCmp( self, snd_list, exp_list, xid_ignore=True, hdr_only=True ):
131 return testutils.ofmsgSndCmp( self, snd_list, exp_list, xid_ignore, hdr_only )
132
133 def setRule( self, sv, rule, num_try ):
134 return testutils.setRule( self, sv, rule, num_try )
135
136 def chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites ):
137 return testutils.chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites )
138
139 def chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count ):
140 return testutils.chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count )
141
142 def chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count ):
143 return testutils.chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count )
144
145 def recvStats( self, swId, typ ):
146 return testutils.recvStats( self, swId, typ )
147
148 def ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only ):
149 return testutils.ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only )
150
151 def genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt ):
152 return testutils.genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt )
153
154 def genFlowModFlush( self ):
adminbae64d82013-08-01 10:50:15 -0700155 return testutils.genFlowModFlush()
kelvin8ec71442015-01-15 16:57:00 -0800156
157 def genPhyPort( self, name, addr, port_no ):
158 return testutils.genPhyPort( name, addr, port_no )
159
160 def disconnect( self, handle ):
adminbae64d82013-08-01 10:50:15 -0700161 response = ''
kelvin8ec71442015-01-15 16:57:00 -0800162 """
adminbae64d82013-08-01 10:50:15 -0700163 if self.handle:
164 self.handle = handle
kelvin8ec71442015-01-15 16:57:00 -0800165 response = self.execute( cmd="exit",prompt="(.*)",timeout=120 )
adminbae64d82013-08-01 10:50:15 -0700166 else :
kelvin8ec71442015-01-15 16:57:00 -0800167 main.log.error( "Connection failed to the host" )
adminbae64d82013-08-01 10:50:15 -0700168 response = main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800169 """
170 return response
171
172 def setUp( self, basic_logger ):
adminbae64d82013-08-01 10:50:15 -0700173 self.logger = basic_logger
kelvin8ec71442015-01-15 16:57:00 -0800174 # basic_logger.info( "** START TEST CASE " + str( self ) )
adminbae64d82013-08-01 10:50:15 -0700175 if basic_timeout == 0:
176 self.timeout = None
177 else:
178 self.timeout = basic_timeout
179 self.fv = None
180 self.sv = None
181 self.controllers = []
182 self.switches = []
kelvin8ec71442015-01-15 16:57:00 -0800183
184 def close_log_handles( self ):
185 self.tearDown()
186 vars( main )[ self.name + 'log' ].removeHandler( self.log_handler )
187 # if self.logfile_handler:
adminbae64d82013-08-01 10:50:15 -0700188 # self.logfile_handler.close()
kelvin8ec71442015-01-15 16:57:00 -0800189
adminbae64d82013-08-01 10:50:15 -0700190 return main.TRUE
191