1
2 """
3 Created on 26-Oct-2012
4
5 author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com )
6
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
11 ( at your option ) any later version.
12
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
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
22 fvtapidriver is the basic driver which will handle the fvtapidriver functions
23 """
24 """
25 There are two changes required in flowvisor-test framework :
26
27 1. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None'
28 2. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json"
29
30 """
31 import pexpect
32 import struct
33 import fcntl
34 import os
35 import signal
36 import re
37 import sys
38 from common.apidriver import API
39 import logging
40
41 sys.path.append( path + "/lib/flowvisor-test/tests" )
42 sys.path.append( path + "/lib/flowvisor-test/src/python/" )
43
44 import templatetest
45 import testutils
46 import oftest.cstruct as ofp
47 import oftest.message as message
48 import oftest.parse as parse
49 import oftest.action as action
50 import oftest.error as error
51 import socket
52 import __builtin__
53
54 config_default = {
55 "param": None,
56 "fv_cmd": "/home/openflow/flowvisor/scripts/flowvisor.sh",
57 "platform": "local",
58 "controller_host": "127.0.0.1",
59 "controller_port": 6633,
60 "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"
72 }
73
74
76 """
77 Set up function for basic test classes
78 config: The configuration dictionary; see fvt
79 """
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
87 basic_fv_cmd = config[ "fv_cmd" ]
88 basic_timeout = config[ "timeout" ]
89 basic_port_map = config[ "port_map" ]
90 basic_config = config
91
92
94
98
99 - def connect( self, **connectargs ):
100 for key in connectargs:
101 vars( self )[ key ] = connectargs[ key ]
102
103 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 )
116 return main.TRUE
117
119 dl_src = vars( testutils )[ dl_src ]
120 return testutils.simplePacket( dl_src=dl_src )
121
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
141 return testutils.recvStats( self, swId, typ )
142
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
151
153 return testutils.genPhyPort( name, addr, port_no )
154
156 response = ''
157 """
158 if self.handle:
159 self.handle = handle
160 response = self.execute( cmd="exit",prompt="(.*)",timeout=120 )
161 else :
162 main.log.error( "Connection failed to the host" )
163 response = main.FALSE
164 """
165 return response
166
167 - def setUp( self, basic_logger ):
168 self.logger = basic_logger
169
170 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 = []
178
180 self.tearDown()
181 vars( main )[ self.name + 'log' ].removeHandler( self.log_handler )
182
183
184
185 return main.TRUE
186