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 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.protocol.OFFlowRemoved; |
| 35 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 36 | import org.projectfloodlight.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> |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 43 | * It is responsible for converting Intents into FlowMods and seeing that they |
| 44 | * are properly installed. |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 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(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 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 | /*** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 114 | * This function is for sending intent state notification to other ONOS |
| 115 | * instances. The argument of "domainSwitchDpids" is required for |
| 116 | * 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) { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 129 | case REMOVE: |
| 130 | if (installed) { |
| 131 | newState = success ? IntentState.DEL_ACK |
| 132 | : IntentState.DEL_PENDING; |
| 133 | } else { |
| 134 | newState = IntentState.DEL_REQ; |
| 135 | } |
| 136 | break; |
| 137 | case ADD: |
| 138 | default: |
| 139 | if (installed) { |
| 140 | if (domainSwitchDpids != null) { |
| 141 | states.domainSwitchDpids.addAll(domainSwitchDpids); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 142 | } |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 143 | newState = success ? IntentState.INST_ACK : IntentState.INST_NACK; |
| 144 | } else { |
| 145 | newState = IntentState.INST_REQ; |
| 146 | } |
| 147 | break; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 148 | } |
| 149 | states.put(i.intent.getId(), newState); |
| 150 | } |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 151 | |
| 152 | if (log.isTraceEnabled()) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 153 | log.trace("sendNotifications, states {}, domainSwitchDpids {}", |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 154 | states, states.domainSwitchDpids); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 157 | // Send notifications using the same key every time |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 158 | // and receive them by entryAdded() and entryUpdated() |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 159 | intentStateChannel.addTransientEntry(key, states); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 160 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 161 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Uses the entryUpdated() method. This should only be called once |
| 164 | * because we always use the same key. |
| 165 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 166 | @Override |
| 167 | public void entryAdded(IntentOperationList value) { |
| 168 | entryUpdated(value); |
| 169 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 170 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 171 | /* |
| 172 | * (non-Javadoc) |
| 173 | * @see net.onrc.onos.core.datagrid.IEventChannelListener#entryRemoved(java.lang.Object) |
| 174 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 175 | @Override |
| 176 | public void entryRemoved(IntentOperationList value) { |
| 177 | // This channel is a queue, so this method is not needed |
| 178 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 179 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 180 | /** |
| 181 | * Adds the new intents to the event queue. |
| 182 | * |
Sho SHIMIZU | 6947445 | 2014-06-20 09:17:40 -0700 | [diff] [blame] | 183 | * @param value list of new intents |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 184 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 185 | @Override |
| 186 | public void entryUpdated(IntentOperationList value) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 187 | putIntentOpsInfoInParentMap(value); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 188 | log("start_intentNotifRecv"); |
| 189 | log("begin_sendReceivedNotif"); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 190 | sendNotifications(value, false, false, null); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 191 | log("end_sendReceivedNotif"); |
| 192 | log("finish"); |
Brian O'Connor | 85dd8f2 | 2014-02-25 11:43:07 -0800 | [diff] [blame] | 193 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 194 | log.debug("Added OperationList {}", value); |
| 195 | try { |
| 196 | intentQueue.put(value); |
| 197 | } catch (InterruptedException e) { |
| 198 | log.warn("Error putting to intent queue: {}", e.getMessage()); |
| 199 | } |
| 200 | } |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 201 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 202 | /** |
| 203 | * Add intent information to parent map. |
| 204 | * |
| 205 | * @param intentOps list of Intents and new states |
| 206 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 207 | private void putIntentOpsInfoInParentMap(IntentOperationList intentOps) { |
| 208 | for (IntentOperation i : intentOps) { |
| 209 | if (!(i.intent instanceof PathIntent)) { |
| 210 | log.warn("Not a path intent: {}", i); |
| 211 | continue; |
| 212 | } |
| 213 | PathIntent intent = (PathIntent) i.intent; |
| 214 | Intent parent = intent.getParentIntent(); |
| 215 | if (parent instanceof ShortestPathIntent) { |
| 216 | parentIntentMap.put(parent.getId(), parent); |
| 217 | } else { |
| 218 | log.warn("Unsupported Intent: {}", parent); |
| 219 | continue; |
| 220 | } |
| 221 | } |
| 222 | } |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 223 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 224 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 225 | /** |
| 226 | * Formatted log for debugging. |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 227 | * <p> |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 228 | * TODO: merge this into debugging framework |
| 229 | * |
| 230 | * @param step the step of computation |
| 231 | */ |
Brian O'Connor | 85dd8f2 | 2014-02-25 11:43:07 -0800 | [diff] [blame] | 232 | public static void log(String step) { |
Pavlin Radoslavov | 964f8ae | 2014-04-18 16:44:14 -0700 | [diff] [blame] | 233 | log.debug("Time:{}, Step:{}", System.nanoTime(), step); |
Brian O'Connor | 85dd8f2 | 2014-02-25 11:43:07 -0800 | [diff] [blame] | 234 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 235 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 236 | /* |
| 237 | * (non-Javadoc) |
| 238 | * @see net.floodlightcontroller.core.module.IFloodlightModule#init |
| 239 | * (net.floodlightcontroller.core.module.FloodlightModuleContext) |
| 240 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 241 | @Override |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 242 | public void init(FloodlightModuleContext context) |
| 243 | throws FloodlightModuleException { |
| 244 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 245 | topologyService = context.getServiceImpl(ITopologyService.class); |
| 246 | datagridService = context.getServiceImpl(IDatagridService.class); |
| 247 | flowPusher = context.getServiceImpl(IFlowPusherService.class); |
| 248 | planCalc = new PlanCalcRuntime(); |
| 249 | planInstall = new PlanInstallRuntime(floodlightProvider, flowPusher); |
| 250 | eventListener = new EventListener(); |
| 251 | } |
| 252 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 253 | /* |
| 254 | * (non-Javadoc) |
| 255 | * @see net.floodlightcontroller.core.module.IFloodlightModule#startUp |
| 256 | * (net.floodlightcontroller.core.module.FloodlightModuleContext) |
| 257 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 258 | @Override |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 259 | public void startUp(FloodlightModuleContext context) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 260 | // start subscriber |
| 261 | datagridService.addListener(PATH_INTENT_CHANNEL_NAME, |
| 262 | eventListener, |
| 263 | Long.class, |
| 264 | IntentOperationList.class); |
| 265 | eventListener.start(); |
| 266 | // start publisher |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 267 | intentStateChannel = datagridService.createChannel( |
| 268 | INTENT_STATE_EVENT_CHANNEL_NAME, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 269 | Long.class, |
| 270 | IntentStateList.class); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 271 | floodlightProvider.addOFMessageListener(OFType.FLOW_REMOVED, this); |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 272 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 273 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 274 | /* |
| 275 | * (non-Javadoc) |
| 276 | * @see net.floodlightcontroller.core.module.IFloodlightModule#getModuleDependencies() |
| 277 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 278 | @Override |
| 279 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 280 | Collection<Class<? extends IFloodlightService>> l = |
| 281 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 282 | l.add(IFloodlightProviderService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 283 | l.add(ITopologyService.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 284 | l.add(IDatagridService.class); |
| 285 | l.add(IFlowPusherService.class); |
| 286 | return l; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 287 | } |
Toshio Koide | 3a52ef3 | 2014-02-28 12:10:26 -0800 | [diff] [blame] | 288 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 289 | /* |
| 290 | * (non-Javadoc) |
| 291 | * @see net.floodlightcontroller.core.module.IFloodlightModule#getModuleServices() |
| 292 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 293 | @Override |
| 294 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 295 | // no services, for now |
| 296 | return null; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 299 | /* |
| 300 | * (non-Javadoc) |
| 301 | * @see net.floodlightcontroller.core.module.IFloodlightModule#getServiceImpls() |
| 302 | */ |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 303 | @Override |
| 304 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 305 | // no services, for now |
| 306 | return null; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 307 | } |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 308 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 309 | /** |
| 310 | * Handles FlowRemoved messages from the switches. |
| 311 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 312 | @Override |
| 313 | public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) { |
| 314 | if (msg.getType().equals(OFType.FLOW_REMOVED) && |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 315 | (msg instanceof OFFlowRemoved)) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 316 | OFFlowRemoved flowRemovedMsg = (OFFlowRemoved) msg; |
| 317 | |
| 318 | if (log.isTraceEnabled()) { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 319 | log.trace("Receive flowRemoved from sw {} : Cookie {}", |
| 320 | sw.getId(), flowRemovedMsg.getCookie()); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 323 | String intentParentId = Long.toString(flowRemovedMsg.getCookie().getValue()); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 324 | Intent intent = parentIntentMap.get(intentParentId); |
| 325 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 326 | // We assume if the path src sw flow entry is expired, |
| 327 | // the path is expired. |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 328 | if (!isFlowSrcRemoved(sw.getId(), intentParentId)) { |
| 329 | return Command.CONTINUE; |
| 330 | } |
| 331 | |
| 332 | ShortestPathIntent spfIntent = null; |
| 333 | if (!(intent instanceof ShortestPathIntent)) { |
| 334 | return Command.CONTINUE; |
| 335 | } |
| 336 | spfIntent = (ShortestPathIntent) intent; |
| 337 | String pathIntentId = spfIntent.getPathIntentId(); |
| 338 | |
| 339 | IntentStateList states = new IntentStateList(); |
| 340 | IntentState newState = IntentState.DEL_ACK; |
| 341 | states.put(pathIntentId, newState); |
| 342 | Set<Long> domainSwitchDpids = floodlightProvider.getSwitches().keySet(); |
| 343 | if (domainSwitchDpids != null) { |
| 344 | states.domainSwitchDpids.addAll(domainSwitchDpids); |
| 345 | } |
| 346 | parentIntentMap.remove(intentParentId); |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame] | 347 | log.debug("addEntry to intentStateChannel intentId {}, states {}", |
| 348 | pathIntentId, newState); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 349 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 350 | intentStateChannel.addTransientEntry(flowRemovedMsg.getCookie().getValue(), |
| 351 | states); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | return Command.CONTINUE; |
| 355 | } |
| 356 | |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 357 | /** |
| 358 | * Check to see if the flow's source switch entry is removed/expired. |
| 359 | * |
| 360 | * @param dpid DPID of affected switch |
| 361 | * @param shortestPathIntentId Intent to check |
Jonathan Hart | 99ff20a | 2014-06-15 16:53:00 -0700 | [diff] [blame] | 362 | * @return true if the flow's source switch entry is removed or expired, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 363 | * otherwise false. |
Brian O'Connor | c89d286 | 2014-06-13 00:51:04 -0700 | [diff] [blame] | 364 | */ |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 365 | private boolean isFlowSrcRemoved(long dpid, String shortestPathIntentId) { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 366 | Intent intent = parentIntentMap.get(shortestPathIntentId); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 367 | ShortestPathIntent spfIntent = null; |
| 368 | if (intent instanceof ShortestPathIntent) { |
| 369 | spfIntent = (ShortestPathIntent) intent; |
| 370 | } |
| 371 | |
| 372 | if (spfIntent == null) { |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | long srcSwDpid = spfIntent.getSrcSwitchDpid(); |
| 377 | if (srcSwDpid == dpid) { |
| 378 | return true; |
| 379 | } |
| 380 | |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public String getName() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 386 | return "planInstall"; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | @Override |
| 390 | public boolean isCallbackOrderingPrereq(OFType type, String name) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 391 | return false; |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public boolean isCallbackOrderingPostreq(OFType type, String name) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 396 | return false; |
| 397 | } |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 398 | |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 399 | } |