Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2011, Big Switch Networks, Inc. |
| 3 | * Originally created by David Erickson, Stanford University |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | * not use this file except in compliance with the License. You may obtain |
| 7 | * a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | * License for the specific language governing permissions and limitations |
| 15 | * under the License. |
| 16 | **/ |
| 17 | |
| 18 | package net.floodlightcontroller.core; |
| 19 | |
| 20 | import java.io.IOException; |
| 21 | import java.util.Collection; |
| 22 | import java.util.Date; |
| 23 | import java.util.List; |
| 24 | import java.util.Map; |
| 25 | import java.util.concurrent.Future; |
| 26 | import net.floodlightcontroller.core.IFloodlightProviderService.Role; |
| 27 | |
| 28 | import org.jboss.netty.channel.Channel; |
| 29 | import org.openflow.protocol.OFFeaturesReply; |
| 30 | import org.openflow.protocol.OFMessage; |
| 31 | import org.openflow.protocol.OFPhysicalPort; |
| 32 | import org.openflow.protocol.OFStatisticsRequest; |
| 33 | import org.openflow.protocol.statistics.OFDescriptionStatistics; |
| 34 | import org.openflow.protocol.statistics.OFStatistics; |
| 35 | |
| 36 | /** |
| 37 | * |
| 38 | * |
| 39 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 40 | */ |
| 41 | public interface IOFSwitch { |
| 42 | // Attribute keys |
| 43 | public static final String SWITCH_DESCRIPTION_FUTURE = "DescriptionFuture"; |
| 44 | public static final String SWITCH_DESCRIPTION_DATA = "DescriptionData"; |
| 45 | public static final String SWITCH_SUPPORTS_NX_ROLE = "supportsNxRole"; |
| 46 | public static final String SWITCH_IS_CORE_SWITCH = "isCoreSwitch"; |
| 47 | public static final String PROP_FASTWILDCARDS = "FastWildcards"; |
| 48 | public static final String PROP_REQUIRES_L3_MATCH = "requiresL3Match"; |
| 49 | public static final String PROP_SUPPORTS_OFPP_TABLE = "supportsOfppTable"; |
| 50 | public static final String PROP_SUPPORTS_OFPP_FLOOD = "supportsOfppFlood"; |
| 51 | public static final String PROP_SUPPORTS_NETMASK_TBL = "supportsNetmaskTbl"; |
| 52 | |
| 53 | /** |
| 54 | * Writes to the OFMessage to the output stream. |
| 55 | * The message will be handed to the floodlightProvider for possible filtering |
| 56 | * and processing by message listeners |
| 57 | * @param m |
| 58 | * @param bc |
| 59 | * @throws IOException |
| 60 | */ |
| 61 | public void write(OFMessage m, FloodlightContext bc) throws IOException; |
| 62 | |
| 63 | /** |
| 64 | * Writes the list of messages to the output stream |
| 65 | * The message will be handed to the floodlightProvider for possible filtering |
| 66 | * and processing by message listeners. |
| 67 | * @param msglist |
| 68 | * @param bc |
| 69 | * @throws IOException |
| 70 | */ |
| 71 | public void write(List<OFMessage> msglist, FloodlightContext bc) throws IOException; |
| 72 | |
| 73 | /** |
| 74 | * |
| 75 | * @throws IOException |
| 76 | */ |
| 77 | public void disconnectOutputStream(); |
| 78 | |
| 79 | /** |
| 80 | * FIXME: remove getChannel(). All access to the channel should be through |
| 81 | * wrapper functions in IOFSwitch |
| 82 | * @return |
| 83 | */ |
| 84 | public Channel getChannel(); |
| 85 | |
| 86 | /** |
| 87 | * Returns switch features from features Reply |
| 88 | * @return |
| 89 | */ |
| 90 | public int getBuffers(); |
| 91 | |
| 92 | public int getActions(); |
| 93 | |
| 94 | public int getCapabilities(); |
| 95 | |
| 96 | public byte getTables(); |
| 97 | |
| 98 | /** |
| 99 | * Set the OFFeaturesReply message returned by the switch during initial |
| 100 | * handshake. |
| 101 | * @param featuresReply |
| 102 | */ |
| 103 | public void setFeaturesReply(OFFeaturesReply featuresReply); |
| 104 | |
| 105 | /** |
| 106 | * Set the SwitchProperties based on it's description |
| 107 | * @param description |
| 108 | */ |
| 109 | public void setSwitchProperties(OFDescriptionStatistics description); |
| 110 | |
| 111 | /** |
| 112 | * Get list of all enabled ports. This will typically be different from |
| 113 | * the list of ports in the OFFeaturesReply, since that one is a static |
| 114 | * snapshot of the ports at the time the switch connected to the controller |
| 115 | * whereas this port list also reflects the port status messages that have |
| 116 | * been received. |
| 117 | * @return Unmodifiable list of ports not backed by the underlying collection |
| 118 | */ |
| 119 | public Collection<OFPhysicalPort> getEnabledPorts(); |
| 120 | |
| 121 | /** |
| 122 | * Get list of the port numbers of all enabled ports. This will typically |
| 123 | * be different from the list of ports in the OFFeaturesReply, since that |
| 124 | * one is a static snapshot of the ports at the time the switch connected |
| 125 | * to the controller whereas this port list also reflects the port status |
| 126 | * messages that have been received. |
| 127 | * @return Unmodifiable list of ports not backed by the underlying collection |
| 128 | */ |
| 129 | public Collection<Short> getEnabledPortNumbers(); |
| 130 | |
| 131 | /** |
| 132 | * Retrieve the port object by the port number. The port object |
| 133 | * is the one that reflects the port status updates that have been |
| 134 | * received, not the one from the features reply. |
| 135 | * @param portNumber |
| 136 | * @return port object |
| 137 | */ |
| 138 | public OFPhysicalPort getPort(short portNumber); |
| 139 | |
| 140 | /** |
| 141 | * Retrieve the port object by the port name. The port object |
| 142 | * is the one that reflects the port status updates that have been |
| 143 | * received, not the one from the features reply. |
| 144 | * @param portName |
| 145 | * @return port object |
| 146 | */ |
| 147 | public OFPhysicalPort getPort(String portName); |
| 148 | |
| 149 | /** |
| 150 | * Add or modify a switch port. This is called by the core controller |
| 151 | * code in response to a OFPortStatus message. It should not typically be |
| 152 | * called by other floodlight applications. |
| 153 | * @param port |
| 154 | */ |
| 155 | public void setPort(OFPhysicalPort port); |
| 156 | |
| 157 | /** |
| 158 | * Delete a port for the switch. This is called by the core controller |
| 159 | * code in response to a OFPortStatus message. It should not typically be |
| 160 | * called by other floodlight applications. |
| 161 | * @param portNumber |
| 162 | */ |
| 163 | public void deletePort(short portNumber); |
| 164 | |
| 165 | /** |
| 166 | * Delete a port for the switch. This is called by the core controller |
| 167 | * code in response to a OFPortStatus message. It should not typically be |
| 168 | * called by other floodlight applications. |
| 169 | * @param portName |
| 170 | */ |
| 171 | public void deletePort(String portName); |
| 172 | |
| 173 | /** |
| 174 | * Get list of all ports. This will typically be different from |
| 175 | * the list of ports in the OFFeaturesReply, since that one is a static |
| 176 | * snapshot of the ports at the time the switch connected to the controller |
| 177 | * whereas this port list also reflects the port status messages that have |
| 178 | * been received. |
| 179 | * @return Unmodifiable list of ports |
| 180 | */ |
| 181 | public Collection<OFPhysicalPort> getPorts(); |
| 182 | |
| 183 | /** |
| 184 | * @param portName |
| 185 | * @return Whether a port is enabled per latest port status message |
| 186 | * (not configured down nor link down nor in spanning tree blocking state) |
| 187 | */ |
| 188 | public boolean portEnabled(short portName); |
| 189 | |
| 190 | /** |
| 191 | * @param portNumber |
| 192 | * @return Whether a port is enabled per latest port status message |
| 193 | * (not configured down nor link down nor in spanning tree blocking state) |
| 194 | */ |
| 195 | public boolean portEnabled(String portName); |
| 196 | |
| 197 | /** |
| 198 | * @param port |
| 199 | * @return Whether a port is enabled per latest port status message |
| 200 | * (not configured down nor link down nor in spanning tree blocking state) |
| 201 | */ |
| 202 | public boolean portEnabled(OFPhysicalPort port); |
| 203 | |
| 204 | /** |
| 205 | * Get the datapathId of the switch |
| 206 | * @return |
| 207 | */ |
| 208 | public long getId(); |
| 209 | |
| 210 | /** |
| 211 | * Get a string version of the ID for this switch |
| 212 | * @return |
| 213 | */ |
| 214 | public String getStringId(); |
| 215 | |
| 216 | /** |
| 217 | * Retrieves attributes of this switch |
| 218 | * @return |
| 219 | */ |
| 220 | public Map<Object, Object> getAttributes(); |
| 221 | |
| 222 | /** |
| 223 | * Retrieves the date the switch connected to this controller |
| 224 | * @return the date |
| 225 | */ |
| 226 | public Date getConnectedSince(); |
| 227 | |
| 228 | /** |
| 229 | * Returns the next available transaction id |
| 230 | * @return |
| 231 | */ |
| 232 | public int getNextTransactionId(); |
| 233 | |
| 234 | /** |
| 235 | * Returns a Future object that can be used to retrieve the asynchronous |
| 236 | * OFStatisticsReply when it is available. |
| 237 | * |
| 238 | * @param request statistics request |
| 239 | * @return Future object wrapping OFStatisticsReply |
| 240 | * @throws IOException |
| 241 | */ |
| 242 | public Future<List<OFStatistics>> getStatistics(OFStatisticsRequest request) |
| 243 | throws IOException; |
| 244 | |
| 245 | /** |
| 246 | * Returns a Future object that can be used to retrieve the asynchronous |
| 247 | * OFStatisticsReply when it is available. |
| 248 | * |
| 249 | * @param request statistics request |
| 250 | * @return Future object wrapping OFStatisticsReply |
| 251 | * @throws IOException |
| 252 | */ |
| 253 | public Future<OFFeaturesReply> getFeaturesReplyFromSwitch() |
| 254 | throws IOException; |
| 255 | |
| 256 | /** |
| 257 | * Deliver the featuresReply future reply |
| 258 | * @param reply the reply to deliver |
| 259 | */ |
| 260 | void deliverOFFeaturesReply(OFMessage reply); |
| 261 | |
| 262 | /* |
| 263 | * Cancel features reply with a specific transction ID |
| 264 | * @param transactionId the transaction ID |
| 265 | */ |
| 266 | public void cancelFeaturesReply(int transactionId); |
| 267 | |
| 268 | /** |
| 269 | * Check if the switch is still connected; |
| 270 | * Only call while holding processMessageLock |
| 271 | * @return whether the switch is still disconnected |
| 272 | */ |
| 273 | public boolean isConnected(); |
| 274 | |
| 275 | /** |
| 276 | * Set whether the switch is connected |
| 277 | * Only call while holding modifySwitchLock |
| 278 | * @param connected whether the switch is connected |
| 279 | */ |
| 280 | public void setConnected(boolean connected); |
| 281 | |
| 282 | /** |
| 283 | * Get the current role of the controller for the switch |
| 284 | * @return the role of the controller |
| 285 | */ |
| 286 | public Role getRole(); |
| 287 | |
| 288 | /** |
| 289 | * Check if the controller is an active controller for the switch. |
| 290 | * The controller is active if its role is MASTER or EQUAL. |
| 291 | * @return whether the controller is active |
| 292 | */ |
| 293 | public boolean isActive(); |
| 294 | |
| 295 | /** |
| 296 | * Deliver the statistics future reply |
| 297 | * @param reply the reply to deliver |
| 298 | */ |
| 299 | public void deliverStatisticsReply(OFMessage reply); |
| 300 | |
| 301 | /** |
| 302 | * Cancel the statistics reply with the given transaction ID |
| 303 | * @param transactionId the transaction ID |
| 304 | */ |
| 305 | public void cancelStatisticsReply(int transactionId); |
| 306 | |
| 307 | /** |
| 308 | * Cancel all statistics replies |
| 309 | */ |
| 310 | public void cancelAllStatisticsReplies(); |
| 311 | |
| 312 | /** |
| 313 | * Checks if a specific switch property exists for this switch |
| 314 | * @param name name of property |
| 315 | * @return value for name |
| 316 | */ |
| 317 | boolean hasAttribute(String name); |
| 318 | |
| 319 | /** |
| 320 | * Set properties for switch specific behavior |
| 321 | * @param name name of property |
| 322 | * @return value for name |
| 323 | */ |
| 324 | Object getAttribute(String name); |
| 325 | |
| 326 | /** |
| 327 | * Set properties for switch specific behavior |
| 328 | * @param name name of property |
| 329 | * @param value value for name |
| 330 | */ |
| 331 | void setAttribute(String name, Object value); |
| 332 | |
| 333 | /** |
| 334 | * Set properties for switch specific behavior |
| 335 | * @param name name of property |
| 336 | * @return current value for name or null (if not present) |
| 337 | */ |
| 338 | Object removeAttribute(String name); |
| 339 | |
| 340 | /** |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 341 | * Setup an unconnected switch with the info required. |
| 342 | * @param dpid of the switch |
| 343 | */ |
| 344 | public void setupRemoteSwitch(Long dpid); |
| 345 | |
| 346 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 347 | * Clear all flowmods on this switch |
| 348 | */ |
| 349 | public void clearAllFlowMods(); |
| 350 | |
| 351 | /** |
| 352 | * Update broadcast cache |
| 353 | * @param data |
| 354 | * @return true if there is a cache hit |
| 355 | * false if there is no cache hit. |
| 356 | */ |
| 357 | public boolean updateBroadcastCache(Long entry, Short port); |
| 358 | |
| 359 | /** |
| 360 | * Get the portBroadcastCacheHits |
| 361 | * @return |
| 362 | */ |
| 363 | public Map<Short, Long> getPortBroadcastHits(); |
| 364 | |
| 365 | /** |
| 366 | * Send a flow statistics request to the switch. This call returns after |
| 367 | * sending the stats. request to the switch. |
| 368 | * @param request flow statistics request message |
| 369 | * @param xid transaction id, must be obtained by using the getXid() API. |
| 370 | * @param caller the caller of the API. receive() callback of this |
| 371 | * caller would be called when the reply from the switch is received. |
| 372 | * @return the transaction id for the message sent to the switch. The |
| 373 | * transaction id can be used to match the response with the request. Note |
| 374 | * that the transaction id is unique only within the scope of this switch. |
| 375 | * @throws IOException |
| 376 | */ |
| 377 | public void sendStatsQuery(OFStatisticsRequest request, int xid, |
| 378 | IOFMessageListener caller) throws IOException; |
| 379 | |
| 380 | /** |
| 381 | * Flush all flows queued for this switch in the current thread. |
| 382 | * NOTE: The contract is limited to the current thread |
| 383 | */ |
| 384 | public void flush(); |
| 385 | } |