blob: 264c94d68e699dd57520537b694da3cdcadb3b6b [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
33##@var platform
34# A string representing the platform under test. Tested below
35# for determining other variables.
36
37##@var switch_cxn_type
38# How does the test framework communicate to the switch?
39#
40# Options include:
41# @arg localhost: Switch is running on same host as tests
42# @arg ssh: Use paramiko to control ssh connection. Needs switch
43# IP and other params
44#
45# For ssh, additional variables include
46# @arg switch_ip = "192.168.2.21"
47# @arg switch_username = "root"
48# @arg switch_password
49
50##@var switch_init
51# A function to be called to initialize the switch. May be None
52# to indicate no such function needs to be called.
53
54##@var switch_connect
55# Function to be called to prompt the switch to connect to the
56# controller. The function may need to maintain connection state
57# as it could be called multiple times between disconnects.
58
59##@var switch_disconnect
60# Function to be called to force the switch to disconnect from the
61# controller.
62
Dan Talayco9be11bc2010-02-12 22:58:46 -080063##@var controller_host
64# Gives the controller host address to use
Dan Talayco34089522010-02-07 23:07:41 -080065
66##@var controller_port
67# Gives the controller port to use
68
Dan Talayco9be11bc2010-02-12 22:58:46 -080069# platform = "sw_userspace"
Dan Talayco34089522010-02-07 23:07:41 -080070# platform = "sw_kernelspace"
Dan Talayco9be11bc2010-02-12 22:58:46 -080071platform = "bcm_indigo"
Dan Talayco34089522010-02-07 23:07:41 -080072# platform = "stanford_lb4g"
73
Dan Talayco9be11bc2010-02-12 22:58:46 -080074
75# These can be moved into platform specific code if needed
76
77RCV_TIMEOUT_DEFAULT = 10
78RCV_SIZE_DEFAULT = 4096
79CONTROLLER_HOST_DEFAULT = ''
80CONTROLLER_PORT_DEFAULT = 6633
81
Dan Talaycod7e2dbe2010-02-13 21:51:15 -080082# Timeout in seconds for initial connection
83INIT_CONNECT_TIMEOUT = 4
84
Dan Talayco9be11bc2010-02-12 22:58:46 -080085# Number of switch connection requests to queue
86LISTEN_QUEUE_SIZE = 1
87
Dan Talayco34089522010-02-07 23:07:41 -080088if platform == "sw_userspace":
89 interface_ofport_map = {
90 1 : "eth2",
91 2 : "eth3",
92 3 : "eth4",
93 4 : "eth5"
94 }
95 switch_cxn_type = "localhost"
96 switch_init = None # TBD
97 switch_connect = None # TBD
98 switch_disconnect = None # TBD
Dan Talayco9be11bc2010-02-12 22:58:46 -080099 controller_host = "172.27.74.158"
Dan Talayco34089522010-02-07 23:07:41 -0800100 controller_port = 7000
101
102elif platform == "bcm_indigo":
Dan Talayco9be11bc2010-02-12 22:58:46 -0800103 interface_ofport_map = {
Dan Talayco710438c2010-02-18 15:16:07 -0800104 23 : "eth2",
105 24 : "eth3",
106 25 : "eth4",
107 26 : "eth5"
Dan Talayco9be11bc2010-02-12 22:58:46 -0800108 }
109 # For SSH connections to switch
Dan Talayco34089522010-02-07 23:07:41 -0800110 switch_cxn_type = "ssh"
111 switch_ip = "192.168.2.21"
112 switch_username = "root"
113 switch_password = "OpenFlow"
114 switch_init = None # TBD
115 switch_connect = None # TBD
116 switch_disconnect = None # TBD
Dan Talayco9be11bc2010-02-12 22:58:46 -0800117 controller_host = "192.168.2.2"
118# controller_host = "172.27.74.26"
Dan Talaycodba4c342010-02-15 14:13:02 -0800119 controller_port = 6634
Dan Talayco9be11bc2010-02-12 22:58:46 -0800120
121
122# Debug levels
123DEBUG_ALL = 0
124DEBUG_VERBOSE = 1
125DEBUG_INFO = 2
126DEBUG_WARN = 3
127DEBUG_ERROR = 4
128DEBUG_CRITICAL = 5
129DEBUG_NONE = 6 # For current setting only; not for string level
130
Dan Talaycodba4c342010-02-15 14:13:02 -0800131debug_level_default = DEBUG_WARN
132
Dan Talayco9be11bc2010-02-12 22:58:46 -0800133dbg_string = [
134 "DBG ALL ",
135 "VERBOSE ",
136 "INFO ",
137 "WARN ",
138 "ERROR ",
139 "CRITICAL "
140 ]
141
142def debug_log(module, cur_level, level, string):
143 """
144 Log a debug message
145
146 Compare the debug level to the current level and display
147 the string if appropriate.
148 @param module String representing the module reporting the info/error
149 @param cur_level The module's current debug level
150 @param level The level of the error message
151 @param string String to report
152
153 @todo Allow file logging options, etc
154 @todo Add timestamps
155 """
156
157 if level >= cur_level:
158 #@todo Support output redirection based on debug level
159 print module + ":" + dbg_string[level] + ":" + string
160