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