Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent.runtime; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.List; |
| 6 | import java.util.Map; |
| 7 | import java.util.Set; |
| 8 | import java.util.concurrent.BlockingQueue; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 9 | import java.util.concurrent.ConcurrentHashMap; |
| 10 | import java.util.concurrent.ConcurrentMap; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 11 | import java.util.concurrent.LinkedBlockingQueue; |
| 12 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 13 | import net.floodlightcontroller.core.FloodlightContext; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 14 | import net.floodlightcontroller.core.IFloodlightProviderService; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 15 | import net.floodlightcontroller.core.IOFMessageListener; |
| 16 | import net.floodlightcontroller.core.IOFSwitch; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 17 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 18 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 19 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 20 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 21 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 22 | import net.onrc.onos.core.datagrid.IEventChannel; |
| 23 | import net.onrc.onos.core.datagrid.IEventChannelListener; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 24 | import net.onrc.onos.core.flowprogrammer.IFlowPusherService; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 25 | import net.onrc.onos.core.intent.FlowEntry; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 26 | import net.onrc.onos.core.intent.Intent; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.intent.Intent.IntentState; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 28 | import net.onrc.onos.core.intent.IntentOperation; |
| 29 | import net.onrc.onos.core.intent.IntentOperationList; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 30 | import net.onrc.onos.core.intent.PathIntent; |
| 31 | import net.onrc.onos.core.intent.ShortestPathIntent; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.topology.ITopologyService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 33 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 34 | import org.openflow.protocol.OFFlowRemoved; |
| 35 | import org.openflow.protocol.OFMessage; |
| 36 | import org.openflow.protocol.OFType; |
Brian O'Connor | 5e73c01 | 2014-02-20 14:54:34 -0800 | [diff] [blame] | 37 | import org.slf4j.Logger; |
| 38 | import org.slf4j.LoggerFactory; |
| 39 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 40 | /** |
| 41 | * The PlanInstallModule contains the PlanCalcRuntime and PlanInstallRuntime. |
| 42 | * <p> |
| 43 | * It is responsible for converting Intents into FlowMods and seeing that |
| 44 | * they are properly installed. |
| 45 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 46 | public class PlanInstallModule implements IFloodlightModule, IOFMessageListener { |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 47 | |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 48 | protected volatile IFloodlightProviderService floodlightProvider; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 49 | protected volatile ITopologyService topologyService; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 50 | protected volatile IDatagridService datagridService; |
| 51 | protected volatile IFlowPusherService flowPusher; |
| 52 | private PlanCalcRuntime planCalc; |
| 53 | private PlanInstallRuntime planInstall; |
| 54 | private EventListener eventListener; |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 55 | private IEventChannel<Long, IntentStateList> intentStateChannel; |
Ray Milkey | ec83894 | 2014-04-09 11:28:43 -0700 | [diff] [blame] | 56 | private static final Logger log = LoggerFactory.getLogger(PlanInstallModule.class); |
Brian O'Connor | 9b712f6 | 2014-02-20 14:22:20 -0800 | [diff] [blame] | 57 | |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 58 | private static final String PATH_INTENT_CHANNEL_NAME = "onos.pathintent"; |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 59 | private static final String INTENT_STATE_EVENT_CHANNEL_NAME = "onos.pathintent_state"; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 60 | private ConcurrentMap<String, Intent> parentIntentMap = new ConcurrentHashMap<String, Intent>(); |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 61 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 62 | /** |
| 63 | * EventListener for Intent updates from the PathCalcRuntime module. |
| 64 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 65 | class EventListener extends Thread |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 66 | implements IEventChannelListener<Long, IntentOperationList> { |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 67 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 68 | private BlockingQueue<IntentOperationList> intentQueue = new LinkedBlockingQueue<>(); |
| 69 | private Long key = Long.valueOf(0); |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 70 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 71 | /** |
| 72 | * Poll the Intent queue for events. |
| 73 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 74 | @Override |
| 75 | public void run() { |
| 76 | while (true) { |
| 77 | try { |
| 78 | IntentOperationList intents = intentQueue.take(); |
| 79 | //TODO: consider draining the remaining intent lists |
| 80 | // and processing in one big batch |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 81 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | processIntents(intents); |
| 83 | } catch (InterruptedException e) { |
| 84 | log.warn("Error taking from intent queue: {}", e.getMessage()); |
| 85 | } |
| 86 | } |
| 87 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 88 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 89 | /** |
| 90 | * Process events received from the event queue. |
| 91 | * <p> |
| 92 | * First, compute a plan, and then install it. |
| 93 | * |
| 94 | * @param intents list of new Intent events |
| 95 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 96 | private void processIntents(IntentOperationList intents) { |
| 97 | log("start_processIntents"); |
| 98 | log.debug("Processing OperationList {}", intents); |
| 99 | log("begin_computePlan"); |
| 100 | List<Set<FlowEntry>> plan = planCalc.computePlan(intents); |
| 101 | log("end_computePlan"); |
| 102 | log.debug("Plan: {}", plan); |
| 103 | log("begin_installPlan"); |
| 104 | boolean success = planInstall.installPlan(plan); |
| 105 | log("end_installPlan"); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 106 | Set<Long> domainSwitchDpids = floodlightProvider.getSwitches().keySet(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 107 | log("begin_sendInstallNotif"); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 108 | sendNotifications(intents, true, success, domainSwitchDpids); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 109 | log("end_sendInstallNotif"); |
| 110 | log("finish"); |
| 111 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 112 | |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 113 | /*** |
| 114 | * This function is for sending intent state notification to other ONOS instances. |
| 115 | * The argument of "domainSwitchDpids" is required for dispatching this ONOS's managed switches. |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 116 | * |
| 117 | * @param intents list of intents |
| 118 | * @param installed true if Intents were installed |
| 119 | * @param success true if updates succeeded |
| 120 | * @param domainSwitchDpids set of affected switches |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 121 | */ |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 122 | private void sendNotifications(IntentOperationList intents, |
| 123 | boolean installed, boolean success, Set<Long> domainSwitchDpids) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | IntentStateList states = new IntentStateList(); |
| 125 | for (IntentOperation i : intents) { |
| 126 | IntentState newState; |
| 127 | switch (i.operator) { |
| 128 | case REMOVE: |
| 129 | if (installed) { |
| 130 | newState = success ? IntentState.DEL_ACK : IntentState.DEL_PENDING; |
| 131 | } else { |
| 132 | newState = IntentState.DEL_REQ; |
| 133 | } |
| 134 | break; |
| 135 | case ADD: |
| 136 | default: |
| 137 | if (installed) { |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 138 | if (domainSwitchDpids != null) { |
| 139 | states.domainSwitchDpids.addAll(domainSwitchDpids); |
| 140 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 141 | newState = success ? IntentState.INST_ACK : IntentState.INST_NACK; |
| 142 | } else { |
| 143 | newState = IntentState.INST_REQ; |
| 144 | } |
| 145 | break; |
| 146 | } |
| 147 | states.put(i.intent.getId(), newState); |
| 148 | } |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 149 | |
| 150 | if (log.isTraceEnabled()) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 151 | log.trace("sendNotifications, states {}, domainSwitchDpids {}", |
| 152 | states, states.domainSwitchDpids); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 155 | // Send notifications using the same key every time |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 156 | // and receive them by entryAdded() and entryUpdated() |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 157 | intentStateChannel.addTransientEntry(key, states); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 158 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 159 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 160 | /** |
| 161 | * Uses the entryUpdated() method. This should only be called once |
| 162 | * because we always use the same key. |
| 163 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 164 | @Override |
| 165 | public void entryAdded(IntentOperationList value) { |
| 166 | entryUpdated(value); |
| 167 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 168 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 169 | /* |
| 170 | * (non-Javadoc) |
| 171 | * @see net.onrc.onos.core.datagrid.IEventChannelListener#entryRemoved(java.lang.Object) |
| 172 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 173 | @Override |
| 174 | public void entryRemoved(IntentOperationList value) { |
| 175 | // This channel is a queue, so this method is not needed |
| 176 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 177 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 178 | /** |
| 179 | * Adds the new intents to the event queue. |
| 180 | * |
Sho SHIMIZU | 6947445 | 2014-06-20 09:17:40 -0700 | [diff] [blame] | 181 | * @param value list of new intents |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 182 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 183 | @Override |
| 184 | public void entryUpdated(IntentOperationList value) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 185 | putIntentOpsInfoInParentMap(value); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 186 | log("start_intentNotifRecv"); |
| 187 | log("begin_sendReceivedNotif"); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 188 | sendNotifications(value, false, false, null); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 189 | log("end_sendReceivedNotif"); |
| 190 | log("finish"); |
Brian O'Connor | 85dd8f2 | 2014-02-25 11:43:07 -0800 | [diff] [blame] | 191 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 192 | log.debug("Added OperationList {}", value); |
| 193 | try { |
| 194 | intentQueue.put(value); |
| 195 | } catch (InterruptedException e) { |
| 196 | log.warn("Error putting to intent queue: {}", e.getMessage()); |
| 197 | } |
| 198 | } |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 199 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 200 | /** |
| 201 | * Add intent information to parent map. |
| 202 | * |
| 203 | * @param intentOps list of Intents and new states |
| 204 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 205 | private void putIntentOpsInfoInParentMap(IntentOperationList intentOps) { |
| 206 | for (IntentOperation i : intentOps) { |
| 207 | if (!(i.intent instanceof PathIntent)) { |
| 208 | log.warn("Not a path intent: {}", i); |
| 209 | continue; |
| 210 | } |
| 211 | PathIntent intent = (PathIntent) i.intent; |
| 212 | Intent parent = intent.getParentIntent(); |
| 213 | if (parent instanceof ShortestPathIntent) { |
| 214 | parentIntentMap.put(parent.getId(), parent); |
| 215 | } else { |
| 216 | log.warn("Unsupported Intent: {}", parent); |
| 217 | continue; |
| 218 | } |
| 219 | } |
| 220 | } |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 221 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 222 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 223 | /** |
| 224 | * Formatted log for debugging. |
| 225 | * TODO: merge this into debugging framework |
| 226 | * |
| 227 | * @param step the step of computation |
| 228 | */ |
Brian O'Connor | 85dd8f2 | 2014-02-25 11:43:07 -0800 | [diff] [blame] | 229 | public static void log(String step) { |
Pavlin Radoslavov | 964f8ae | 2014-04-18 16:44:14 -0700 | [diff] [blame] | 230 | log.debug("Time:{}, Step:{}", System.nanoTime(), step); |
Brian O'Connor | 85dd8f2 | 2014-02-25 11:43:07 -0800 | [diff] [blame] | 231 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 232 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 233 | /* |
| 234 | * (non-Javadoc) |
| 235 | * @see net.floodlightcontroller.core.module.IFloodlightModule#init |
| 236 | * (net.floodlightcontroller.core.module.FloodlightModuleContext) |
| 237 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 238 | @Override |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 239 | public void init(FloodlightModuleContext context) |
| 240 | throws FloodlightModuleException { |
| 241 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 242 | topologyService = context.getServiceImpl(ITopologyService.class); |
| 243 | datagridService = context.getServiceImpl(IDatagridService.class); |
| 244 | flowPusher = context.getServiceImpl(IFlowPusherService.class); |
| 245 | planCalc = new PlanCalcRuntime(); |
| 246 | planInstall = new PlanInstallRuntime(floodlightProvider, flowPusher); |
| 247 | eventListener = new EventListener(); |
| 248 | } |
| 249 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 250 | /* |
| 251 | * (non-Javadoc) |
| 252 | * @see net.floodlightcontroller.core.module.IFloodlightModule#startUp |
| 253 | * (net.floodlightcontroller.core.module.FloodlightModuleContext) |
| 254 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 255 | @Override |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 256 | public void startUp(FloodlightModuleContext context) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 257 | // start subscriber |
| 258 | datagridService.addListener(PATH_INTENT_CHANNEL_NAME, |
| 259 | eventListener, |
| 260 | Long.class, |
| 261 | IntentOperationList.class); |
| 262 | eventListener.start(); |
| 263 | // start publisher |
| 264 | intentStateChannel = datagridService.createChannel(INTENT_STATE_EVENT_CHANNEL_NAME, |
| 265 | Long.class, |
| 266 | IntentStateList.class); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 267 | floodlightProvider.addOFMessageListener(OFType.FLOW_REMOVED, this); |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 268 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 269 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 270 | /* |
| 271 | * (non-Javadoc) |
| 272 | * @see net.floodlightcontroller.core.module.IFloodlightModule#getModuleDependencies() |
| 273 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 274 | @Override |
| 275 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 276 | Collection<Class<? extends IFloodlightService>> l = |
| 277 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 278 | l.add(IFloodlightProviderService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 279 | l.add(ITopologyService.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 280 | l.add(IDatagridService.class); |
| 281 | l.add(IFlowPusherService.class); |
| 282 | return l; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 283 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 284 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 285 | /* |
| 286 | * (non-Javadoc) |
| 287 | * @see net.floodlightcontroller.core.module.IFloodlightModule#getModuleServices() |
| 288 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 289 | @Override |
| 290 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 291 | // no services, for now |
| 292 | return null; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 295 | /* |
| 296 | * (non-Javadoc) |
| 297 | * @see net.floodlightcontroller.core.module.IFloodlightModule#getServiceImpls() |
| 298 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 299 | @Override |
| 300 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 301 | // no services, for now |
| 302 | return null; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 303 | } |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 304 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 305 | /** |
| 306 | * Handles FlowRemoved messages from the switches. |
| 307 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 308 | @Override |
| 309 | public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) { |
| 310 | if (msg.getType().equals(OFType.FLOW_REMOVED) && |
| 311 | (msg instanceof OFFlowRemoved)) { |
| 312 | OFFlowRemoved flowRemovedMsg = (OFFlowRemoved) msg; |
| 313 | |
| 314 | if (log.isTraceEnabled()) { |
| 315 | log.trace("Receive flowRemoved from sw {} : Cookie {}", |
| 316 | sw.getId(), flowRemovedMsg.getCookie()); |
| 317 | } |
| 318 | |
| 319 | String intentParentId = Long.toString(flowRemovedMsg.getCookie()); |
| 320 | Intent intent = parentIntentMap.get(intentParentId); |
| 321 | |
| 322 | //We assume if the path src sw flow entry is expired, |
| 323 | //the path is expired. |
| 324 | if (!isFlowSrcRemoved(sw.getId(), intentParentId)) { |
| 325 | return Command.CONTINUE; |
| 326 | } |
| 327 | |
| 328 | ShortestPathIntent spfIntent = null; |
| 329 | if (!(intent instanceof ShortestPathIntent)) { |
| 330 | return Command.CONTINUE; |
| 331 | } |
| 332 | spfIntent = (ShortestPathIntent) intent; |
| 333 | String pathIntentId = spfIntent.getPathIntentId(); |
| 334 | |
| 335 | IntentStateList states = new IntentStateList(); |
| 336 | IntentState newState = IntentState.DEL_ACK; |
| 337 | states.put(pathIntentId, newState); |
| 338 | Set<Long> domainSwitchDpids = floodlightProvider.getSwitches().keySet(); |
| 339 | if (domainSwitchDpids != null) { |
| 340 | states.domainSwitchDpids.addAll(domainSwitchDpids); |
| 341 | } |
| 342 | parentIntentMap.remove(intentParentId); |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 343 | log.debug("addEntry to intentStateChannel intentId {}, states {}", |
| 344 | pathIntentId, newState); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 345 | |
| 346 | intentStateChannel.addTransientEntry(flowRemovedMsg.getCookie(), states); |
| 347 | } |
| 348 | |
| 349 | return Command.CONTINUE; |
| 350 | } |
| 351 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 352 | /** |
| 353 | * Check to see if the flow's source switch entry is removed/expired. |
| 354 | * |
| 355 | * @param dpid DPID of affected switch |
| 356 | * @param shortestPathIntentId Intent to check |
Jonathan Hart | 99ff20a | 2014-06-15 16:53:00 -0700 | [diff] [blame] | 357 | * @return true if the flow's source switch entry is removed or expired, |
| 358 | * otherwise false. |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 359 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 360 | private boolean isFlowSrcRemoved(long dpid, String shortestPathIntentId) { |
| 361 | Intent intent = parentIntentMap.get(shortestPathIntentId); |
| 362 | ShortestPathIntent spfIntent = null; |
| 363 | if (intent instanceof ShortestPathIntent) { |
| 364 | spfIntent = (ShortestPathIntent) intent; |
| 365 | } |
| 366 | |
| 367 | if (spfIntent == null) { |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | long srcSwDpid = spfIntent.getSrcSwitchDpid(); |
| 372 | if (srcSwDpid == dpid) { |
| 373 | return true; |
| 374 | } |
| 375 | |
| 376 | return false; |
| 377 | } |
| 378 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 379 | /* |
| 380 | * (non-Javadoc) |
| 381 | * @see net.floodlightcontroller.core.IListener#getName() |
| 382 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 383 | @Override |
| 384 | public String getName() { |
| 385 | // TODO Auto-generated method stub |
| 386 | return null; |
| 387 | } |
| 388 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 389 | /* |
| 390 | * (non-Javadoc) |
| 391 | * @see net.floodlightcontroller.core.IListener#isCallbackOrderingPrereq(java.lang.Object, java.lang.String) |
| 392 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 393 | @Override |
| 394 | public boolean isCallbackOrderingPrereq(OFType type, String name) { |
| 395 | // TODO Auto-generated method stub |
| 396 | return false; |
| 397 | } |
| 398 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 399 | /* |
| 400 | * (non-Javadoc) |
| 401 | * @see net.floodlightcontroller.core.IListener#isCallbackOrderingPostreq(java.lang.Object, java.lang.String) |
| 402 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 403 | @Override |
| 404 | public boolean isCallbackOrderingPostreq(OFType type, String name) { |
| 405 | // TODO Auto-generated method stub |
| 406 | return false; |
| 407 | } |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 408 | } |