blob: 7f4f77de68213736b2c02447d40f3efacbb4dd7d [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -07002 * Copyright 2011, Big Switch Networks, Inc.
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08003 * Originally created by David Erickson, Stanford University
Ray Milkey269ffb92014-04-03 14:43:30 -07004 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08005 * 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.util.List;
21import java.util.Map;
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070022import java.util.Set;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080023
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070024import net.floodlightcontroller.core.internal.Controller.Counters;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080025import net.floodlightcontroller.core.module.IFloodlightService;
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070026import net.onrc.onos.core.packet.Ethernet;
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070027import net.onrc.onos.core.util.OnosInstanceId;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080028
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070029import org.projectfloodlight.openflow.protocol.OFControllerRole;
30import org.projectfloodlight.openflow.protocol.OFFactory;
31import org.projectfloodlight.openflow.protocol.OFType;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032
33/**
34 * The interface exposed by the core bundle that allows you to interact
35 * with connected switches.
36 *
37 * @author David Erickson (daviderickson@cs.stanford.edu)
38 */
39public interface IFloodlightProviderService extends IFloodlightService {
40
41 /**
42 * A value stored in the floodlight context containing a parsed packet
Ray Milkey269ffb92014-04-03 14:43:30 -070043 * representation of the payload of a packet-in message.
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080044 */
Ray Milkey269ffb92014-04-03 14:43:30 -070045 public static final String CONTEXT_PI_PAYLOAD =
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080046 "net.floodlightcontroller.core.IFloodlightProvider.piPayload";
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070047 public static final String CONTEXT_PI_INPORT =
48 "net.floodlightcontroller.core.IFloodlightProvider.piInPort";;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080049 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070050 * The role of the controller as it pertains to a particular switch.
51 * Note that this definition of the role enum is different from the
52 * OF1.3 definition. It is maintained here to be backward compatible to
53 * earlier versions of the controller code. This enum is translated
54 * to the OF1.3 enum, before role messages are sent to the switch.
55 * See sendRoleRequestMessage method in OFSwitchImpl
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080056 */
Ray Milkey269ffb92014-04-03 14:43:30 -070057 public static enum Role {
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070058 EQUAL(OFControllerRole.ROLE_EQUAL),
59 MASTER(OFControllerRole.ROLE_MASTER),
60 SLAVE(OFControllerRole.ROLE_SLAVE);
61
62 private final int nxRole;
63
64 private Role(OFControllerRole nxRole) {
65 this.nxRole = nxRole.ordinal();
66 }
67 /*
68 private static Map<Integer,Role> nxRoleToEnum
69 = new HashMap<Integer,Role>();
70 static {
71 for(Role r: Role.values())
72 nxRoleToEnum.put(r.toNxRole(), r);
73 }
74 public int toNxRole() {
75 return nxRole;
76 }
77 // Return the enum representing the given nxRole or null if no
78 // such role exists
79 public static Role fromNxRole(int nxRole) {
80 return nxRoleToEnum.get(nxRole);
81 }*/
Ray Milkey269ffb92014-04-03 14:43:30 -070082 }
83
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080084 /**
Ray Milkey269ffb92014-04-03 14:43:30 -070085 * A FloodlightContextStore object that can be used to retrieve the
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080086 * packet-in payload
87 */
Ray Milkey269ffb92014-04-03 14:43:30 -070088 public static final FloodlightContextStore<Ethernet> bcStore =
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080089 new FloodlightContextStore<Ethernet>();
90
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070091
92 //************************
93 // Controller related
94 //************************
95
96 /**
97 * Get the current mapping of controller IDs to their IP addresses
98 * Returns a copy of the current mapping.
99 *
100 * @see IHAListener
101 */
102 public Map<String, String> getControllerNodeIPs();
103
104 /**
105 * Return the controller start time in milliseconds
106 *
107 * @return
108 */
109 public long getSystemStartTime();
110
111 /**
112 * Run the main I/O loop of the Controller.
113 */
114 public void run();
115
116// /**
117// * Terminate the process
118// */
119// public void terminate();
120
121 //************************
122 // OF Message Listener related
123 //************************
124
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800125 /**
126 * Adds an OpenFlow message listener
Ray Milkey269ffb92014-04-03 14:43:30 -0700127 *
128 * @param type The OFType the component wants to listen for
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800129 * @param listener The component that wants to listen for the message
130 */
131 public void addOFMessageListener(OFType type, IOFMessageListener listener);
132
133 /**
134 * Removes an OpenFlow message listener
Ray Milkey269ffb92014-04-03 14:43:30 -0700135 *
136 * @param type The OFType the component no long wants to listen for
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800137 * @param listener The component that no longer wants to receive the message
138 */
139 public void removeOFMessageListener(OFType type, IOFMessageListener listener);
Ray Milkey269ffb92014-04-03 14:43:30 -0700140
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800141 /**
142 * Return a non-modifiable list of all current listeners
Ray Milkey269ffb92014-04-03 14:43:30 -0700143 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800144 * @return listeners
145 */
146 public Map<OFType, List<IOFMessageListener>> getListeners();
147
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700148 //************************
149 // Switch & SwitchListener related
150 //************************
Pavlin Radoslavov695f8952014-07-23 16:57:01 -0700151
152 /**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800153 * Returns an unmodifiable map of all actively connected OpenFlow switches. This doesn't
154 * contain switches that are connected but the controller's in the slave role.
Ray Milkey269ffb92014-04-03 14:43:30 -0700155 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800156 * @return the set of actively connected switches
157 */
158 public Map<Long, IOFSwitch> getSwitches();
Ray Milkey269ffb92014-04-03 14:43:30 -0700159
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800160 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700161 * Configure controller to always clear the flow table on the switch,
162 * when it connects to controller. This will be true for first time switch
163 * reconnect, as well as a switch re-attaching to Controller after HA
164 * switch over to ACTIVE role
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800165 */
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700166 public void setAlwaysClearFlowsOnSwAdd(boolean value);
Ray Milkey269ffb92014-04-03 14:43:30 -0700167
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800168 /**
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -0700169 * Gets the unique ID used to identify this ONOS instance in the cluster.
170 *
171 * @return ONOS Instance ID.
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800172 */
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -0700173 public OnosInstanceId getOnosInstanceId();
Ray Milkey269ffb92014-04-03 14:43:30 -0700174
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800175 /**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800176 * Add a switch listener
Ray Milkey269ffb92014-04-03 14:43:30 -0700177 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800178 * @param listener The module that wants to listen for events
179 */
180 public void addOFSwitchListener(IOFSwitchListener listener);
181
182 /**
183 * Remove a switch listener
Ray Milkey269ffb92014-04-03 14:43:30 -0700184 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800185 * @param listener The The module that no longer wants to listen for events
186 */
187 public void removeOFSwitchListener(IOFSwitchListener listener);
Ray Milkey269ffb92014-04-03 14:43:30 -0700188
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700189
190
191 //************************
192 // Utility methods
193 //************************
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800194
195 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700196 * Gets the Factory
Ray Milkey269ffb92014-04-03 14:43:30 -0700197 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800198 * @return an OpenFlow message factory
199 */
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700200 public OFFactory getOFMessageFactory_13();
201 public OFFactory getOFMessageFactory_10();
Ray Milkey269ffb92014-04-03 14:43:30 -0700202
203 /**
204 * Publish updates to Controller updates queue
205 *
206 * @param IUpdate
207 */
208 public void publishUpdate(IUpdate update);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800209
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700210// /**
211// * Re-injects an OFMessage back into the packet processing chain
212// *
213// * @param sw The switch to use for the message
214// * @param msg the message to inject
215// * @return True if successfully re-injected, false otherwise
216// */
217// public boolean injectOfMessage(IOFSwitch sw, OFMessage msg);
218//
219// /**
220// * Re-injects an OFMessage back into the packet processing chain
221// *
222// * @param sw The switch to use for the message
223// * @param msg the message to inject
224// * @param bContext a floodlight context to use if required
225// * @return True if successfully re-injected, false otherwise
226// */
227// public boolean injectOfMessage(IOFSwitch sw, OFMessage msg,
228// FloodlightContext bContext);
229//
230// /**
231// * Process written messages through the message listeners for the controller
232// *
233// * @param sw The switch being written to
234// * @param m the message
235// * @param bc any accompanying context object
236// */
237// public void handleOutgoingMessage(IOFSwitch sw, OFMessage m,
238// FloodlightContext bc);
239
240
241 /**
242 * Return the default set of counters
243 * @return
244 */
245 public Counters getCounters();
246
247 void setAlwaysClearFlowsOnSwActivate(boolean value);
248
249 Map<String, Long> getMemory();
250
251 Long getUptime();
252
253 Set<Long> getAllSwitchDpids();
254
255 IOFSwitch getSwitch(long dpid);
256
257 /**
258 * Record a switch event in in-memory debug-event
259 * @param switchDPID
260 * @param reason Reason for this event
261 * @param flushNow see debug-event flushing in IDebugEventService
262 */
263 public void addSwitchEvent(long switchDPID, String reason, boolean flushNow);
264
265 Set<Long> getAllMasterSwitchDpids();
266
267 Set<Long> getAllEqualSwitchDpids();
268
269 IOFSwitch getMasterSwitch(long dpid);
270
271 IOFSwitch getEqualSwitch(long dpid);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800272}