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 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 39 | ##@var controller_host |
| 40 | # Gives the controller host address to use |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 41 | |
| 42 | ##@var controller_port |
| 43 | # Gives the controller port to use |
| 44 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 45 | # platform = "sw_userspace" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 46 | # platform = "sw_kernelspace" |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 47 | platform = "bcm_indigo" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 48 | # platform = "stanford_lb4g" |
| 49 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 50 | |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 51 | if platform == "sw_userspace": |
| 52 | interface_ofport_map = { |
| 53 | 1 : "eth2", |
| 54 | 2 : "eth3", |
| 55 | 3 : "eth4", |
| 56 | 4 : "eth5" |
| 57 | } |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 58 | controller_host = "172.27.74.158" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 59 | controller_port = 7000 |
| 60 | |
| 61 | elif platform == "bcm_indigo": |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 62 | interface_ofport_map = { |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 63 | 23 : "eth2", |
| 64 | 24 : "eth3", |
| 65 | 25 : "eth4", |
| 66 | 26 : "eth5" |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 67 | } |
| 68 | # For SSH connections to switch |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 69 | controller_host = "192.168.2.2" |
| 70 | # controller_host = "172.27.74.26" |
Dan Talayco | dba4c34 | 2010-02-15 14:13:02 -0800 | [diff] [blame] | 71 | controller_port = 6634 |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 72 | |
| 73 | |
Dan Talayco | f307f3f | 2010-02-19 11:42:29 -0800 | [diff] [blame] | 74 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 75 | # Debug levels |
| 76 | DEBUG_ALL = 0 |
| 77 | DEBUG_VERBOSE = 1 |
| 78 | DEBUG_INFO = 2 |
| 79 | DEBUG_WARN = 3 |
| 80 | DEBUG_ERROR = 4 |
| 81 | DEBUG_CRITICAL = 5 |
| 82 | DEBUG_NONE = 6 # For current setting only; not for string level |
| 83 | |
Dan Talayco | dba4c34 | 2010-02-15 14:13:02 -0800 | [diff] [blame] | 84 | debug_level_default = DEBUG_WARN |
| 85 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 86 | dbg_string = [ |
| 87 | "DBG ALL ", |
| 88 | "VERBOSE ", |
| 89 | "INFO ", |
| 90 | "WARN ", |
| 91 | "ERROR ", |
| 92 | "CRITICAL " |
| 93 | ] |
| 94 | |
Dan Talayco | f307f3f | 2010-02-19 11:42:29 -0800 | [diff] [blame] | 95 | |
| 96 | # These can be moved into platform specific code if needed |
| 97 | |
| 98 | RCV_TIMEOUT_DEFAULT = 10 |
| 99 | RCV_SIZE_DEFAULT = 4096 |
| 100 | CONTROLLER_HOST_DEFAULT = '' |
| 101 | CONTROLLER_PORT_DEFAULT = 6633 |
| 102 | |
| 103 | # Timeout in seconds for initial connection |
| 104 | INIT_CONNECT_TIMEOUT = 4 |
| 105 | |
| 106 | # Number of switch connection requests to queue |
| 107 | LISTEN_QUEUE_SIZE = 1 |
| 108 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 109 | def 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 Talayco | 90576bd | 2010-02-19 10:59:02 -0800 | [diff] [blame] | 122 | @todo Consider using the native Python logging module |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 123 | """ |
| 124 | |
| 125 | if level >= cur_level: |
| 126 | #@todo Support output redirection based on debug level |
| 127 | print module + ":" + dbg_string[level] + ":" + string |
| 128 | |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 129 | |
| 130 | def 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 Talayco | 90576bd | 2010-02-19 10:59:02 -0800 | [diff] [blame] | 138 | 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 Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 144 | """ |
| 145 | if not condition: |
| 146 | debug_log("OFT", debug_level_default, DEBUG_CRITICAL, |
| 147 | "Internal error: " + string) |
| 148 | sys.exit(1) |
| 149 | |