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 | |
| 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 Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 63 | ##@var controller_host |
| 64 | # Gives the controller host address to use |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 65 | |
| 66 | ##@var controller_port |
| 67 | # Gives the controller port to use |
| 68 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 69 | # platform = "sw_userspace" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 70 | # platform = "sw_kernelspace" |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 71 | platform = "bcm_indigo" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 72 | # platform = "stanford_lb4g" |
| 73 | |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 74 | |
| 75 | # These can be moved into platform specific code if needed |
| 76 | |
| 77 | RCV_TIMEOUT_DEFAULT = 10 |
| 78 | RCV_SIZE_DEFAULT = 4096 |
| 79 | CONTROLLER_HOST_DEFAULT = '' |
| 80 | CONTROLLER_PORT_DEFAULT = 6633 |
| 81 | |
| 82 | # Number of switch connection requests to queue |
| 83 | LISTEN_QUEUE_SIZE = 1 |
| 84 | |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 85 | if platform == "sw_userspace": |
| 86 | interface_ofport_map = { |
| 87 | 1 : "eth2", |
| 88 | 2 : "eth3", |
| 89 | 3 : "eth4", |
| 90 | 4 : "eth5" |
| 91 | } |
| 92 | switch_cxn_type = "localhost" |
| 93 | switch_init = None # TBD |
| 94 | switch_connect = None # TBD |
| 95 | switch_disconnect = None # TBD |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 96 | controller_host = "172.27.74.158" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 97 | controller_port = 7000 |
| 98 | |
| 99 | elif platform == "bcm_indigo": |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 100 | interface_ofport_map = { |
| 101 | 1 : "eth2", |
| 102 | 2 : "eth3", |
| 103 | 3 : "eth4", |
| 104 | 4 : "eth5" |
| 105 | } |
| 106 | # For SSH connections to switch |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 107 | switch_cxn_type = "ssh" |
| 108 | switch_ip = "192.168.2.21" |
| 109 | switch_username = "root" |
| 110 | switch_password = "OpenFlow" |
| 111 | switch_init = None # TBD |
| 112 | switch_connect = None # TBD |
| 113 | switch_disconnect = None # TBD |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 114 | controller_host = "192.168.2.2" |
| 115 | # controller_host = "172.27.74.26" |
Dan Talayco | 3408952 | 2010-02-07 23:07:41 -0800 | [diff] [blame] | 116 | controller_port = 7000 |
Dan Talayco | 9be11bc | 2010-02-12 22:58:46 -0800 | [diff] [blame] | 117 | |
| 118 | |
| 119 | # Debug levels |
| 120 | DEBUG_ALL = 0 |
| 121 | DEBUG_VERBOSE = 1 |
| 122 | DEBUG_INFO = 2 |
| 123 | DEBUG_WARN = 3 |
| 124 | DEBUG_ERROR = 4 |
| 125 | DEBUG_CRITICAL = 5 |
| 126 | DEBUG_NONE = 6 # For current setting only; not for string level |
| 127 | |
| 128 | dbg_string = [ |
| 129 | "DBG ALL ", |
| 130 | "VERBOSE ", |
| 131 | "INFO ", |
| 132 | "WARN ", |
| 133 | "ERROR ", |
| 134 | "CRITICAL " |
| 135 | ] |
| 136 | |
| 137 | def debug_log(module, cur_level, level, string): |
| 138 | """ |
| 139 | Log a debug message |
| 140 | |
| 141 | Compare the debug level to the current level and display |
| 142 | the string if appropriate. |
| 143 | @param module String representing the module reporting the info/error |
| 144 | @param cur_level The module's current debug level |
| 145 | @param level The level of the error message |
| 146 | @param string String to report |
| 147 | |
| 148 | @todo Allow file logging options, etc |
| 149 | @todo Add timestamps |
| 150 | """ |
| 151 | |
| 152 | if level >= cur_level: |
| 153 | #@todo Support output redirection based on debug level |
| 154 | print module + ":" + dbg_string[level] + ":" + string |
| 155 | |