blob: e28d7be494961f23a7bd9fb10c51af0b8c223514 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * 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 Krishnaswamy345ee992012-12-13 20:29:48 -080017
18package net.floodlightcontroller.core;
19
20import java.io.IOException;
21import java.util.Collection;
22import java.util.Date;
23import java.util.List;
24import java.util.Map;
25import java.util.concurrent.Future;
Jonathan Harta99ec672014-04-03 11:30:34 -070026
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080027import net.floodlightcontroller.core.IFloodlightProviderService.Role;
28
29import org.jboss.netty.channel.Channel;
30import org.openflow.protocol.OFFeaturesReply;
31import org.openflow.protocol.OFMessage;
32import org.openflow.protocol.OFPhysicalPort;
33import org.openflow.protocol.OFStatisticsRequest;
34import org.openflow.protocol.statistics.OFDescriptionStatistics;
35import org.openflow.protocol.statistics.OFStatistics;
36
37/**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080038 * @author David Erickson (daviderickson@cs.stanford.edu)
39 */
40public interface IOFSwitch {
41 // Attribute keys
42 public static final String SWITCH_DESCRIPTION_FUTURE = "DescriptionFuture";
43 public static final String SWITCH_DESCRIPTION_DATA = "DescriptionData";
44 public static final String SWITCH_SUPPORTS_NX_ROLE = "supportsNxRole";
45 public static final String SWITCH_IS_CORE_SWITCH = "isCoreSwitch";
46 public static final String PROP_FASTWILDCARDS = "FastWildcards";
47 public static final String PROP_REQUIRES_L3_MATCH = "requiresL3Match";
48 public static final String PROP_SUPPORTS_OFPP_TABLE = "supportsOfppTable";
49 public static final String PROP_SUPPORTS_OFPP_FLOOD = "supportsOfppFlood";
50 public static final String PROP_SUPPORTS_NETMASK_TBL = "supportsNetmaskTbl";
Ray Milkey269ffb92014-04-03 14:43:30 -070051
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080052 /**
53 * Writes to the OFMessage to the output stream.
54 * The message will be handed to the floodlightProvider for possible filtering
55 * and processing by message listeners
Ray Milkey269ffb92014-04-03 14:43:30 -070056 *
57 * @param m
58 * @param bc
59 * @throws IOException
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080060 */
Ray Milkey269ffb92014-04-03 14:43:30 -070061 public void write(OFMessage m, FloodlightContext bc) throws IOException;
62
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080063 /**
64 * Writes the list of messages to the output stream
65 * The message will be handed to the floodlightProvider for possible filtering
66 * and processing by message listeners.
Ray Milkey269ffb92014-04-03 14:43:30 -070067 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080068 * @param msglist
69 * @param bc
70 * @throws IOException
71 */
72 public void write(List<OFMessage> msglist, FloodlightContext bc) throws IOException;
Ray Milkey269ffb92014-04-03 14:43:30 -070073
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080074 /**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080075 * @throws IOException
76 */
77 public void disconnectOutputStream();
78
79 /**
80 * FIXME: remove getChannel(). All access to the channel should be through
Ray Milkey269ffb92014-04-03 14:43:30 -070081 * wrapper functions in IOFSwitch
82 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -070083 * @return the channel to the switch
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080084 */
85 public Channel getChannel();
86
87 /**
88 * Returns switch features from features Reply
Ray Milkey269ffb92014-04-03 14:43:30 -070089 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -070090 * @return the switch buffers
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080091 */
92 public int getBuffers();
Ray Milkey269ffb92014-04-03 14:43:30 -070093
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080094 public int getActions();
Ray Milkey269ffb92014-04-03 14:43:30 -070095
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080096 public int getCapabilities();
Ray Milkey269ffb92014-04-03 14:43:30 -070097
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080098 public byte getTables();
99
100 /**
101 * Set the OFFeaturesReply message returned by the switch during initial
102 * handshake.
Ray Milkey269ffb92014-04-03 14:43:30 -0700103 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800104 * @param featuresReply
105 */
106 public void setFeaturesReply(OFFeaturesReply featuresReply);
Ray Milkey269ffb92014-04-03 14:43:30 -0700107
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800108 /**
109 * Set the SwitchProperties based on it's description
Ray Milkey269ffb92014-04-03 14:43:30 -0700110 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800111 * @param description
112 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700113 public void setSwitchProperties(OFDescriptionStatistics description);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800114
115 /**
116 * Get list of all enabled ports. This will typically be different from
117 * the list of ports in the OFFeaturesReply, since that one is a static
118 * snapshot of the ports at the time the switch connected to the controller
119 * whereas this port list also reflects the port status messages that have
120 * been received.
Ray Milkey269ffb92014-04-03 14:43:30 -0700121 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800122 * @return Unmodifiable list of ports not backed by the underlying collection
123 */
124 public Collection<OFPhysicalPort> getEnabledPorts();
Ray Milkey269ffb92014-04-03 14:43:30 -0700125
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800126 /**
127 * Get list of the port numbers of all enabled ports. This will typically
128 * be different from the list of ports in the OFFeaturesReply, since that
Ray Milkey269ffb92014-04-03 14:43:30 -0700129 * one is a static snapshot of the ports at the time the switch connected
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800130 * to the controller whereas this port list also reflects the port status
131 * messages that have been received.
Ray Milkey269ffb92014-04-03 14:43:30 -0700132 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800133 * @return Unmodifiable list of ports not backed by the underlying collection
134 */
135 public Collection<Short> getEnabledPortNumbers();
136
137 /**
138 * Retrieve the port object by the port number. The port object
139 * is the one that reflects the port status updates that have been
140 * received, not the one from the features reply.
Ray Milkey269ffb92014-04-03 14:43:30 -0700141 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800142 * @param portNumber
143 * @return port object
144 */
145 public OFPhysicalPort getPort(short portNumber);
Ray Milkey269ffb92014-04-03 14:43:30 -0700146
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800147 /**
148 * Retrieve the port object by the port name. The port object
149 * is the one that reflects the port status updates that have been
150 * received, not the one from the features reply.
Ray Milkey269ffb92014-04-03 14:43:30 -0700151 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800152 * @param portName
153 * @return port object
154 */
155 public OFPhysicalPort getPort(String portName);
Ray Milkey269ffb92014-04-03 14:43:30 -0700156
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800157 /**
158 * Add or modify a switch port. This is called by the core controller
159 * code in response to a OFPortStatus message. It should not typically be
160 * called by other floodlight applications.
Ray Milkey269ffb92014-04-03 14:43:30 -0700161 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800162 * @param port
163 */
164 public void setPort(OFPhysicalPort port);
165
166 /**
167 * Delete a port for the switch. This is called by the core controller
168 * code in response to a OFPortStatus message. It should not typically be
169 * called by other floodlight applications.
Ray Milkey269ffb92014-04-03 14:43:30 -0700170 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800171 * @param portNumber
172 */
173 public void deletePort(short portNumber);
Ray Milkey269ffb92014-04-03 14:43:30 -0700174
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800175 /**
176 * Delete a port for the switch. This is called by the core controller
177 * code in response to a OFPortStatus message. It should not typically be
178 * called by other floodlight applications.
Ray Milkey269ffb92014-04-03 14:43:30 -0700179 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800180 * @param portName
181 */
182 public void deletePort(String portName);
Ray Milkey269ffb92014-04-03 14:43:30 -0700183
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800184 /**
185 * Get list of all ports. This will typically be different from
186 * the list of ports in the OFFeaturesReply, since that one is a static
187 * snapshot of the ports at the time the switch connected to the controller
188 * whereas this port list also reflects the port status messages that have
189 * been received.
Ray Milkey269ffb92014-04-03 14:43:30 -0700190 *
191 * @return Unmodifiable list of ports
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800192 */
193 public Collection<OFPhysicalPort> getPorts();
194
195 /**
196 * @param portName
197 * @return Whether a port is enabled per latest port status message
198 * (not configured down nor link down nor in spanning tree blocking state)
199 */
200 public boolean portEnabled(short portName);
Ray Milkey269ffb92014-04-03 14:43:30 -0700201
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800202 /**
203 * @param portNumber
204 * @return Whether a port is enabled per latest port status message
205 * (not configured down nor link down nor in spanning tree blocking state)
206 */
207 public boolean portEnabled(String portName);
208
209 /**
210 * @param port
211 * @return Whether a port is enabled per latest port status message
212 * (not configured down nor link down nor in spanning tree blocking state)
213 */
214 public boolean portEnabled(OFPhysicalPort port);
215
216 /**
217 * Get the datapathId of the switch
Ray Milkey269ffb92014-04-03 14:43:30 -0700218 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -0700219 * @return switch dpid as a long
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800220 */
221 public long getId();
222
223 /**
224 * Get a string version of the ID for this switch
Ray Milkey269ffb92014-04-03 14:43:30 -0700225 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -0700226 * @return switch dpid as a String
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800227 */
228 public String getStringId();
Ray Milkey269ffb92014-04-03 14:43:30 -0700229
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800230 /**
231 * Retrieves attributes of this switch
Ray Milkey269ffb92014-04-03 14:43:30 -0700232 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -0700233 * @return attributes of the switch
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800234 */
235 public Map<Object, Object> getAttributes();
236
237 /**
238 * Retrieves the date the switch connected to this controller
Ray Milkey269ffb92014-04-03 14:43:30 -0700239 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800240 * @return the date
241 */
242 public Date getConnectedSince();
243
244 /**
245 * Returns the next available transaction id
Ray Milkey269ffb92014-04-03 14:43:30 -0700246 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -0700247 * @return next available transaction id
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800248 */
249 public int getNextTransactionId();
250
251 /**
252 * Returns a Future object that can be used to retrieve the asynchronous
253 * OFStatisticsReply when it is available.
254 *
255 * @param request statistics request
256 * @return Future object wrapping OFStatisticsReply
Ray Milkey269ffb92014-04-03 14:43:30 -0700257 * @throws IOException
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800258 */
259 public Future<List<OFStatistics>> getStatistics(OFStatisticsRequest request)
260 throws IOException;
Ray Milkey269ffb92014-04-03 14:43:30 -0700261
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800262 /**
263 * Returns a Future object that can be used to retrieve the asynchronous
264 * OFStatisticsReply when it is available.
265 *
266 * @param request statistics request
267 * @return Future object wrapping OFStatisticsReply
Ray Milkey269ffb92014-04-03 14:43:30 -0700268 * @throws IOException
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800269 */
270 public Future<OFFeaturesReply> getFeaturesReplyFromSwitch()
271 throws IOException;
272
273 /**
274 * Deliver the featuresReply future reply
Ray Milkey269ffb92014-04-03 14:43:30 -0700275 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800276 * @param reply the reply to deliver
277 */
278 void deliverOFFeaturesReply(OFMessage reply);
279
280 /*
281 * Cancel features reply with a specific transction ID
282 * @param transactionId the transaction ID
283 */
284 public void cancelFeaturesReply(int transactionId);
285
286 /**
287 * Check if the switch is still connected;
288 * Only call while holding processMessageLock
Ray Milkey269ffb92014-04-03 14:43:30 -0700289 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800290 * @return whether the switch is still disconnected
291 */
292 public boolean isConnected();
Ray Milkey269ffb92014-04-03 14:43:30 -0700293
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800294 /**
295 * Set whether the switch is connected
296 * Only call while holding modifySwitchLock
Ray Milkey269ffb92014-04-03 14:43:30 -0700297 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800298 * @param connected whether the switch is connected
299 */
300 public void setConnected(boolean connected);
Ray Milkey269ffb92014-04-03 14:43:30 -0700301
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800302 /**
303 * Get the current role of the controller for the switch
Ray Milkey269ffb92014-04-03 14:43:30 -0700304 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800305 * @return the role of the controller
306 */
307 public Role getRole();
Ray Milkey269ffb92014-04-03 14:43:30 -0700308
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800309 /**
310 * Check if the controller is an active controller for the switch.
311 * The controller is active if its role is MASTER or EQUAL.
Ray Milkey269ffb92014-04-03 14:43:30 -0700312 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800313 * @return whether the controller is active
314 */
315 public boolean isActive();
Ray Milkey269ffb92014-04-03 14:43:30 -0700316
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800317 /**
318 * Deliver the statistics future reply
Ray Milkey269ffb92014-04-03 14:43:30 -0700319 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800320 * @param reply the reply to deliver
321 */
322 public void deliverStatisticsReply(OFMessage reply);
Ray Milkey269ffb92014-04-03 14:43:30 -0700323
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800324 /**
325 * Cancel the statistics reply with the given transaction ID
Ray Milkey269ffb92014-04-03 14:43:30 -0700326 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800327 * @param transactionId the transaction ID
328 */
329 public void cancelStatisticsReply(int transactionId);
Ray Milkey269ffb92014-04-03 14:43:30 -0700330
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800331 /**
332 * Cancel all statistics replies
333 */
334 public void cancelAllStatisticsReplies();
335
336 /**
337 * Checks if a specific switch property exists for this switch
Ray Milkey269ffb92014-04-03 14:43:30 -0700338 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800339 * @param name name of property
340 * @return value for name
341 */
342 boolean hasAttribute(String name);
343
344 /**
345 * Set properties for switch specific behavior
Ray Milkey269ffb92014-04-03 14:43:30 -0700346 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800347 * @param name name of property
348 * @return value for name
349 */
350 Object getAttribute(String name);
351
352 /**
353 * Set properties for switch specific behavior
Ray Milkey269ffb92014-04-03 14:43:30 -0700354 *
355 * @param name name of property
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800356 * @param value value for name
357 */
358 void setAttribute(String name, Object value);
359
360 /**
361 * Set properties for switch specific behavior
Ray Milkey269ffb92014-04-03 14:43:30 -0700362 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800363 * @param name name of property
364 * @return current value for name or null (if not present)
365 */
366 Object removeAttribute(String name);
367
368 /**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800369 * Clear all flowmods on this switch
370 */
371 public void clearAllFlowMods();
372
373 /**
374 * Update broadcast cache
Ray Milkey269ffb92014-04-03 14:43:30 -0700375 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800376 * @param data
377 * @return true if there is a cache hit
Ray Milkey269ffb92014-04-03 14:43:30 -0700378 * false if there is no cache hit.
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800379 */
380 public boolean updateBroadcastCache(Long entry, Short port);
Ray Milkey269ffb92014-04-03 14:43:30 -0700381
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800382 /**
383 * Get the portBroadcastCacheHits
Ray Milkey269ffb92014-04-03 14:43:30 -0700384 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -0700385 * @return port broadcast cache hits
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800386 */
387 public Map<Short, Long> getPortBroadcastHits();
388
389 /**
390 * Send a flow statistics request to the switch. This call returns after
391 * sending the stats. request to the switch.
Ray Milkey269ffb92014-04-03 14:43:30 -0700392 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800393 * @param request flow statistics request message
Ray Milkey269ffb92014-04-03 14:43:30 -0700394 * @param xid transaction id, must be obtained by using the getXid() API.
395 * @param caller the caller of the API. receive() callback of this
396 * caller would be called when the reply from the switch is received.
397 * @return the transaction id for the message sent to the switch. The
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800398 * transaction id can be used to match the response with the request. Note
399 * that the transaction id is unique only within the scope of this switch.
400 * @throws IOException
401 */
402 public void sendStatsQuery(OFStatisticsRequest request, int xid,
Ray Milkey269ffb92014-04-03 14:43:30 -0700403 IOFMessageListener caller) throws IOException;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800404
405 /**
406 * Flush all flows queued for this switch in the current thread.
407 * NOTE: The contract is limited to the current thread
408 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700409 public void flush();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800410}