blob: fa063eddaffacce13a25fc641680e78fbcb8247a [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());
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800216 datagridService.notificationSendTopologyElementAdded(topologyElement);
217 // Add the ports
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700218 // TODO: Add only ports that are UP?
219 for (OFPhysicalPort port : sw.getPorts()) {
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800220 TopologyElement topologyElementPort =
221 new TopologyElement(sw.getId(),
222 port.getPortNumber());
223 datagridService.notificationSendTopologyElementAdded(topologyElementPort);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700224 }
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800225
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700226 // Add all links that might be connected already
227 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
228 // Add all reverse links as well
229 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
230 links.addAll(reverseLinks);
231 for (Link link : links) {
232 TopologyElement topologyElementLink =
233 new TopologyElement(link.getSrc(),
234 link.getSrcPort(),
235 link.getDst(),
236 link.getDstPort());
237 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
238 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700239 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700240 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800241 }
242
243 @Override
244 public void removedSwitch(IOFSwitch sw) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700245 if (registryService.hasControl(sw.getId())) {
246 if (swStore.deleteSwitch(sw.getStringId())) {
247 // TODO publish DELETE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700248 TopologyElement topologyElement =
249 new TopologyElement(sw.getId());
250 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700251 }
252 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800253 }
254
255 @Override
256 public void switchPortChanged(Long switchId) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700257 // NOTE: Event not needed here. This callback always coincide with add/remove callback.
Pankaj Berdeda809572013-02-22 15:31:20 -0800258 }
259
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700260
261 @Override
262 public void switchPortAdded(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700263 if (swStore.addPort(HexString.toHexString(switchId), port)) {
264 // TODO publish ADD_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700265 TopologyElement topologyElement =
266 new TopologyElement(switchId, port.getPortNumber());
267 datagridService.notificationSendTopologyElementAdded(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700268 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700269 }
270
271 @Override
272 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700273 if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
274 // TODO publish DELETE_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700275 TopologyElement topologyElement =
276 new TopologyElement(switchId, port.getPortNumber());
277 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700278 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700279 }
280
Pankaj Berdeda809572013-02-22 15:31:20 -0800281 @Override
282 public String getName() {
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700283 return "NetworkGraphPublisher";
Pankaj Berdeda809572013-02-22 15:31:20 -0800284 }
285
286 @Override
287 public void deviceAdded(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800288 log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
289 devStore.addDevice(device);
290 }
291
292 @Override
293 public void deviceRemoved(IDevice device) {
294 // TODO Auto-generated method stub
Pankaj Berdeda809572013-02-22 15:31:20 -0800295 }
296
297 @Override
298 public void deviceMoved(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800299 devStore.changeDeviceAttachments(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800300 }
301
302 @Override
303 public void deviceIPV4AddrChanged(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800304 devStore.changeDeviceIPv4Address(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800305 }
306
307 @Override
308 public void deviceVlanChanged(IDevice device) {
309 // TODO Auto-generated method stub
310 }
311
312
313 @Override
314 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700315 Collection<Class<? extends IFloodlightService>> l =
316 new ArrayList<Class<? extends IFloodlightService>>();
317 l.add(INetworkGraphService.class);
318 return l;
Pankaj Berdeda809572013-02-22 15:31:20 -0800319 }
320
321 @Override
322 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700323 Map<Class<? extends IFloodlightService>,
324 IFloodlightService> m =
325 new HashMap<Class<? extends IFloodlightService>,
326 IFloodlightService>();
327 m.put(INetworkGraphService.class, this);
328 return m;
Pankaj Berdeda809572013-02-22 15:31:20 -0800329 }
330
331 @Override
332 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
333 Collection<Class<? extends IFloodlightService>> l =
334 new ArrayList<Class<? extends IFloodlightService>>();
335 l.add(IFloodlightProviderService.class);
336 l.add(IDeviceService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700337 l.add(IDatagridService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700338 l.add(IThreadPoolService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800339 return l;
340 }
341
342 @Override
343 public void init(FloodlightModuleContext context)
344 throws FloodlightModuleException {
Pankaj Berdeda809572013-02-22 15:31:20 -0800345 Map<String, String> configMap = context.getConfigParams(this);
346 String conf = configMap.get(DBConfigFile);
Toshio Koidebfe9b922013-06-18 10:56:05 -0700347 op = new GraphDBOperation(conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800348
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700349 floodlightProvider =
350 context.getServiceImpl(IFloodlightProviderService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800351 deviceService = context.getServiceImpl(IDeviceService.class);
Pankaj Berde00e90882013-06-10 21:25:05 -0700352 linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700353 threadPool = context.getServiceImpl(IThreadPoolService.class);
354 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700355 datagridService = context.getServiceImpl(IDatagridService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800356
Pankaj Berdeda809572013-02-22 15:31:20 -0800357 devStore = new DeviceStorageImpl();
358 devStore.init(conf);
359
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700360 swStore = new SwitchStorageImpl();
361 swStore.init(conf);
Pankaj Berde00e90882013-06-10 21:25:05 -0700362
363 linkStore = new LinkStorageImpl();
364 linkStore.init(conf);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700365
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700366 log.debug("Initializing NetworkGraphPublisher module with {}", conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800367
368 }
369
370 @Override
371 public void startUp(FloodlightModuleContext context) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700372 Map<String, String> configMap = context.getConfigParams(this);
373 String cleanupNeeded = configMap.get(CleanupEnabled);
374
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700375 deviceService.addListener(this);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700376 floodlightProvider.addOFSwitchListener(this);
Pankaj Berde00e90882013-06-10 21:25:05 -0700377 linkDiscovery.addListener(this);
Pankaj Berde9d6b5072013-04-03 11:51:23 -0700378
379 log.debug("Adding EventListener");
Toshio Koide70ba38b2013-06-13 14:05:05 -0700380 IDBConnection conn = op.getDBConnection();
381 conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700382 // Setup the Cleanup task.
Pankaj Berde99fcee12013-03-18 09:41:53 -0700383 if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700384 ScheduledExecutorService ses = threadPool.getScheduledExecutor();
385 cleanupTask = new SingletonTask(ses, new SwitchCleanup());
Pankaj Berde99fcee12013-03-18 09:41:53 -0700386 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS);
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700387 }
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700388
389 //
390 // NOTE: No need to register with the Datagrid Service,
391 // because we don't need to receive any notifications from it.
392 //
Pankaj Berdeda809572013-02-22 15:31:20 -0800393 }
394
395}