blob: 620b3e9f5ad772774fe9db6fe2b98ee431fc07ec [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
3Created 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
22fvtapidriver is the basic driver which will handle the fvtapidriver functions
23'''
24'''
25There 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
30'''
31import pexpect
32import struct
33import fcntl
34import os
35import signal
36import re
37import sys
38sys.path.append("../")
39from common.apidriver import API
40import logging
41
42sys.path.append(path+"/lib/flowvisor-test/tests")
43sys.path.append(path+"/lib/flowvisor-test/src/python/")
44
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 = {
56 "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"
73}
74
75def test_set_init(config):
76 """
77 Set up function for basic test classes
78 @param 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
92class FvtApiDriver(API,templatetest.TemplateTest):
93
94 def __init__(self):
95 super(API, self).__init__()
96 print 'init'
97
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(self, fv_cmd=basic_fv_cmd)
113
114 self.chkSetUpCondition(self.fv, sv_ret, ctl_ret, sw_ret)
115 return main.TRUE
116
117 def simplePacket(self,dl_src):
118 dl_src = vars(testutils)[dl_src]
119 return testutils.simplePacket(dl_src = dl_src)
120
121 def genPacketIn(self, in_port, pkt):
122 return testutils.genPacketIn(in_port=in_port, pkt=pkt)
123
124 def ofmsgSndCmp(self, snd_list, exp_list, xid_ignore=True, hdr_only=True):
125 return testutils.ofmsgSndCmp(self, snd_list, exp_list, xid_ignore, hdr_only)
126
127 def setRule(self,sv,rule,num_try) :
128 return testutils.setRule(self,sv,rule,num_try)
129
130 def chkFlowdb(self,controller_number,switch_number,exp_count,exp_rewrites) :
131 return testutils.chkFlowdb(self,controller_number,switch_number,exp_count,exp_rewrites)
132
133 def chkSwitchStats(self, switch_number, ofproto, exp_snd_count, exp_rcv_count):
134 return testutils.chkSwitchStats(self, switch_number, ofproto, exp_snd_count, exp_rcv_count)
135
136 def chkSliceStats(self,controller_number,ofproto,exp_snd_count,exp_rcv_count) :
137 return testutils.chkSliceStats(self,controller_number,ofproto,exp_snd_count,exp_rcv_count)
138
139 def recvStats(self,swId,typ) :
140 return testutils.recvStats(self,swId,typ)
141
142 def ofmsgSndCmpWithXid(self,snd_list,exp_list,xid_ignore,hdr_only) :
143 return testutils.ofmsgSndCmpWithXid(self,snd_list,exp_list,xid_ignore,hdr_only)
144
145 def genPacketOut(self,xid,buffer_id,in_port,action_ports,pkt) :
146 return testutils.genPacketOut(self,xid,buffer_id,in_port,action_ports,pkt)
147
148 def genFlowModFlush(self) :
149 return testutils.genFlowModFlush()
150
151 def genPhyPort(self,name,addr,port_no) :
152 return testutils.genPhyPort(name,addr,port_no)
153
154 def disconnect(self,handle):
155 response = ''
156 '''
157 if self.handle:
158 self.handle = handle
159 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
160 else :
161 main.log.error("Connection failed to the host")
162 response = main.FALSE
163 '''
164 return response
165
166 def setUp(self,basic_logger):
167 self.logger = basic_logger
168 #basic_logger.info("** START TEST CASE " + str(self))
169 if basic_timeout == 0:
170 self.timeout = None
171 else:
172 self.timeout = basic_timeout
173 self.fv = None
174 self.sv = None
175 self.controllers = []
176 self.switches = []
177
178 def close_log_handles(self) :
179 self.tearDown()
180 vars(main)[self.name+'log'].removeHandler(self.log_handler)
181 #if self.logfile_handler:
182 # self.logfile_handler.close()
183
184 return main.TRUE
185
186