Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 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 | **/ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 25 | import java.util.Set; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 26 | import java.util.concurrent.Future; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 27 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 28 | import net.floodlightcontroller.core.IFloodlightProviderService.Role; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 29 | import net.floodlightcontroller.debugcounter.IDebugCounterService; |
| 30 | import net.floodlightcontroller.debugcounter.IDebugCounterService.CounterException; |
| 31 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
| 32 | import net.floodlightcontroller.util.OrderedCollection; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 33 | |
| 34 | import org.jboss.netty.channel.Channel; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 35 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 36 | import org.projectfloodlight.openflow.protocol.OFCapabilities; |
| 37 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 38 | import org.projectfloodlight.openflow.protocol.OFFeaturesReply; |
| 39 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 40 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 41 | import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; |
| 42 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
| 43 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
| 44 | import org.projectfloodlight.openflow.protocol.OFStatsRequest; |
| 45 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 46 | import org.projectfloodlight.openflow.types.U64; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 47 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 48 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 49 | public interface IOFSwitch { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 50 | |
| 51 | /** |
| 52 | * OF1.3 switches should support role-request messages as in the 1.3 spec. |
| 53 | * OF1.0 switches may or may not support the Nicira role request extensions. |
| 54 | * To indicate the support, this property should be set by the associated |
| 55 | * OF1.0 switch driver in the net.onrc.onos.core.drivermanager package. |
| 56 | * The property will be ignored for OF1.3 switches. |
| 57 | */ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 58 | public static final String SWITCH_SUPPORTS_NX_ROLE = "supportsNxRole"; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 59 | |
| 60 | |
| 61 | //************************ |
| 62 | // Channel related |
| 63 | //************************ |
| 64 | |
| 65 | /** |
| 66 | * Disconnects the switch by closing the TCP connection. Results in a call |
| 67 | * to the channel handler's channelDisconnected method for cleanup |
| 68 | * @throws IOException |
| 69 | */ |
| 70 | public void disconnectSwitch(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 71 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 72 | /** |
| 73 | * Writes to the OFMessage to the output stream. |
| 74 | * The message will be handed to the floodlightProvider for possible filtering |
| 75 | * and processing by message listeners |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 76 | * |
| 77 | * @param m |
| 78 | * @param bc |
| 79 | * @throws IOException |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 80 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 81 | public void write(OFMessage m, FloodlightContext bc) throws IOException; |
| 82 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 83 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 84 | * Writes the list of messages to the output stream. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 85 | * The message will be handed to the floodlightProvider for possible filtering |
| 86 | * and processing by message listeners. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 87 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 88 | * @param msglist |
| 89 | * @param bc |
| 90 | * @throws IOException |
| 91 | */ |
| 92 | public void write(List<OFMessage> msglist, FloodlightContext bc) throws IOException; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 93 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 94 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 95 | * Gets the date the switch connected to this controller. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 96 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 97 | * @return the date |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 98 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 99 | public Date getConnectedSince(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 100 | |
| 101 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 102 | * Gets the next available transaction id. |
| 103 | * |
| 104 | * @return the next transaction ID |
| 105 | */ |
| 106 | public int getNextTransactionId(); |
| 107 | |
| 108 | /** |
| 109 | * Checks if the switch is still connected. |
| 110 | * Only call while holding processMessageLock |
| 111 | * |
| 112 | * @return whether the switch is still disconnected |
| 113 | */ |
| 114 | public boolean isConnected(); |
| 115 | |
| 116 | /** |
| 117 | * Sets whether the switch is connected. |
| 118 | * Only call while holding modifySwitchLock |
| 119 | * |
| 120 | * @param connected whether the switch is connected |
| 121 | */ |
| 122 | public void setConnected(boolean connected); |
| 123 | |
| 124 | /** |
| 125 | * Flushes all flows queued for this switch in the current thread. |
| 126 | * NOTE: The contract is limited to the current thread |
| 127 | */ |
| 128 | public void flush(); |
| 129 | |
| 130 | /** |
| 131 | * Sets the Netty Channel this switch instance is associated with. |
| 132 | * <p> |
| 133 | * Called immediately after instantiation |
| 134 | * |
| 135 | * @param channel |
| 136 | */ |
| 137 | public void setChannel(Channel channel); |
| 138 | |
| 139 | //************************ |
| 140 | // Switch features related |
| 141 | //************************ |
| 142 | |
| 143 | /** |
| 144 | * Gets the datapathId of the switch. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 145 | * |
Jonathan Hart | 99ff20a | 2014-06-15 16:53:00 -0700 | [diff] [blame] | 146 | * @return the switch buffers |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 147 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 148 | public long getId(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 149 | |
| 150 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 151 | * Gets a string version of the ID for this switch. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 152 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 153 | * @return string version of the ID |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 154 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 155 | public String getStringId(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 156 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 157 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 158 | * Gets the number of buffers. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 159 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 160 | * @return the number of buffers |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 161 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 162 | public int getNumBuffers(); |
| 163 | |
| 164 | public Set<OFCapabilities> getCapabilities(); |
| 165 | |
| 166 | public byte getNumTables(); |
| 167 | |
| 168 | /** |
| 169 | * Returns an OFDescStatsReply message object. Use the methods contained |
| 170 | * to retrieve switch descriptions for Manufacturer, Hw/Sw version etc. |
| 171 | */ |
| 172 | public OFDescStatsReply getSwitchDescription(); |
| 173 | |
| 174 | // /** |
| 175 | // * Returns a Future object that can be used to retrieve the asynchronous |
| 176 | // * OFStatisticsReply when it is available. |
| 177 | // * |
| 178 | // * @param request statistics request |
| 179 | // * @return Future object wrapping OFStatisticsReply |
| 180 | // * @throws IOException |
| 181 | // */ |
| 182 | // public Future<OFFeaturesReply> getFeaturesReplyFromSwitch() |
| 183 | // throws IOException; |
| 184 | // |
| 185 | // /** |
| 186 | // * Deliver the featuresReply future reply |
| 187 | // * |
| 188 | // * @param reply the reply to deliver |
| 189 | // */ |
| 190 | // void deliverOFFeaturesReply(OFMessage reply); |
| 191 | |
| 192 | /** |
| 193 | * Cancel features reply with a specific transaction ID |
| 194 | * @param transactionId the transaction ID |
| 195 | */ |
| 196 | public void cancelFeaturesReply(int transactionId); |
| 197 | |
| 198 | /** |
| 199 | * Gets the OFActionType set. |
| 200 | * <p> |
| 201 | * getActions has relevance only for an OpenFlow 1.0 switch. |
| 202 | * For OF1.3, each table can support different actions |
| 203 | * |
| 204 | * @return the action set |
| 205 | */ |
| 206 | public Set<OFActionType> getActions(); |
| 207 | |
| 208 | public void setOFVersion(OFVersion ofv); |
| 209 | |
| 210 | public OFVersion getOFVersion(); |
| 211 | |
| 212 | |
| 213 | //************************ |
| 214 | // Switch port related |
| 215 | //************************ |
| 216 | |
| 217 | /** |
| 218 | * the type of change that happened to an open flow port |
| 219 | */ |
| 220 | public enum PortChangeType { |
| 221 | /** Either a new port has been added by the switch, or we are |
| 222 | * adding a port we just deleted (via a prior notification) due to |
| 223 | * a change in the portNumber-portName mapping. |
| 224 | */ |
| 225 | ADD, |
| 226 | /** some other feature of the port has changed (eg. speed)*/ |
| 227 | OTHER_UPDATE, |
| 228 | /** Either a port has been deleted by the switch, or we are deleting |
| 229 | * a port whose portNumber-portName mapping has changed. Note that in |
| 230 | * the latter case, a subsequent notification will be sent out to add a |
| 231 | * port with the new portNumber-portName mapping. |
| 232 | */ |
| 233 | DELETE, |
| 234 | /** Port is up (i.e. enabled). Presumably an earlier notification had |
| 235 | * indicated that it was down. To be UP implies that the port is |
| 236 | * administratively considered UP (see ofp_port_config) AND the port |
| 237 | * link is up AND the port is no longer blocked (see ofp_port_state). |
| 238 | */ |
| 239 | UP, |
| 240 | /** Port is down (i.e. disabled). Presumably an earlier notification had |
| 241 | * indicated that it was up, or the port was always up. |
| 242 | * To be DOWN implies that the port has been either |
| 243 | * administratively brought down (see ofp_port_config) OR the port |
| 244 | * link is down OR the port is blocked (see ofp_port_state). |
| 245 | */ |
| 246 | DOWN, |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Describes a change of an open flow port. |
| 251 | */ |
| 252 | public static class PortChangeEvent { |
| 253 | public final OFPortDesc port; |
| 254 | public final PortChangeType type; |
| 255 | /** |
| 256 | * @param port |
| 257 | * @param type |
| 258 | */ |
| 259 | public PortChangeEvent(OFPortDesc port, |
| 260 | PortChangeType type) { |
| 261 | this.port = port; |
| 262 | this.type = type; |
| 263 | } |
| 264 | /* (non-Javadoc) |
| 265 | * @see java.lang.Object#hashCode() |
| 266 | */ |
| 267 | @Override |
| 268 | public int hashCode() { |
| 269 | final int prime = 31; |
| 270 | int result = 1; |
| 271 | result = prime * result + ((port == null) ? 0 : port.hashCode()); |
| 272 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
| 273 | return result; |
| 274 | } |
| 275 | /* (non-Javadoc) |
| 276 | * @see java.lang.Object#equals(java.lang.Object) |
| 277 | */ |
| 278 | @Override |
| 279 | public boolean equals(Object obj) { |
| 280 | if (this == obj) return true; |
| 281 | if (obj == null) return false; |
| 282 | if (getClass() != obj.getClass()) return false; |
| 283 | PortChangeEvent other = (PortChangeEvent) obj; |
| 284 | if (port == null) { |
| 285 | if (other.port != null) return false; |
| 286 | } else if (!port.equals(other.port)) return false; |
| 287 | if (type != other.type) return false; |
| 288 | return true; |
| 289 | } |
| 290 | /* (non-Javadoc) |
| 291 | * @see java.lang.Object#toString() |
| 292 | */ |
| 293 | @Override |
| 294 | public String toString() { |
| 295 | return "[" + type + " " + port.toString() + "]"; |
| 296 | } |
| 297 | } |
| 298 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * Get list of all enabled ports. This will typically be different from |
| 302 | * the list of ports in the OFFeaturesReply, since that one is a static |
| 303 | * snapshot of the ports at the time the switch connected to the controller |
| 304 | * whereas this port list also reflects the port status messages that have |
| 305 | * been received. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 306 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 307 | * @return Unmodifiable list of ports not backed by the underlying collection |
| 308 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 309 | public Collection<OFPortDesc> getEnabledPorts(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 310 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 311 | /** |
| 312 | * Get list of the port numbers of all enabled ports. This will typically |
| 313 | * be different from the list of ports in the OFFeaturesReply, since that |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 314 | * one is a static snapshot of the ports at the time the switch connected |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 315 | * to the controller whereas this port list also reflects the port status |
| 316 | * messages that have been received. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 317 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 318 | * @return Unmodifiable list of ports not backed by the underlying collection |
| 319 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 320 | public Collection<Integer> getEnabledPortNumbers(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 321 | |
| 322 | /** |
| 323 | * Retrieve the port object by the port number. The port object |
| 324 | * is the one that reflects the port status updates that have been |
| 325 | * received, not the one from the features reply. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 326 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 327 | * @param portNumber |
| 328 | * @return port object |
| 329 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 330 | public OFPortDesc getPort(int portNumber); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 331 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 332 | /** |
| 333 | * Retrieve the port object by the port name. The port object |
| 334 | * is the one that reflects the port status updates that have been |
| 335 | * received, not the one from the features reply. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 336 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 337 | * @param portName |
| 338 | * @return port object |
| 339 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 340 | public OFPortDesc getPort(String portName); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 341 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 342 | /** |
| 343 | * Add or modify a switch port. This is called by the core controller |
| 344 | * code in response to a OFPortStatus message. It should not typically be |
| 345 | * called by other floodlight applications. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 346 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 347 | * OFPPR_MODIFY and OFPPR_ADD will be treated as equivalent. The OpenFlow |
| 348 | * spec is not clear on whether portNames are portNumbers are considered |
| 349 | * authoritative identifiers. We treat portNames <-> portNumber mappings |
| 350 | * as fixed. If they change, we delete all previous conflicting ports and |
| 351 | * add all new ports. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 352 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 353 | * @param ps the port status message |
| 354 | * @return the ordered Collection of changes "applied" to the old ports |
| 355 | * of the switch according to the PortStatus message. A single PortStatus |
| 356 | * message can result in multiple changes. |
| 357 | * If portName <-> portNumber mappings have |
| 358 | * changed, the iteration order ensures that delete events for old |
| 359 | * conflicting appear before before events adding new ports |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 360 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 361 | public OrderedCollection<PortChangeEvent> processOFPortStatus(OFPortStatus ps); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 362 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 363 | /** |
| 364 | * Get list of all ports. This will typically be different from |
| 365 | * the list of ports in the OFFeaturesReply, since that one is a static |
| 366 | * snapshot of the ports at the time the switch connected to the controller |
| 367 | * whereas this port list also reflects the port status messages that have |
| 368 | * been received. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 369 | * |
| 370 | * @return Unmodifiable list of ports |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 371 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 372 | public Collection<OFPortDesc> getPorts(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 373 | |
| 374 | /** |
| 375 | * @param portName |
| 376 | * @return Whether a port is enabled per latest port status message |
| 377 | * (not configured down nor link down nor in spanning tree blocking state) |
| 378 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 379 | public boolean portEnabled(int portName); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 380 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 381 | /** |
| 382 | * @param portNumber |
| 383 | * @return Whether a port is enabled per latest port status message |
| 384 | * (not configured down nor link down nor in spanning tree blocking state) |
| 385 | */ |
| 386 | public boolean portEnabled(String portName); |
| 387 | |
| 388 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 389 | * Compute the changes that would be required to replace the old ports |
| 390 | * of this switch with the new ports |
| 391 | * @param ports new ports to set |
| 392 | * @return the ordered collection of changes "applied" to the old ports |
| 393 | * of the switch in order to set them to the new set. |
| 394 | * If portName <-> portNumber mappings have |
| 395 | * changed, the iteration order ensures that delete events for old |
| 396 | * conflicting appear before before events adding new ports |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 397 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 398 | public OrderedCollection<PortChangeEvent> |
| 399 | comparePorts(Collection<OFPortDesc> ports); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 400 | |
| 401 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 402 | * Replace the ports of this switch with the given ports. |
| 403 | * @param ports new ports to set |
| 404 | * @return the ordered collection of changes "applied" to the old ports |
| 405 | * of the switch in order to set them to the new set. |
| 406 | * If portName <-> portNumber mappings have |
| 407 | * changed, the iteration order ensures that delete events for old |
| 408 | * conflicting appear before before events adding new ports |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 409 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 410 | public OrderedCollection<PortChangeEvent> |
| 411 | setPorts(Collection<OFPortDesc> ports); |
| 412 | |
| 413 | // XXX S The odd use of providing an API call to 'set ports' (above) would |
| 414 | // logically suggest that there should be a way to delete or unset the ports. |
| 415 | // Right now we forbid this. We should probably not use setPorts too. |
| 416 | // |
| 417 | // /** |
| 418 | // * Delete a port for the switch. This is called by the core controller |
| 419 | // * code in response to a OFPortStatus message. It should not typically be |
| 420 | // * called by other floodlight applications. |
| 421 | // * |
| 422 | // * @param portNumber |
| 423 | // */ |
| 424 | // public void deletePort(short portNumber); |
| 425 | // |
| 426 | // /** |
| 427 | // * Delete a port for the switch. This is called by the core controller |
| 428 | // * code in response to a OFPortStatus message. It should not typically be |
| 429 | // * called by other floodlight applications. |
| 430 | // * |
| 431 | // * @param portName |
| 432 | // */ |
| 433 | // public void deletePort(String portName); |
| 434 | |
| 435 | |
| 436 | //******************************************* |
| 437 | // IOFSwitch object attributes |
| 438 | //************************ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 439 | |
| 440 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 441 | * Gets attributes of this switch. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 442 | * |
Jonathan Hart | 99ff20a | 2014-06-15 16:53:00 -0700 | [diff] [blame] | 443 | * @return attributes of the switch |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 444 | */ |
| 445 | public Map<Object, Object> getAttributes(); |
| 446 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 447 | /** |
| 448 | * Checks if a specific switch property exists for this switch |
| 449 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 450 | * @param name name of property |
| 451 | * @return value for name |
| 452 | */ |
| 453 | boolean hasAttribute(String name); |
| 454 | |
| 455 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 456 | * Gets properties for switch specific behavior. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 457 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 458 | * @param name name of property |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 459 | * @return 'value' for 'name', or null if no entry for 'name' exists |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 460 | */ |
| 461 | Object getAttribute(String name); |
| 462 | |
| 463 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 464 | * Sets properties for switch specific behavior. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 465 | * |
| 466 | * @param name name of property |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 467 | * @param value value for name |
| 468 | */ |
| 469 | void setAttribute(String name, Object value); |
| 470 | |
| 471 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 472 | * Removes properties for switch specific behavior. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 473 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 474 | * @param name name of property |
| 475 | * @return current value for name or null (if not present) |
| 476 | */ |
| 477 | Object removeAttribute(String name); |
| 478 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 479 | //************************ |
| 480 | // Switch statistics |
| 481 | //************************ |
| 482 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 483 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 484 | * Delivers the statistics future reply. |
| 485 | * |
| 486 | * @param reply the reply to deliver |
| 487 | */ |
| 488 | public void deliverStatisticsReply(OFMessage reply); |
| 489 | |
| 490 | /** |
| 491 | * Cancels the statistics reply with the given transaction ID. |
| 492 | * |
| 493 | * @param transactionId the transaction ID |
| 494 | */ |
| 495 | public void cancelStatisticsReply(int transactionId); |
| 496 | |
| 497 | /** |
| 498 | * Cancels all statistics replies. |
| 499 | */ |
| 500 | public void cancelAllStatisticsReplies(); |
| 501 | |
| 502 | /** |
| 503 | * Gets a Future object that can be used to retrieve the asynchronous. |
| 504 | * OFStatisticsReply when it is available. |
| 505 | * |
| 506 | * @param request statistics request |
| 507 | * @return Future object wrapping OFStatisticsReply |
| 508 | * @throws IOException |
| 509 | */ |
| 510 | public Future<List<OFStatsReply>> getStatistics(OFStatsRequest<?> request) |
| 511 | throws IOException; |
| 512 | |
| 513 | //************************ |
| 514 | // Switch other utilities |
| 515 | //************************ |
| 516 | |
| 517 | /** |
| 518 | * Clears all flowmods on this switch. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 519 | */ |
| 520 | public void clearAllFlowMods(); |
| 521 | |
| 522 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 523 | * Gets the current role of this controller for this IOFSwitch. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 524 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 525 | public Role getRole(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 526 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 527 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 528 | * Sets this controller's Role for this IOFSwitch to role. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 529 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 530 | * @param role |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 531 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 532 | public void setRole(Role role); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 533 | |
| 534 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 535 | * Gets the next generation ID. |
| 536 | * <p> |
| 537 | * Note: relevant for role request messages in OF1.3 |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 538 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 539 | * @return next generation ID |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 540 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 541 | public U64 getNextGenerationId(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 542 | |
| 543 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 544 | * Sets IFloodlightProviderService for this switch instance. |
| 545 | * <p> |
| 546 | * Called immediately after instantiation |
| 547 | * |
| 548 | * @param controller |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 549 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 550 | public void setFloodlightProvider(IFloodlightProviderService controller); |
| 551 | |
| 552 | /** |
| 553 | * Sets IThreadPoolService for this switch instance. |
| 554 | * <p> |
| 555 | * Called immediately after instantiation |
| 556 | * |
| 557 | * @param threadPool |
| 558 | */ |
| 559 | public void setThreadPoolService(IThreadPoolService threadPool); |
| 560 | |
| 561 | /** |
| 562 | * Set debug counter service for per-switch counters |
| 563 | * Called immediately after instantiation |
| 564 | * @param debugCounters |
| 565 | * @throws CounterException |
| 566 | */ |
| 567 | public void setDebugCounterService(IDebugCounterService debugCounter) |
| 568 | throws CounterException; |
| 569 | |
| 570 | /** |
| 571 | * Start this switch driver's sub handshake. This might be a no-op but |
| 572 | * this method must be called at least once for the switch to be become |
| 573 | * ready. |
| 574 | * This method must only be called from the I/O thread |
| 575 | * @throws IOException |
| 576 | * @throws SwitchDriverSubHandshakeAlreadyStarted if the sub-handshake has |
| 577 | * already been started |
| 578 | */ |
| 579 | public void startDriverHandshake() throws IOException; |
| 580 | |
| 581 | /** |
| 582 | * Check if the sub-handshake for this switch driver has been completed. |
| 583 | * This method can only be called after startDriverHandshake() |
| 584 | * |
| 585 | * This methods must only be called from the I/O thread |
| 586 | * @return true if the sub-handshake has been completed. False otherwise |
| 587 | * @throws SwitchDriverSubHandshakeNotStarted if startDriverHandshake() has |
| 588 | * not been called yet. |
| 589 | */ |
| 590 | public boolean isDriverHandshakeComplete(); |
| 591 | |
| 592 | /** |
| 593 | * Pass the given OFMessage to the driver as part of this driver's |
| 594 | * sub-handshake. Must not be called after the handshake has been completed |
| 595 | * This methods must only be called from the I/O thread |
| 596 | * @param m The message that the driver should process |
| 597 | * @throws SwitchDriverSubHandshakeCompleted if isDriverHandshake() returns |
| 598 | * false before this method call |
| 599 | * @throws SwitchDriverSubHandshakeNotStarted if startDriverHandshake() has |
| 600 | * not been called yet. |
| 601 | */ |
| 602 | public void processDriverHandshakeMessage(OFMessage m); |
| 603 | |
| 604 | /** |
| 605 | * Set the flow table full flag in the switch |
| 606 | * XXX S Rethink this for multiple tables |
| 607 | */ |
| 608 | public void setTableFull(boolean isFull); |
| 609 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 610 | } |