Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 2 | * Copyright 2011, Big Switch Networks, Inc. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 3 | * Originally created by David Erickson, Stanford University |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 4 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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 | |
| 18 | package net.floodlightcontroller.core; |
| 19 | |
| 20 | import java.util.List; |
| 21 | import java.util.Map; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 22 | import java.util.Set; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 23 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 24 | import net.floodlightcontroller.core.internal.Controller.Counters; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 25 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 26 | import net.onrc.onos.core.packet.Ethernet; |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.util.OnosInstanceId; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 28 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.protocol.OFControllerRole; |
| 30 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 31 | import org.projectfloodlight.openflow.protocol.OFType; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 32 | |
| 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 | */ |
| 39 | public interface IFloodlightProviderService extends IFloodlightService { |
| 40 | |
| 41 | /** |
| 42 | * A value stored in the floodlight context containing a parsed packet |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 43 | * representation of the payload of a packet-in message. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 44 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | public static final String CONTEXT_PI_PAYLOAD = |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 46 | "net.floodlightcontroller.core.IFloodlightProvider.piPayload"; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 47 | public static final String CONTEXT_PI_INPORT = |
| 48 | "net.floodlightcontroller.core.IFloodlightProvider.piInPort";; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 49 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 50 | * 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 56 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 57 | public static enum Role { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 58 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | } |
| 83 | |
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 | * A FloodlightContextStore object that can be used to retrieve the |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 86 | * packet-in payload |
| 87 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 88 | public static final FloodlightContextStore<Ethernet> bcStore = |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 89 | new FloodlightContextStore<Ethernet>(); |
| 90 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 91 | |
| 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 125 | /** |
| 126 | * Adds an OpenFlow message listener |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 127 | * |
| 128 | * @param type The OFType the component wants to listen for |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 129 | * @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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 135 | * |
| 136 | * @param type The OFType the component no long wants to listen for |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 137 | * @param listener The component that no longer wants to receive the message |
| 138 | */ |
| 139 | public void removeOFMessageListener(OFType type, IOFMessageListener listener); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 140 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 141 | /** |
| 142 | * Return a non-modifiable list of all current listeners |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 143 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 144 | * @return listeners |
| 145 | */ |
| 146 | public Map<OFType, List<IOFMessageListener>> getListeners(); |
| 147 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 148 | //************************ |
| 149 | // Switch & SwitchListener related |
| 150 | //************************ |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 151 | |
| 152 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 153 | * 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 155 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 156 | * @return the set of actively connected switches |
| 157 | */ |
| 158 | public Map<Long, IOFSwitch> getSwitches(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 159 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 160 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 161 | * 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 165 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 166 | public void setAlwaysClearFlowsOnSwAdd(boolean value); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 167 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 168 | /** |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 169 | * Gets the unique ID used to identify this ONOS instance in the cluster. |
| 170 | * |
| 171 | * @return ONOS Instance ID. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 172 | */ |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 173 | public OnosInstanceId getOnosInstanceId(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 174 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 175 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 176 | * Add a switch listener |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 177 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 178 | * @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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 184 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 185 | * @param listener The The module that no longer wants to listen for events |
| 186 | */ |
| 187 | public void removeOFSwitchListener(IOFSwitchListener listener); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 188 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 189 | |
| 190 | |
| 191 | //************************ |
| 192 | // Utility methods |
| 193 | //************************ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 194 | |
| 195 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 196 | * Gets the Factory |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 197 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 198 | * @return an OpenFlow message factory |
| 199 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 200 | public OFFactory getOFMessageFactory_13(); |
| 201 | public OFFactory getOFMessageFactory_10(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * Publish updates to Controller updates queue |
| 205 | * |
| 206 | * @param IUpdate |
| 207 | */ |
| 208 | public void publishUpdate(IUpdate update); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 209 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 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 | // * @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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 272 | } |