blob: f278846c68c392e57ac90d1244250fcde937802b [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
Dan Talayco9be11bc2010-02-12 22:58:46 -080039##@var controller_host
40# Gives the controller host address to use
Dan Talayco34089522010-02-07 23:07:41 -080041
42##@var controller_port
43# Gives the controller port to use
44
Dan Talayco9be11bc2010-02-12 22:58:46 -080045# platform = "sw_userspace"
Dan Talayco34089522010-02-07 23:07:41 -080046# platform = "sw_kernelspace"
Dan Talayco9be11bc2010-02-12 22:58:46 -080047platform = "bcm_indigo"
Dan Talayco34089522010-02-07 23:07:41 -080048# platform = "stanford_lb4g"
49
Dan Talayco9be11bc2010-02-12 22:58:46 -080050
Dan Talayco34089522010-02-07 23:07:41 -080051if platform == "sw_userspace":
52 interface_ofport_map = {
53 1 : "eth2",
54 2 : "eth3",
55 3 : "eth4",
56 4 : "eth5"
57 }
Dan Talayco9be11bc2010-02-12 22:58:46 -080058 controller_host = "172.27.74.158"
Dan Talayco34089522010-02-07 23:07:41 -080059 controller_port = 7000
60
61elif platform == "bcm_indigo":
Dan Talayco9be11bc2010-02-12 22:58:46 -080062 interface_ofport_map = {
Dan Talayco710438c2010-02-18 15:16:07 -080063 23 : "eth2",
64 24 : "eth3",
65 25 : "eth4",
66 26 : "eth5"
Dan Talayco9be11bc2010-02-12 22:58:46 -080067 }
68 # For SSH connections to switch
Dan Talayco9be11bc2010-02-12 22:58:46 -080069 controller_host = "192.168.2.2"
70# controller_host = "172.27.74.26"
Dan Talaycodba4c342010-02-15 14:13:02 -080071 controller_port = 6634
Dan Talayco9be11bc2010-02-12 22:58:46 -080072
73
Dan Talaycof307f3f2010-02-19 11:42:29 -080074
Dan Talayco9be11bc2010-02-12 22:58:46 -080075# Debug levels
76DEBUG_ALL = 0
77DEBUG_VERBOSE = 1
78DEBUG_INFO = 2
79DEBUG_WARN = 3
80DEBUG_ERROR = 4
81DEBUG_CRITICAL = 5
82DEBUG_NONE = 6 # For current setting only; not for string level
83
Dan Talaycodba4c342010-02-15 14:13:02 -080084debug_level_default = DEBUG_WARN
85
Dan Talayco9be11bc2010-02-12 22:58:46 -080086dbg_string = [
87 "DBG ALL ",
88 "VERBOSE ",
89 "INFO ",
90 "WARN ",
91 "ERROR ",
92 "CRITICAL "
93 ]
94
Dan Talaycof307f3f2010-02-19 11:42:29 -080095
96# These can be moved into platform specific code if needed
97
98RCV_TIMEOUT_DEFAULT = 10
99RCV_SIZE_DEFAULT = 4096
100CONTROLLER_HOST_DEFAULT = ''
101CONTROLLER_PORT_DEFAULT = 6633
102
103# Timeout in seconds for initial connection
104INIT_CONNECT_TIMEOUT = 4
105
106# Number of switch connection requests to queue
107LISTEN_QUEUE_SIZE = 1
108
Dan Talayco9be11bc2010-02-12 22:58:46 -0800109def debug_log(module, cur_level, level, string):
110 """
111 Log a debug message
112
113 Compare the debug level to the current level and display
114 the string if appropriate.
115 @param module String representing the module reporting the info/error
116 @param cur_level The module's current debug level
117 @param level The level of the error message
118 @param string String to report
119
120 @todo Allow file logging options, etc
121 @todo Add timestamps
Dan Talayco90576bd2010-02-19 10:59:02 -0800122 @todo Consider using the native Python logging module
Dan Talayco9be11bc2010-02-12 22:58:46 -0800123 """
124
125 if level >= cur_level:
126 #@todo Support output redirection based on debug level
127 print module + ":" + dbg_string[level] + ":" + string
128
Dan Talaycoe226eb12010-02-18 23:06:30 -0800129
130def oft_assert(condition, string):
131 """
132 Test framework assertion check
133
134 @param condition The boolean condition to check
135 @param string String to print if error
136
137 If condition is not true, it is considered a test framework
Dan Talayco90576bd2010-02-19 10:59:02 -0800138 failure and exit is called.
139
140 This assert is meant to represent a violation in the
141 assumptions of how the test framework is supposed to work
142 (for example, an inconsistent packet queue state) rather than
143 a test failure.
Dan Talaycoe226eb12010-02-18 23:06:30 -0800144 """
145 if not condition:
146 debug_log("OFT", debug_level_default, DEBUG_CRITICAL,
147 "Internal error: " + string)
148 sys.exit(1)
149