From c90c2ca43006e023005a5dddbbb477f80329e45c Mon Sep 17 00:00:00 2001 From: Kalvin Hom Date: Thu, 13 Jun 2013 14:12:31 -0700 Subject: [PATCH] HostTracker Fixes Fixes the following: Hosts not being added due to SwitchManager not being set and NullPointerException Conversion added from Device to HostNodeConnector REST Service nb/v2/host/default will show hosts Known problems still need fixing: - hosts cannot ping each other. - When mininet is already running and switches are there, startup for controller is fine. If controller already running, then mininet started and new switches added, controller is throwing errors. - GUI isn't showing hosts in the diagram. Change-Id: I16290feb269f4bfff8bb0f28e9d5601f0d9b1386 Signed-off-by: Kalvin Hom --- opendaylight/hosttracker_new/api/pom.xml | 4 +- .../controller/hosttracker/IDevice.java | 4 + .../hosttracker_new/implementation/pom.xml | 2 +- .../hosttracker/internal/Activator.java | 9 ++- .../hosttracker/internal/Device.java | 24 ++++++ .../internal/DeviceManagerImpl.java | 81 ++++++++++++++++++- .../src/test/resources/logback.xml | 13 +++ 7 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 opendaylight/hosttracker_new/implementation/src/test/resources/logback.xml diff --git a/opendaylight/hosttracker_new/api/pom.xml b/opendaylight/hosttracker_new/api/pom.xml index a4c2f2ecdf..6a98c71e6a 100644 --- a/opendaylight/hosttracker_new/api/pom.xml +++ b/opendaylight/hosttracker_new/api/pom.xml @@ -22,8 +22,8 @@ - org.opendaylight.controller.hosttracker_new, - org.opendaylight.controller.hosttracker_new.hostAware + org.opendaylight.controller.hosttracker, + org.opendaylight.controller.hosttracker.hostAware org.opendaylight.controller.sal.core, diff --git a/opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/IDevice.java b/opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/IDevice.java index d9cd3f18fb..b2ba643a0c 100644 --- a/opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/IDevice.java +++ b/opendaylight/hosttracker_new/api/src/main/java/org/opendaylight/controller/hosttracker/IDevice.java @@ -35,6 +35,8 @@ package org.opendaylight.controller.hosttracker; import java.util.Date; +import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; + /** * Represents an independent device on the network. A device consists of a set * of entities, and all the information known about a given device comes only @@ -132,4 +134,6 @@ public interface IDevice { */ public IEntityClass getEntityClass(); + public HostNodeConnector toHostNodeConnector(); + } diff --git a/opendaylight/hosttracker_new/implementation/pom.xml b/opendaylight/hosttracker_new/implementation/pom.xml index 0201fd87e4..804f5e3638 100644 --- a/opendaylight/hosttracker_new/implementation/pom.xml +++ b/opendaylight/hosttracker_new/implementation/pom.xml @@ -52,7 +52,7 @@ org.opendaylight.controller.sal.packet.address, org.opendaylight.controller.switchmanager, org.opendaylight.controller.clustering.services, - org.opendaylight.controller.hosttracker_new.hostAware, + org.opendaylight.controller.hosttracker.hostAware, javax.xml.bind.annotation, javax.xml.bind, org.apache.felix.dm, 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 631a65ae12..2cf1c1d6fe 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 @@ -13,6 +13,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.sal.core.ComponentActivatorAbstractBase; import org.opendaylight.controller.sal.packet.IDataPacketService; import org.opendaylight.controller.sal.packet.IListenDataPacket; @@ -74,9 +75,11 @@ public class Activator extends ComponentActivatorAbstractBase { Dictionary props = new Hashtable(); props.put("salListenerName", "devicemanager"); - c.setInterface(new String[] { IDeviceService.class.getName(), - IListenDataPacket.class.getName(), - ITopologyManagerAware.class.getName() }, props); + c.setInterface( + new String[] { IDeviceService.class.getName(), + IfIptoHost.class.getName(), + IListenDataPacket.class.getName(), + ITopologyManagerAware.class.getName() }, props); c.add(createContainerServiceDependency(containerName) .setService(ISwitchManager.class) 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 90911fe152..50e77ec643 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 @@ -33,6 +33,7 @@ package org.opendaylight.controller.hosttracker.internal; +import java.net.InetAddress; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -51,6 +52,7 @@ import org.opendaylight.controller.hosttracker.IDeviceService.DeviceField; import org.opendaylight.controller.hosttracker.IEntityClass; import org.opendaylight.controller.hosttracker.SwitchPort; import org.opendaylight.controller.hosttracker.SwitchPort.ErrorStatus; +import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.utils.HexEncode; import org.slf4j.Logger; @@ -779,6 +781,28 @@ public class Device implements IDevice { return true; } + public HostNodeConnector toHostNodeConnector() { + Integer[] ipv4s = this.getIPv4Addresses(); + try { + InetAddress ip = InetAddress.getByName(ipv4s[ipv4s.length - 1] + .toString()); + byte[] macAddr = macLongToByte(this.getMACAddress()); + HostNodeConnector nc = new HostNodeConnector(macAddr, ip, null, + (short) 0); + return nc; + } catch (Exception e) { + return null; + } + } + + private byte[] macLongToByte(long mac) { + byte[] macAddr = new byte[6]; + for (int i = 0; i < 6; i++) { + macAddr[5 - i] = (byte) (mac >> (8 * i)); + } + return macAddr; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); 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 8435a94f58..bda1372311 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 @@ -37,6 +37,7 @@ import static org.opendaylight.controller.hosttracker.internal.DeviceManagerImpl import static org.opendaylight.controller.hosttracker.internal.DeviceManagerImpl.DeviceUpdate.Change.CHANGE; import static org.opendaylight.controller.hosttracker.internal.DeviceManagerImpl.DeviceUpdate.Change.DELETE; +import java.net.InetAddress; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -54,6 +55,7 @@ import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -64,7 +66,9 @@ import org.opendaylight.controller.hosttracker.IDeviceService; 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.SwitchPort; +import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; import org.opendaylight.controller.sal.core.Edge; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType; @@ -79,6 +83,7 @@ import org.opendaylight.controller.sal.topology.TopoEdgeUpdate; import org.opendaylight.controller.sal.utils.ListenerDispatcher; import org.opendaylight.controller.sal.utils.MultiIterator; import org.opendaylight.controller.sal.utils.SingletonTask; +import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.switchmanager.ISwitchManager; import org.opendaylight.controller.topologymanager.ITopologyManager; import org.opendaylight.controller.topologymanager.ITopologyManagerAware; @@ -93,7 +98,7 @@ import org.slf4j.LoggerFactory; * @author readams */ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener, - IListenDataPacket, ITopologyManagerAware { + IListenDataPacket, ITopologyManagerAware, IfIptoHost { protected static Logger logger = LoggerFactory .getLogger(DeviceManagerImpl.class); @@ -534,6 +539,18 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener, // IDeviceManagerService // ********************* + void setSwitchManager(ISwitchManager s) { + logger.debug("SwitchManager set"); + this.switchManager = s; + } + + void unsetSwitchManager(ISwitchManager s) { + if (this.switchManager == s) { + logger.debug("SwitchManager removed!"); + this.switchManager = null; + } + } + @Override public IDevice getDevice(Long deviceKey) { return deviceMap.get(deviceKey); @@ -2043,6 +2060,68 @@ public class DeviceManagerImpl implements IDeviceService, IEntityClassListener, */ } + @Override + public HostNodeConnector hostFind(InetAddress networkAddress) { + // TODO Auto-generated method stub + return null; + } + + @Override + public HostNodeConnector hostQuery(InetAddress networkAddress) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Future discoverHost(InetAddress networkAddress) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List> getHostNetworkHierarchy(InetAddress hostAddress) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Set getAllHosts() { + Collection devices = Collections + .unmodifiableCollection(deviceMap.values()); + Iterator i = devices.iterator(); + Set nc = new HashSet(); + while (i.hasNext()) { + Device device = i.next(); + nc.add(device.toHostNodeConnector()); + } + return nc; + } + + @Override + public Set getActiveStaticHosts() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Set getInactiveStaticHosts() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Status addStaticHost(String networkAddress, String dataLayerAddress, + NodeConnector nc, String vlan) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Status removeStaticHost(String networkAddress) { + // TODO Auto-generated method stub + return null; + } + /** * For testing: consolidate the store NOW */ diff --git a/opendaylight/hosttracker_new/implementation/src/test/resources/logback.xml b/opendaylight/hosttracker_new/implementation/src/test/resources/logback.xml new file mode 100644 index 0000000000..5fa21fecfc --- /dev/null +++ b/opendaylight/hosttracker_new/implementation/src/test/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + -- 2.36.6