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