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