blob: 6364a2fe85af8d49777c835ce7eccd52ae1b4d04 [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
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
176 @Override
177 public void linkDiscoveryUpdate(LDUpdate update) {
Pankaj Berde00e90882013-06-10 21:25:05 -0700178 Link lt = new Link(update.getSrc(),update.getSrcPort(),update.getDst(),update.getDstPort());
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200179 //log.debug("{}:LinkDicoveryUpdate(): Updating Link {}",this.getClass(), lt);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700180
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200181 switch (update.getOperation()) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700182 case LINK_REMOVED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200183 log.debug("LinkDiscoveryUpdate(): Removing link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700184
185 if (linkStore.deleteLink(lt)) {
186 // TODO publish DELETE_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700187 TopologyElement topologyElement =
188 new TopologyElement(update.getSrc(),
189 update.getSrcPort(),
190 update.getDst(),
191 update.getDstPort());
192 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700193 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700194 break;
Pankaj Berde00e90882013-06-10 21:25:05 -0700195 case LINK_UPDATED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200196 log.debug("LinkDiscoveryUpdate(): Updating link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700197
Naoki Shiotab2d17e82013-10-18 18:08:16 -0700198 LinkInfo linfo = linkStore.getLinkInfo(lt);
199 // TODO update "linfo" using portState derived using "update"
Naoki Shiota987a5722013-10-23 11:59:36 -0700200 if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) {
201 // TODO publish UPDATE_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700202 //
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);
Naoki Shiota987a5722013-10-23 11:59:36 -0700212 }
Pankaj Berde00e90882013-06-10 21:25:05 -0700213 break;
214 case LINK_ADDED:
Jonathan Harte7c2d2f2013-07-27 18:08:34 +1200215 log.debug("LinkDiscoveryUpdate(): Adding link {}", lt);
Naoki Shiota987a5722013-10-23 11:59:36 -0700216
217 if (linkStore.addLink(lt)) {
218 // TODO publish ADD_LINK event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700219 TopologyElement topologyElement =
220 new TopologyElement(update.getSrc(),
221 update.getSrcPort(),
222 update.getDst(),
223 update.getDstPort());
224 datagridService.notificationSendTopologyElementAdded(topologyElement);
Naoki Shiota987a5722013-10-23 11:59:36 -0700225 }
Pankaj Berde00e90882013-06-10 21:25:05 -0700226 break;
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700227 default:
228 break;
229 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800230
231 }
232
233 @Override
234 public void addedSwitch(IOFSwitch sw) {
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700235 if (registryService.hasControl(sw.getId())) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700236 if (swStore.addSwitch(sw)) {
237 // TODO publish ADD_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700238 TopologyElement topologyElement =
239 new TopologyElement(sw.getId());
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800240 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800241
242 // Publish: add the ports
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700243 // TODO: Add only ports that are UP?
244 for (OFPhysicalPort port : sw.getPorts()) {
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800245 TopologyElement topologyElementPort =
246 new TopologyElement(sw.getId(),
247 port.getPortNumber());
248 datagridService.notificationSendTopologyElementAdded(topologyElementPort);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700249 }
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800250
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700251 // Add all links that might be connected already
252 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
253 // Add all reverse links as well
254 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
255 links.addAll(reverseLinks);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800256
257 // Publish: add the links
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700258 for (Link link : links) {
259 TopologyElement topologyElementLink =
260 new TopologyElement(link.getSrc(),
261 link.getSrcPort(),
262 link.getDst(),
263 link.getDstPort());
264 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
265 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700266 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700267 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800268 }
269
270 @Override
271 public void removedSwitch(IOFSwitch sw) {
Jonathan Hartadc63892013-11-08 14:03:55 -0800272 /*
Naoki Shiota987a5722013-10-23 11:59:36 -0700273 if (registryService.hasControl(sw.getId())) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800274 // Get the affected ports
275 List<Short> ports = swStore.getPorts(HexString.toHexString(sw.getId()));
276 // Get the affected links
277 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
278 // Get the affected reverse links
279 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
280 links.addAll(reverseLinks);
281
Naoki Shiota987a5722013-10-23 11:59:36 -0700282 if (swStore.deleteSwitch(sw.getStringId())) {
283 // TODO publish DELETE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700284 TopologyElement topologyElement =
285 new TopologyElement(sw.getId());
286 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800287
288 // Publish: remove the affected ports
289 for (Short port : ports) {
290 TopologyElement topologyElementPort =
291 new TopologyElement(sw.getId(), port);
292 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
293 }
294 // Publish: remove the affected links
295 for (Link link : links) {
296 TopologyElement topologyElementLink =
297 new TopologyElement(link.getSrc(),
298 link.getSrcPort(),
299 link.getDst(),
300 link.getDstPort());
301 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
302 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700303 }
304 }
Jonathan Hartadc63892013-11-08 14:03:55 -0800305 */
Pankaj Berdeda809572013-02-22 15:31:20 -0800306 }
307
308 @Override
309 public void switchPortChanged(Long switchId) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700310 // NOTE: Event not needed here. This callback always coincide with add/remove callback.
Pankaj Berdeda809572013-02-22 15:31:20 -0800311 }
312
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700313
314 @Override
315 public void switchPortAdded(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700316 if (swStore.addPort(HexString.toHexString(switchId), port)) {
317 // TODO publish ADD_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700318 TopologyElement topologyElement =
319 new TopologyElement(switchId, port.getPortNumber());
320 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800321
322 // Add all links that might be connected already
323 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
324 // Add all reverse links as well
325 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
326 links.addAll(reverseLinks);
327
328 // Publish: add the links
329 for (Link link : links) {
330 TopologyElement topologyElementLink =
331 new TopologyElement(link.getSrc(),
332 link.getSrcPort(),
333 link.getDst(),
334 link.getDstPort());
335 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
336 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700337 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700338 }
339
340 @Override
341 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800342 // Remove all links that might be connected already
343 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
344 // Remove all reverse links as well
345 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
346 links.addAll(reverseLinks);
347
Naoki Shiota987a5722013-10-23 11:59:36 -0700348 if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
349 // TODO publish DELETE_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700350 TopologyElement topologyElement =
351 new TopologyElement(switchId, port.getPortNumber());
352 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800353
354 // Publish: remove the links
355 for (Link link : links) {
356 TopologyElement topologyElementLink =
357 new TopologyElement(link.getSrc(),
358 link.getSrcPort(),
359 link.getDst(),
360 link.getDstPort());
361 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
362 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700363 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700364 }
365
Pankaj Berdeda809572013-02-22 15:31:20 -0800366 @Override
367 public String getName() {
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700368 return "NetworkGraphPublisher";
Pankaj Berdeda809572013-02-22 15:31:20 -0800369 }
370
371 @Override
372 public void deviceAdded(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800373 log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
374 devStore.addDevice(device);
375 }
376
377 @Override
378 public void deviceRemoved(IDevice device) {
379 // TODO Auto-generated method stub
Jonathan Hart4fce4ed2013-11-01 21:29:21 -0700380 devStore.removeDevice(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800381 }
382
383 @Override
384 public void deviceMoved(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800385 devStore.changeDeviceAttachments(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800386 }
387
388 @Override
389 public void deviceIPV4AddrChanged(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800390 devStore.changeDeviceIPv4Address(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800391 }
392
393 @Override
394 public void deviceVlanChanged(IDevice device) {
395 // TODO Auto-generated method stub
396 }
397
398
399 @Override
400 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700401 Collection<Class<? extends IFloodlightService>> l =
402 new ArrayList<Class<? extends IFloodlightService>>();
403 l.add(INetworkGraphService.class);
404 return l;
Pankaj Berdeda809572013-02-22 15:31:20 -0800405 }
406
407 @Override
408 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700409 Map<Class<? extends IFloodlightService>,
410 IFloodlightService> m =
411 new HashMap<Class<? extends IFloodlightService>,
412 IFloodlightService>();
413 m.put(INetworkGraphService.class, this);
414 return m;
Pankaj Berdeda809572013-02-22 15:31:20 -0800415 }
416
417 @Override
418 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
419 Collection<Class<? extends IFloodlightService>> l =
420 new ArrayList<Class<? extends IFloodlightService>>();
421 l.add(IFloodlightProviderService.class);
422 l.add(IDeviceService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700423 l.add(IDatagridService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700424 l.add(IThreadPoolService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800425 return l;
426 }
427
428 @Override
429 public void init(FloodlightModuleContext context)
430 throws FloodlightModuleException {
Pankaj Berdeda809572013-02-22 15:31:20 -0800431 Map<String, String> configMap = context.getConfigParams(this);
432 String conf = configMap.get(DBConfigFile);
Toshio Koidebfe9b922013-06-18 10:56:05 -0700433 op = new GraphDBOperation(conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800434
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700435 floodlightProvider =
436 context.getServiceImpl(IFloodlightProviderService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800437 deviceService = context.getServiceImpl(IDeviceService.class);
Pankaj Berde00e90882013-06-10 21:25:05 -0700438 linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700439 threadPool = context.getServiceImpl(IThreadPoolService.class);
440 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700441 datagridService = context.getServiceImpl(IDatagridService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800442
Pankaj Berdeda809572013-02-22 15:31:20 -0800443 devStore = new DeviceStorageImpl();
444 devStore.init(conf);
445
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700446 swStore = new SwitchStorageImpl();
447 swStore.init(conf);
Pankaj Berde00e90882013-06-10 21:25:05 -0700448
449 linkStore = new LinkStorageImpl();
450 linkStore.init(conf);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700451
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700452 log.debug("Initializing NetworkGraphPublisher module with {}", conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800453
454 }
455
456 @Override
457 public void startUp(FloodlightModuleContext context) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700458 Map<String, String> configMap = context.getConfigParams(this);
459 String cleanupNeeded = configMap.get(CleanupEnabled);
460
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700461 deviceService.addListener(this);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700462 floodlightProvider.addOFSwitchListener(this);
Pankaj Berde00e90882013-06-10 21:25:05 -0700463 linkDiscovery.addListener(this);
Pankaj Berde9d6b5072013-04-03 11:51:23 -0700464
465 log.debug("Adding EventListener");
Toshio Koide70ba38b2013-06-13 14:05:05 -0700466 IDBConnection conn = op.getDBConnection();
467 conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700468 // Setup the Cleanup task.
Pankaj Berde99fcee12013-03-18 09:41:53 -0700469 if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700470 ScheduledExecutorService ses = threadPool.getScheduledExecutor();
471 cleanupTask = new SingletonTask(ses, new SwitchCleanup());
Pankaj Berde99fcee12013-03-18 09:41:53 -0700472 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS);
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700473 }
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700474
475 //
476 // NOTE: No need to register with the Datagrid Service,
477 // because we don't need to receive any notifications from it.
478 //
Pankaj Berdeda809572013-02-22 15:31:20 -0800479 }
480
481}