blob: da5a6f421ee3ec8676fa5029033eaae357d7ecfd [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
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()) {
Jonathan Hart8a5d0972013-12-04 10:02:44 -0800245 TopologyElement topologyElementPort =
246 new TopologyElement(sw.getId(), port.getPortNumber());
247 datagridService.notificationSendTopologyElementAdded(topologyElementPort);
248
249 // Allow links to be discovered on this port now that it's
250 // in the database
251 linkDiscovery.RemoveFromSuppressLLDPs(sw.getId(), port.getPortNumber());
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700252 }
Pavlin Radoslavov649c97d2013-11-04 16:00:23 -0800253
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700254 // Add all links that might be connected already
255 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
256 // Add all reverse links as well
257 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
258 links.addAll(reverseLinks);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800259
260 // Publish: add the links
Pavlin Radoslavov0fe70022013-11-02 16:13:12 -0700261 for (Link link : links) {
262 TopologyElement topologyElementLink =
263 new TopologyElement(link.getSrc(),
264 link.getSrcPort(),
265 link.getDst(),
266 link.getDstPort());
267 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
268 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700269 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700270 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800271 }
272
273 @Override
274 public void removedSwitch(IOFSwitch sw) {
Jonathan Hartadc63892013-11-08 14:03:55 -0800275 /*
Naoki Shiota987a5722013-10-23 11:59:36 -0700276 if (registryService.hasControl(sw.getId())) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800277 // Get the affected ports
278 List<Short> ports = swStore.getPorts(HexString.toHexString(sw.getId()));
279 // Get the affected links
280 List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId()));
281 // Get the affected reverse links
282 List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId()));
283 links.addAll(reverseLinks);
284
Naoki Shiota987a5722013-10-23 11:59:36 -0700285 if (swStore.deleteSwitch(sw.getStringId())) {
286 // TODO publish DELETE_SWITCH event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700287 TopologyElement topologyElement =
288 new TopologyElement(sw.getId());
289 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800290
291 // Publish: remove the affected ports
292 for (Short port : ports) {
293 TopologyElement topologyElementPort =
294 new TopologyElement(sw.getId(), port);
295 datagridService.notificationSendTopologyElementRemoved(topologyElementPort);
296 }
297 // Publish: remove the affected links
298 for (Link link : links) {
299 TopologyElement topologyElementLink =
300 new TopologyElement(link.getSrc(),
301 link.getSrcPort(),
302 link.getDst(),
303 link.getDstPort());
304 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
305 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700306 }
307 }
Jonathan Hartadc63892013-11-08 14:03:55 -0800308 */
Pankaj Berdeda809572013-02-22 15:31:20 -0800309 }
310
311 @Override
312 public void switchPortChanged(Long switchId) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700313 // NOTE: Event not needed here. This callback always coincide with add/remove callback.
Pankaj Berdeda809572013-02-22 15:31:20 -0800314 }
315
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700316
317 @Override
318 public void switchPortAdded(Long switchId, OFPhysicalPort port) {
Naoki Shiota987a5722013-10-23 11:59:36 -0700319 if (swStore.addPort(HexString.toHexString(switchId), port)) {
Jonathan Hart8a5d0972013-12-04 10:02:44 -0800320 // Allow links to be discovered on this port now that it's
321 // in the database
322 linkDiscovery.RemoveFromSuppressLLDPs(switchId, port.getPortNumber());
323
Naoki Shiota987a5722013-10-23 11:59:36 -0700324 // TODO publish ADD_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700325 TopologyElement topologyElement =
326 new TopologyElement(switchId, port.getPortNumber());
327 datagridService.notificationSendTopologyElementAdded(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800328
329 // Add all links that might be connected already
330 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
331 // Add all reverse links as well
332 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
333 links.addAll(reverseLinks);
334
335 // Publish: add the links
336 for (Link link : links) {
337 TopologyElement topologyElementLink =
338 new TopologyElement(link.getSrc(),
339 link.getSrcPort(),
340 link.getDst(),
341 link.getDstPort());
342 datagridService.notificationSendTopologyElementAdded(topologyElementLink);
343 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700344 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700345 }
346
347 @Override
348 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800349 // Remove all links that might be connected already
350 List<Link> links = linkStore.getLinks(switchId, port.getPortNumber());
351 // Remove all reverse links as well
352 List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber());
353 links.addAll(reverseLinks);
354
Naoki Shiota987a5722013-10-23 11:59:36 -0700355 if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
356 // TODO publish DELETE_PORT event here
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700357 TopologyElement topologyElement =
358 new TopologyElement(switchId, port.getPortNumber());
359 datagridService.notificationSendTopologyElementRemoved(topologyElement);
Pavlin Radoslavovfb157282013-11-05 08:40:13 -0800360
361 // Publish: remove the links
362 for (Link link : links) {
363 TopologyElement topologyElementLink =
364 new TopologyElement(link.getSrc(),
365 link.getSrcPort(),
366 link.getDst(),
367 link.getDstPort());
368 datagridService.notificationSendTopologyElementRemoved(topologyElementLink);
369 }
Naoki Shiota987a5722013-10-23 11:59:36 -0700370 }
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700371 }
372
Pankaj Berdeda809572013-02-22 15:31:20 -0800373 @Override
374 public String getName() {
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700375 return "NetworkGraphPublisher";
Pankaj Berdeda809572013-02-22 15:31:20 -0800376 }
377
378 @Override
379 public void deviceAdded(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800380 log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
381 devStore.addDevice(device);
Jonathan Hartd3003252013-11-15 09:44:46 -0800382 for (int intIpv4Address : device.getIPv4Addresses()) {
383 datagridService.sendArpRequest(
384 ArpMessage.newReply(InetAddresses.fromInteger(intIpv4Address)));
385 }
Pankaj Berdeda809572013-02-22 15:31:20 -0800386 }
387
388 @Override
389 public void deviceRemoved(IDevice device) {
390 // TODO Auto-generated method stub
Jonathan Hart4fce4ed2013-11-01 21:29:21 -0700391 devStore.removeDevice(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800392 }
393
394 @Override
395 public void deviceMoved(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800396 devStore.changeDeviceAttachments(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800397 }
398
399 @Override
400 public void deviceIPV4AddrChanged(IDevice device) {
Pankaj Berdeda809572013-02-22 15:31:20 -0800401 devStore.changeDeviceIPv4Address(device);
Pankaj Berdeda809572013-02-22 15:31:20 -0800402 }
403
404 @Override
405 public void deviceVlanChanged(IDevice device) {
406 // TODO Auto-generated method stub
407 }
408
409
410 @Override
411 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700412 Collection<Class<? extends IFloodlightService>> l =
413 new ArrayList<Class<? extends IFloodlightService>>();
414 l.add(INetworkGraphService.class);
415 return l;
Pankaj Berdeda809572013-02-22 15:31:20 -0800416 }
417
418 @Override
419 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Pavlin Radoslavov28069402013-10-18 18:43:11 -0700420 Map<Class<? extends IFloodlightService>,
421 IFloodlightService> m =
422 new HashMap<Class<? extends IFloodlightService>,
423 IFloodlightService>();
424 m.put(INetworkGraphService.class, this);
425 return m;
Pankaj Berdeda809572013-02-22 15:31:20 -0800426 }
427
428 @Override
429 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
430 Collection<Class<? extends IFloodlightService>> l =
431 new ArrayList<Class<? extends IFloodlightService>>();
432 l.add(IFloodlightProviderService.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -0800433 //l.add(IDeviceService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700434 l.add(IDatagridService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700435 l.add(IThreadPoolService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800436 return l;
437 }
438
439 @Override
440 public void init(FloodlightModuleContext context)
441 throws FloodlightModuleException {
Pankaj Berdeda809572013-02-22 15:31:20 -0800442 Map<String, String> configMap = context.getConfigParams(this);
443 String conf = configMap.get(DBConfigFile);
Toshio Koidebfe9b922013-06-18 10:56:05 -0700444 op = new GraphDBOperation(conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800445
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700446 floodlightProvider =
447 context.getServiceImpl(IFloodlightProviderService.class);
Jonathan Hartd857ad62013-12-14 18:08:17 -0800448 //deviceService = context.getServiceImpl(IDeviceService.class);
Pankaj Berde00e90882013-06-10 21:25:05 -0700449 linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700450 threadPool = context.getServiceImpl(IThreadPoolService.class);
451 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700452 datagridService = context.getServiceImpl(IDatagridService.class);
Pankaj Berdeda809572013-02-22 15:31:20 -0800453
Pankaj Berdeda809572013-02-22 15:31:20 -0800454 devStore = new DeviceStorageImpl();
455 devStore.init(conf);
456
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700457 swStore = new SwitchStorageImpl();
458 swStore.init(conf);
Pankaj Berde00e90882013-06-10 21:25:05 -0700459
460 linkStore = new LinkStorageImpl();
461 linkStore.init(conf);
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700462
HIGUCHI Yuta155cfc52013-06-14 15:54:16 -0700463 log.debug("Initializing NetworkGraphPublisher module with {}", conf);
Pankaj Berdeda809572013-02-22 15:31:20 -0800464
465 }
466
467 @Override
468 public void startUp(FloodlightModuleContext context) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700469 Map<String, String> configMap = context.getConfigParams(this);
470 String cleanupNeeded = configMap.get(CleanupEnabled);
471
Jonathan Hartd857ad62013-12-14 18:08:17 -0800472 //deviceService.addListener(this);
Pankaj Berde465ac7c2013-05-23 13:47:49 -0700473 floodlightProvider.addOFSwitchListener(this);
Pankaj Berde00e90882013-06-10 21:25:05 -0700474 linkDiscovery.addListener(this);
Pankaj Berde9d6b5072013-04-03 11:51:23 -0700475
476 log.debug("Adding EventListener");
Toshio Koide70ba38b2013-06-13 14:05:05 -0700477 IDBConnection conn = op.getDBConnection();
478 conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
Pankaj Berdef08d5ff2013-03-14 17:03:07 -0700479 // Setup the Cleanup task.
Pankaj Berde99fcee12013-03-18 09:41:53 -0700480 if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700481 ScheduledExecutorService ses = threadPool.getScheduledExecutor();
482 cleanupTask = new SingletonTask(ses, new SwitchCleanup());
Pankaj Berde99fcee12013-03-18 09:41:53 -0700483 cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS);
Pankaj Berde1e3e5ba2013-03-15 13:17:53 -0700484 }
Pavlin Radoslavov8442e492013-10-25 21:54:13 -0700485
486 //
487 // NOTE: No need to register with the Datagrid Service,
488 // because we don't need to receive any notifications from it.
489 //
Pankaj Berdeda809572013-02-22 15:31:20 -0800490 }
491
492}