Formalized HostStore in preparation for separating managers and stores.
diff --git a/core/api/src/main/java/org/onlab/onos/net/host/HostStore.java b/core/api/src/main/java/org/onlab/onos/net/host/HostStore.java
new file mode 100644
index 0000000..cb5ed64
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/host/HostStore.java
@@ -0,0 +1,102 @@
+package org.onlab.onos.net.host;
+
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Host;
+import org.onlab.onos.net.HostId;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+
+import java.util.Set;
+
+/**
+ * Manages inventory of end-station hosts. It may do so using whatever
+ * means are appropriate.
+ */
+public interface HostStore {
+
+ /**
+ * Creates a new host or updates the existing one based on the specified
+ * description.
+ *
+ * @param providerId provider identification
+ * @param hostId host identification
+ * @param hostDescription host description data
+ * @return appropriate event or null if no change resulted
+ */
+ HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
+ HostDescription hostDescription);
+
+ /**
+ * Removes the specified host from the inventory.
+ *
+ * @param hostId host identification
+ * @return remove event or null if host was not found
+ */
+ HostEvent removeHost(HostId hostId);
+
+ /**
+ * Returns the number of hosts in the store.
+ *
+ * @return host count
+ */
+ int getHostCount();
+
+ /**
+ * Returns a collection of all hosts in the store.
+ *
+ * @return iterable collection of all hosts
+ */
+ Iterable<Host> getHosts();
+
+ /**
+ * Returns the host with the specified identifer.
+ *
+ * @param hostId host identification
+ * @return host or null if not found
+ */
+ Host getHost(HostId hostId);
+
+ /**
+ * Returns the set of all hosts within the specified VLAN.
+ *
+ * @param vlanId vlan id
+ * @return set of hosts in the vlan
+ */
+ Set<Host> getHosts(VlanId vlanId);
+
+ /**
+ * Returns the set of hosts with the specified MAC address.
+ *
+ * @param mac mac address
+ * @return set of hosts with the given mac
+ */
+ Set<Host> getHosts(MacAddress mac);
+
+ /**
+ * Returns the set of hosts with the specified IP address.
+ *
+ * @param ip ip address
+ * @return set of hosts with the given IP
+ */
+ Set<Host> getHosts(IpAddress ip);
+
+ /**
+ * Returns the set of hosts whose location falls on the given connection point.
+ *
+ * @param connectPoint connection point
+ * @return set of hosts
+ */
+ Set<Host> getConnectedHosts(ConnectPoint connectPoint);
+
+ /**
+ * Returns the set of hosts whose location falls on the given device.
+ *
+ * @param deviceId infrastructure device identifier
+ * @return set of hosts
+ */
+ Set<Host> getConnectedHosts(DeviceId deviceId);
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/link/LinkStore.java b/core/api/src/main/java/org/onlab/onos/net/link/LinkStore.java
index 3c3c1fb..4391471 100644
--- a/core/api/src/main/java/org/onlab/onos/net/link/LinkStore.java
+++ b/core/api/src/main/java/org/onlab/onos/net/link/LinkStore.java
@@ -8,7 +8,8 @@
import java.util.Set;
/**
- * Manages inventory of infrastructure links using whatever means are appropriate.
+ * Manages inventory of infrastructure links. It may do so using whatever
+ * means are appropriate.
*/
public interface LinkStore {
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
index 3fa9dc2..30c506ff 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
@@ -60,6 +60,7 @@
public void deactivate() {
log.info("Stopped");
}
+
@Override
public int getDeviceCount() {
return devices.size();
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
index 43e06f5..9cf235b 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
@@ -20,6 +20,7 @@
import org.onlab.onos.net.host.HostProviderRegistry;
import org.onlab.onos.net.host.HostProviderService;
import org.onlab.onos.net.host.HostService;
+import org.onlab.onos.net.host.HostStore;
import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.onlab.packet.IpAddress;
@@ -47,7 +48,8 @@
private final AbstractListenerRegistry<HostEvent, HostListener>
listenerRegistry = new AbstractListenerRegistry<>();
- private final SimpleHostStore store = new SimpleHostStore();
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected HostStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java
index f1a64e7..1febb67 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java
@@ -4,6 +4,7 @@
import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED;
import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED;
+import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collections;
import java.util.HashSet;
@@ -11,6 +12,10 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultHost;
import org.onlab.onos.net.DeviceId;
@@ -18,6 +23,7 @@
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.host.HostDescription;
import org.onlab.onos.net.host.HostEvent;
+import org.onlab.onos.net.host.HostStore;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
@@ -26,29 +32,37 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
+import org.slf4j.Logger;
/**
* Manages inventory of end-station hosts using trivial in-memory
* implementation.
*/
-public class SimpleHostStore {
+@Component(immediate = true)
+@Service
+public class SimpleHostStore implements HostStore {
+ private final Logger log = getLogger(getClass());
+
+ // Host inventory
private final Map<HostId, Host> hosts = new ConcurrentHashMap<>();
- // hosts sorted based on their location
+ // Hosts tracked by their location
private final Multimap<ConnectPoint, Host> locations = HashMultimap.create();
- /**
- * Creates a new host or updates the existing one based on the specified
- * description.
- *
- * @param providerId provider identification
- * @param hostId host identification
- * @param hostDescription host description data
- * @return appropriate event or null if no change resulted
- */
- HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
- HostDescription hostDescription) {
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
+ HostDescription hostDescription) {
Host host = hosts.get(hostId);
if (host == null) {
return createHost(providerId, hostId, hostDescription);
@@ -102,13 +116,8 @@
return event;
}
- /**
- * Removes the specified host from the inventory.
- *
- * @param hostId host identification
- * @return remove event or null if host was not found
- */
- HostEvent removeHost(HostId hostId) {
+ @Override
+ public HostEvent removeHost(HostId hostId) {
synchronized (this) {
Host host = hosts.remove(hostId);
if (host != null) {
@@ -119,41 +128,23 @@
}
}
- /**
- * Returns the number of hosts in the store.
- *
- * @return host count
- */
- int getHostCount() {
+ @Override
+ public int getHostCount() {
return hosts.size();
}
- /**
- * Returns a collection of all hosts in the store.
- *
- * @return iterable collection of all hosts
- */
- Iterable<Host> getHosts() {
+ @Override
+ public Iterable<Host> getHosts() {
return Collections.unmodifiableSet(new HashSet<>(hosts.values()));
}
- /**
- * Returns the host with the specified identifer.
- *
- * @param hostId host identification
- * @return host or null if not found
- */
- Host getHost(HostId hostId) {
+ @Override
+ public Host getHost(HostId hostId) {
return hosts.get(hostId);
}
- /**
- * Returns the set of all hosts within the specified VLAN.
- *
- * @param vlanId vlan id
- * @return set of hosts in the vlan
- */
- Set<Host> getHosts(VlanId vlanId) {
+ @Override
+ public Set<Host> getHosts(VlanId vlanId) {
Set<Host> vlanset = new HashSet<>();
for (Host h : hosts.values()) {
if (h.vlan().equals(vlanId)) {
@@ -163,13 +154,8 @@
return vlanset;
}
- /**
- * Returns the set of hosts with the specified MAC address.
- *
- * @param mac mac address
- * @return set of hosts with the given mac
- */
- Set<Host> getHosts(MacAddress mac) {
+ @Override
+ public Set<Host> getHosts(MacAddress mac) {
Set<Host> macset = new HashSet<>();
for (Host h : hosts.values()) {
if (h.mac().equals(mac)) {
@@ -179,13 +165,8 @@
return macset;
}
- /**
- * Returns the set of hosts with the specified IP address.
- *
- * @param ip ip address
- * @return set of hosts with the given IP
- */
- Set<Host> getHosts(IpAddress ip) {
+ @Override
+ public Set<Host> getHosts(IpAddress ip) {
Set<Host> ipset = new HashSet<>();
for (Host h : hosts.values()) {
if (h.ipAddresses().contains(ip)) {
@@ -195,22 +176,12 @@
return ipset;
}
- /**
- * Returns the set of hosts whose location falls on the given connection point.
- *
- * @param connectPoint connection point
- * @return set of hosts
- */
- Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
+ @Override
+ public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
return ImmutableSet.copyOf(locations.get(connectPoint));
}
- /**
- * Returns the set of hosts whose location falls on the given device.
- *
- * @param deviceId infrastructure device identifier
- * @return set of hosts
- */
+ @Override
public Set<Host> getConnectedHosts(DeviceId deviceId) {
Set<Host> hostset = new HashSet<>();
for (ConnectPoint p : locations.keySet()) {
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkStore.java
index 1dd724c..935e5dc 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkStore.java
@@ -3,7 +3,9 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
+import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultLink;
@@ -13,6 +15,7 @@
import org.onlab.onos.net.link.LinkEvent;
import org.onlab.onos.net.link.LinkStore;
import org.onlab.onos.net.provider.ProviderId;
+import org.slf4j.Logger;
import java.util.Collections;
import java.util.HashSet;
@@ -24,6 +27,7 @@
import static org.onlab.onos.net.Link.Type.DIRECT;
import static org.onlab.onos.net.Link.Type.INDIRECT;
import static org.onlab.onos.net.link.LinkEvent.Type.*;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Manages inventory of infrastructure links using trivial in-memory structures
@@ -33,6 +37,8 @@
@Service
public class SimpleLinkStore implements LinkStore {
+ private final Logger log = getLogger(getClass());
+
// Link inventory
private final Map<LinkKey, DefaultLink> links = new ConcurrentHashMap<>();
@@ -40,7 +46,17 @@
private final Multimap<DeviceId, Link> srcLinks = HashMultimap.create();
private final Multimap<DeviceId, Link> dstLinks = HashMultimap.create();
- private static final Set<Link> EMPTY = ImmutableSet.copyOf(new Link[]{});
+ private static final Set<Link> EMPTY = ImmutableSet.of();
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
@Override
public int getLinkCount() {
diff --git a/core/trivial/src/test/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManagerTest.java b/core/trivial/src/test/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManagerTest.java
index 67c14b0..1ee61df 100644
--- a/core/trivial/src/test/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManagerTest.java
+++ b/core/trivial/src/test/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManagerTest.java
@@ -73,6 +73,7 @@
@Before
public void setUp() {
mgr = new SimpleHostManager();
+ mgr.store = new SimpleHostStore();
mgr.eventDispatcher = new TestEventDispatcher();
registry = mgr;
mgr.activate();