blob: 5f73d9a34b43035dba46a178dbe757efbbae4e24 [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;
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070030import org.projectfloodlight.openflow.protocol.OFType;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080031
32/**
33 * The interface exposed by the core bundle that allows you to interact
34 * with connected switches.
35 *
36 * @author David Erickson (daviderickson@cs.stanford.edu)
37 */
38public interface IFloodlightProviderService extends IFloodlightService {
39
40 /**
41 * A value stored in the floodlight context containing a parsed packet
Ray Milkey269ffb92014-04-03 14:43:30 -070042 * representation of the payload of a packet-in message.
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080043 */
Ray Milkey269ffb92014-04-03 14:43:30 -070044 public static final String CONTEXT_PI_PAYLOAD =
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080045 "net.floodlightcontroller.core.IFloodlightProvider.piPayload";
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070046 public static final String CONTEXT_PI_INPORT =
47 "net.floodlightcontroller.core.IFloodlightProvider.piInPort";;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080048 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070049 * The role of the controller as it pertains to a particular switch.
50 * Note that this definition of the role enum is different from the
51 * OF1.3 definition. It is maintained here to be backward compatible to
52 * earlier versions of the controller code. This enum is translated
53 * to the OF1.3 enum, before role messages are sent to the switch.
54 * See sendRoleRequestMessage method in OFSwitchImpl
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080055 */
Ray Milkey269ffb92014-04-03 14:43:30 -070056 public static enum Role {
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070057 EQUAL(OFControllerRole.ROLE_EQUAL),
58 MASTER(OFControllerRole.ROLE_MASTER),
59 SLAVE(OFControllerRole.ROLE_SLAVE);
60
61 private final int nxRole;
62
63 private Role(OFControllerRole nxRole) {
64 this.nxRole = nxRole.ordinal();
65 }
66 /*
67 private static Map<Integer,Role> nxRoleToEnum
68 = new HashMap<Integer,Role>();
69 static {
70 for(Role r: Role.values())
71 nxRoleToEnum.put(r.toNxRole(), r);
72 }
73 public int toNxRole() {
74 return nxRole;
75 }
76 // Return the enum representing the given nxRole or null if no
77 // such role exists
78 public static Role fromNxRole(int nxRole) {
79 return nxRoleToEnum.get(nxRole);
80 }*/
Ray Milkey269ffb92014-04-03 14:43:30 -070081 }
82
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080083 /**
Ray Milkey269ffb92014-04-03 14:43:30 -070084 * A FloodlightContextStore object that can be used to retrieve the
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080085 * packet-in payload
86 */
Ray Milkey269ffb92014-04-03 14:43:30 -070087 public static final FloodlightContextStore<Ethernet> bcStore =
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080088 new FloodlightContextStore<Ethernet>();
89
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070090
91 //************************
92 // Controller related
93 //************************
94
95 /**
96 * Get the current mapping of controller IDs to their IP addresses
97 * Returns a copy of the current mapping.
98 *
99 * @see IHAListener
100 */
101 public Map<String, String> getControllerNodeIPs();
102
103 /**
104 * Return the controller start time in milliseconds
105 *
106 * @return
107 */
108 public long getSystemStartTime();
109
110 /**
111 * Run the main I/O loop of the Controller.
112 */
113 public void run();
114
115// /**
116// * Terminate the process
117// */
118// public void terminate();
119
120 //************************
121 // OF Message Listener related
122 //************************
123
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800124 /**
125 * Adds an OpenFlow message listener
Ray Milkey269ffb92014-04-03 14:43:30 -0700126 *
127 * @param type The OFType the component wants to listen for
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800128 * @param listener The component that wants to listen for the message
129 */
130 public void addOFMessageListener(OFType type, IOFMessageListener listener);
131
132 /**
133 * Removes an OpenFlow message listener
Ray Milkey269ffb92014-04-03 14:43:30 -0700134 *
135 * @param type The OFType the component no long wants to listen for
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800136 * @param listener The component that no longer wants to receive the message
137 */
138 public void removeOFMessageListener(OFType type, IOFMessageListener listener);
Ray Milkey269ffb92014-04-03 14:43:30 -0700139
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800140 /**
141 * Return a non-modifiable list of all current listeners
Ray Milkey269ffb92014-04-03 14:43:30 -0700142 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800143 * @return listeners
144 */
145 public Map<OFType, List<IOFMessageListener>> getListeners();
146
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700147 //************************
148 // Switch & SwitchListener related
149 //************************
Pavlin Radoslavov695f8952014-07-23 16:57:01 -0700150
151 /**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800152 * Returns an unmodifiable map of all actively connected OpenFlow switches. This doesn't
153 * contain switches that are connected but the controller's in the slave role.
Ray Milkey269ffb92014-04-03 14:43:30 -0700154 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800155 * @return the set of actively connected switches
156 */
157 public Map<Long, IOFSwitch> getSwitches();
Ray Milkey269ffb92014-04-03 14:43:30 -0700158
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800159 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700160 * Configure controller to always clear the flow table on the switch,
161 * when it connects to controller. This will be true for first time switch
162 * reconnect, as well as a switch re-attaching to Controller after HA
163 * switch over to ACTIVE role
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800164 */
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700165 public void setAlwaysClearFlowsOnSwAdd(boolean value);
Ray Milkey269ffb92014-04-03 14:43:30 -0700166
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800167 /**
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -0700168 * Gets the unique ID used to identify this ONOS instance in the cluster.
169 *
170 * @return ONOS Instance ID.
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800171 */
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -0700172 public OnosInstanceId getOnosInstanceId();
Ray Milkey269ffb92014-04-03 14:43:30 -0700173
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800174 /**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800175 * Add a switch listener
Ray Milkey269ffb92014-04-03 14:43:30 -0700176 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800177 * @param listener The module that wants to listen for events
178 */
179 public void addOFSwitchListener(IOFSwitchListener listener);
180
181 /**
182 * Remove a switch listener
Ray Milkey269ffb92014-04-03 14:43:30 -0700183 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800184 * @param listener The The module that no longer wants to listen for events
185 */
186 public void removeOFSwitchListener(IOFSwitchListener listener);
Ray Milkey269ffb92014-04-03 14:43:30 -0700187
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700188
189
190 //************************
191 // Utility methods
192 //************************
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800193
194 /**
Ray Milkey269ffb92014-04-03 14:43:30 -0700195 * Publish updates to Controller updates queue
196 *
197 * @param IUpdate
198 */
199 public void publishUpdate(IUpdate update);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800200
Brian O'Connorc67f9fa2014-08-07 18:17:46 -0700201// /**
202// * Re-injects an OFMessage back into the packet processing chain
203// *
204// * @param sw The switch to use for the message
205// * @param msg the message to inject
206// * @return True if successfully re-injected, false otherwise
207// */
208// public boolean injectOfMessage(IOFSwitch sw, OFMessage msg);
209//
210// /**
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// * @param bContext a floodlight context to use if required
216// * @return True if successfully re-injected, false otherwise
217// */
218// public boolean injectOfMessage(IOFSwitch sw, OFMessage msg,
219// FloodlightContext bContext);
220//
221// /**
222// * Process written messages through the message listeners for the controller
223// *
224// * @param sw The switch being written to
225// * @param m the message
226// * @param bc any accompanying context object
227// */
228// public void handleOutgoingMessage(IOFSwitch sw, OFMessage m,
229// FloodlightContext bc);
230
231
232 /**
233 * Return the default set of counters
234 * @return
235 */
236 public Counters getCounters();
237
238 void setAlwaysClearFlowsOnSwActivate(boolean value);
239
240 Map<String, Long> getMemory();
241
242 Long getUptime();
243
244 Set<Long> getAllSwitchDpids();
245
246 IOFSwitch getSwitch(long dpid);
247
248 /**
249 * Record a switch event in in-memory debug-event
250 * @param switchDPID
251 * @param reason Reason for this event
252 * @param flushNow see debug-event flushing in IDebugEventService
253 */
254 public void addSwitchEvent(long switchDPID, String reason, boolean flushNow);
255
256 Set<Long> getAllMasterSwitchDpids();
257
258 Set<Long> getAllEqualSwitchDpids();
259
260 IOFSwitch getMasterSwitch(long dpid);
261
262 IOFSwitch getEqualSwitch(long dpid);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800263}