blob: ee3dfdcd9a937b58d2cb318bbeed6b0800f0ee5e [file] [log] [blame]
Dan Talayco34089522010-02-07 23:07:41 -08001"""
2OpenFlow Test Framework
3
4Configuration fragment
5
6This file contains Python code to specify the configuration
7of the system under test.
8
9This is a work in progress. The code below is for illustration only.
10
11The configuration information is extensible in that any
12Python code may be added to this file (or its imports) and will
13be available to test cases.
14
15A platform identifier is given at the top of the file and most
16other information is determined by testing this value. Additional
17files may also be imported based on the platform.
18
19The configuration must specify a mapping from system interfaces
20available to the test framework to OpenFlow port numbers on the
21switch under test. This is done in the interface_ofport_map
22dictionary. Future extensions may include specifying a driver
23for the port (so as to allow remote packet generation) and to
24specify a switch instance (to allow multiple switches to be
25tested together).
26
27Currently, the assumption is that ports are bidirectional, so
28specifying "OF port 1 is connnected to eth2" implies this is so
29for both TX and RX.
30
31"""
32
Dan Talaycoe226eb12010-02-18 23:06:30 -080033import sys
34
Dan Talayco34089522010-02-07 23:07:41 -080035##@var platform
36# A string representing the platform under test. Tested below
37# for determining other variables.
38
39##@var switch_cxn_type
40# How does the test framework communicate to the switch?
41#
42# Options include:
43# @arg localhost: Switch is running on same host as tests
44# @arg ssh: Use paramiko to control ssh connection. Needs switch
45# IP and other params
46#
47# For ssh, additional variables include
48# @arg switch_ip = "192.168.2.21"
49# @arg switch_username = "root"
50# @arg switch_password
51
52##@var switch_init
53# A function to be called to initialize the switch. May be None
54# to indicate no such function needs to be called.
55
56##@var switch_connect
57# Function to be called to prompt the switch to connect to the
58# controller. The function may need to maintain connection state
59# as it could be called multiple times between disconnects.
60
61##@var switch_disconnect
62# Function to be called to force the switch to disconnect from the
63# controller.
64
Dan Talayco9be11bc2010-02-12 22:58:46 -080065##@var controller_host
66# Gives the controller host address to use
Dan Talayco34089522010-02-07 23:07:41 -080067
68##@var controller_port
69# Gives the controller port to use
70
Dan Talayco9be11bc2010-02-12 22:58:46 -080071# platform = "sw_userspace"
Dan Talayco34089522010-02-07 23:07:41 -080072# platform = "sw_kernelspace"
Dan Talayco9be11bc2010-02-12 22:58:46 -080073platform = "bcm_indigo"
Dan Talayco34089522010-02-07 23:07:41 -080074# platform = "stanford_lb4g"
75
Dan Talayco9be11bc2010-02-12 22:58:46 -080076
77# These can be moved into platform specific code if needed
78
79RCV_TIMEOUT_DEFAULT = 10
80RCV_SIZE_DEFAULT = 4096
81CONTROLLER_HOST_DEFAULT = ''
82CONTROLLER_PORT_DEFAULT = 6633
83
Dan Talaycod7e2dbe2010-02-13 21:51:15 -080084# Timeout in seconds for initial connection
85INIT_CONNECT_TIMEOUT = 4
86
Dan Talayco9be11bc2010-02-12 22:58:46 -080087# Number of switch connection requests to queue
88LISTEN_QUEUE_SIZE = 1
89
Dan Talayco34089522010-02-07 23:07:41 -080090if platform == "sw_userspace":
91 interface_ofport_map = {
92 1 : "eth2",
93 2 : "eth3",
94 3 : "eth4",
95 4 : "eth5"
96 }
97 switch_cxn_type = "localhost"
98 switch_init = None # TBD
99 switch_connect = None # TBD
100 switch_disconnect = None # TBD
Dan Talayco9be11bc2010-02-12 22:58:46 -0800101 controller_host = "172.27.74.158"
Dan Talayco34089522010-02-07 23:07:41 -0800102 controller_port = 7000
103
104elif platform == "bcm_indigo":
Dan Talayco9be11bc2010-02-12 22:58:46 -0800105 interface_ofport_map = {
Dan Talayco710438c2010-02-18 15:16:07 -0800106 23 : "eth2",
107 24 : "eth3",
108 25 : "eth4",
109 26 : "eth5"
Dan Talayco9be11bc2010-02-12 22:58:46 -0800110 }
111 # For SSH connections to switch
Dan Talayco34089522010-02-07 23:07:41 -0800112 switch_cxn_type = "ssh"
113 switch_ip = "192.168.2.21"
114 switch_username = "root"
115 switch_password = "OpenFlow"
116 switch_init = None # TBD
117 switch_connect = None # TBD
118 switch_disconnect = None # TBD
Dan Talayco9be11bc2010-02-12 22:58:46 -0800119 controller_host = "192.168.2.2"
120# controller_host = "172.27.74.26"
Dan Talaycodba4c342010-02-15 14:13:02 -0800121 controller_port = 6634
Dan Talayco9be11bc2010-02-12 22:58:46 -0800122
123
124# Debug levels
125DEBUG_ALL = 0
126DEBUG_VERBOSE = 1
127DEBUG_INFO = 2
128DEBUG_WARN = 3
129DEBUG_ERROR = 4
130DEBUG_CRITICAL = 5
131DEBUG_NONE = 6 # For current setting only; not for string level
132
Dan Talaycodba4c342010-02-15 14:13:02 -0800133debug_level_default = DEBUG_WARN
134
Dan Talayco9be11bc2010-02-12 22:58:46 -0800135dbg_string = [
136 "DBG ALL ",
137 "VERBOSE ",
138 "INFO ",
139 "WARN ",
140 "ERROR ",
141 "CRITICAL "
142 ]
143
144def debug_log(module, cur_level, level, string):
145 """
146 Log a debug message
147
148 Compare the debug level to the current level and display
149 the string if appropriate.
150 @param module String representing the module reporting the info/error
151 @param cur_level The module's current debug level
152 @param level The level of the error message
153 @param string String to report
154
155 @todo Allow file logging options, etc
156 @todo Add timestamps
Dan Talayco90576bd2010-02-19 10:59:02 -0800157 @todo Consider using the native Python logging module
Dan Talayco9be11bc2010-02-12 22:58:46 -0800158 """
159
160 if level >= cur_level:
161 #@todo Support output redirection based on debug level
162 print module + ":" + dbg_string[level] + ":" + string
163
Dan Talaycoe226eb12010-02-18 23:06:30 -0800164
165def oft_assert(condition, string):
166 """
167 Test framework assertion check
168
169 @param condition The boolean condition to check
170 @param string String to print if error
171
172 If condition is not true, it is considered a test framework
Dan Talayco90576bd2010-02-19 10:59:02 -0800173 failure and exit is called.
174
175 This assert is meant to represent a violation in the
176 assumptions of how the test framework is supposed to work
177 (for example, an inconsistent packet queue state) rather than
178 a test failure.
Dan Talaycoe226eb12010-02-18 23:06:30 -0800179 """
180 if not condition:
181 debug_log("OFT", debug_level_default, DEBUG_CRITICAL,
182 "Internal error: " + string)
183 sys.exit(1)
184