Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 1 | """ |
| 2 | OpenFlow Test Framework |
| 3 | |
| 4 | Configuration fragment |
| 5 | |
| 6 | This file contains Python code to specify the configuration |
| 7 | of the system under test. |
| 8 | |
| 9 | This is a work in progress. The code below is for illustration only. |
| 10 | |
| 11 | The configuration information is extensible in that any |
| 12 | Python code may be added to this file (or its imports) and will |
| 13 | be available to test cases. |
| 14 | |
| 15 | A platform identifier is given at the top of the file and most |
| 16 | other information is determined by testing this value. Additional |
| 17 | files may also be imported based on the platform. |
| 18 | |
| 19 | The configuration must specify a mapping from system interfaces |
| 20 | available to the test framework to OpenFlow port numbers on the |
| 21 | switch under test. This is done in the interface_ofport_map |
| 22 | dictionary. Future extensions may include specifying a driver |
| 23 | for the port (so as to allow remote packet generation) and to |
| 24 | specify a switch instance (to allow multiple switches to be |
| 25 | tested together). |
| 26 | |
| 27 | Currently, the assumption is that ports are bidirectional, so |
| 28 | specifying "OF port 1 is connnected to eth2" implies this is so |
| 29 | for both TX and RX. |
| 30 | |
| 31 | """ |
| 32 | |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 33 | import sys |
| 34 | |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 35 | ##@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 Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 65 | ##@var controller_host |
| 66 | # Gives the controller host address to use |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 67 | |
| 68 | ##@var controller_port |
| 69 | # Gives the controller port to use |
| 70 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 71 | # platform = "sw_userspace" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 72 | # platform = "sw_kernelspace" |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 73 | platform = "bcm_indigo" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 74 | # platform = "stanford_lb4g" |
| 75 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 76 | |
| 77 | # These can be moved into platform specific code if needed |
| 78 | |
| 79 | RCV_TIMEOUT_DEFAULT = 10 |
| 80 | RCV_SIZE_DEFAULT = 4096 |
| 81 | CONTROLLER_HOST_DEFAULT = '' |
| 82 | CONTROLLER_PORT_DEFAULT = 6633 |
| 83 | |
Dan Talayco | d7e2dbe | 2010-02-13 21:51:15 -0800 | [diff] [blame] | 84 | # Timeout in seconds for initial connection |
| 85 | INIT_CONNECT_TIMEOUT = 4 |
| 86 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 87 | # Number of switch connection requests to queue |
| 88 | LISTEN_QUEUE_SIZE = 1 |
| 89 | |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 90 | if 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 Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 101 | controller_host = "172.27.74.158" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 102 | controller_port = 7000 |
| 103 | |
| 104 | elif platform == "bcm_indigo": |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 105 | interface_ofport_map = { |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 106 | 23 : "eth2", |
| 107 | 24 : "eth3", |
| 108 | 25 : "eth4", |
| 109 | 26 : "eth5" |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 110 | } |
| 111 | # For SSH connections to switch |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 112 | 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 Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 119 | controller_host = "192.168.2.2" |
| 120 | # controller_host = "172.27.74.26" |
Dan Talayco | dba4c34 | 2010-02-15 14:13:02 -0800 | [diff] [blame] | 121 | controller_port = 6634 |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 122 | |
| 123 | |
| 124 | # Debug levels |
| 125 | DEBUG_ALL = 0 |
| 126 | DEBUG_VERBOSE = 1 |
| 127 | DEBUG_INFO = 2 |
| 128 | DEBUG_WARN = 3 |
| 129 | DEBUG_ERROR = 4 |
| 130 | DEBUG_CRITICAL = 5 |
| 131 | DEBUG_NONE = 6 # For current setting only; not for string level |
| 132 | |
Dan Talayco | dba4c34 | 2010-02-15 14:13:02 -0800 | [diff] [blame] | 133 | debug_level_default = DEBUG_WARN |
| 134 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 135 | dbg_string = [ |
| 136 | "DBG ALL ", |
| 137 | "VERBOSE ", |
| 138 | "INFO ", |
| 139 | "WARN ", |
| 140 | "ERROR ", |
| 141 | "CRITICAL " |
| 142 | ] |
| 143 | |
| 144 | def 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 |
| 157 | """ |
| 158 | |
| 159 | if level >= cur_level: |
| 160 | #@todo Support output redirection based on debug level |
| 161 | print module + ":" + dbg_string[level] + ":" + string |
| 162 | |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 163 | |
| 164 | def oft_assert(condition, string): |
| 165 | """ |
| 166 | Test framework assertion check |
| 167 | |
| 168 | @param condition The boolean condition to check |
| 169 | @param string String to print if error |
| 170 | |
| 171 | If condition is not true, it is considered a test framework |
| 172 | failure and exit is called |
| 173 | """ |
| 174 | if not condition: |
| 175 | debug_log("OFT", debug_level_default, DEBUG_CRITICAL, |
| 176 | "Internal error: " + string) |
| 177 | sys.exit(1) |
| 178 | |