blob: 535981245841a248181524478413fe197fc5853e [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
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**/
17
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/**
38 *
39 *
40 * @author David Erickson (daviderickson@cs.stanford.edu)
41 */
42public interface IOFSwitch {
43 // Attribute keys
44 public static final String SWITCH_DESCRIPTION_FUTURE = "DescriptionFuture";
45 public static final String SWITCH_DESCRIPTION_DATA = "DescriptionData";
46 public static final String SWITCH_SUPPORTS_NX_ROLE = "supportsNxRole";
47 public static final String SWITCH_IS_CORE_SWITCH = "isCoreSwitch";
48 public static final String PROP_FASTWILDCARDS = "FastWildcards";
49 public static final String PROP_REQUIRES_L3_MATCH = "requiresL3Match";
50 public static final String PROP_SUPPORTS_OFPP_TABLE = "supportsOfppTable";
51 public static final String PROP_SUPPORTS_OFPP_FLOOD = "supportsOfppFlood";
52 public static final String PROP_SUPPORTS_NETMASK_TBL = "supportsNetmaskTbl";
53
54 /**
55 * Writes to the OFMessage to the output stream.
56 * The message will be handed to the floodlightProvider for possible filtering
57 * and processing by message listeners
58 * @param m
59 * @param bc
60 * @throws IOException
61 */
62 public void write(OFMessage m, FloodlightContext bc) throws IOException;
63
64 /**
65 * Writes the list of messages to the output stream
66 * The message will be handed to the floodlightProvider for possible filtering
67 * and processing by message listeners.
68 * @param msglist
69 * @param bc
70 * @throws IOException
71 */
72 public void write(List<OFMessage> msglist, FloodlightContext bc) throws IOException;
73
74 /**
75 *
76 * @throws IOException
77 */
78 public void disconnectOutputStream();
79
80 /**
81 * FIXME: remove getChannel(). All access to the channel should be through
82 * wrapper functions in IOFSwitch
83 * @return
84 */
85 public Channel getChannel();
86
87 /**
88 * Returns switch features from features Reply
89 * @return
90 */
91 public int getBuffers();
92
93 public int getActions();
94
95 public int getCapabilities();
96
97 public byte getTables();
98
99 /**
100 * Set the OFFeaturesReply message returned by the switch during initial
101 * handshake.
102 * @param featuresReply
103 */
104 public void setFeaturesReply(OFFeaturesReply featuresReply);
105
106 /**
107 * Set the SwitchProperties based on it's description
108 * @param description
109 */
110 public void setSwitchProperties(OFDescriptionStatistics description);
111
112 /**
113 * Get list of all enabled ports. This will typically be different from
114 * the list of ports in the OFFeaturesReply, since that one is a static
115 * snapshot of the ports at the time the switch connected to the controller
116 * whereas this port list also reflects the port status messages that have
117 * been received.
118 * @return Unmodifiable list of ports not backed by the underlying collection
119 */
120 public Collection<OFPhysicalPort> getEnabledPorts();
121
122 /**
123 * Get list of the port numbers of all enabled ports. This will typically
124 * be different from the list of ports in the OFFeaturesReply, since that
125 * one is a static snapshot of the ports at the time the switch connected
126 * to the controller whereas this port list also reflects the port status
127 * messages that have been received.
128 * @return Unmodifiable list of ports not backed by the underlying collection
129 */
130 public Collection<Short> getEnabledPortNumbers();
131
132 /**
133 * Retrieve the port object by the port number. The port object
134 * is the one that reflects the port status updates that have been
135 * received, not the one from the features reply.
136 * @param portNumber
137 * @return port object
138 */
139 public OFPhysicalPort getPort(short portNumber);
140
141 /**
142 * Retrieve the port object by the port name. The port object
143 * is the one that reflects the port status updates that have been
144 * received, not the one from the features reply.
145 * @param portName
146 * @return port object
147 */
148 public OFPhysicalPort getPort(String portName);
149
150 /**
151 * Add or modify a switch port. This is called by the core controller
152 * code in response to a OFPortStatus message. It should not typically be
153 * called by other floodlight applications.
154 * @param port
155 */
156 public void setPort(OFPhysicalPort port);
157
158 /**
159 * Delete a port for the switch. This is called by the core controller
160 * code in response to a OFPortStatus message. It should not typically be
161 * called by other floodlight applications.
162 * @param portNumber
163 */
164 public void deletePort(short portNumber);
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.
170 * @param portName
171 */
172 public void deletePort(String portName);
173
174 /**
175 * Get list of all ports. This will typically be different from
176 * the list of ports in the OFFeaturesReply, since that one is a static
177 * snapshot of the ports at the time the switch connected to the controller
178 * whereas this port list also reflects the port status messages that have
179 * been received.
180 * @return Unmodifiable list of ports
181 */
182 public Collection<OFPhysicalPort> getPorts();
183
184 /**
185 * @param portName
186 * @return Whether a port is enabled per latest port status message
187 * (not configured down nor link down nor in spanning tree blocking state)
188 */
189 public boolean portEnabled(short portName);
190
191 /**
192 * @param portNumber
193 * @return Whether a port is enabled per latest port status message
194 * (not configured down nor link down nor in spanning tree blocking state)
195 */
196 public boolean portEnabled(String portName);
197
198 /**
199 * @param port
200 * @return Whether a port is enabled per latest port status message
201 * (not configured down nor link down nor in spanning tree blocking state)
202 */
203 public boolean portEnabled(OFPhysicalPort port);
204
205 /**
206 * Get the datapathId of the switch
207 * @return
208 */
209 public long getId();
210
211 /**
212 * Get a string version of the ID for this switch
213 * @return
214 */
215 public String getStringId();
216
217 /**
218 * Retrieves attributes of this switch
219 * @return
220 */
221 public Map<Object, Object> getAttributes();
222
223 /**
224 * Retrieves the date the switch connected to this controller
225 * @return the date
226 */
227 public Date getConnectedSince();
228
229 /**
230 * Returns the next available transaction id
231 * @return
232 */
233 public int getNextTransactionId();
234
235 /**
236 * Returns a Future object that can be used to retrieve the asynchronous
237 * OFStatisticsReply when it is available.
238 *
239 * @param request statistics request
240 * @return Future object wrapping OFStatisticsReply
241 * @throws IOException
242 */
243 public Future<List<OFStatistics>> getStatistics(OFStatisticsRequest request)
244 throws IOException;
245
246 /**
247 * Returns a Future object that can be used to retrieve the asynchronous
248 * OFStatisticsReply when it is available.
249 *
250 * @param request statistics request
251 * @return Future object wrapping OFStatisticsReply
252 * @throws IOException
253 */
254 public Future<OFFeaturesReply> getFeaturesReplyFromSwitch()
255 throws IOException;
256
257 /**
258 * Deliver the featuresReply future reply
259 * @param reply the reply to deliver
260 */
261 void deliverOFFeaturesReply(OFMessage reply);
262
263 /*
264 * Cancel features reply with a specific transction ID
265 * @param transactionId the transaction ID
266 */
267 public void cancelFeaturesReply(int transactionId);
268
269 /**
270 * Check if the switch is still connected;
271 * Only call while holding processMessageLock
272 * @return whether the switch is still disconnected
273 */
274 public boolean isConnected();
275
276 /**
277 * Set whether the switch is connected
278 * Only call while holding modifySwitchLock
279 * @param connected whether the switch is connected
280 */
281 public void setConnected(boolean connected);
282
283 /**
284 * Get the current role of the controller for the switch
285 * @return the role of the controller
286 */
287 public Role getRole();
288
289 /**
290 * Check if the controller is an active controller for the switch.
291 * The controller is active if its role is MASTER or EQUAL.
292 * @return whether the controller is active
293 */
294 public boolean isActive();
295
296 /**
297 * Deliver the statistics future reply
298 * @param reply the reply to deliver
299 */
300 public void deliverStatisticsReply(OFMessage reply);
301
302 /**
303 * Cancel the statistics reply with the given transaction ID
304 * @param transactionId the transaction ID
305 */
306 public void cancelStatisticsReply(int transactionId);
307
308 /**
309 * Cancel all statistics replies
310 */
311 public void cancelAllStatisticsReplies();
312
313 /**
314 * Checks if a specific switch property exists for this switch
315 * @param name name of property
316 * @return value for name
317 */
318 boolean hasAttribute(String name);
319
320 /**
321 * Set properties for switch specific behavior
322 * @param name name of property
323 * @return value for name
324 */
325 Object getAttribute(String name);
326
327 /**
328 * Set properties for switch specific behavior
329 * @param name name of property
330 * @param value value for name
331 */
332 void setAttribute(String name, Object value);
333
334 /**
335 * Set properties for switch specific behavior
336 * @param name name of property
337 * @return current value for name or null (if not present)
338 */
339 Object removeAttribute(String name);
340
341 /**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800342 * Clear all flowmods on this switch
343 */
344 public void clearAllFlowMods();
345
346 /**
347 * Update broadcast cache
348 * @param data
349 * @return true if there is a cache hit
350 * false if there is no cache hit.
351 */
352 public boolean updateBroadcastCache(Long entry, Short port);
353
354 /**
355 * Get the portBroadcastCacheHits
356 * @return
357 */
358 public Map<Short, Long> getPortBroadcastHits();
359
360 /**
361 * Send a flow statistics request to the switch. This call returns after
362 * sending the stats. request to the switch.
363 * @param request flow statistics request message
364 * @param xid transaction id, must be obtained by using the getXid() API.
365 * @param caller the caller of the API. receive() callback of this
366 * caller would be called when the reply from the switch is received.
367 * @return the transaction id for the message sent to the switch. The
368 * transaction id can be used to match the response with the request. Note
369 * that the transaction id is unique only within the scope of this switch.
370 * @throws IOException
371 */
372 public void sendStatsQuery(OFStatisticsRequest request, int xid,
373 IOFMessageListener caller) throws IOException;
374
375 /**
376 * Flush all flows queued for this switch in the current thread.
377 * NOTE: The contract is limited to the current thread
378 */
379 public void flush();
380}