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