blob: 05ab39dfbd2a462a15f5e3bb9ac25bd56623a5fe [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 Berdeda809572013-02-22 15:31:20 -080011import net.floodlightcontroller.core.IFloodlightProviderService;
12import net.floodlightcontroller.core.IOFSwitch;
13import net.floodlightcontroller.core.IOFSwitchListener;
Pankaj Berdeda809572013-02-22 15:31:20 -080014import net.floodlightcontroller.core.module.FloodlightModuleContext;
15import net.floodlightcontroller.core.module.FloodlightModuleException;
16import net.floodlightcontroller.core.module.IFloodlightModule;
17import net.floodlightcontroller.core.module.IFloodlightService;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070018import net.floodlightcontroller.core.util.SingletonTask;
Pankaj Berdeda809572013-02-22 15:31:20 -080019import net.floodlightcontroller.devicemanager.IDevice;
20import net.floodlightcontroller.devicemanager.IDeviceListener;
Pankaj Berde00e90882013-06-10 21:25:05 -070021import net.floodlightcontroller.routing.Link;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070022import net.floodlightcontroller.threadpool.IThreadPoolService;
Jonathan Hart7804bea2014-01-07 10:50:52 -080023import net.floodlightcontroller.util.MACAddress;
Pavlin Radoslavov8442e492013-10-25 21:54:13 -070024import net.onrc.onos.datagrid.IDatagridService;
Pankaj Berde38646d62013-06-21 11:34:04 -070025import net.onrc.onos.graph.GraphDBConnection;
26import net.onrc.onos.graph.GraphDBOperation;
27import net.onrc.onos.graph.IDBConnection;
28import net.onrc.onos.graph.LocalTopologyEventListener;
HIGUCHI Yuta2d011582013-06-15 01:47:11 -070029import net.onrc.onos.ofcontroller.core.IDeviceStorage;
30import net.onrc.onos.ofcontroller.core.ILinkStorage;
HIGUCHI Yuta20514902013-06-12 11:24:16 -070031import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
HIGUCHI Yuta20514902013-06-12 11:24:16 -070032import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
Jonathan Hartd857ad62013-12-14 18:08:17 -080033import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
34import net.onrc.onos.ofcontroller.core.ISwitchStorage;
HIGUCHI Yuta2d011582013-06-15 01:47:11 -070035import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl;
36import net.onrc.onos.ofcontroller.core.internal.LinkStorageImpl;
HIGUCHI Yutaed49ef72013-06-12 11:34:10 -070037import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
HIGUCHI Yutaa56fbde2013-06-17 14:26:05 -070038import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
39import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
Naoki Shiotab2d17e82013-10-18 18:08:16 -070040import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
Jonathan Hart7804bea2014-01-07 10:50:52 -080041import net.onrc.onos.ofcontroller.proxyarp.ArpReplyNotification;
Pavlin Radoslavov8442e492013-10-25 21:54:13 -070042import net.onrc.onos.ofcontroller.topology.TopologyElement;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070043import net.onrc.onos.registry.controller.IControllerRegistryService;
44import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback;
45import net.onrc.onos.registry.controller.RegistryException;
Pankaj Berdeda809572013-02-22 15:31:20 -080046
Jonathan Hartd857ad62013-12-14 18:08:17 -080047import org.openflow.protocol.OFPhysicalPort;
48import org.openflow.util.HexString;
49import org.slf4j.Logger;
50import org.slf4j.LoggerFactory;
51
52import com.google.common.net.InetAddresses;
53
Pavlin Radoslavov28069402013-10-18 18:43:11 -070054public class NetworkGraphPublisher implements IDeviceListener,
55 IOFSwitchListener,
56 IOFSwitchPortListener,
57 ILinkDiscoveryListener,
58 IFloodlightModule,
59 INetworkGraphService {
Pankaj Berdeda809572013-02-22 15:31:20 -080060
61 protected IDeviceStorage devStore;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070062 protected ISwitchStorage swStore;
Pankaj Berde00e90882013-06-10 21:25:05 -070063 protected ILinkStorage linkStore;
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070064 protected final static Logger log = LoggerFactory.getLogger(NetworkGraphPublisher.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -080065 //protected IDeviceService deviceService;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070066 protected IControllerRegistryService registryService;
Toshio Koide70ba38b2013-06-13 14:05:05 -070067 protected GraphDBOperation op;
Pankaj Berdeda809572013-02-22 15:31:20 -080068
69 protected static final String DBConfigFile = "dbconf";
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -070070 protected static final String CleanupEnabled = "EnableCleanup";
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070071 protected IThreadPoolService threadPool;
Pankaj Berde465ac7c2013-05-23 13:47:49 -070072 protected IFloodlightProviderService floodlightProvider;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070073
Pankaj Berde62016142013-04-09 15:35:50 -070074 protected final int CLEANUP_TASK_INTERVAL = 60; // 1 min
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070075 protected SingletonTask cleanupTask;
Pankaj Berde00e90882013-06-10 21:25:05 -070076 protected ILinkDiscoveryService linkDiscovery;
Pavlin Radoslavov8442e492013-10-25 21:54:13 -070077
78 protected IDatagridService datagridService;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070079
80 /**
81 * Cleanup and synch switch state from registry
82 */
83 protected class SwitchCleanup implements ControlChangeCallback, Runnable {
84 @Override
85 public void run() {
86 try {
87 log.debug("Running cleanup thread");
88 switchCleanup();
89 }
90 catch (Exception e) {
91 log.error("Error in cleanup thread", e);
92 } finally {
Toshio Koide70ba38b2013-06-13 14:05:05 -070093 op.close();
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070094 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL,
Pankaj Berde99fcee12013-03-18 09:41:53 -070095 TimeUnit.SECONDS);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070096 }
97 }
98
99 @Override
100 public void controlChanged(long dpid, boolean hasControl) {
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700101 if (hasControl) {
Pankaj Berde99fcee12013-03-18 09:41:53 -0700102 log.debug("got control to set inactive sw {}", HexString.toHexString(dpid));
Naoki Shiota987a5722013-10-23 11:59:36 -0700103 try {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800104 // Get the affected ports
105 List<Short> ports = swStore.getPorts(HexString.toHexString(dpid));
106 // Get the affected links
107 List<Link> links = linkStore.getLinks(HexString.toHexString(dpid));
108 // Get the affected reverse links
109 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(dpid));
110 links.addAll(reverseLinks);
111
Jonathan Hartadc63892013-11-08 14:03:55 -0800112 //if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
113 if (swStore.deactivateSwitch(HexString.toHexString(dpid))) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700114 registryService.releaseControl(dpid);
115
116 // TODO publish UPDATE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700117 //
118 // NOTE: Here we explicitly send
119 // notification to remove the
120 // switch, because it is inactive
121 //
122 TopologyElement topologyElement =
123 new TopologyElement(dpid);
124 datagridService.notificationSendTopologyElementRemoved(topologyElement);
125
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800126 // Publish: remove the affected ports
127 for (Short port : ports) {
128 TopologyElement topologyElementPort =
129 new TopologyElement(dpid, port);
130 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
131 }
132 // Publish: remove the affected links
133 for (Link link : links) {
134 TopologyElement topologyElementLink =
135 new TopologyElement(link.getSrc(),
136 link.getSrcPort(),
137 link.getDst(),
138 link.getDstPort());
139 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
140 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700141 }
142 } catch (Exception e) {
143 log.error("Error in SwitchCleanup:controlChanged ", e);
144 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700145 }
146 }
147 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700148
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700149 protected void switchCleanup() {
Toshio Koide70ba38b2013-06-13 14:05:05 -0700150 op.close();
151 Iterable<ISwitchObject> switches = op.getActiveSwitches();
Jonathan Hartf02a0932013-03-18 18:30:48 -0700152
153 log.debug("Checking for inactive switches");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700154 // For each switch check if a controller exists in controller registry
155 for (ISwitchObject sw: switches) {
Jonathan Hartf02a0932013-03-18 18:30:48 -0700156 //log.debug("checking if switch is inactive: {}", sw.getDPID());
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700157 try {
158 long dpid = HexString.toLong(sw.getDPID());
159 String controller = registryService.getControllerForSwitch(dpid);
160 if (controller == null) {
Pankaj Berde99fcee12013-03-18 09:41:53 -0700161 log.debug("request Control to set inactive sw {}", HexString.toHexString(dpid));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700162 registryService.requestControl(dpid, new SwitchCleanup());
Umesh Krishnaswamy255b9882013-04-02 19:55:43 -0700163 //} else {
164 // log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700165 }
166 } catch (NumberFormatException e) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700167 log.debug("Caught NumberFormatException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700168 e.printStackTrace();
169 } catch (RegistryException e) {
Jonathan Hart4baf3be2013-03-21 18:26:13 -0700170 log.debug("Caught RegistryException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700171 e.printStackTrace();
Naoki Shiota987a5722013-10-23 11:59:36 -0700172 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700173 }
Toshio Koide70ba38b2013-06-13 14:05:05 -0700174 op.close();
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700175 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800176
pingping-lin00926032013-12-18 12:13:08 +0800177 @Override
178 public void linkDiscoveryUpdate(LDUpdate update) {
179 Link lt = new Link(update.getSrc(),update.getSrcPort(),update.getDst(),update.getDstPort());
180 //log.debug("{}:LinkDicoveryUpdate(): Updating Link {}",this.getClass(), lt);
Pankaj Berdeda809572013-02-22 15:31:20 -0800181
pingping-lin00926032013-12-18 12:13:08 +0800182 switch (update.getOperation()) {
183 case LINK_REMOVED:
184 log.debug("LinkDiscoveryUpdate(): Removing link {}", lt);
185
186 if (linkStore.deleteLink(lt)) {
187 // TODO publish DELETE_LINK event here
188 TopologyElement topologyElement =
189 new TopologyElement(update.getSrc(),
190 update.getSrcPort(),
191 update.getDst(),
192 update.getDstPort());
193 datagridService.notificationSendTopologyElementRemoved(topologyElement);
194 }
195 break;
196 case LINK_UPDATED:
197 log.debug("LinkDiscoveryUpdate(): Updating link {}", lt);
198
199 LinkInfo linfo = linkStore.getLinkInfo(lt);
200 // TODO update "linfo" using portState derived using "update"
201 if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) {
202 // TODO publish UPDATE_LINK event here
203 //
204 // TODO NOTE: Here we assume that updated
205 // link is UP.
206 //
207 TopologyElement topologyElement =
208 new TopologyElement(update.getSrc(),
209 update.getSrcPort(),
210 update.getDst(),
211 update.getDstPort());
212 datagridService.notificationSendTopologyElementUpdated(topologyElement);
213 }
214 break;
215 case LINK_ADDED:
216 log.debug("LinkDiscoveryUpdate(): Adding link {}", lt);
217
218 if (linkStore.addLink(lt)) {
219 // TODO publish ADD_LINK event here
220 TopologyElement topologyElement =
221 new TopologyElement(update.getSrc(),
222 update.getSrcPort(),
223 update.getDst(),
224 update.getDstPort());
225 datagridService.notificationSendTopologyElementAdded(topologyElement);
226 }
227
228 break;
229 default:
230 break;
231 }
232
233 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800234
235 @Override
236 public void addedSwitch(IOFSwitch sw) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700237 if (registryService.hasControl(sw.getId())) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700238 if (swStore.addSwitch(sw)) {
239 // TODO publish ADD_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700240 TopologyElement topologyElement =
241 new TopologyElement(sw.getId());
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800242 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800243
244 // Publish: add the ports
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700245 // TODO: Add only ports that are UP?
246 for (OFPhysicalPort port : sw.getPorts()) {
Jonathan Hart8a5d0972013-12-04 10:02:44 -0800247 TopologyElement topologyElementPort =
248 new TopologyElement(sw.getId(), port.getPortNumber());
249 datagridService.notificationSendTopologyElementAdded(topologyElementPort);
250
251 // Allow links to be discovered on this port now that it's
252 // in the database
253 linkDiscovery.RemoveFromSuppressLLDPs(sw.getId(), port.getPortNumber());
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700254 }
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800255
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700256 // Add all links that might be connected already
257 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
258 // Add all reverse links as well
259 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
260 links.addAll(reverseLinks);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800261
262 // Publish: add the links
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700263 for (Link link : links) {
264 TopologyElement topologyElementLink =
265 new TopologyElement(link.getSrc(),
266 link.getSrcPort(),
267 link.getDst(),
268 link.getDstPort());
269 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
270 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700271 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700272 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800273 }
274
275 @Override
276 public void removedSwitch(IOFSwitch sw) {
Jonathan Hartadc63892013-11-08 14:03:55 -0800277 /*
Naoki Shiota987a5722013-10-23 11:59:36 -0700278 if (registryService.hasControl(sw.getId())) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800279 // Get the affected ports
280 List<Short> ports = swStore.getPorts(HexString.toHexString(sw.getId()));
281 // Get the affected links
282 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
283 // Get the affected reverse links
284 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
285 links.addAll(reverseLinks);
286
Naoki Shiota987a5722013-10-23 11:59:36 -0700287 if (swStore.deleteSwitch(sw.getStringId())) {
288 // TODO publish DELETE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700289 TopologyElement topologyElement =
290 new TopologyElement(sw.getId());
291 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800292
293 // Publish: remove the affected ports
294 for (Short port : ports) {
295 TopologyElement topologyElementPort =
296 new TopologyElement(sw.getId(), port);
297 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
298 }
299 // Publish: remove the affected links
300 for (Link link : links) {
301 TopologyElement topologyElementLink =
302 new TopologyElement(link.getSrc(),
303 link.getSrcPort(),
304 link.getDst(),
305 link.getDstPort());
306 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
307 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700308 }
309 }
Jonathan Hartadc63892013-11-08 14:03:55 -0800310 */
Pankaj Berdeda809572013-02-22 15:31:20 -0800311 }
312
313 @Override
314 public void switchPortChanged(Long switchId) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700315 // NOTE: Event not needed here. This callback always coincide with add/remove callback.
Pankaj Berdeda809572013-02-22 15:31:20 -0800316 }
317
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700318
319 @Override
320 public void switchPortAdded(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700321 if (swStore.addPort(HexString.toHexString(switchId), port)) {
Jonathan Hart8a5d0972013-12-04 10:02:44 -0800322 // Allow links to be discovered on this port now that it's
323 // in the database
324 linkDiscovery.RemoveFromSuppressLLDPs(switchId, port.getPortNumber());
325
Naoki Shiota987a5722013-10-23 11:59:36 -0700326 // TODO publish ADD_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700327 TopologyElement topologyElement =
328 new TopologyElement(switchId, port.getPortNumber());
329 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800330
331 // Add all links that might be connected already
332 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
333 // Add all reverse links as well
334 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
335 links.addAll(reverseLinks);
336
337 // Publish: add the links
338 for (Link link : links) {
339 TopologyElement topologyElementLink =
340 new TopologyElement(link.getSrc(),
341 link.getSrcPort(),
342 link.getDst(),
343 link.getDstPort());
344 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
345 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700346 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700347 }
348
349 @Override
350 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800351 // Remove all links that might be connected already
352 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
353 // Remove all reverse links as well
354 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
355 links.addAll(reverseLinks);
356
Naoki Shiota987a5722013-10-23 11:59:36 -0700357 if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
358 // TODO publish DELETE_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700359 TopologyElement topologyElement =
360 new TopologyElement(switchId, port.getPortNumber());
361 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800362
363 // Publish: remove the links
364 for (Link link : links) {
365 TopologyElement topologyElementLink =
366 new TopologyElement(link.getSrc(),
367 link.getSrcPort(),
368 link.getDst(),
369 link.getDstPort());
370 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
371 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700372 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700373 }
374
Pankaj Berdeda809572013-02-22 15:31:20 -0800375 @Override
376 public String getName() {
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700377 return "NetworkGraphPublisher";
Pankaj Berdeda809572013-02-22 15:31:20 -0800378 }
379
380 @Override
381 public void deviceAdded(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800382 log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
383 devStore.addDevice(device);
Jonathan Hartd3003252013-11-15 09:44:46 -0800384 for (int intIpv4Address : device.getIPv4Addresses()) {
Jonathan Hart7804bea2014-01-07 10:50:52 -0800385 datagridService.sendArpReplyNotification(new ArpReplyNotification(
386 InetAddresses.fromInteger(intIpv4Address),
387 MACAddress.valueOf(device.getMACAddress())));
Jonathan Hartd3003252013-11-15 09:44:46 -0800388 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800389 }
390
391 @Override
392 public void deviceRemoved(IDevice device) {
393 // TODO Auto-generated method stub
Jonathan Hart4fce4ed2013-11-01 21:29:21 -0700394 devStore.removeDevice(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800395 }
396
397 @Override
398 public void deviceMoved(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800399 devStore.changeDeviceAttachments(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800400 }
401
402 @Override
403 public void deviceIPV4AddrChanged(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800404 devStore.changeDeviceIPv4Address(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800405 }
406
407 @Override
408 public void deviceVlanChanged(IDevice device) {
409 // TODO Auto-generated method stub
410 }
411
412
413 @Override
414 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700415 Collection<Class<? extends IFloodlightService>> l =
416 new ArrayList<Class<? extends IFloodlightService>>();
417 l.add(INetworkGraphService.class);
418 return l;
Pankaj Berdeda809572013-02-22 15:31:20 -0800419 }
420
421 @Override
422 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700423 Map<Class<? extends IFloodlightService>,
424 IFloodlightService> m =
425 new HashMap<Class<? extends IFloodlightService>,
426 IFloodlightService>();
427 m.put(INetworkGraphService.class, this);
428 return m;
Pankaj Berdeda809572013-02-22 15:31:20 -0800429 }
430
431 @Override
432 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
433 Collection<Class<? extends IFloodlightService>> l =
434 new ArrayList<Class<? extends IFloodlightService>>();
435 l.add(IFloodlightProviderService.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -0800436 //l.add(IDeviceService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700437 l.add(IDatagridService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700438 l.add(IThreadPoolService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800439 return l;
440 }
441
442 @Override
443 public void init(FloodlightModuleContext context)
444 throws FloodlightModuleException {
Pankaj Berdeda809572013-02-22 15:31:20 -0800445 Map<String, String> configMap = context.getConfigParams(this);
446 String conf = configMap.get(DBConfigFile);
Toshio Koidebfe9b922013-06-18 10:56:05 -0700447 op = new GraphDBOperation(conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800448
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700449 floodlightProvider =
450 context.getServiceImpl(IFloodlightProviderService.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -0800451 //deviceService = context.getServiceImpl(IDeviceService.class);
Pankaj Berde00e90882013-06-10 21:25:05 -0700452 linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700453 threadPool = context.getServiceImpl(IThreadPoolService.class);
454 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700455 datagridService = context.getServiceImpl(IDatagridService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800456
Pankaj Berdeda809572013-02-22 15:31:20 -0800457 devStore = new DeviceStorageImpl();
458 devStore.init(conf);
459
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700460 swStore = new SwitchStorageImpl();
461 swStore.init(conf);
Pankaj Berde00e90882013-06-10 21:25:05 -0700462
463 linkStore = new LinkStorageImpl();
464 linkStore.init(conf);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700465
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700466 log.debug("Initializing NetworkGraphPublisher module with {}", conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800467
468 }
469
470 @Override
471 public void startUp(FloodlightModuleContext context) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700472 Map<String, String> configMap = context.getConfigParams(this);
473 String cleanupNeeded = configMap.get(CleanupEnabled);
474
Jonathan Hartd857ad62013-12-14 18:08:17 -0800475 //deviceService.addListener(this);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700476 floodlightProvider.addOFSwitchListener(this);
Pankaj Berde00e90882013-06-10 21:25:05 -0700477 linkDiscovery.addListener(this);
Pankaj Berde9d6b5072013-04-03 11:51:23 -0700478
479 log.debug("Adding EventListener");
Toshio Koide70ba38b2013-06-13 14:05:05 -0700480 IDBConnection conn = op.getDBConnection();
481 conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700482 // Setup the Cleanup task.
Pankaj Berde99fcee12013-03-18 09:41:53 -0700483 if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700484 ScheduledExecutorService ses = threadPool.getScheduledExecutor();
485 cleanupTask = new SingletonTask(ses, new SwitchCleanup());
Pankaj Berde99fcee12013-03-18 09:41:53 -0700486 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS);
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700487 }
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700488
489 //
490 // NOTE: No need to register with the Datagrid Service,
491 // because we don't need to receive any notifications from it.
492 //
Pankaj Berdeda809572013-02-22 15:31:20 -0800493 }
494
495}