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; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 30 | import org.projectfloodlight.openflow.protocol.OFType; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 31 | |
| 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 | */ |
| 38 | public interface IFloodlightProviderService extends IFloodlightService { |
| 39 | |
| 40 | /** |
| 41 | * A value stored in the floodlight context containing a parsed packet |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | * representation of the payload of a packet-in message. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 43 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | public static final String CONTEXT_PI_PAYLOAD = |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 45 | "net.floodlightcontroller.core.IFloodlightProvider.piPayload"; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 46 | public static final String CONTEXT_PI_INPORT = |
| 47 | "net.floodlightcontroller.core.IFloodlightProvider.piInPort";; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 48 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 49 | * 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 55 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 56 | public static enum Role { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 57 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 83 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 84 | * A FloodlightContextStore object that can be used to retrieve the |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 85 | * packet-in payload |
| 86 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 87 | public static final FloodlightContextStore<Ethernet> bcStore = |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 88 | new FloodlightContextStore<Ethernet>(); |
| 89 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 90 | |
| 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 124 | /** |
| 125 | * Adds an OpenFlow message listener |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 126 | * |
| 127 | * @param type The OFType the component wants to listen for |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 128 | * @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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 134 | * |
| 135 | * @param type The OFType the component no long wants to listen for |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 136 | * @param listener The component that no longer wants to receive the message |
| 137 | */ |
| 138 | public void removeOFMessageListener(OFType type, IOFMessageListener listener); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 139 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 140 | /** |
| 141 | * Return a non-modifiable list of all current listeners |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 142 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 143 | * @return listeners |
| 144 | */ |
| 145 | public Map<OFType, List<IOFMessageListener>> getListeners(); |
| 146 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 147 | //************************ |
| 148 | // Switch & SwitchListener related |
| 149 | //************************ |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 150 | |
| 151 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 152 | * 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 154 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 155 | * @return the set of actively connected switches |
| 156 | */ |
| 157 | public Map<Long, IOFSwitch> getSwitches(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 158 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 159 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 160 | * 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 164 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 165 | public void setAlwaysClearFlowsOnSwAdd(boolean value); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 166 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 167 | /** |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 168 | * Gets the unique ID used to identify this ONOS instance in the cluster. |
| 169 | * |
| 170 | * @return ONOS Instance ID. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 171 | */ |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 172 | public OnosInstanceId getOnosInstanceId(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 173 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 174 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 175 | * Add a switch listener |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 176 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 177 | * @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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 183 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 184 | * @param listener The The module that no longer wants to listen for events |
| 185 | */ |
| 186 | public void removeOFSwitchListener(IOFSwitchListener listener); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 187 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 188 | |
| 189 | |
| 190 | //************************ |
| 191 | // Utility methods |
| 192 | //************************ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 193 | |
| 194 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 195 | * Publish updates to Controller updates queue |
| 196 | * |
| 197 | * @param IUpdate |
| 198 | */ |
| 199 | public void publishUpdate(IUpdate update); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 200 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 201 | // /** |
| 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 263 | } |