blob: 22241cec67cf70fb3644d71bb7894d2509f7cff3 [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() {
Yuta HIGUCHI61509a42013-12-17 10:41:04 -080085 String old = Thread.currentThread().getName();
Yuta HIGUCHI1412e8c2014-01-03 17:19:01 -080086 Thread.currentThread().setName("SwitchCleanup@" + old);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070087 try {
88 log.debug("Running cleanup thread");
89 switchCleanup();
90 }
91 catch (Exception e) {
92 log.error("Error in cleanup thread", e);
93 } finally {
Toshio Koide70ba38b2013-06-13 14:05:05 -070094 op.close();
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070095 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL,
Pankaj Berde99fcee12013-03-18 09:41:53 -070096 TimeUnit.SECONDS);
Yuta HIGUCHI61509a42013-12-17 10:41:04 -080097 Thread.currentThread().setName(old);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -070098 }
99 }
100
101 @Override
102 public void controlChanged(long dpid, boolean hasControl) {
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700103 if (hasControl) {
Pankaj Berde99fcee12013-03-18 09:41:53 -0700104 log.debug("got control to set inactive sw {}", HexString.toHexString(dpid));
Naoki Shiota987a5722013-10-23 11:59:36 -0700105 try {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800106 // Get the affected ports
107 List<Short> ports = swStore.getPorts(HexString.toHexString(dpid));
108 // Get the affected links
109 List<Link> links = linkStore.getLinks(HexString.toHexString(dpid));
110 // Get the affected reverse links
111 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(dpid));
112 links.addAll(reverseLinks);
113
Jonathan Hartadc63892013-11-08 14:03:55 -0800114 //if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
115 if (swStore.deactivateSwitch(HexString.toHexString(dpid))) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700116 registryService.releaseControl(dpid);
117
118 // TODO publish UPDATE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700119 //
120 // NOTE: Here we explicitly send
121 // notification to remove the
122 // switch, because it is inactive
123 //
124 TopologyElement topologyElement =
125 new TopologyElement(dpid);
126 datagridService.notificationSendTopologyElementRemoved(topologyElement);
127
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800128 // Publish: remove the affected ports
129 for (Short port : ports) {
130 TopologyElement topologyElementPort =
131 new TopologyElement(dpid, port);
132 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
133 }
134 // Publish: remove the affected links
135 for (Link link : links) {
136 TopologyElement topologyElementLink =
137 new TopologyElement(link.getSrc(),
138 link.getSrcPort(),
139 link.getDst(),
140 link.getDstPort());
141 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
142 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700143 }
144 } catch (Exception e) {
145 log.error("Error in SwitchCleanup:controlChanged ", e);
146 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700147 }
148 }
149 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700150
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700151 protected void switchCleanup() {
Toshio Koide70ba38b2013-06-13 14:05:05 -0700152 op.close();
153 Iterable<ISwitchObject> switches = op.getActiveSwitches();
Jonathan Hartf02a0932013-03-18 18:30:48 -0700154
155 log.debug("Checking for inactive switches");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700156 // For each switch check if a controller exists in controller registry
157 for (ISwitchObject sw: switches) {
Jonathan Hartf02a0932013-03-18 18:30:48 -0700158 //log.debug("checking if switch is inactive: {}", sw.getDPID());
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700159 try {
160 long dpid = HexString.toLong(sw.getDPID());
161 String controller = registryService.getControllerForSwitch(dpid);
162 if (controller == null) {
Pankaj Berde99fcee12013-03-18 09:41:53 -0700163 log.debug("request Control to set inactive sw {}", HexString.toHexString(dpid));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700164 registryService.requestControl(dpid, new SwitchCleanup());
Umesh Krishnaswamy255b9882013-04-02 19:55:43 -0700165 //} else {
166 // log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700167 }
168 } catch (NumberFormatException e) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700169 log.debug("Caught NumberFormatException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700170 e.printStackTrace();
171 } catch (RegistryException e) {
Jonathan Hart4baf3be2013-03-21 18:26:13 -0700172 log.debug("Caught RegistryException trying to requestControl in cleanup thread");
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700173 e.printStackTrace();
Naoki Shiota987a5722013-10-23 11:59:36 -0700174 }
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700175 }
Toshio Koide70ba38b2013-06-13 14:05:05 -0700176 op.close();
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700177 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800178
pingping-lin00926032013-12-18 12:13:08 +0800179 @Override
180 public void linkDiscoveryUpdate(LDUpdate update) {
181 Link lt = new Link(update.getSrc(),update.getSrcPort(),update.getDst(),update.getDstPort());
182 //log.debug("{}:LinkDicoveryUpdate(): Updating Link {}",this.getClass(), lt);
Pankaj Berdeda809572013-02-22 15:31:20 -0800183
pingping-lin00926032013-12-18 12:13:08 +0800184 switch (update.getOperation()) {
185 case LINK_REMOVED:
186 log.debug("LinkDiscoveryUpdate(): Removing link {}", lt);
187
188 if (linkStore.deleteLink(lt)) {
189 // TODO publish DELETE_LINK event here
190 TopologyElement topologyElement =
191 new TopologyElement(update.getSrc(),
192 update.getSrcPort(),
193 update.getDst(),
194 update.getDstPort());
195 datagridService.notificationSendTopologyElementRemoved(topologyElement);
196 }
197 break;
198 case LINK_UPDATED:
199 log.debug("LinkDiscoveryUpdate(): Updating link {}", lt);
200
201 LinkInfo linfo = linkStore.getLinkInfo(lt);
202 // TODO update "linfo" using portState derived using "update"
203 if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) {
204 // TODO publish UPDATE_LINK event here
205 //
206 // TODO NOTE: Here we assume that updated
207 // link is UP.
208 //
209 TopologyElement topologyElement =
210 new TopologyElement(update.getSrc(),
211 update.getSrcPort(),
212 update.getDst(),
213 update.getDstPort());
214 datagridService.notificationSendTopologyElementUpdated(topologyElement);
215 }
216 break;
217 case LINK_ADDED:
218 log.debug("LinkDiscoveryUpdate(): Adding link {}", lt);
219
220 if (linkStore.addLink(lt)) {
221 // TODO publish ADD_LINK event here
222 TopologyElement topologyElement =
223 new TopologyElement(update.getSrc(),
224 update.getSrcPort(),
225 update.getDst(),
226 update.getDstPort());
227 datagridService.notificationSendTopologyElementAdded(topologyElement);
228 }
229
230 break;
231 default:
232 break;
233 }
234
235 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800236
237 @Override
238 public void addedSwitch(IOFSwitch sw) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700239 if (registryService.hasControl(sw.getId())) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700240 if (swStore.addSwitch(sw)) {
241 // TODO publish ADD_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700242 TopologyElement topologyElement =
243 new TopologyElement(sw.getId());
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800244 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800245
246 // Publish: add the ports
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700247 // TODO: Add only ports that are UP?
248 for (OFPhysicalPort port : sw.getPorts()) {
Jonathan Hart8a5d0972013-12-04 10:02:44 -0800249 TopologyElement topologyElementPort =
250 new TopologyElement(sw.getId(), port.getPortNumber());
251 datagridService.notificationSendTopologyElementAdded(topologyElementPort);
252
253 // Allow links to be discovered on this port now that it's
254 // in the database
255 linkDiscovery.RemoveFromSuppressLLDPs(sw.getId(), port.getPortNumber());
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700256 }
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800257
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700258 // Add all links that might be connected already
259 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
260 // Add all reverse links as well
261 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
262 links.addAll(reverseLinks);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800263
264 // Publish: add the links
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700265 for (Link link : links) {
266 TopologyElement topologyElementLink =
267 new TopologyElement(link.getSrc(),
268 link.getSrcPort(),
269 link.getDst(),
270 link.getDstPort());
271 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
272 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700273 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700274 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800275 }
276
277 @Override
278 public void removedSwitch(IOFSwitch sw) {
Jonathan Hartadc63892013-11-08 14:03:55 -0800279 /*
Naoki Shiota987a5722013-10-23 11:59:36 -0700280 if (registryService.hasControl(sw.getId())) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800281 // Get the affected ports
282 List<Short> ports = swStore.getPorts(HexString.toHexString(sw.getId()));
283 // Get the affected links
284 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
285 // Get the affected reverse links
286 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
287 links.addAll(reverseLinks);
288
Naoki Shiota987a5722013-10-23 11:59:36 -0700289 if (swStore.deleteSwitch(sw.getStringId())) {
290 // TODO publish DELETE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700291 TopologyElement topologyElement =
292 new TopologyElement(sw.getId());
293 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800294
295 // Publish: remove the affected ports
296 for (Short port : ports) {
297 TopologyElement topologyElementPort =
298 new TopologyElement(sw.getId(), port);
299 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
300 }
301 // Publish: remove the affected links
302 for (Link link : links) {
303 TopologyElement topologyElementLink =
304 new TopologyElement(link.getSrc(),
305 link.getSrcPort(),
306 link.getDst(),
307 link.getDstPort());
308 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
309 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700310 }
311 }
Jonathan Hartadc63892013-11-08 14:03:55 -0800312 */
Pankaj Berdeda809572013-02-22 15:31:20 -0800313 }
314
315 @Override
316 public void switchPortChanged(Long switchId) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700317 // NOTE: Event not needed here. This callback always coincide with add/remove callback.
Pankaj Berdeda809572013-02-22 15:31:20 -0800318 }
319
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700320
321 @Override
322 public void switchPortAdded(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700323 if (swStore.addPort(HexString.toHexString(switchId), port)) {
Jonathan Hart8a5d0972013-12-04 10:02:44 -0800324 // Allow links to be discovered on this port now that it's
325 // in the database
326 linkDiscovery.RemoveFromSuppressLLDPs(switchId, port.getPortNumber());
327
Naoki Shiota987a5722013-10-23 11:59:36 -0700328 // TODO publish ADD_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700329 TopologyElement topologyElement =
330 new TopologyElement(switchId, port.getPortNumber());
331 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800332
333 // Add all links that might be connected already
334 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
335 // Add all reverse links as well
336 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
337 links.addAll(reverseLinks);
338
339 // Publish: add the links
340 for (Link link : links) {
341 TopologyElement topologyElementLink =
342 new TopologyElement(link.getSrc(),
343 link.getSrcPort(),
344 link.getDst(),
345 link.getDstPort());
346 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
347 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700348 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700349 }
350
351 @Override
352 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800353 // Remove all links that might be connected already
354 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
355 // Remove all reverse links as well
356 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
357 links.addAll(reverseLinks);
358
Naoki Shiota987a5722013-10-23 11:59:36 -0700359 if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
360 // TODO publish DELETE_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700361 TopologyElement topologyElement =
362 new TopologyElement(switchId, port.getPortNumber());
363 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800364
365 // Publish: remove the links
366 for (Link link : links) {
367 TopologyElement topologyElementLink =
368 new TopologyElement(link.getSrc(),
369 link.getSrcPort(),
370 link.getDst(),
371 link.getDstPort());
372 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
373 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700374 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700375 }
376
Pankaj Berdeda809572013-02-22 15:31:20 -0800377 @Override
378 public String getName() {
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700379 return "NetworkGraphPublisher";
Pankaj Berdeda809572013-02-22 15:31:20 -0800380 }
381
382 @Override
383 public void deviceAdded(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800384 log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
385 devStore.addDevice(device);
Jonathan Hartd3003252013-11-15 09:44:46 -0800386 for (int intIpv4Address : device.getIPv4Addresses()) {
387 datagridService.sendArpRequest(
388 ArpMessage.newReply(InetAddresses.fromInteger(intIpv4Address)));
389 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800390 }
391
392 @Override
393 public void deviceRemoved(IDevice device) {
394 // TODO Auto-generated method stub
Jonathan Hart4fce4ed2013-11-01 21:29:21 -0700395 devStore.removeDevice(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800396 }
397
398 @Override
399 public void deviceMoved(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800400 devStore.changeDeviceAttachments(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800401 }
402
403 @Override
404 public void deviceIPV4AddrChanged(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800405 devStore.changeDeviceIPv4Address(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800406 }
407
408 @Override
409 public void deviceVlanChanged(IDevice device) {
410 // TODO Auto-generated method stub
411 }
412
413
414 @Override
415 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700416 Collection<Class<? extends IFloodlightService>> l =
417 new ArrayList<Class<? extends IFloodlightService>>();
418 l.add(INetworkGraphService.class);
419 return l;
Pankaj Berdeda809572013-02-22 15:31:20 -0800420 }
421
422 @Override
423 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700424 Map<Class<? extends IFloodlightService>,
425 IFloodlightService> m =
426 new HashMap<Class<? extends IFloodlightService>,
427 IFloodlightService>();
428 m.put(INetworkGraphService.class, this);
429 return m;
Pankaj Berdeda809572013-02-22 15:31:20 -0800430 }
431
432 @Override
433 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
434 Collection<Class<? extends IFloodlightService>> l =
435 new ArrayList<Class<? extends IFloodlightService>>();
436 l.add(IFloodlightProviderService.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -0800437 //l.add(IDeviceService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700438 l.add(IDatagridService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700439 l.add(IThreadPoolService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800440 return l;
441 }
442
443 @Override
444 public void init(FloodlightModuleContext context)
445 throws FloodlightModuleException {
Pankaj Berdeda809572013-02-22 15:31:20 -0800446 Map<String, String> configMap = context.getConfigParams(this);
447 String conf = configMap.get(DBConfigFile);
Toshio Koidebfe9b922013-06-18 10:56:05 -0700448 op = new GraphDBOperation(conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800449
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700450 floodlightProvider =
451 context.getServiceImpl(IFloodlightProviderService.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -0800452 //deviceService = context.getServiceImpl(IDeviceService.class);
Pankaj Berde00e90882013-06-10 21:25:05 -0700453 linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700454 threadPool = context.getServiceImpl(IThreadPoolService.class);
455 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700456 datagridService = context.getServiceImpl(IDatagridService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800457
Pankaj Berdeda809572013-02-22 15:31:20 -0800458 devStore = new DeviceStorageImpl();
459 devStore.init(conf);
460
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700461 swStore = new SwitchStorageImpl();
462 swStore.init(conf);
Pankaj Berde00e90882013-06-10 21:25:05 -0700463
464 linkStore = new LinkStorageImpl();
465 linkStore.init(conf);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700466
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700467 log.debug("Initializing NetworkGraphPublisher module with {}", conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800468
469 }
470
471 @Override
472 public void startUp(FloodlightModuleContext context) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700473 Map<String, String> configMap = context.getConfigParams(this);
474 String cleanupNeeded = configMap.get(CleanupEnabled);
475
Jonathan Hartd857ad62013-12-14 18:08:17 -0800476 //deviceService.addListener(this);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700477 floodlightProvider.addOFSwitchListener(this);
Pankaj Berde00e90882013-06-10 21:25:05 -0700478 linkDiscovery.addListener(this);
Pankaj Berde9d6b5072013-04-03 11:51:23 -0700479
480 log.debug("Adding EventListener");
Toshio Koide70ba38b2013-06-13 14:05:05 -0700481 IDBConnection conn = op.getDBConnection();
482 conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700483 // Setup the Cleanup task.
Pankaj Berde99fcee12013-03-18 09:41:53 -0700484 if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700485 ScheduledExecutorService ses = threadPool.getScheduledExecutor();
486 cleanupTask = new SingletonTask(ses, new SwitchCleanup());
Pankaj Berde99fcee12013-03-18 09:41:53 -0700487 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS);
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700488 }
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700489
490 //
491 // NOTE: No need to register with the Datagrid Service,
492 // because we don't need to receive any notifications from it.
493 //
Pankaj Berdeda809572013-02-22 15:31:20 -0800494 }
495
496}