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