blob: d777202b2b8234ec5a285cdf311740729a52139a [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;
Pavlin Radoslavov8442e492013-10-25 21:54:13 -070023import net.onrc.onos.datagrid.IDatagridService;
Pankaj Berde38646d62013-06-21 11:34:04 -070024import net.onrc.onos.graph.GraphDBConnection;
25import net.onrc.onos.graph.GraphDBOperation;
26import net.onrc.onos.graph.IDBConnection;
27import net.onrc.onos.graph.LocalTopologyEventListener;
HIGUCHI Yuta2d011582013-06-15 01:47:11 -070028import net.onrc.onos.ofcontroller.core.IDeviceStorage;
29import net.onrc.onos.ofcontroller.core.ILinkStorage;
HIGUCHI Yuta20514902013-06-12 11:24:16 -070030import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
HIGUCHI Yuta20514902013-06-12 11:24:16 -070031import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
Jonathan Hartd857ad62013-12-14 18:08:17 -080032import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
33import net.onrc.onos.ofcontroller.core.ISwitchStorage;
HIGUCHI Yuta2d011582013-06-15 01:47:11 -070034import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl;
35import net.onrc.onos.ofcontroller.core.internal.LinkStorageImpl;
HIGUCHI Yutaed49ef72013-06-12 11:34:10 -070036import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
HIGUCHI Yutaa56fbde2013-06-17 14:26:05 -070037import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
38import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
Naoki Shiotab2d17e82013-10-18 18:08:16 -070039import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
Jonathan Hartd3003252013-11-15 09:44:46 -080040import net.onrc.onos.ofcontroller.proxyarp.ArpMessage;
Pavlin Radoslavov8442e492013-10-25 21:54:13 -070041import net.onrc.onos.ofcontroller.topology.TopologyElement;
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070042import net.onrc.onos.registry.controller.IControllerRegistryService;
43import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback;
44import net.onrc.onos.registry.controller.RegistryException;
Pankaj Berdeda809572013-02-22 15:31:20 -080045
Jonathan Hartd857ad62013-12-14 18:08:17 -080046import org.openflow.protocol.OFPhysicalPort;
47import org.openflow.util.HexString;
48import org.slf4j.Logger;
49import org.slf4j.LoggerFactory;
50
51import com.google.common.net.InetAddresses;
52
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);
Jonathan Hartd857ad62013-12-14 18:08:17 -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
Jonathan Hartadc63892013-11-08 14:03:55 -0800111 //if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
112 if (swStore.deactivateSwitch(HexString.toHexString(dpid))) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700113 registryService.releaseControl(dpid);
114
115 // TODO publish UPDATE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700116 //
117 // NOTE: Here we explicitly send
118 // notification to remove the
119 // switch, because it is inactive
120 //
121 TopologyElement topologyElement =
122 new TopologyElement(dpid);
123 datagridService.notificationSendTopologyElementRemoved(topologyElement);
124
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800125 // Publish: remove the affected ports
126 for (Short port : ports) {
127 TopologyElement topologyElementPort =
128 new TopologyElement(dpid, port);
129 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
130 }
131 // Publish: remove the affected links
132 for (Link link : links) {
133 TopologyElement topologyElementLink =
134 new TopologyElement(link.getSrc(),
135 link.getSrcPort(),
136 link.getDst(),
137 link.getDstPort());
138 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
139 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700140 }
141 } catch (Exception e) {
142 log.error("Error in SwitchCleanup:controlChanged ", e);
143 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700144 }
145 }
146 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700147
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700148 protected void switchCleanup() {
Toshio Koide70ba38b2013-06-13 14:05:05 -0700149 op.close();
150 Iterable<ISwitchObject> switches = op.getActiveSwitches();
Jonathan Hartf02a0932013-03-18 18:30:48 -0700151
152 log.debug("Checking for inactive switches");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700153 // For each switch check if a controller exists in controller registry
154 for (ISwitchObject sw: switches) {
Jonathan Hartf02a0932013-03-18 18:30:48 -0700155 //log.debug("checking if switch is inactive: {}", sw.getDPID());
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700156 try {
157 long dpid = HexString.toLong(sw.getDPID());
158 String controller = registryService.getControllerForSwitch(dpid);
159 if (controller == null) {
Pankaj Berde99fcee12013-03-18 09:41:53 -0700160 log.debug("request Control to set inactive sw {}", HexString.toHexString(dpid));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700161 registryService.requestControl(dpid, new SwitchCleanup());
Umesh Krishnaswamy255b9882013-04-02 19:55:43 -0700162 //} else {
163 // log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700164 }
165 } catch (NumberFormatException e) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700166 log.debug("Caught NumberFormatException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700167 e.printStackTrace();
168 } catch (RegistryException e) {
Jonathan Hart4baf3be2013-03-21 18:26:13 -0700169 log.debug("Caught RegistryException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700170 e.printStackTrace();
Naoki Shiota987a5722013-10-23 11:59:36 -0700171 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700172 }
Toshio Koide70ba38b2013-06-13 14:05:05 -0700173 op.close();
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700174 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800175
pingping-lin00926032013-12-18 12:13:08 +0800176 @Override
177 public void linkDiscoveryUpdate(LDUpdate update) {
178 Link lt = new Link(update.getSrc(),update.getSrcPort(),update.getDst(),update.getDstPort());
179 //log.debug("{}:LinkDicoveryUpdate(): Updating Link {}",this.getClass(), lt);
Pankaj Berdeda809572013-02-22 15:31:20 -0800180
pingping-lin00926032013-12-18 12:13:08 +0800181 switch (update.getOperation()) {
182 case LINK_REMOVED:
183 log.debug("LinkDiscoveryUpdate(): Removing link {}", lt);
184
185 if (linkStore.deleteLink(lt)) {
186 // TODO publish DELETE_LINK event here
187 TopologyElement topologyElement =
188 new TopologyElement(update.getSrc(),
189 update.getSrcPort(),
190 update.getDst(),
191 update.getDstPort());
192 datagridService.notificationSendTopologyElementRemoved(topologyElement);
193 }
194 break;
195 case LINK_UPDATED:
196 log.debug("LinkDiscoveryUpdate(): Updating link {}", lt);
197
198 LinkInfo linfo = linkStore.getLinkInfo(lt);
199 // TODO update "linfo" using portState derived using "update"
200 if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) {
201 // TODO publish UPDATE_LINK event here
202 //
203 // TODO NOTE: Here we assume that updated
204 // link is UP.
205 //
206 TopologyElement topologyElement =
207 new TopologyElement(update.getSrc(),
208 update.getSrcPort(),
209 update.getDst(),
210 update.getDstPort());
211 datagridService.notificationSendTopologyElementUpdated(topologyElement);
212 }
213 break;
214 case LINK_ADDED:
215 log.debug("LinkDiscoveryUpdate(): Adding link {}", lt);
216
217 if (linkStore.addLink(lt)) {
218 // TODO publish ADD_LINK event here
219 TopologyElement topologyElement =
220 new TopologyElement(update.getSrc(),
221 update.getSrcPort(),
222 update.getDst(),
223 update.getDstPort());
224 datagridService.notificationSendTopologyElementAdded(topologyElement);
225 }
226
227 break;
228 default:
229 break;
230 }
231
232 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800233
234 @Override
235 public void addedSwitch(IOFSwitch sw) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700236 if (registryService.hasControl(sw.getId())) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700237 if (swStore.addSwitch(sw)) {
238 // TODO publish ADD_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700239 TopologyElement topologyElement =
240 new TopologyElement(sw.getId());
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800241 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800242
243 // Publish: add the ports
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700244 // TODO: Add only ports that are UP?
245 for (OFPhysicalPort port : sw.getPorts()) {
Jonathan Hart8a5d0972013-12-04 10:02:44 -0800246 TopologyElement topologyElementPort =
247 new TopologyElement(sw.getId(), port.getPortNumber());
248 datagridService.notificationSendTopologyElementAdded(topologyElementPort);
249
250 // Allow links to be discovered on this port now that it's
251 // in the database
252 linkDiscovery.RemoveFromSuppressLLDPs(sw.getId(), port.getPortNumber());
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700253 }
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800254
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700255 // Add all links that might be connected already
256 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
257 // Add all reverse links as well
258 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
259 links.addAll(reverseLinks);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800260
261 // Publish: add the links
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700262 for (Link link : links) {
263 TopologyElement topologyElementLink =
264 new TopologyElement(link.getSrc(),
265 link.getSrcPort(),
266 link.getDst(),
267 link.getDstPort());
268 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
269 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700270 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700271 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800272 }
273
274 @Override
275 public void removedSwitch(IOFSwitch sw) {
Jonathan Hartadc63892013-11-08 14:03:55 -0800276 /*
Naoki Shiota987a5722013-10-23 11:59:36 -0700277 if (registryService.hasControl(sw.getId())) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800278 // Get the affected ports
279 List<Short> ports = swStore.getPorts(HexString.toHexString(sw.getId()));
280 // Get the affected links
281 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
282 // Get the affected reverse links
283 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
284 links.addAll(reverseLinks);
285
Naoki Shiota987a5722013-10-23 11:59:36 -0700286 if (swStore.deleteSwitch(sw.getStringId())) {
287 // TODO publish DELETE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700288 TopologyElement topologyElement =
289 new TopologyElement(sw.getId());
290 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800291
292 // Publish: remove the affected ports
293 for (Short port : ports) {
294 TopologyElement topologyElementPort =
295 new TopologyElement(sw.getId(), port);
296 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
297 }
298 // Publish: remove the affected links
299 for (Link link : links) {
300 TopologyElement topologyElementLink =
301 new TopologyElement(link.getSrc(),
302 link.getSrcPort(),
303 link.getDst(),
304 link.getDstPort());
305 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
306 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700307 }
308 }
Jonathan Hartadc63892013-11-08 14:03:55 -0800309 */
Pankaj Berdeda809572013-02-22 15:31:20 -0800310 }
311
312 @Override
313 public void switchPortChanged(Long switchId) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700314 // NOTE: Event not needed here. This callback always coincide with add/remove callback.
Pankaj Berdeda809572013-02-22 15:31:20 -0800315 }
316
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700317
318 @Override
319 public void switchPortAdded(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700320 if (swStore.addPort(HexString.toHexString(switchId), port)) {
Jonathan Hart8a5d0972013-12-04 10:02:44 -0800321 // Allow links to be discovered on this port now that it's
322 // in the database
323 linkDiscovery.RemoveFromSuppressLLDPs(switchId, port.getPortNumber());
324
Naoki Shiota987a5722013-10-23 11:59:36 -0700325 // TODO publish ADD_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700326 TopologyElement topologyElement =
327 new TopologyElement(switchId, port.getPortNumber());
328 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800329
330 // Add all links that might be connected already
331 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
332 // Add all reverse links as well
333 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
334 links.addAll(reverseLinks);
335
336 // Publish: add the links
337 for (Link link : links) {
338 TopologyElement topologyElementLink =
339 new TopologyElement(link.getSrc(),
340 link.getSrcPort(),
341 link.getDst(),
342 link.getDstPort());
343 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
344 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700345 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700346 }
347
348 @Override
349 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800350 // Remove all links that might be connected already
351 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
352 // Remove all reverse links as well
353 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
354 links.addAll(reverseLinks);
355
Naoki Shiota987a5722013-10-23 11:59:36 -0700356 if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
357 // TODO publish DELETE_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700358 TopologyElement topologyElement =
359 new TopologyElement(switchId, port.getPortNumber());
360 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800361
362 // Publish: remove the links
363 for (Link link : links) {
364 TopologyElement topologyElementLink =
365 new TopologyElement(link.getSrc(),
366 link.getSrcPort(),
367 link.getDst(),
368 link.getDstPort());
369 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
370 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700371 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700372 }
373
Pankaj Berdeda809572013-02-22 15:31:20 -0800374 @Override
375 public String getName() {
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700376 return "NetworkGraphPublisher";
Pankaj Berdeda809572013-02-22 15:31:20 -0800377 }
378
379 @Override
380 public void deviceAdded(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800381 log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
382 devStore.addDevice(device);
Jonathan Hartd3003252013-11-15 09:44:46 -0800383 for (int intIpv4Address : device.getIPv4Addresses()) {
384 datagridService.sendArpRequest(
385 ArpMessage.newReply(InetAddresses.fromInteger(intIpv4Address)));
386 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800387 }
388
389 @Override
390 public void deviceRemoved(IDevice device) {
391 // TODO Auto-generated method stub
Jonathan Hart4fce4ed2013-11-01 21:29:21 -0700392 devStore.removeDevice(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800393 }
394
395 @Override
396 public void deviceMoved(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800397 devStore.changeDeviceAttachments(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800398 }
399
400 @Override
401 public void deviceIPV4AddrChanged(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800402 devStore.changeDeviceIPv4Address(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800403 }
404
405 @Override
406 public void deviceVlanChanged(IDevice device) {
407 // TODO Auto-generated method stub
408 }
409
410
411 @Override
412 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700413 Collection<Class<? extends IFloodlightService>> l =
414 new ArrayList<Class<? extends IFloodlightService>>();
415 l.add(INetworkGraphService.class);
416 return l;
Pankaj Berdeda809572013-02-22 15:31:20 -0800417 }
418
419 @Override
420 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700421 Map<Class<? extends IFloodlightService>,
422 IFloodlightService> m =
423 new HashMap<Class<? extends IFloodlightService>,
424 IFloodlightService>();
425 m.put(INetworkGraphService.class, this);
426 return m;
Pankaj Berdeda809572013-02-22 15:31:20 -0800427 }
428
429 @Override
430 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
431 Collection<Class<? extends IFloodlightService>> l =
432 new ArrayList<Class<? extends IFloodlightService>>();
433 l.add(IFloodlightProviderService.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -0800434 //l.add(IDeviceService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700435 l.add(IDatagridService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700436 l.add(IThreadPoolService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800437 return l;
438 }
439
440 @Override
441 public void init(FloodlightModuleContext context)
442 throws FloodlightModuleException {
Pankaj Berdeda809572013-02-22 15:31:20 -0800443 Map<String, String> configMap = context.getConfigParams(this);
444 String conf = configMap.get(DBConfigFile);
Toshio Koidebfe9b922013-06-18 10:56:05 -0700445 op = new GraphDBOperation(conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800446
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700447 floodlightProvider =
448 context.getServiceImpl(IFloodlightProviderService.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -0800449 //deviceService = context.getServiceImpl(IDeviceService.class);
Pankaj Berde00e90882013-06-10 21:25:05 -0700450 linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700451 threadPool = context.getServiceImpl(IThreadPoolService.class);
452 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700453 datagridService = context.getServiceImpl(IDatagridService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800454
Pankaj Berdeda809572013-02-22 15:31:20 -0800455 devStore = new DeviceStorageImpl();
456 devStore.init(conf);
457
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700458 swStore = new SwitchStorageImpl();
459 swStore.init(conf);
Pankaj Berde00e90882013-06-10 21:25:05 -0700460
461 linkStore = new LinkStorageImpl();
462 linkStore.init(conf);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700463
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700464 log.debug("Initializing NetworkGraphPublisher module with {}", conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800465
466 }
467
468 @Override
469 public void startUp(FloodlightModuleContext context) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700470 Map<String, String> configMap = context.getConfigParams(this);
471 String cleanupNeeded = configMap.get(CleanupEnabled);
472
Jonathan Hartd857ad62013-12-14 18:08:17 -0800473 //deviceService.addListener(this);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700474 floodlightProvider.addOFSwitchListener(this);
Pankaj Berde00e90882013-06-10 21:25:05 -0700475 linkDiscovery.addListener(this);
Pankaj Berde9d6b5072013-04-03 11:51:23 -0700476
477 log.debug("Adding EventListener");
Toshio Koide70ba38b2013-06-13 14:05:05 -0700478 IDBConnection conn = op.getDBConnection();
479 conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700480 // Setup the Cleanup task.
Pankaj Berde99fcee12013-03-18 09:41:53 -0700481 if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700482 ScheduledExecutorService ses = threadPool.getScheduledExecutor();
483 cleanupTask = new SingletonTask(ses, new SwitchCleanup());
Pankaj Berde99fcee12013-03-18 09:41:53 -0700484 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS);
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700485 }
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700486
487 //
488 // NOTE: No need to register with the Datagrid Service,
489 // because we don't need to receive any notifications from it.
490 //
Pankaj Berdeda809572013-02-22 15:31:20 -0800491 }
492
493}