blob: 563d5756f77717896e8d8c2ed71f99430360b3ed [file] [log] [blame]
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -07001package net.onrc.onos.ofcontroller.floodlightlistener;
Pankaj Berdeda809572013-02-22 15:31:20 -08002
3import java.util.ArrayList;
4import java.util.Collection;
Pavlin Radoslavov28069402013-10-18 18:43:11 -07005import java.util.HashMap;
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -07006import java.util.List;
Pankaj Berdeda809572013-02-22 15:31:20 -08007import java.util.Map;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -07008import java.util.concurrent.ScheduledExecutorService;
9import java.util.concurrent.TimeUnit;
Pankaj Berdeda809572013-02-22 15:31:20 -080010
Pankaj Berde465ac7c2013-05-23 13:47:49 -070011import org.openflow.protocol.OFPhysicalPort;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070012import org.openflow.util.HexString;
Pankaj Berdeda809572013-02-22 15:31:20 -080013import org.slf4j.Logger;
14import org.slf4j.LoggerFactory;
15
16import net.floodlightcontroller.core.IFloodlightProviderService;
17import net.floodlightcontroller.core.IOFSwitch;
18import net.floodlightcontroller.core.IOFSwitchListener;
Pankaj Berdeda809572013-02-22 15:31:20 -080019import net.floodlightcontroller.core.module.FloodlightModuleContext;
20import net.floodlightcontroller.core.module.FloodlightModuleException;
21import net.floodlightcontroller.core.module.IFloodlightModule;
22import net.floodlightcontroller.core.module.IFloodlightService;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070023import net.floodlightcontroller.core.util.SingletonTask;
Pankaj Berdeda809572013-02-22 15:31:20 -080024import net.floodlightcontroller.devicemanager.IDevice;
25import net.floodlightcontroller.devicemanager.IDeviceListener;
26import net.floodlightcontroller.devicemanager.IDeviceService;
Pankaj Berde00e90882013-06-10 21:25:05 -070027import net.floodlightcontroller.routing.Link;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070028import net.floodlightcontroller.threadpool.IThreadPoolService;
Pavlin Radoslavov8442e492013-10-25 21:54:13 -070029
30import net.onrc.onos.datagrid.IDatagridService;
Pankaj Berde38646d62013-06-21 11:34:04 -070031import net.onrc.onos.graph.GraphDBConnection;
32import net.onrc.onos.graph.GraphDBOperation;
33import net.onrc.onos.graph.IDBConnection;
34import net.onrc.onos.graph.LocalTopologyEventListener;
HIGUCHI Yuta2d011582013-06-15 01:47:11 -070035import net.onrc.onos.ofcontroller.core.IDeviceStorage;
36import net.onrc.onos.ofcontroller.core.ILinkStorage;
HIGUCHI Yuta36cf0762013-06-14 14:25:38 -070037import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
HIGUCHI Yuta20514902013-06-12 11:24:16 -070038import net.onrc.onos.ofcontroller.core.ISwitchStorage;
39import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
HIGUCHI Yuta20514902013-06-12 11:24:16 -070040import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
41import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
HIGUCHI Yuta2d011582013-06-15 01:47:11 -070042import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl;
43import net.onrc.onos.ofcontroller.core.internal.LinkStorageImpl;
HIGUCHI Yutaed49ef72013-06-12 11:34:10 -070044import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
HIGUCHI Yutaa56fbde2013-06-17 14:26:05 -070045import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
46import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
Naoki Shiotab2d17e82013-10-18 18:08:16 -070047import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
Pavlin Radoslavov8442e492013-10-25 21:54:13 -070048import net.onrc.onos.ofcontroller.topology.TopologyElement;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070049import net.onrc.onos.registry.controller.IControllerRegistryService;
50import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback;
51import net.onrc.onos.registry.controller.RegistryException;
Pankaj Berdeda809572013-02-22 15:31:20 -080052
Pavlin Radoslavov28069402013-10-18 18:43:11 -070053public class NetworkGraphPublisher implements IDeviceListener,
54 IOFSwitchListener,
55 IOFSwitchPortListener,
56 ILinkDiscoveryListener,
57 IFloodlightModule,
58 INetworkGraphService {
Pankaj Berdeda809572013-02-22 15:31:20 -080059
60 protected IDeviceStorage devStore;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070061 protected ISwitchStorage swStore;
Pankaj Berde00e90882013-06-10 21:25:05 -070062 protected ILinkStorage linkStore;
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070063 protected final static Logger log = LoggerFactory.getLogger(NetworkGraphPublisher.class);
Pankaj Berdeda809572013-02-22 15:31:20 -080064 protected IDeviceService deviceService;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070065 protected IControllerRegistryService registryService;
Toshio Koide70ba38b2013-06-13 14:05:05 -070066 protected GraphDBOperation op;
Pankaj Berdeda809572013-02-22 15:31:20 -080067
68 protected static final String DBConfigFile = "dbconf";
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -070069 protected static final String CleanupEnabled = "EnableCleanup";
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070070 protected IThreadPoolService threadPool;
Pankaj Berde465ac7c2013-05-23 13:47:49 -070071 protected IFloodlightProviderService floodlightProvider;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070072
Pankaj Berde62016142013-04-09 15:35:50 -070073 protected final int CLEANUP_TASK_INTERVAL = 60; // 1 min
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070074 protected SingletonTask cleanupTask;
Pankaj Berde00e90882013-06-10 21:25:05 -070075 protected ILinkDiscoveryService linkDiscovery;
Pavlin Radoslavov8442e492013-10-25 21:54:13 -070076
77 protected IDatagridService datagridService;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070078
79 /**
80 * Cleanup and synch switch state from registry
81 */
82 protected class SwitchCleanup implements ControlChangeCallback, Runnable {
83 @Override
84 public void run() {
85 try {
86 log.debug("Running cleanup thread");
87 switchCleanup();
88 }
89 catch (Exception e) {
90 log.error("Error in cleanup thread", e);
91 } finally {
Toshio Koide70ba38b2013-06-13 14:05:05 -070092 op.close();
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070093 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL,
Pankaj Berde99fcee12013-03-18 09:41:53 -070094 TimeUnit.SECONDS);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070095 }
96 }
97
98 @Override
99 public void controlChanged(long dpid, boolean hasControl) {
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700100 if (hasControl) {
Pankaj Berde99fcee12013-03-18 09:41:53 -0700101 log.debug("got control to set inactive sw {}", HexString.toHexString(dpid));
Naoki Shiota987a5722013-10-23 11:59:36 -0700102 try {
103 if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
104 registryService.releaseControl(dpid);
105
106 // TODO publish UPDATE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700107 //
108 // NOTE: Here we explicitly send
109 // notification to remove the
110 // switch, because it is inactive
111 //
112 TopologyElement topologyElement =
113 new TopologyElement(dpid);
114 datagridService.notificationSendTopologyElementRemoved(topologyElement);
115
Naoki Shiota987a5722013-10-23 11:59:36 -0700116 }
117 } catch (Exception e) {
118 log.error("Error in SwitchCleanup:controlChanged ", e);
119 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700120 }
121 }
122 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700123
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700124 protected void switchCleanup() {
Toshio Koide70ba38b2013-06-13 14:05:05 -0700125 op.close();
126 Iterable<ISwitchObject> switches = op.getActiveSwitches();
Jonathan Hartf02a0932013-03-18 18:30:48 -0700127
128 log.debug("Checking for inactive switches");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700129 // For each switch check if a controller exists in controller registry
130 for (ISwitchObject sw: switches) {
Jonathan Hartf02a0932013-03-18 18:30:48 -0700131 //log.debug("checking if switch is inactive: {}", sw.getDPID());
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700132 try {
133 long dpid = HexString.toLong(sw.getDPID());
134 String controller = registryService.getControllerForSwitch(dpid);
135 if (controller == null) {
Pankaj Berde99fcee12013-03-18 09:41:53 -0700136 log.debug("request Control to set inactive sw {}", HexString.toHexString(dpid));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700137 registryService.requestControl(dpid, new SwitchCleanup());
Umesh Krishnaswamy255b9882013-04-02 19:55:43 -0700138 //} else {
139 // log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700140 }
141 } catch (NumberFormatException e) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700142 log.debug("Caught NumberFormatException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700143 e.printStackTrace();
144 } catch (RegistryException e) {
Jonathan Hart4baf3be2013-03-21 18:26:13 -0700145 log.debug("Caught RegistryException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700146 e.printStackTrace();
Naoki Shiota987a5722013-10-23 11:59:36 -0700147 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700148 }
Toshio Koide70ba38b2013-06-13 14:05:05 -0700149 op.close();
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700150 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800151
152 @Override
153 public void linkDiscoveryUpdate(LDUpdate update) {
Pankaj Berde00e90882013-06-10 21:25:05 -0700154 Link lt = new Link(update.getSrc(),update.getSrcPort(),update.getDst(),update.getDstPort());
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200155 //log.debug("{}:LinkDicoveryUpdate(): Updating Link {}",this.getClass(), lt);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700156
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200157 switch (update.getOperation()) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700158 case LINK_REMOVED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200159 log.debug("LinkDiscoveryUpdate(): Removing link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700160
161 if (linkStore.deleteLink(lt)) {
162 // TODO publish DELETE_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700163 TopologyElement topologyElement =
164 new TopologyElement(update.getSrc(),
165 update.getSrcPort(),
166 update.getDst(),
167 update.getDstPort());
168 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700169 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700170 break;
Pankaj Berde00e90882013-06-10 21:25:05 -0700171 case LINK_UPDATED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200172 log.debug("LinkDiscoveryUpdate(): Updating link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700173
Naoki Shiotab2d17e82013-10-18 18:08:16 -0700174 LinkInfo linfo = linkStore.getLinkInfo(lt);
175 // TODO update "linfo" using portState derived using "update"
Naoki Shiota987a5722013-10-23 11:59:36 -0700176 if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) {
177 // TODO publish UPDATE_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700178 //
179 // TODO NOTE: Here we assume that updated
180 // link is UP.
181 //
182 TopologyElement topologyElement =
183 new TopologyElement(update.getSrc(),
184 update.getSrcPort(),
185 update.getDst(),
186 update.getDstPort());
187 datagridService.notificationSendTopologyElementUpdated(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700188 }
Pankaj Berde00e90882013-06-10 21:25:05 -0700189 break;
190 case LINK_ADDED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200191 log.debug("LinkDiscoveryUpdate(): Adding link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700192
193 if (linkStore.addLink(lt)) {
194 // TODO publish ADD_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700195 TopologyElement topologyElement =
196 new TopologyElement(update.getSrc(),
197 update.getSrcPort(),
198 update.getDst(),
199 update.getDstPort());
200 datagridService.notificationSendTopologyElementAdded(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700201 }
Pankaj Berde00e90882013-06-10 21:25:05 -0700202 break;
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700203 default:
204 break;
205 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800206
207 }
208
209 @Override
210 public void addedSwitch(IOFSwitch sw) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700211 if (registryService.hasControl(sw.getId())) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700212 if (swStore.addSwitch(sw)) {
213 // TODO publish ADD_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700214 TopologyElement topologyElement =
215 new TopologyElement(sw.getId());
216 // TODO: Add only ports that are UP?
217 for (OFPhysicalPort port : sw.getPorts()) {
218 topologyElement.addSwitchPort(port.getPortNumber());
219 }
220 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700221 // Add all links that might be connected already
222 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
223 // Add all reverse links as well
224 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
225 links.addAll(reverseLinks);
226 for (Link link : links) {
227 TopologyElement topologyElementLink =
228 new TopologyElement(link.getSrc(),
229 link.getSrcPort(),
230 link.getDst(),
231 link.getDstPort());
232 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
233 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700234 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700235 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800236 }
237
238 @Override
239 public void removedSwitch(IOFSwitch sw) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700240 if (registryService.hasControl(sw.getId())) {
241 if (swStore.deleteSwitch(sw.getStringId())) {
242 // TODO publish DELETE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700243 TopologyElement topologyElement =
244 new TopologyElement(sw.getId());
245 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700246 }
247 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800248 }
249
250 @Override
251 public void switchPortChanged(Long switchId) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700252 // NOTE: Event not needed here. This callback always coincide with add/remove callback.
Pankaj Berdeda809572013-02-22 15:31:20 -0800253 }
254
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700255
256 @Override
257 public void switchPortAdded(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700258 if (swStore.addPort(HexString.toHexString(switchId), port)) {
259 // TODO publish ADD_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700260 TopologyElement topologyElement =
261 new TopologyElement(switchId, port.getPortNumber());
262 datagridService.notificationSendTopologyElementAdded(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700263 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700264 }
265
266 @Override
267 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700268 if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
269 // TODO publish DELETE_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700270 TopologyElement topologyElement =
271 new TopologyElement(switchId, port.getPortNumber());
272 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700273 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700274 }
275
Pankaj Berdeda809572013-02-22 15:31:20 -0800276 @Override
277 public String getName() {
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700278 return "NetworkGraphPublisher";
Pankaj Berdeda809572013-02-22 15:31:20 -0800279 }
280
281 @Override
282 public void deviceAdded(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800283 log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
284 devStore.addDevice(device);
285 }
286
287 @Override
288 public void deviceRemoved(IDevice device) {
289 // TODO Auto-generated method stub
Pankaj Berdeda809572013-02-22 15:31:20 -0800290 }
291
292 @Override
293 public void deviceMoved(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800294 devStore.changeDeviceAttachments(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800295 }
296
297 @Override
298 public void deviceIPV4AddrChanged(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800299 devStore.changeDeviceIPv4Address(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800300 }
301
302 @Override
303 public void deviceVlanChanged(IDevice device) {
304 // TODO Auto-generated method stub
305 }
306
307
308 @Override
309 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700310 Collection<Class<? extends IFloodlightService>> l =
311 new ArrayList<Class<? extends IFloodlightService>>();
312 l.add(INetworkGraphService.class);
313 return l;
Pankaj Berdeda809572013-02-22 15:31:20 -0800314 }
315
316 @Override
317 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700318 Map<Class<? extends IFloodlightService>,
319 IFloodlightService> m =
320 new HashMap<Class<? extends IFloodlightService>,
321 IFloodlightService>();
322 m.put(INetworkGraphService.class, this);
323 return m;
Pankaj Berdeda809572013-02-22 15:31:20 -0800324 }
325
326 @Override
327 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
328 Collection<Class<? extends IFloodlightService>> l =
329 new ArrayList<Class<? extends IFloodlightService>>();
330 l.add(IFloodlightProviderService.class);
331 l.add(IDeviceService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700332 l.add(IDatagridService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700333 l.add(IThreadPoolService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800334 return l;
335 }
336
337 @Override
338 public void init(FloodlightModuleContext context)
339 throws FloodlightModuleException {
Pankaj Berdeda809572013-02-22 15:31:20 -0800340 Map<String, String> configMap = context.getConfigParams(this);
341 String conf = configMap.get(DBConfigFile);
Toshio Koidebfe9b922013-06-18 10:56:05 -0700342 op = new GraphDBOperation(conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800343
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700344 floodlightProvider =
345 context.getServiceImpl(IFloodlightProviderService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800346 deviceService = context.getServiceImpl(IDeviceService.class);
Pankaj Berde00e90882013-06-10 21:25:05 -0700347 linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700348 threadPool = context.getServiceImpl(IThreadPoolService.class);
349 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700350 datagridService = context.getServiceImpl(IDatagridService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800351
Pankaj Berdeda809572013-02-22 15:31:20 -0800352 devStore = new DeviceStorageImpl();
353 devStore.init(conf);
354
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700355 swStore = new SwitchStorageImpl();
356 swStore.init(conf);
Pankaj Berde00e90882013-06-10 21:25:05 -0700357
358 linkStore = new LinkStorageImpl();
359 linkStore.init(conf);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700360
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700361 log.debug("Initializing NetworkGraphPublisher module with {}", conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800362
363 }
364
365 @Override
366 public void startUp(FloodlightModuleContext context) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700367 Map<String, String> configMap = context.getConfigParams(this);
368 String cleanupNeeded = configMap.get(CleanupEnabled);
369
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700370 deviceService.addListener(this);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700371 floodlightProvider.addOFSwitchListener(this);
Pankaj Berde00e90882013-06-10 21:25:05 -0700372 linkDiscovery.addListener(this);
Pankaj Berde9d6b5072013-04-03 11:51:23 -0700373
374 log.debug("Adding EventListener");
Toshio Koide70ba38b2013-06-13 14:05:05 -0700375 IDBConnection conn = op.getDBConnection();
376 conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700377 // Setup the Cleanup task.
Pankaj Berde99fcee12013-03-18 09:41:53 -0700378 if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700379 ScheduledExecutorService ses = threadPool.getScheduledExecutor();
380 cleanupTask = new SingletonTask(ses, new SwitchCleanup());
Pankaj Berde99fcee12013-03-18 09:41:53 -0700381 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS);
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700382 }
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700383
384 //
385 // NOTE: No need to register with the Datagrid Service,
386 // because we don't need to receive any notifications from it.
387 //
Pankaj Berdeda809572013-02-22 15:31:20 -0800388 }
389
390}