From feeb64e96e1bfbb4d5492ddabcf70e7f43ad4082 Mon Sep 17 00:00:00 2001 From: Kalvin Hom Date: Thu, 13 Jun 2013 18:25:52 -0700 Subject: [PATCH] Add IfNewHostNotify to DeviceManager Small changes so that DeviceManager uses IfNewHostNotify as listener to pass new host info. SimpleForwardingManager app should now function, creating flows and allowing hosts to ping each other. Change-Id: I457696238c9bd14d7b897ef76dbbf8c738578329 Signed-off-by: Kalvin Hom --- .../hosttracker/internal/Activator.java | 11 ++--- .../hosttracker/internal/Device.java | 6 ++- .../internal/DeviceManagerImpl.java | 44 ++++++++++++++++--- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java b/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java index 2cf1c1d6fe..cb02476607 100644 --- a/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java +++ b/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java @@ -14,6 +14,7 @@ import java.util.Hashtable; import org.apache.felix.dm.Component; import org.opendaylight.controller.hosttracker.IDeviceService; import org.opendaylight.controller.hosttracker.IfIptoHost; +import org.opendaylight.controller.hosttracker.IfNewHostNotify; import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; import org.opendaylight.controller.sal.packet.IDataPacketService; import org.opendaylight.controller.sal.packet.IListenDataPacket; @@ -91,6 +92,11 @@ public class Activator extends ComponentActivatorAbstractBase { .setCallbacks("setDataPacketService", "unsetDataPacketService").setRequired(true)); + c.add(createContainerServiceDependency(containerName) + .setService(IfNewHostNotify.class) + .setCallbacks("setNewHostNotify", + "unsetNewHostNotify").setRequired(false)); + // c.add(createContainerServiceDependency(containerName).setService( // IClusterContainerServices.class).setCallbacks( // "setClusterContainerService", @@ -99,11 +105,6 @@ public class Activator extends ComponentActivatorAbstractBase { .setService(ITopologyManager.class) .setCallbacks("setTopologyManager", "unsetTopologyManager") .setRequired(false)); - - c.add(createContainerServiceDependency(containerName) - .setService(IDataPacketService.class) - .setCallbacks("setDataPacketService", - "unsetDataPacketService").setRequired(true)); } } diff --git a/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Device.java b/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Device.java index 50e77ec643..a97cb27383 100755 --- a/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Device.java +++ b/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Device.java @@ -784,10 +784,14 @@ public class Device implements IDevice { public HostNodeConnector toHostNodeConnector() { Integer[] ipv4s = this.getIPv4Addresses(); try { + Entity e = this.entities[this.entities.length-1]; + NodeConnector n = null; + if(e!=null) + n = e.getPort(); InetAddress ip = InetAddress.getByName(ipv4s[ipv4s.length - 1] .toString()); byte[] macAddr = macLongToByte(this.getMACAddress()); - HostNodeConnector nc = new HostNodeConnector(macAddr, ip, null, + HostNodeConnector nc = new HostNodeConnector(macAddr, ip, n, (short) 0); return nc; } catch (Exception e) { diff --git a/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java b/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java index bda1372311..0a70b72575 100755 --- a/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java +++ b/opendaylight/hosttracker_new/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/DeviceManagerImpl.java @@ -67,6 +67,7 @@ import org.opendaylight.controller.hosttracker.IEntityClass; import org.opendaylight.controller.hosttracker.IEntityClassListener; import org.opendaylight.controller.hosttracker.IEntityClassifierService; import org.opendaylight.controller.hosttracker.IfIptoHost; +import org.opendaylight.controller.hosttracker.IfNewHostNotify; import org.opendaylight.controller.hosttracker.SwitchPort; import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; import org.opendaylight.controller.sal.core.Edge; @@ -290,6 +291,10 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener, */ protected ListenerDispatcher deviceListeners; + /** + * Using the IfNewHostNotify to notify listeners of host changes. + */ + private Set newHostNotify = Collections.synchronizedSet(new HashSet()); /** * A device update event to be dispatched */ @@ -429,6 +434,14 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener, // Dependency injection // ******************** + void setNewHostNotify(IfNewHostNotify obj){ + this.newHostNotify.add(obj); + } + + void unsetNewHostNotify(IfNewHostNotify obj){ + this.newHostNotify.remove(obj); + } + void setDataPacketService(IDataPacketService s) { this.dataPacketService = s; } @@ -780,11 +793,11 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener, if (inPkt == null) { return PacketResult.IGNORED; } - try { - throw new Exception("Sample"); - } catch (Exception e) { - logger.error("Sample stack trace", e); - } +// try { +// throw new Exception("Sample"); +// } catch (Exception e) { +// logger.error("Sample stack trace", e); +// } Packet formattedPak = this.dataPacketService.decodeDataPacket(inPkt); Ethernet eth; @@ -1444,9 +1457,28 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener, protected void notifyListeners(List listeners, DeviceUpdate update) { - if (listeners == null) { + if (listeners == null && newHostNotify.isEmpty()) { return; } + /** + * TODO: IfNewHostNotify is needed for current controller API. + * Adding logic so that existing apps (like SimpleForwardingManager) + * work. IDeviceListener adds additional methods and uses IListener's + * callback ordering. The two interfaces need to be merged. + */ + + for (IfNewHostNotify notify : newHostNotify){ + switch (update.change) { + case ADD: + notify.notifyHTClient(update.device.toHostNodeConnector()); + break; + } + } + + /** + * TODO: Remove this section as IDeviceListener functionality gets + * merged with IfNewHostNotify + */ for (IDeviceListener listener : listeners) { switch (update.change) { case ADD: -- 2.36.6