blob: 648f6f15068461db2f676d0857dc1cff7cbe9385 [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 {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800103 // Get the affected ports
104 List<Short> ports = swStore.getPorts(HexString.toHexString(dpid));
105 // Get the affected links
106 List<Link> links = linkStore.getLinks(HexString.toHexString(dpid));
107 // Get the affected reverse links
108 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(dpid));
109 links.addAll(reverseLinks);
110
Naoki Shiota987a5722013-10-23 11:59:36 -0700111 if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
112 registryService.releaseControl(dpid);
113
114 // TODO publish UPDATE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700115 //
116 // NOTE: Here we explicitly send
117 // notification to remove the
118 // switch, because it is inactive
119 //
120 TopologyElement topologyElement =
121 new TopologyElement(dpid);
122 datagridService.notificationSendTopologyElementRemoved(topologyElement);
123
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800124 // Publish: remove the affected ports
125 for (Short port : ports) {
126 TopologyElement topologyElementPort =
127 new TopologyElement(dpid, port);
128 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
129 }
130 // Publish: remove the affected links
131 for (Link link : links) {
132 TopologyElement topologyElementLink =
133 new TopologyElement(link.getSrc(),
134 link.getSrcPort(),
135 link.getDst(),
136 link.getDstPort());
137 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
138 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700139 }
140 } catch (Exception e) {
141 log.error("Error in SwitchCleanup:controlChanged ", e);
142 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700143 }
144 }
145 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700146
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700147 protected void switchCleanup() {
Toshio Koide70ba38b2013-06-13 14:05:05 -0700148 op.close();
149 Iterable<ISwitchObject> switches = op.getActiveSwitches();
Jonathan Hartf02a0932013-03-18 18:30:48 -0700150
151 log.debug("Checking for inactive switches");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700152 // For each switch check if a controller exists in controller registry
153 for (ISwitchObject sw: switches) {
Jonathan Hartf02a0932013-03-18 18:30:48 -0700154 //log.debug("checking if switch is inactive: {}", sw.getDPID());
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700155 try {
156 long dpid = HexString.toLong(sw.getDPID());
157 String controller = registryService.getControllerForSwitch(dpid);
158 if (controller == null) {
Pankaj Berde99fcee12013-03-18 09:41:53 -0700159 log.debug("request Control to set inactive sw {}", HexString.toHexString(dpid));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700160 registryService.requestControl(dpid, new SwitchCleanup());
Umesh Krishnaswamy255b9882013-04-02 19:55:43 -0700161 //} else {
162 // log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700163 }
164 } catch (NumberFormatException e) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700165 log.debug("Caught NumberFormatException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700166 e.printStackTrace();
167 } catch (RegistryException e) {
Jonathan Hart4baf3be2013-03-21 18:26:13 -0700168 log.debug("Caught RegistryException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700169 e.printStackTrace();
Naoki Shiota987a5722013-10-23 11:59:36 -0700170 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700171 }
Toshio Koide70ba38b2013-06-13 14:05:05 -0700172 op.close();
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700173 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800174
175 @Override
176 public void linkDiscoveryUpdate(LDUpdate update) {
Pankaj Berde00e90882013-06-10 21:25:05 -0700177 Link lt = new Link(update.getSrc(),update.getSrcPort(),update.getDst(),update.getDstPort());
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200178 //log.debug("{}:LinkDicoveryUpdate(): Updating Link {}",this.getClass(), lt);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700179
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200180 switch (update.getOperation()) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700181 case LINK_REMOVED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200182 log.debug("LinkDiscoveryUpdate(): Removing link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700183
184 if (linkStore.deleteLink(lt)) {
185 // TODO publish DELETE_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700186 TopologyElement topologyElement =
187 new TopologyElement(update.getSrc(),
188 update.getSrcPort(),
189 update.getDst(),
190 update.getDstPort());
191 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700192 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700193 break;
Pankaj Berde00e90882013-06-10 21:25:05 -0700194 case LINK_UPDATED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200195 log.debug("LinkDiscoveryUpdate(): Updating link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700196
Naoki Shiotab2d17e82013-10-18 18:08:16 -0700197 LinkInfo linfo = linkStore.getLinkInfo(lt);
198 // TODO update "linfo" using portState derived using "update"
Naoki Shiota987a5722013-10-23 11:59:36 -0700199 if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) {
200 // TODO publish UPDATE_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700201 //
202 // TODO NOTE: Here we assume that updated
203 // link is UP.
204 //
205 TopologyElement topologyElement =
206 new TopologyElement(update.getSrc(),
207 update.getSrcPort(),
208 update.getDst(),
209 update.getDstPort());
210 datagridService.notificationSendTopologyElementUpdated(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700211 }
Pankaj Berde00e90882013-06-10 21:25:05 -0700212 break;
213 case LINK_ADDED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200214 log.debug("LinkDiscoveryUpdate(): Adding link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700215
216 if (linkStore.addLink(lt)) {
217 // TODO publish ADD_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700218 TopologyElement topologyElement =
219 new TopologyElement(update.getSrc(),
220 update.getSrcPort(),
221 update.getDst(),
222 update.getDstPort());
223 datagridService.notificationSendTopologyElementAdded(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700224 }
Pankaj Berde00e90882013-06-10 21:25:05 -0700225 break;
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700226 default:
227 break;
228 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800229
230 }
231
232 @Override
233 public void addedSwitch(IOFSwitch sw) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700234 if (registryService.hasControl(sw.getId())) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700235 if (swStore.addSwitch(sw)) {
236 // TODO publish ADD_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700237 TopologyElement topologyElement =
238 new TopologyElement(sw.getId());
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800239 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800240
241 // Publish: add the ports
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700242 // TODO: Add only ports that are UP?
243 for (OFPhysicalPort port : sw.getPorts()) {
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800244 TopologyElement topologyElementPort =
245 new TopologyElement(sw.getId(),
246 port.getPortNumber());
247 datagridService.notificationSendTopologyElementAdded(topologyElementPort);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700248 }
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800249
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700250 // Add all links that might be connected already
251 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
252 // Add all reverse links as well
253 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
254 links.addAll(reverseLinks);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800255
256 // Publish: add the links
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700257 for (Link link : links) {
258 TopologyElement topologyElementLink =
259 new TopologyElement(link.getSrc(),
260 link.getSrcPort(),
261 link.getDst(),
262 link.getDstPort());
263 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
264 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700265 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700266 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800267 }
268
269 @Override
270 public void removedSwitch(IOFSwitch sw) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700271 if (registryService.hasControl(sw.getId())) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800272 // Get the affected ports
273 List<Short> ports = swStore.getPorts(HexString.toHexString(sw.getId()));
274 // Get the affected links
275 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
276 // Get the affected reverse links
277 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
278 links.addAll(reverseLinks);
279
Naoki Shiota987a5722013-10-23 11:59:36 -0700280 if (swStore.deleteSwitch(sw.getStringId())) {
281 // TODO publish DELETE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700282 TopologyElement topologyElement =
283 new TopologyElement(sw.getId());
284 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800285
286 // Publish: remove the affected ports
287 for (Short port : ports) {
288 TopologyElement topologyElementPort =
289 new TopologyElement(sw.getId(), port);
290 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
291 }
292 // Publish: remove the affected links
293 for (Link link : links) {
294 TopologyElement topologyElementLink =
295 new TopologyElement(link.getSrc(),
296 link.getSrcPort(),
297 link.getDst(),
298 link.getDstPort());
299 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
300 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700301 }
302 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800303 }
304
305 @Override
306 public void switchPortChanged(Long switchId) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700307 // NOTE: Event not needed here. This callback always coincide with add/remove callback.
Pankaj Berdeda809572013-02-22 15:31:20 -0800308 }
309
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700310
311 @Override
312 public void switchPortAdded(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700313 if (swStore.addPort(HexString.toHexString(switchId), port)) {
314 // TODO publish ADD_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700315 TopologyElement topologyElement =
316 new TopologyElement(switchId, port.getPortNumber());
317 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800318
319 // Add all links that might be connected already
320 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
321 // Add all reverse links as well
322 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
323 links.addAll(reverseLinks);
324
325 // Publish: add the links
326 for (Link link : links) {
327 TopologyElement topologyElementLink =
328 new TopologyElement(link.getSrc(),
329 link.getSrcPort(),
330 link.getDst(),
331 link.getDstPort());
332 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
333 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700334 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700335 }
336
337 @Override
338 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800339 // Remove all links that might be connected already
340 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
341 // Remove all reverse links as well
342 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
343 links.addAll(reverseLinks);
344
Naoki Shiota987a5722013-10-23 11:59:36 -0700345 if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
346 // TODO publish DELETE_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700347 TopologyElement topologyElement =
348 new TopologyElement(switchId, port.getPortNumber());
349 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800350
351 // Publish: remove the links
352 for (Link link : links) {
353 TopologyElement topologyElementLink =
354 new TopologyElement(link.getSrc(),
355 link.getSrcPort(),
356 link.getDst(),
357 link.getDstPort());
358 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
359 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700360 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700361 }
362
Pankaj Berdeda809572013-02-22 15:31:20 -0800363 @Override
364 public String getName() {
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700365 return "NetworkGraphPublisher";
Pankaj Berdeda809572013-02-22 15:31:20 -0800366 }
367
368 @Override
369 public void deviceAdded(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800370 log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
371 devStore.addDevice(device);
372 }
373
374 @Override
375 public void deviceRemoved(IDevice device) {
376 // TODO Auto-generated method stub
Jonathan Hart4fce4ed2013-11-01 21:29:21 -0700377 devStore.removeDevice(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800378 }
379
380 @Override
381 public void deviceMoved(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800382 devStore.changeDeviceAttachments(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800383 }
384
385 @Override
386 public void deviceIPV4AddrChanged(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800387 devStore.changeDeviceIPv4Address(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800388 }
389
390 @Override
391 public void deviceVlanChanged(IDevice device) {
392 // TODO Auto-generated method stub
393 }
394
395
396 @Override
397 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700398 Collection<Class<? extends IFloodlightService>> l =
399 new ArrayList<Class<? extends IFloodlightService>>();
400 l.add(INetworkGraphService.class);
401 return l;
Pankaj Berdeda809572013-02-22 15:31:20 -0800402 }
403
404 @Override
405 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700406 Map<Class<? extends IFloodlightService>,
407 IFloodlightService> m =
408 new HashMap<Class<? extends IFloodlightService>,
409 IFloodlightService>();
410 m.put(INetworkGraphService.class, this);
411 return m;
Pankaj Berdeda809572013-02-22 15:31:20 -0800412 }
413
414 @Override
415 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
416 Collection<Class<? extends IFloodlightService>> l =
417 new ArrayList<Class<? extends IFloodlightService>>();
418 l.add(IFloodlightProviderService.class);
419 l.add(IDeviceService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700420 l.add(IDatagridService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700421 l.add(IThreadPoolService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800422 return l;
423 }
424
425 @Override
426 public void init(FloodlightModuleContext context)
427 throws FloodlightModuleException {
Pankaj Berdeda809572013-02-22 15:31:20 -0800428 Map<String, String> configMap = context.getConfigParams(this);
429 String conf = configMap.get(DBConfigFile);
Toshio Koidebfe9b922013-06-18 10:56:05 -0700430 op = new GraphDBOperation(conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800431
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700432 floodlightProvider =
433 context.getServiceImpl(IFloodlightProviderService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800434 deviceService = context.getServiceImpl(IDeviceService.class);
Pankaj Berde00e90882013-06-10 21:25:05 -0700435 linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700436 threadPool = context.getServiceImpl(IThreadPoolService.class);
437 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700438 datagridService = context.getServiceImpl(IDatagridService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800439
Pankaj Berdeda809572013-02-22 15:31:20 -0800440 devStore = new DeviceStorageImpl();
441 devStore.init(conf);
442
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700443 swStore = new SwitchStorageImpl();
444 swStore.init(conf);
Pankaj Berde00e90882013-06-10 21:25:05 -0700445
446 linkStore = new LinkStorageImpl();
447 linkStore.init(conf);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700448
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700449 log.debug("Initializing NetworkGraphPublisher module with {}", conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800450
451 }
452
453 @Override
454 public void startUp(FloodlightModuleContext context) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700455 Map<String, String> configMap = context.getConfigParams(this);
456 String cleanupNeeded = configMap.get(CleanupEnabled);
457
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700458 deviceService.addListener(this);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700459 floodlightProvider.addOFSwitchListener(this);
Pankaj Berde00e90882013-06-10 21:25:05 -0700460 linkDiscovery.addListener(this);
Pankaj Berde9d6b5072013-04-03 11:51:23 -0700461
462 log.debug("Adding EventListener");
Toshio Koide70ba38b2013-06-13 14:05:05 -0700463 IDBConnection conn = op.getDBConnection();
464 conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700465 // Setup the Cleanup task.
Pankaj Berde99fcee12013-03-18 09:41:53 -0700466 if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700467 ScheduledExecutorService ses = threadPool.getScheduledExecutor();
468 cleanupTask = new SingletonTask(ses, new SwitchCleanup());
Pankaj Berde99fcee12013-03-18 09:41:53 -0700469 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS);
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700470 }
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700471
472 //
473 // NOTE: No need to register with the Datagrid Service,
474 // because we don't need to receive any notifications from it.
475 //
Pankaj Berdeda809572013-02-22 15:31:20 -0800476 }
477
478}