From a22e44963c31452b6ea17745b652456b8b991101 Mon Sep 17 00:00:00 2001 From: Gabriel Robitaille-Montpetit Date: Thu, 31 Jul 2014 15:59:52 -0400 Subject: [PATCH] Added hosttracker shell for karaf (rebased) Change-Id: I6c8eec9fddcd1a7d82e12e27f232fdaad65607b2 Signed-off-by: Gabriel Robitaille-Montpetit --- features/nsf/src/main/resources/features.xml | 1 + opendaylight/commons/opendaylight/pom.xml | 1 + .../hosttracker/IHostTrackerShell.java | 9 ++++ .../hosttracker/internal/Activator.java | 2 + .../hosttracker/internal/HostTracker.java | 23 +++++++- opendaylight/hosttracker/shell/pom.xml | 52 +++++++++++++++++++ .../shell/DumpFailedARPReqList.java | 28 ++++++++++ .../shell/DumpPendingARPReqList.java | 28 ++++++++++ .../OSGI-INF/blueprint/blueprint.xml | 17 ++++++ .../shell/HostTrackerShellTest.java | 47 +++++++++++++++++ 10 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 opendaylight/hosttracker/api/src/main/java/org/opendaylight/controller/hosttracker/IHostTrackerShell.java create mode 100644 opendaylight/hosttracker/shell/pom.xml create mode 100644 opendaylight/hosttracker/shell/src/main/java/org/opendaylight/controller/hosttracker/shell/DumpFailedARPReqList.java create mode 100644 opendaylight/hosttracker/shell/src/main/java/org/opendaylight/controller/hosttracker/shell/DumpPendingARPReqList.java create mode 100644 opendaylight/hosttracker/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 opendaylight/hosttracker/shell/src/test/java/org/opendaylight/controller/hosttracker/shell/HostTrackerShellTest.java diff --git a/features/nsf/src/main/resources/features.xml b/features/nsf/src/main/resources/features.xml index fb61f33fb3..cc3e274ef9 100644 --- a/features/nsf/src/main/resources/features.xml +++ b/features/nsf/src/main/resources/features.xml @@ -40,6 +40,7 @@ mvn:org.opendaylight.controller/hosttracker/${hosttracker.api.version} mvn:org.opendaylight.controller/hosttracker.implementation/${hosttracker.implementation.version} + mvn:org.opendaylight.controller/hosttracker.shell/${hosttracker.shell.version} mvn:org.opendaylight.controller/forwarding.staticrouting diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index be88e4a505..c21ed78064 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -95,6 +95,7 @@ 0.5.2-SNAPSHOT 0.5.2-SNAPSHOT 0.4.2-SNAPSHOT + 1.0.0-SNAPSHOT 0.4.2-SNAPSHOT 0.4.2-SNAPSHOT 0.0.2-SNAPSHOT diff --git a/opendaylight/hosttracker/api/src/main/java/org/opendaylight/controller/hosttracker/IHostTrackerShell.java b/opendaylight/hosttracker/api/src/main/java/org/opendaylight/controller/hosttracker/IHostTrackerShell.java new file mode 100644 index 0000000000..5d11be4826 --- /dev/null +++ b/opendaylight/hosttracker/api/src/main/java/org/opendaylight/controller/hosttracker/IHostTrackerShell.java @@ -0,0 +1,9 @@ +package org.opendaylight.controller.hosttracker; + +import java.util.List; + +public interface IHostTrackerShell{ + + public List dumpPendingArpReqList(); + public List dumpFailedArpReqList(); +} \ No newline at end of file diff --git a/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java b/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java index 825b2453aa..7e527712b1 100644 --- a/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java +++ b/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java @@ -16,6 +16,7 @@ import java.util.Set; import org.apache.felix.dm.Component; import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterContainerServices; +import org.opendaylight.controller.hosttracker.IHostTrackerShell; import org.opendaylight.controller.hosttracker.IfHostListener; import org.opendaylight.controller.hosttracker.IfIptoHost; import org.opendaylight.controller.hosttracker.IfNewHostNotify; @@ -78,6 +79,7 @@ public class Activator extends ComponentActivatorAbstractBase { IInventoryListener.class.getName(), IfIptoHost.class.getName(), IfHostListener.class.getName(), + IHostTrackerShell.class.getName(), ITopologyManagerAware.class.getName(), ICacheUpdateAware.class.getName() }, props); diff --git a/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java b/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java index ce49b599e1..f728b35bbf 100644 --- a/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java +++ b/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java @@ -39,6 +39,7 @@ import org.opendaylight.controller.clustering.services.IClusterContainerServices import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.hosttracker.HostIdFactory; import org.opendaylight.controller.hosttracker.IHostId; +import org.opendaylight.controller.hosttracker.IHostTrackerShell; import org.opendaylight.controller.hosttracker.IPHostId; import org.opendaylight.controller.hosttracker.IPMacHostId; import org.opendaylight.controller.hosttracker.IfHostListener; @@ -100,7 +101,7 @@ import org.slf4j.LoggerFactory; * */ -public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAware, IInventoryListener, +public class HostTracker implements IfIptoHost, IfHostListener, IHostTrackerShell, ISwitchManagerAware, IInventoryListener, ITopologyManagerAware, ICacheUpdateAware, CommandProvider { static final String ACTIVE_HOST_CACHE = "hosttracker.ActiveHosts"; static final String INACTIVE_HOST_CACHE = "hosttracker.InactiveHosts"; @@ -1618,4 +1619,24 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw IHostId id = HostIdFactory.create(addr, null); return getHostNetworkHierarchy(id); } + + @Override + public List dumpPendingArpReqList() { + ARPPending arphost; + List arpReq = new ArrayList(); + for (Entry entry : ARPPendingList.entrySet()) { + arpReq.add(entry.getValue().getHostId().toString()); + } + return arpReq; + } + + @Override + public List dumpFailedArpReqList() { + ARPPending arphost; + List arpReq = new ArrayList(); + for (Entry entry : failedARPReqList.entrySet()) { + arpReq.add(entry.getValue().getHostId().toString()); + } + return arpReq; + } } diff --git a/opendaylight/hosttracker/shell/pom.xml b/opendaylight/hosttracker/shell/pom.xml new file mode 100644 index 0000000000..3f73303180 --- /dev/null +++ b/opendaylight/hosttracker/shell/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + org.opendaylight.controller + commons.opendaylight + 1.4.2-SNAPSHOT + ../../commons/opendaylight + + hosttracker.shell + ${hosttracker.shell.version} + bundle + + + junit + junit + + + org.apache.karaf.shell + org.apache.karaf.shell.console + 3.0.0 + + + org.mockito + mockito-all + + + org.opendaylight.controller + hosttracker.implementation + ${hosttracker.implementation.version} + + + + + + + org.apache.felix + maven-bundle-plugin + ${bundle.plugin.version} + + + org.apache.felix.service.command, + org.apache.karaf.shell.commands, + org.apache.karaf.shell.console, + * + + + + + + + diff --git a/opendaylight/hosttracker/shell/src/main/java/org/opendaylight/controller/hosttracker/shell/DumpFailedARPReqList.java b/opendaylight/hosttracker/shell/src/main/java/org/opendaylight/controller/hosttracker/shell/DumpFailedARPReqList.java new file mode 100644 index 0000000000..ec9971f3c8 --- /dev/null +++ b/opendaylight/hosttracker/shell/src/main/java/org/opendaylight/controller/hosttracker/shell/DumpFailedARPReqList.java @@ -0,0 +1,28 @@ +package org.opendaylight.controller.hosttracker.shell; +/** +* Copyright (c) 2014 Inocybe Technologies, and others. All rights reserved. +* +* This program and the accompanying materials are made available under the +* terms of the Eclipse Public License v1.0 which accompanies this distribution, +* and is available at http://www.eclipse.org/legal/epl-v10.html +*/ + +import org.apache.felix.gogo.commands.Command; +import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.opendaylight.controller.hosttracker.IHostTrackerShell; + +@Command(scope = "hosttracker", name = "dumpFailedARPReqList", description="Display the dump failed ARPReqList") +public class DumpFailedARPReqList extends OsgiCommandSupport{ + + private IHostTrackerShell hostTracker; + + @Override + protected Object doExecute() throws Exception { + System.out.print(hostTracker.dumpFailedArpReqList()); + return null; + } + + public void setHostTracker(IHostTrackerShell hostTracker){ + this.hostTracker = hostTracker; + } +} diff --git a/opendaylight/hosttracker/shell/src/main/java/org/opendaylight/controller/hosttracker/shell/DumpPendingARPReqList.java b/opendaylight/hosttracker/shell/src/main/java/org/opendaylight/controller/hosttracker/shell/DumpPendingARPReqList.java new file mode 100644 index 0000000000..7f52a55bd1 --- /dev/null +++ b/opendaylight/hosttracker/shell/src/main/java/org/opendaylight/controller/hosttracker/shell/DumpPendingARPReqList.java @@ -0,0 +1,28 @@ +package org.opendaylight.controller.hosttracker.shell; +/** +* Copyright (c) 2014 Inocybe Technologies, and others. All rights reserved. +* +* This program and the accompanying materials are made available under the +* terms of the Eclipse Public License v1.0 which accompanies this distribution, +* and is available at http://www.eclipse.org/legal/epl-v10.html +*/ + +import org.apache.felix.gogo.commands.Command; +import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.opendaylight.controller.hosttracker.IHostTrackerShell; + +@Command(scope = "hosttracker", name = "dumpPendingARPReqList", description="Display the dump pending ARPReqList") +public class DumpPendingARPReqList extends OsgiCommandSupport{ + + private IHostTrackerShell hostTracker; + + @Override + protected Object doExecute() throws Exception { + System.out.print(hostTracker.dumpPendingArpReqList()); + return null; + } + + public void setHostTracker(IHostTrackerShell hostTracker){ + this.hostTracker = hostTracker; + } +} \ No newline at end of file diff --git a/opendaylight/hosttracker/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/opendaylight/hosttracker/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000000..ba79b5d8c5 --- /dev/null +++ b/opendaylight/hosttracker/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/opendaylight/hosttracker/shell/src/test/java/org/opendaylight/controller/hosttracker/shell/HostTrackerShellTest.java b/opendaylight/hosttracker/shell/src/test/java/org/opendaylight/controller/hosttracker/shell/HostTrackerShellTest.java new file mode 100644 index 0000000000..a0a5a2e610 --- /dev/null +++ b/opendaylight/hosttracker/shell/src/test/java/org/opendaylight/controller/hosttracker/shell/HostTrackerShellTest.java @@ -0,0 +1,47 @@ +package org.opendaylight.controller.hosttracker.shell; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import org.opendaylight.controller.hosttracker.IHostTrackerShell; + +public class HostTrackerShellTest { + + private final long COMMAND_TIMEOUT = 1000; + private IHostTrackerShell hostTracker; + + @Test + public void testDumpPendingARPReqList() throws Exception { + DumpPendingARPReqList dumpPendTest = new DumpPendingARPReqList(); + hostTracker = mock(IHostTrackerShell.class); + List failedList = new ArrayList(Arrays.asList("a", "b", "c")); + when(hostTracker.dumpPendingArpReqList()).thenReturn(failedList); + dumpPendTest.setHostTracker(hostTracker); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos)); + dumpPendTest.doExecute(); + //Assert.assertTrue(true); + Assert.assertEquals("[a, b, c]", baos.toString()); + } + + @Test + public void testDumpFailedARPReqList() throws Exception { + DumpFailedARPReqList dumpFailTest = new DumpFailedARPReqList(); + hostTracker = mock(IHostTrackerShell.class); + List failedList = new ArrayList(Arrays.asList("a", "b", "c")); + when(hostTracker.dumpFailedArpReqList()).thenReturn(failedList); + dumpFailTest.setHostTracker(hostTracker); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos)); + dumpFailTest.doExecute(); + //Assert.assertTrue(true); + Assert.assertEquals("[a, b, c]", baos.toString()); + } +} -- 2.36.6