Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
diff --git a/cli/pom.xml b/cli/pom.xml
index 80e173d..cc1d9dd 100644
--- a/cli/pom.xml
+++ b/cli/pom.xml
@@ -23,6 +23,10 @@
<artifactId>onos-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onlab-osgi</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
diff --git a/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java b/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
index e4f87ee..184a7e6 100644
--- a/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
@@ -1,8 +1,8 @@
package org.onlab.onos.cli;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
+import org.onlab.osgi.DefaultServiceDirectory;
+import org.onlab.osgi.ServiceNotFoundException;
/**
* Base abstraction of Karaf shell commands.
@@ -15,10 +15,10 @@
* @param serviceClass service class
* @param <T> type of service
* @return service implementation
+ * @throws org.onlab.osgi.ServiceNotFoundException if service is unavailable
*/
public static <T> T get(Class<T> serviceClass) {
- BundleContext bc = FrameworkUtil.getBundle(AbstractShellCommand.class).getBundleContext();
- return bc.getService(bc.getServiceReference(serviceClass));
+ return DefaultServiceDirectory.getService(serviceClass);
}
/**
@@ -27,7 +27,7 @@
* @param format format string; see {@link String#format}
* @param args arguments
*/
- public static void print(String format, Object... args) {
+ public void print(String format, Object... args) {
System.out.println(String.format(format, args));
}
@@ -37,8 +37,23 @@
* @param format format string; see {@link String#format}
* @param args arguments
*/
- public static void error(String format, Object... args) {
+ public void error(String format, Object... args) {
System.err.println(String.format(format, args));
}
+ /**
+ * Executes this command.
+ */
+ protected abstract void execute();
+
+ @Override
+ protected Object doExecute() throws Exception {
+ try {
+ execute();
+ } catch (ServiceNotFoundException e) {
+ error(e.getMessage());
+ }
+ return null;
+ }
+
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java b/cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java
index 1057d6e..1e921b4 100644
--- a/cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java
@@ -29,8 +29,8 @@
};
@Override
- protected Object doExecute() throws Exception {
- ClusterService service = getService(ClusterService.class);
+ protected void execute() {
+ ClusterService service = get(ClusterService.class);
List<ControllerNode> nodes = newArrayList(service.getNodes());
Collections.sort(nodes, ID_COMPARATOR);
ControllerNode self = service.getLocalNode();
@@ -39,7 +39,6 @@
service.getState(node.id()),
node.equals(self) ? "*" : "");
}
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
index a6f3048..f0217de 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
@@ -31,7 +31,7 @@
};
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
int cid = Integer.parseInt(id);
init();
TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
@@ -44,8 +44,6 @@
print("%s", deviceId);
}
}
-
- return null;
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java
index be5105c..2bbfb46 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java
@@ -20,7 +20,7 @@
String id = null;
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
int cid = Integer.parseInt(id);
init();
TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
@@ -31,7 +31,6 @@
print(linkString(link));
}
}
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
index 6bd444a..fe67348 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
@@ -27,7 +27,7 @@
};
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
init();
List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
Collections.sort(clusters, ID_COMPARATOR);
@@ -35,7 +35,6 @@
for (TopologyCluster cluster : clusters) {
print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount());
}
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
index 8750424..e62fe56 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
@@ -35,8 +35,8 @@
};
@Override
- protected Object doExecute() throws Exception {
- DeviceService service = getService(DeviceService.class);
+ protected void execute() {
+ DeviceService service = get(DeviceService.class);
if (uri == null) {
for (Device device : getSortedDevices(service)) {
printDevice(service, device);
@@ -49,7 +49,6 @@
printDevice(service, device);
}
}
- return null;
}
@Override
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
index b4f2385..564d1ea 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
@@ -18,9 +18,8 @@
String uri = null;
@Override
- protected Object doExecute() throws Exception {
- getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri));
- return null;
+ protected void execute() {
+ get(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri));
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
index 32da169..60a203a 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
@@ -23,11 +23,10 @@
String role = null;
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
- getService(DeviceAdminService.class).setRole(DeviceId.deviceId(uri),
+ get(DeviceAdminService.class).setRole(DeviceId.deviceId(uri),
mastershipRole);
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
index 9a90ef2..be102f2 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
@@ -29,12 +29,11 @@
};
@Override
- protected Object doExecute() throws Exception {
- DeviceService service = getService(DeviceService.class);
+ protected void execute() {
+ DeviceService service = get(DeviceService.class);
for (Device device : getSortedDevices(service)) {
printDevice(service, device);
}
- return null;
}
/**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
index 07d15e2..c2ca416 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
@@ -34,14 +34,13 @@
};
@Override
- protected Object doExecute() throws Exception {
- DeviceService deviceService = getService(DeviceService.class);
- FlowRuleService service = getService(FlowRuleService.class);
+ protected void execute() {
+ DeviceService deviceService = get(DeviceService.class);
+ FlowRuleService service = get(FlowRuleService.class);
Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service);
for (Device d : deviceService.getDevices()) {
printFlows(d, flows.get(d));
}
- return null;
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
index 47aa688..29919a8 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
@@ -29,12 +29,11 @@
};
@Override
- protected Object doExecute() throws Exception {
- HostService service = getService(HostService.class);
+ protected void execute() {
+ HostService service = get(HostService.class);
for (Host host : getSortedHosts(service)) {
printHost(host);
}
- return null;
}
/**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
index d74f9e4..4361bd7 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
@@ -23,14 +23,13 @@
String uri = null;
@Override
- protected Object doExecute() throws Exception {
- LinkService service = getService(LinkService.class);
+ protected void execute() {
+ LinkService service = get(LinkService.class);
Iterable<Link> links = uri != null ?
service.getDeviceLinks(deviceId(uri)) : service.getLinks();
for (Link link : links) {
print(linkString(link));
}
- return null;
}
/**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/PathListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/PathListCommand.java
index cdede0b..8bb808a 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/PathListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/PathListCommand.java
@@ -29,13 +29,12 @@
String dst = null;
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
init();
Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst));
for (Path path : paths) {
print(pathString(path));
}
- return null;
}
/**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
index 6c141ae..5c8310f 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
@@ -23,16 +23,15 @@
* Initializes the context for all cluster commands.
*/
protected void init() {
- service = getService(TopologyService.class);
+ service = get(TopologyService.class);
topology = service.currentTopology();
}
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
init();
print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(),
topology.clusterCount(), topology.pathCount());
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java
index 51a0fce..d0e6a70 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java
@@ -16,7 +16,7 @@
public class WipeOutCommand extends ClustersListCommand {
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
DeviceService deviceService = get(DeviceService.class);
for (Device device : deviceService.getDevices()) {
@@ -28,7 +28,6 @@
for (Host host : hostService.getHosts()) {
hostAdminService.removeHost(host.id());
}
- return null;
}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipProvider.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipProvider.java
new file mode 100644
index 0000000..01d91d6
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipProvider.java
@@ -0,0 +1,13 @@
+package org.onlab.onos.cluster;
+
+import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.net.provider.Provider;
+
+/**
+ * Abstraction of a mastership information provider.
+ */
+public interface MastershipProvider extends Provider {
+ // do we get role info from the local OFcontroller impl?
+ // needs to also read from distributed store and emit events?
+ // roleChanged(DeviceId deviceId, MastershipRole newRole);
+}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipProviderService.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipProviderService.java
new file mode 100644
index 0000000..111b2ca
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipProviderService.java
@@ -0,0 +1,18 @@
+package org.onlab.onos.cluster;
+
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.net.provider.ProviderService;
+
+public interface MastershipProviderService extends
+ ProviderService<MastershipProvider> {
+
+ /**
+ * Signals the core that mastership has changed for a device.
+ *
+ * @param deviceId the device ID
+ * @param role the new mastership role of this controller instance
+ */
+ void roleChanged(NodeId nodeId, DeviceId deviceId, MastershipRole role);
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
index 6a9b60e..8da4aa5 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
@@ -37,6 +37,9 @@
*/
MastershipRole requestRoleFor(DeviceId deviceId);
+ // TODO: add facet for requesting a different master than the current one;
+ // abandon mastership (due to loss of connection)
+
/**
* Adds the specified mastership change listener.
*
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
index 728e77d..cb4a076 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
@@ -25,7 +25,7 @@
MastershipRole role);
/**
- * Adds or updates the mastership information for a device.
+ * Adds or updates mastership information for a device.
*
* @param instance controller instance identifier
* @param deviceId device identifier
diff --git a/core/api/src/main/java/org/onlab/onos/net/DefaultPort.java b/core/api/src/main/java/org/onlab/onos/net/DefaultPort.java
index d07def8..534cbe4 100644
--- a/core/api/src/main/java/org/onlab/onos/net/DefaultPort.java
+++ b/core/api/src/main/java/org/onlab/onos/net/DefaultPort.java
@@ -2,13 +2,7 @@
import static com.google.common.base.MoreObjects.toStringHelper;
-import java.util.Collections;
import java.util.Objects;
-import java.util.Set;
-
-import org.onlab.packet.IpPrefix;
-
-import com.google.common.collect.ImmutableSet;
/**
* Default port implementation.
@@ -19,36 +13,18 @@
private final PortNumber number;
private final boolean isEnabled;
- // Attributes
- private final Set<IpPrefix> ipAddresses;
-
- /**
- * Creates a network element attributed to the specified provider.
- *
- * @param element parent network element
- * @param number port number
- * @param isEnabled indicator whether the port is up and active
- */
- public DefaultPort(Element element, PortNumber number,
- boolean isEnabled) {
- this(element, number, isEnabled, null);
- }
-
/**
* Creates a network element attributed to the specified provider.
*
* @param element parent network element
* @param number port number
* @param isEnabled indicator whether the port is up and active
- * @param ipAddresses set of IP addresses assigned to the port
*/
public DefaultPort(Element element, PortNumber number,
- boolean isEnabled, Set<IpPrefix> ipAddresses) {
+ boolean isEnabled) {
this.element = element;
this.number = number;
this.isEnabled = isEnabled;
- this.ipAddresses = (ipAddresses == null) ? Collections.<IpPrefix>emptySet() :
- ImmutableSet.copyOf(ipAddresses);
}
@Override
@@ -94,9 +70,4 @@
return element;
}
- @Override
- public Set<IpPrefix> ipAddresses() {
- return ipAddresses;
- }
-
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/Port.java b/core/api/src/main/java/org/onlab/onos/net/Port.java
index 45b816b..2ebbd15 100644
--- a/core/api/src/main/java/org/onlab/onos/net/Port.java
+++ b/core/api/src/main/java/org/onlab/onos/net/Port.java
@@ -1,8 +1,5 @@
package org.onlab.onos.net;
-import java.util.Set;
-
-import org.onlab.packet.IpPrefix;
/**
* Abstraction of a network port.
@@ -32,12 +29,4 @@
// set of port attributes
- /**
- * Returns the set of IP addresses that are logically configured on this
- * port.
- *
- * @return the set of IP addresses configured on the port. The set is empty
- * if no addresses are configured.
- */
- Set<IpPrefix> ipAddresses();
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceAdminService.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceAdminService.java
index 23856ab..fbfec31 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceAdminService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceAdminService.java
@@ -15,7 +15,7 @@
* @param role requested role
* @deprecated Will be removed in favor of MastershipAdminService.setRole()
*/
- @Deprecated
+// @Deprecated
void setRole(DeviceId deviceId, MastershipRole role);
/**
diff --git a/core/api/src/main/java/org/onlab/onos/net/host/HostAdminService.java b/core/api/src/main/java/org/onlab/onos/net/host/HostAdminService.java
index d94449a..29f6c04 100644
--- a/core/api/src/main/java/org/onlab/onos/net/host/HostAdminService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/host/HostAdminService.java
@@ -1,6 +1,11 @@
package org.onlab.onos.net.host;
+import java.util.Set;
+
+import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.HostId;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
/**
* Service for administering the inventory of end-station hosts.
@@ -14,4 +19,42 @@
*/
void removeHost(HostId hostId);
+ /**
+ * Binds an IP address and optional MAC address to the given connection
+ * point.
+ * <p/>
+ * This method will overwrite any previously held address information for
+ * the connection point.
+ *
+ * @param ip the IP address to bind to the connection point. This parameter
+ * is mandatory and cannot be null.
+ * @param mac the optional MAC address to bind to the connection point. Can
+ * be set to null if no MAC address needs to be bound.
+ * @param connectPoint the connection point to bind the addresses to
+ */
+ void bindAddressesToPort(IpAddress ip, MacAddress mac, ConnectPoint connectPoint);
+
+ /**
+ * Removes all address information for the given connection point.
+ *
+ * @param connectPoint the connection point to remove address information
+ */
+ void unbindAddressesFromPort(ConnectPoint connectPoint);
+
+ /**
+ * Returns the addresses information for all connection points.
+ *
+ * @return the set of address bindings for all connection points
+ */
+ Set<PortAddresses> getAddressBindings();
+
+ /**
+ * Retrieves the addresses that have been bound to the given connection
+ * point.
+ *
+ * @param connectPoint the connection point to retrieve address bindings
+ * for
+ * @return addresses bound to the port
+ */
+ PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint);
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/host/HostService.java b/core/api/src/main/java/org/onlab/onos/net/host/HostService.java
index 3717bea..a0f51b3 100644
--- a/core/api/src/main/java/org/onlab/onos/net/host/HostService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/host/HostService.java
@@ -6,6 +6,7 @@
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
+import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
@@ -87,7 +88,7 @@
*
* @param ip IP address of the host to monitor
*/
- void monitorIp(IpPrefix ip);
+ void startMonitoringIp(IpAddress ip);
/**
* Stops the host service from monitoring an IP address.
@@ -95,7 +96,18 @@
* @param ip IP address to stop monitoring
*/
// TODO clients can cancel other client's requests
- void stopMonitoringIp(IpPrefix ip);
+ void stopMonitoringIp(IpAddress ip);
+
+ /**
+ * Requests the host service to resolve the MAC address for the given IP
+ * address.
+ * <p/>
+ * This will trigger a notification to the host listeners if the MAC
+ * address is found.
+ *
+ * @param ip IP address to find the MAC address for
+ */
+ void requestMac(IpAddress ip);
/**
* Adds the specified host listener.
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
index ea316b2..e3667e3 100644
--- 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
@@ -1,5 +1,7 @@
package org.onlab.onos.net.host;
+import java.util.Set;
+
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
@@ -9,8 +11,6 @@
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
-import java.util.Set;
-
/**
* Manages inventory of end-station hosts; not intended for direct use.
*/
@@ -98,4 +98,34 @@
*/
Set<Host> getConnectedHosts(DeviceId deviceId);
+ /**
+ * Updates the address information for a given port.
+ *
+ * @param addresses the port and address information
+ */
+ void updateAddressBindings(PortAddresses addresses);
+
+ /**
+ * Removes any previously stored address information for a given connection
+ * point.
+ *
+ * @param connectPoint the connection point
+ */
+ void removeAddressBindings(ConnectPoint connectPoint);
+
+ /**
+ * Returns the address bindings stored for all connection points.
+ *
+ * @return the set of address bindings
+ */
+ Set<PortAddresses> getAddressBindings();
+
+ /**
+ * Returns the address bindings for a particular connection point.
+ *
+ * @param connectPoint the connection point to return address information
+ * for
+ * @return address information for the connection point
+ */
+ PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint);
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/host/PortAddresses.java b/core/api/src/main/java/org/onlab/onos/net/host/PortAddresses.java
new file mode 100644
index 0000000..16cc2b1
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/host/PortAddresses.java
@@ -0,0 +1,32 @@
+package org.onlab.onos.net.host;
+
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+
+/**
+ * Represents address information bound to a port.
+ */
+public interface PortAddresses {
+
+ /**
+ * Returns the connection point this address information is bound to.
+ *
+ * @return the connection point
+ */
+ ConnectPoint connectPoint();
+
+ /**
+ * Returns the IP address bound to the port.
+ *
+ * @return the IP address
+ */
+ IpAddress ip();
+
+ /**
+ * Returns the MAC address bound to the port.
+ *
+ * @return the MAC address if one is bound, otherwise null
+ */
+ MacAddress mac();
+}
diff --git a/core/api/src/test/java/org/onlab/onos/net/host/HostServiceAdapter.java b/core/api/src/test/java/org/onlab/onos/net/host/HostServiceAdapter.java
index 6a270cd..f03621c 100644
--- a/core/api/src/test/java/org/onlab/onos/net/host/HostServiceAdapter.java
+++ b/core/api/src/test/java/org/onlab/onos/net/host/HostServiceAdapter.java
@@ -6,6 +6,7 @@
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
+import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
@@ -55,11 +56,15 @@
}
@Override
- public void monitorIp(IpPrefix ip) {
+ public void startMonitoringIp(IpAddress ip) {
}
@Override
- public void stopMonitoringIp(IpPrefix ip) {
+ public void stopMonitoringIp(IpAddress ip) {
+ }
+
+ @Override
+ public void requestMac(IpAddress ip) {
}
@Override
diff --git a/core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java b/core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java
new file mode 100644
index 0000000..492f0d4
--- /dev/null
+++ b/core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java
@@ -0,0 +1,132 @@
+package org.onlab.onos.cluster.impl;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.onos.cluster.MastershipAdminService;
+import org.onlab.onos.cluster.MastershipEvent;
+import org.onlab.onos.cluster.MastershipListener;
+import org.onlab.onos.cluster.MastershipProvider;
+import org.onlab.onos.cluster.MastershipProviderService;
+import org.onlab.onos.cluster.MastershipService;
+import org.onlab.onos.cluster.MastershipStore;
+import org.onlab.onos.cluster.NodeId;
+import org.onlab.onos.event.AbstractListenerRegistry;
+import org.onlab.onos.event.EventDeliveryService;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.net.provider.AbstractProviderRegistry;
+import org.onlab.onos.net.provider.AbstractProviderService;
+import org.slf4j.Logger;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class MastershipManager
+ extends AbstractProviderRegistry<MastershipProvider, MastershipProviderService>
+ implements MastershipService, MastershipAdminService {
+
+ private static final String NODE_ID_NULL = "Node ID cannot be null";
+ private static final String DEVICE_ID_NULL = "Device ID cannot be null";
+ private static final String ROLE_NULL = "Mastership role cannot be null";
+
+ private final Logger log = getLogger(getClass());
+
+ protected final AbstractListenerRegistry<MastershipEvent, MastershipListener>
+ listenerRegistry = new AbstractListenerRegistry<>();
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MastershipStore store;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected EventDeliveryService eventDispatcher;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ClusterManager clusterManager;
+
+ @Activate
+ public void activate() {
+ eventDispatcher.addSink(MastershipEvent.class, listenerRegistry);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ eventDispatcher.removeSink(MastershipEvent.class);
+ log.info("Stopped");
+ }
+
+ @Override
+ public void setRole(NodeId nodeId, DeviceId deviceId, MastershipRole role) {
+ checkNotNull(nodeId, NODE_ID_NULL);
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ checkNotNull(role, ROLE_NULL);
+ store.setRole(nodeId, deviceId, role);
+ }
+
+ @Override
+ public NodeId getMasterFor(DeviceId deviceId) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ return store.getMaster(deviceId);
+ }
+
+ @Override
+ public Set<DeviceId> getDevicesOf(NodeId nodeId) {
+ checkNotNull(nodeId, NODE_ID_NULL);
+ return store.getDevices(nodeId);
+ }
+
+ @Override
+ public MastershipRole requestRoleFor(DeviceId deviceId) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ NodeId id = clusterManager.getLocalNode().id();
+ return store.getRole(id, deviceId);
+ }
+
+ @Override
+ public void addListener(MastershipListener listener) {
+ checkNotNull(listener);
+ listenerRegistry.addListener(listener);
+ }
+
+ @Override
+ public void removeListener(MastershipListener listener) {
+ checkNotNull(listener);
+ listenerRegistry.removeListener(listener);
+ }
+
+ @Override
+ protected MastershipProviderService createProviderService(
+ MastershipProvider provider) {
+ return new InternalMastershipProviderService(provider);
+ }
+
+ private class InternalMastershipProviderService
+ extends AbstractProviderService<MastershipProvider>
+ implements MastershipProviderService {
+
+ protected InternalMastershipProviderService(MastershipProvider provider) {
+ super(provider);
+ }
+
+ @Override
+ public void roleChanged(NodeId nodeId, DeviceId deviceId, MastershipRole role) {
+ // TODO Auto-generated method stub
+ MastershipEvent event =
+ store.addOrUpdateDevice(nodeId, deviceId, role);
+ post(event);
+ }
+ }
+
+ // Posts the specified event to the local event dispatcher.
+ private void post(MastershipEvent event) {
+ if (event != null && eventDispatcher != null) {
+ eventDispatcher.post(event);
+ }
+ }
+
+}
diff --git a/core/net/src/main/java/org/onlab/onos/net/host/impl/DefaultPortAddresses.java b/core/net/src/main/java/org/onlab/onos/net/host/impl/DefaultPortAddresses.java
new file mode 100644
index 0000000..fb656cf
--- /dev/null
+++ b/core/net/src/main/java/org/onlab/onos/net/host/impl/DefaultPortAddresses.java
@@ -0,0 +1,36 @@
+package org.onlab.onos.net.host.impl;
+
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.host.PortAddresses;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+
+public class DefaultPortAddresses implements PortAddresses {
+
+ private final ConnectPoint connectPoint;
+ private final IpAddress ipAddress;
+ private final MacAddress macAddress;
+
+ public DefaultPortAddresses(ConnectPoint connectPoint,
+ IpAddress ip, MacAddress mac) {
+ this.connectPoint = connectPoint;
+ this.ipAddress = ip;
+ this.macAddress = mac;
+ }
+
+ @Override
+ public ConnectPoint connectPoint() {
+ return connectPoint;
+ }
+
+ @Override
+ public IpAddress ip() {
+ return ipAddress;
+ }
+
+ @Override
+ public MacAddress mac() {
+ return macAddress;
+ }
+
+}
diff --git a/core/net/src/main/java/org/onlab/onos/net/host/impl/HostManager.java b/core/net/src/main/java/org/onlab/onos/net/host/impl/HostManager.java
index 1c4cef7..3c1a499 100644
--- a/core/net/src/main/java/org/onlab/onos/net/host/impl/HostManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/host/impl/HostManager.java
@@ -26,8 +26,10 @@
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.host.PortAddresses;
import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
+import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
@@ -118,13 +120,18 @@
}
@Override
- public void monitorIp(IpPrefix ip) {
- // TODO pass through to SimpleHostMonitor
+ public void startMonitoringIp(IpAddress ip) {
+ // TODO pass through to HostMonitor
}
@Override
- public void stopMonitoringIp(IpPrefix ip) {
- // TODO pass through to SimpleHostMonitor
+ public void stopMonitoringIp(IpAddress ip) {
+ // TODO pass through to HostMonitor
+ }
+
+ @Override
+ public void requestMac(IpAddress ip) {
+ // TODO Auto-generated method stub
}
@Override
@@ -147,6 +154,27 @@
}
}
+ @Override
+ public void bindAddressesToPort(IpAddress ip, MacAddress mac,
+ ConnectPoint connectPoint) {
+ store.updateAddressBindings(new DefaultPortAddresses(connectPoint, ip, mac));
+ }
+
+ @Override
+ public void unbindAddressesFromPort(ConnectPoint connectPoint) {
+ store.removeAddressBindings(connectPoint);
+ }
+
+ @Override
+ public Set<PortAddresses> getAddressBindings() {
+ return store.getAddressBindings();
+ }
+
+ @Override
+ public PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint) {
+ return store.getAddressBindingsForPort(connectPoint);
+ }
+
// Personalized host provider service issued to the supplied provider.
private class InternalHostProviderService
extends AbstractProviderService<HostProvider>
diff --git a/core/net/src/main/java/org/onlab/onos/net/host/impl/HostMonitor.java b/core/net/src/main/java/org/onlab/onos/net/host/impl/HostMonitor.java
index 551dec6..ecdb177 100644
--- a/core/net/src/main/java/org/onlab/onos/net/host/impl/HostMonitor.java
+++ b/core/net/src/main/java/org/onlab/onos/net/host/impl/HostMonitor.java
@@ -6,7 +6,6 @@
import org.jboss.netty.util.Timeout;
import org.jboss.netty.util.TimerTask;
-import org.onlab.onos.net.Device;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.device.DeviceService;
@@ -89,7 +88,7 @@
// else (ip isn't in any configured subnet)
// send out all non-external edge ports
- for (Device device : deviceService.getDevices()) {
+ /*for (Device device : deviceService.getDevices()) {
for (Port port : deviceService.getPorts(device.id())) {
for (IpPrefix ip : port.ipAddresses()) {
if (ip.contains(targetIp)) {
@@ -98,7 +97,7 @@
}
}
}
- }
+ }*/
}
diff --git a/core/net/src/test/java/org/onlab/onos/net/device/impl/DistributedDeviceManagerTest.java b/core/net/src/test/java/org/onlab/onos/net/device/impl/DistributedDeviceManagerTest.java
index 222216c..85246e9 100644
--- a/core/net/src/test/java/org/onlab/onos/net/device/impl/DistributedDeviceManagerTest.java
+++ b/core/net/src/test/java/org/onlab/onos/net/device/impl/DistributedDeviceManagerTest.java
@@ -1,10 +1,14 @@
package org.onlab.onos.net.device.impl;
+import com.google.common.collect.Iterables;
+import com.hazelcast.config.Config;
+import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.onos.event.Event;
+import org.onlab.onos.event.impl.TestEventDispatcher;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
@@ -23,13 +27,9 @@
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
-import org.onlab.onos.event.impl.TestEventDispatcher;
import org.onlab.onos.store.StoreService;
import org.onlab.onos.store.device.impl.DistributedDeviceStore;
-
-import com.google.common.collect.Iterables;
-import com.hazelcast.config.Config;
-import com.hazelcast.core.Hazelcast;
+import org.onlab.onos.store.impl.StoreManager;
import java.util.ArrayList;
import java.util.Iterator;
@@ -64,6 +64,7 @@
private DeviceManager mgr;
+ protected StoreManager storeManager;
protected DeviceService service;
protected DeviceAdminService admin;
protected DeviceProviderRegistry registry;
@@ -89,7 +90,11 @@
config.getNetworkConfig().getJoin()
.getMulticastConfig()
.setEnabled(false);
- dstore = new TestDistributedDeviceStore(Hazelcast.newHazelcastInstance(config));
+
+ storeManager = new TestStoreManager(Hazelcast.newHazelcastInstance(config));
+ storeManager.activate();
+
+ dstore = new TestDistributedDeviceStore(storeManager);
dstore.activate();
mgr.store = dstore;
mgr.eventDispatcher = new TestEventDispatcher();
@@ -112,7 +117,7 @@
mgr.deactivate();
dstore.deactivate();
- ((TestDistributedDeviceStore) dstore).shutdownHz();
+ storeManager.deactivate();
}
private void connectDevice(DeviceId deviceId, String swVersion) {
@@ -282,20 +287,19 @@
}
private class TestDistributedDeviceStore extends DistributedDeviceStore {
- public TestDistributedDeviceStore(final HazelcastInstance hazelcastInstance) {
- storeService = new StoreService() {
- @Override
- public HazelcastInstance getHazelcastInstance() {
- return hazelcastInstance;
- }
- };
+ public TestDistributedDeviceStore(StoreService storeService) {
+ this.storeService = storeService;
+ }
+ }
+
+ private class TestStoreManager extends StoreManager {
+ TestStoreManager(HazelcastInstance instance) {
+ this.instance = instance;
}
- /**
- * Shutdowns the hazelcast instance.
- */
- public void shutdownHz() {
- theInstance.shutdown();
+ @Override
+ public void activate() {
+ setupKryoPool();
}
}
}
diff --git a/core/store/src/main/java/org/onlab/onos/store/StoreService.java b/core/store/src/main/java/org/onlab/onos/store/StoreService.java
index a672f54..b10cb7e 100644
--- a/core/store/src/main/java/org/onlab/onos/store/StoreService.java
+++ b/core/store/src/main/java/org/onlab/onos/store/StoreService.java
@@ -15,4 +15,22 @@
*/
HazelcastInstance getHazelcastInstance();
+ /**
+ * Serializes the specified object into bytes using one of the
+ * pre-registered serializers.
+ *
+ * @param obj object to be serialized
+ * @return serialized bytes
+ */
+ public byte[] serialize(final Object obj);
+
+ /**
+ * Deserializes the specified bytes into an object using one of the
+ * pre-registered serializers.
+ *
+ * @param bytes bytes to be deserialized
+ * @return deserialized object
+ */
+ public <T> T deserialize(final byte[] bytes);
+
}
diff --git a/core/store/src/main/java/org/onlab/onos/store/cluster/impl/package-info.java b/core/store/src/main/java/org/onlab/onos/store/cluster/impl/package-info.java
index fe3df5d..9f36b88 100644
--- a/core/store/src/main/java/org/onlab/onos/store/cluster/impl/package-info.java
+++ b/core/store/src/main/java/org/onlab/onos/store/cluster/impl/package-info.java
@@ -1,4 +1,4 @@
/**
* Implementation of a distributed cluster node store using Hazelcast.
*/
-package org.onlab.onos.store.cluster.impl;
\ No newline at end of file
+package org.onlab.onos.store.cluster.impl;
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/DefaultPortSerializer.java b/core/store/src/main/java/org/onlab/onos/store/device/impl/DefaultPortSerializer.java
deleted file mode 100644
index bd0aa06..0000000
--- a/core/store/src/main/java/org/onlab/onos/store/device/impl/DefaultPortSerializer.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.onlab.onos.store.device.impl;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.onlab.onos.net.DefaultPort;
-import org.onlab.onos.net.Element;
-import org.onlab.onos.net.PortNumber;
-import org.onlab.packet.IpPrefix;
-
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.Serializer;
-import com.esotericsoftware.kryo.io.Input;
-import com.esotericsoftware.kryo.io.Output;
-import com.esotericsoftware.kryo.serializers.CollectionSerializer;
-import com.google.common.collect.ImmutableSet;
-
-// TODO move to util, etc.
-/**
- * Kryo Serializer for {@link DefaultPort}.
- */
-public final class DefaultPortSerializer extends
- Serializer<DefaultPort> {
-
- private final CollectionSerializer ipAddrSerializer
- = new CollectionSerializer(IpPrefix.class,
- new IpPrefixSerializer(), false);
-
- /**
- * Default constructor.
- */
- public DefaultPortSerializer() {
- // non-null, immutable
- super(false, true);
- }
-
- @Override
- public void write(Kryo kryo, Output output, DefaultPort object) {
- kryo.writeClassAndObject(output, object.element());
- kryo.writeObject(output, object.number());
- output.writeBoolean(object.isEnabled());
- kryo.writeObject(output, object.ipAddresses(),
- ipAddrSerializer);
- }
-
- @Override
- public DefaultPort read(Kryo kryo, Input input,
- Class<DefaultPort> type) {
- Element element = (Element) kryo.readClassAndObject(input);
- PortNumber number = kryo.readObject(input, PortNumber.class);
- boolean isEnabled = input.readBoolean();
- @SuppressWarnings("unchecked")
- Collection<IpPrefix> ipAddresses = kryo.readObject(
- input, ArrayList.class, ipAddrSerializer);
-
- return new DefaultPort(element, number, isEnabled,
- ImmutableSet.copyOf(ipAddresses));
- }
-}
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java b/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
index fe03cda..207036c 100644
--- a/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
+++ b/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
@@ -1,56 +1,7 @@
package org.onlab.onos.store.device.impl;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
-import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_MASTERSHIP_CHANGED;
-import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_REMOVED;
-import static org.onlab.onos.net.device.DeviceEvent.Type.PORT_ADDED;
-import static org.onlab.onos.net.device.DeviceEvent.Type.PORT_REMOVED;
-import static org.onlab.onos.net.device.DeviceEvent.Type.PORT_UPDATED;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-
-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.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.Service;
-import org.onlab.onos.net.DefaultDevice;
-import org.onlab.onos.net.DefaultPort;
-import org.onlab.onos.net.Device;
-import org.onlab.onos.net.DeviceId;
-import org.onlab.onos.net.Element;
-import org.onlab.onos.net.MastershipRole;
-import org.onlab.onos.net.Port;
-import org.onlab.onos.net.PortNumber;
-import org.onlab.onos.net.device.DeviceDescription;
-import org.onlab.onos.net.device.DeviceEvent;
-import org.onlab.onos.net.device.DeviceStore;
-import org.onlab.onos.net.device.PortDescription;
-import org.onlab.onos.net.provider.ProviderId;
-import org.onlab.onos.store.StoreService;
-import org.onlab.util.KryoPool;
-import org.slf4j.Logger;
-
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.Serializer;
-import com.esotericsoftware.kryo.io.Input;
-import com.esotericsoftware.kryo.io.Output;
import com.google.common.base.Optional;
import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -62,7 +13,43 @@
import com.hazelcast.core.ISet;
import com.hazelcast.core.MapEvent;
-import de.javakaffee.kryoserializers.URISerializer;
+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.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.onos.net.DefaultDevice;
+import org.onlab.onos.net.DefaultPort;
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.net.Port;
+import org.onlab.onos.net.PortNumber;
+import org.onlab.onos.net.device.DeviceDescription;
+import org.onlab.onos.net.device.DeviceEvent;
+import org.onlab.onos.net.device.DeviceStore;
+import org.onlab.onos.net.device.PortDescription;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.store.StoreService;
+import org.onlab.onos.store.impl.AbsentInvalidatingLoadingCache;
+import org.onlab.onos.store.impl.OptionalCacheLoader;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onlab.onos.net.device.DeviceEvent.Type.*;
+import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -76,27 +63,6 @@
public static final String DEVICE_NOT_FOUND = "Device with ID %s not found";
- // FIXME Slice out types used in common to separate pool/namespace.
- private static final KryoPool POOL = KryoPool.newBuilder()
- .register(
- ArrayList.class,
- HashMap.class,
-
- Device.Type.class,
-
- DefaultDevice.class,
- MastershipRole.class,
- Port.class,
- Element.class
- )
- .register(URI.class, new URISerializer())
- .register(ProviderId.class, new ProviderIdSerializer())
- .register(DeviceId.class, new DeviceIdSerializer())
- .register(PortNumber.class, new PortNumberSerializer())
- .register(DefaultPort.class, new DefaultPortSerializer())
- .build()
- .populate(10);
-
// private IMap<DeviceId, DefaultDevice> cache;
private IMap<byte[], byte[]> rawDevices;
private LoadingCache<DeviceId, Optional<DefaultDevice>> devices;
@@ -113,7 +79,6 @@
private IMap<byte[], byte[]> rawDevicePorts;
private LoadingCache<DeviceId, Optional<Map<PortNumber, Port>>> devicePorts;
- // FIXME change to protected once we remove DistributedDeviceManagerTest.
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StoreService storeService;
@@ -130,33 +95,39 @@
// TODO decide on Map name scheme to avoid collision
rawDevices = theInstance.getMap("devices");
- devices = new AbsentInvalidatingLoadingCache<DeviceId, DefaultDevice>(
+ final OptionalCacheLoader<DeviceId, DefaultDevice> deviceLoader
+ = new OptionalCacheLoader<>(storeService, rawDevices);
+ devices = new AbsentInvalidatingLoadingCache<>(
CacheBuilder.newBuilder()
- .build(new OptionalCacheLoader<DeviceId, DefaultDevice>(rawDevices)));
+ .build(deviceLoader));
// refresh/populate cache based on notification from other instance
rawDevices.addEntryListener(
- new RemoteEventHandler<DeviceId, DefaultDevice>(devices),
+ new RemoteEventHandler<>(devices),
includeValue);
rawRoles = theInstance.getMap("roles");
- roles = new AbsentInvalidatingLoadingCache<DeviceId, MastershipRole>(
+ final OptionalCacheLoader<DeviceId, MastershipRole> rolesLoader
+ = new OptionalCacheLoader<>(storeService, rawRoles);
+ roles = new AbsentInvalidatingLoadingCache<>(
CacheBuilder.newBuilder()
- .build(new OptionalCacheLoader<DeviceId, MastershipRole>(rawRoles)));
+ .build(rolesLoader));
// refresh/populate cache based on notification from other instance
rawRoles.addEntryListener(
- new RemoteEventHandler<DeviceId, MastershipRole>(roles),
+ new RemoteEventHandler<>(roles),
includeValue);
- // TODO cache avai
+ // TODO cache availableDevices
availableDevices = theInstance.getSet("availableDevices");
rawDevicePorts = theInstance.getMap("devicePorts");
- devicePorts = new AbsentInvalidatingLoadingCache<DeviceId, Map<PortNumber, Port>>(
+ final OptionalCacheLoader<DeviceId, Map<PortNumber, Port>> devicePortLoader
+ = new OptionalCacheLoader<>(storeService, rawDevicePorts);
+ devicePorts = new AbsentInvalidatingLoadingCache<>(
CacheBuilder.newBuilder()
- .build(new OptionalCacheLoader<DeviceId, Map<PortNumber, Port>>(rawDevicePorts)));
+ .build(devicePortLoader));
// refresh/populate cache based on notification from other instance
rawDevicePorts.addEntryListener(
- new RemoteEventHandler<DeviceId, Map<PortNumber, Port>>(devicePorts),
+ new RemoteEventHandler<>(devicePorts),
includeValue);
}
@@ -185,7 +156,7 @@
// }
// TODO builder v.s. copyOf. Guava semms to be using copyOf?
- Builder<Device> builder = ImmutableSet.<Device>builder();
+ Builder<Device> builder = ImmutableSet.builder();
for (Optional<DefaultDevice> e : devices.asMap().values()) {
if (e.isPresent()) {
builder.add(e.get());
@@ -202,7 +173,7 @@
@Override
public DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId,
- DeviceDescription deviceDescription) {
+ DeviceDescription deviceDescription) {
DefaultDevice device = devices.getUnchecked(deviceId).orNull();
if (device == null) {
return createDevice(providerId, deviceId, deviceDescription);
@@ -227,7 +198,7 @@
// For now claim the device as a master automatically.
rawRoles.put(deviceIdBytes, serialize(MastershipRole.MASTER));
- roles.put(deviceId, Optional.of(MastershipRole.MASTER));
+ roles.put(deviceId, Optional.of(MastershipRole.MASTER));
}
return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, null);
}
@@ -237,7 +208,7 @@
DeviceDescription desc) {
// We allow only certain attributes to trigger update
if (!Objects.equals(device.hwVersion(), desc.hwVersion()) ||
- !Objects.equals(device.swVersion(), desc.swVersion())) {
+ !Objects.equals(device.swVersion(), desc.swVersion())) {
DefaultDevice updated = new DefaultDevice(providerId, device.id(),
desc.type(),
@@ -272,7 +243,7 @@
@Override
public List<DeviceEvent> updatePorts(DeviceId deviceId,
- List<PortDescription> portDescriptions) {
+ List<PortDescription> portDescriptions) {
List<DeviceEvent> events = new ArrayList<>();
synchronized (this) {
Device device = devices.getUnchecked(deviceId).orNull();
@@ -370,7 +341,7 @@
@Override
public DeviceEvent updatePortStatus(DeviceId deviceId,
- PortDescription portDescription) {
+ PortDescription portDescription) {
synchronized (this) {
Device device = devices.getUnchecked(deviceId).orNull();
checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
@@ -432,30 +403,12 @@
}
// TODO cache serialized DeviceID if we suffer from serialization cost
-
- private static byte[] serialize(final Object obj) {
- return POOL.serialize(obj);
+ private byte[] serialize(final Object obj) {
+ return storeService.serialize(obj);
}
- private static <T> T deserialize(final byte[] bytes) {
- if (bytes == null) {
- return null;
- }
- return POOL.deserialize(bytes);
- }
-
- public static final class DeviceIdSerializer extends Serializer<DeviceId> {
-
- @Override
- public void write(Kryo kryo, Output output, DeviceId object) {
- kryo.writeObject(output, object.uri());
- }
-
- @Override
- public DeviceId read(Kryo kryo, Input input, Class<DeviceId> type) {
- final URI uri = kryo.readObject(input, URI.class);
- return DeviceId.deviceId(uri);
- }
+ private <T> T deserialize(final byte[] bytes) {
+ return storeService.deserialize(bytes);
}
/**
@@ -464,7 +417,7 @@
* @param <K> IMap key type after deserialization
* @param <V> IMap value type after deserialization
*/
- public static final class RemoteEventHandler<K, V> extends
+ public final class RemoteEventHandler<K, V> extends
EntryAdapter<byte[], byte[]> {
private LoadingCache<K, Optional<V>> cache;
@@ -486,14 +439,13 @@
@Override
public void entryUpdated(EntryEvent<byte[], byte[]> event) {
- cache.put(POOL.<K>deserialize(event.getKey()),
- Optional.of(POOL.<V>deserialize(
- event.getValue())));
+ cache.put(storeService.<K>deserialize(event.getKey()),
+ Optional.of(storeService.<V>deserialize(event.getValue())));
}
@Override
public void entryRemoved(EntryEvent<byte[], byte[]> event) {
- cache.invalidate(POOL.<DeviceId>deserialize(event.getKey()));
+ cache.invalidate(storeService.<K>deserialize(event.getKey()));
}
@Override
@@ -501,37 +453,4 @@
entryUpdated(event);
}
}
-
- /**
- * CacheLoader to wrap Map value with Optional,
- * to handle negative hit on underlying IMap.
- *
- * @param <K> IMap key type after deserialization
- * @param <V> IMap value type after deserialization
- */
- public static final class OptionalCacheLoader<K, V> extends
- CacheLoader<K, Optional<V>> {
-
- private IMap<byte[], byte[]> rawMap;
-
- /**
- * Constructor.
- *
- * @param rawMap underlying IMap
- */
- public OptionalCacheLoader(IMap<byte[], byte[]> rawMap) {
- this.rawMap = checkNotNull(rawMap);
- }
-
- @Override
- public Optional<V> load(K key) throws Exception {
- byte[] keyBytes = serialize(key);
- byte[] valBytes = rawMap.get(keyBytes);
- if (valBytes == null) {
- return Optional.absent();
- }
- V dev = deserialize(valBytes);
- return Optional.of(dev);
- }
- }
}
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/AbsentInvalidatingLoadingCache.java b/core/store/src/main/java/org/onlab/onos/store/impl/AbsentInvalidatingLoadingCache.java
similarity index 77%
rename from core/store/src/main/java/org/onlab/onos/store/device/impl/AbsentInvalidatingLoadingCache.java
rename to core/store/src/main/java/org/onlab/onos/store/impl/AbsentInvalidatingLoadingCache.java
index df88c31..df4e70a 100644
--- a/core/store/src/main/java/org/onlab/onos/store/device/impl/AbsentInvalidatingLoadingCache.java
+++ b/core/store/src/main/java/org/onlab/onos/store/impl/AbsentInvalidatingLoadingCache.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.store.device.impl;
+package org.onlab.onos.store.impl;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@@ -7,9 +7,24 @@
import com.google.common.cache.ForwardingLoadingCache.SimpleForwardingLoadingCache;
import com.google.common.cache.LoadingCache;
+/**
+ * Wrapper around LoadingCache to handle negative hit scenario.
+ * <p>
+ * When the LoadingCache returned Absent,
+ * this implementation will invalidate the entry immediately to avoid
+ * caching negative hits.
+ *
+ * @param <K> Cache key type
+ * @param <V> Cache value type. (Optional{@literal <V>})
+ */
public class AbsentInvalidatingLoadingCache<K, V> extends
SimpleForwardingLoadingCache<K, Optional<V>> {
+ /**
+ * Constructor.
+ *
+ * @param delegate actual {@link LoadingCache} to delegate loading.
+ */
public AbsentInvalidatingLoadingCache(LoadingCache<K, Optional<V>> delegate) {
super(delegate);
}
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/OptionalCacheLoader.java b/core/store/src/main/java/org/onlab/onos/store/impl/OptionalCacheLoader.java
new file mode 100644
index 0000000..47a42ee
--- /dev/null
+++ b/core/store/src/main/java/org/onlab/onos/store/impl/OptionalCacheLoader.java
@@ -0,0 +1,45 @@
+package org.onlab.onos.store.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.onlab.onos.store.StoreService;
+
+import com.google.common.base.Optional;
+import com.google.common.cache.CacheLoader;
+import com.hazelcast.core.IMap;
+
+/**
+ * CacheLoader to wrap Map value with Optional,
+ * to handle negative hit on underlying IMap.
+ *
+ * @param <K> IMap key type after deserialization
+ * @param <V> IMap value type after deserialization
+ */
+public final class OptionalCacheLoader<K, V> extends
+ CacheLoader<K, Optional<V>> {
+
+ private final StoreService storeService;
+ private IMap<byte[], byte[]> rawMap;
+
+ /**
+ * Constructor.
+ *
+ * @param storeService to use for serialization
+ * @param rawMap underlying IMap
+ */
+ public OptionalCacheLoader(StoreService storeService, IMap<byte[], byte[]> rawMap) {
+ this.storeService = checkNotNull(storeService);
+ this.rawMap = checkNotNull(rawMap);
+ }
+
+ @Override
+ public Optional<V> load(K key) throws Exception {
+ byte[] keyBytes = storeService.serialize(key);
+ byte[] valBytes = rawMap.get(keyBytes);
+ if (valBytes == null) {
+ return Optional.absent();
+ }
+ V dev = storeService.deserialize(valBytes);
+ return Optional.of(dev);
+ }
+}
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java b/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java
index c638177..2725175 100644
--- a/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java
+++ b/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java
@@ -2,14 +2,33 @@
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
+import de.javakaffee.kryoserializers.URISerializer;
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.DefaultDevice;
+import org.onlab.onos.net.DefaultPort;
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Element;
+import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.net.Port;
+import org.onlab.onos.net.PortNumber;
+import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.StoreService;
+import org.onlab.onos.store.serializers.DefaultPortSerializer;
+import org.onlab.onos.store.serializers.DeviceIdSerializer;
+import org.onlab.onos.store.serializers.PortNumberSerializer;
+import org.onlab.onos.store.serializers.ProviderIdSerializer;
+import org.onlab.util.KryoPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+
/**
* Auxiliary bootstrap of distributed store.
*/
@@ -20,15 +39,45 @@
private final Logger log = LoggerFactory.getLogger(getClass());
protected HazelcastInstance instance;
+ private KryoPool serializerPool;
+
@Activate
public void activate() {
instance = Hazelcast.newHazelcastInstance();
+ setupKryoPool();
log.info("Started");
}
+ /**
+ * Sets up the common serialzers pool.
+ */
+ protected void setupKryoPool() {
+ // FIXME Slice out types used in common to separate pool/namespace.
+ serializerPool = KryoPool.newBuilder()
+ .register(
+ ArrayList.class,
+ HashMap.class,
+
+ Device.Type.class,
+
+ DefaultDevice.class,
+ MastershipRole.class,
+ Port.class,
+ Element.class
+ )
+ .register(URI.class, new URISerializer())
+ .register(ProviderId.class, new ProviderIdSerializer())
+ .register(DeviceId.class, new DeviceIdSerializer())
+ .register(PortNumber.class, new PortNumberSerializer())
+ .register(DefaultPort.class, new DefaultPortSerializer())
+ .build()
+ .populate(10);
+ }
+
@Deactivate
public void deactivate() {
+ instance.shutdown();
log.info("Stopped");
}
@@ -36,4 +85,19 @@
public HazelcastInstance getHazelcastInstance() {
return instance;
}
+
+
+ @Override
+ public byte[] serialize(final Object obj) {
+ return serializerPool.serialize(obj);
+ }
+
+ @Override
+ public <T> T deserialize(final byte[] bytes) {
+ if (bytes == null) {
+ return null;
+ }
+ return serializerPool.deserialize(bytes);
+ }
+
}
diff --git a/core/store/src/main/java/org/onlab/onos/store/package-info.java b/core/store/src/main/java/org/onlab/onos/store/package-info.java
index e0b6956..bea7fb0 100644
--- a/core/store/src/main/java/org/onlab/onos/store/package-info.java
+++ b/core/store/src/main/java/org/onlab/onos/store/package-info.java
@@ -2,4 +2,4 @@
* Common abstractions and facilities for implementing distributed store
* using Hazelcast.
*/
-package org.onlab.onos.store;
\ No newline at end of file
+package org.onlab.onos.store;
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java b/core/store/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java
new file mode 100644
index 0000000..836adea
--- /dev/null
+++ b/core/store/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java
@@ -0,0 +1,43 @@
+package org.onlab.onos.store.serializers;
+
+import org.onlab.onos.net.DefaultPort;
+import org.onlab.onos.net.Element;
+import org.onlab.onos.net.PortNumber;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+// TODO move to util, etc.
+/**
+ * Kryo Serializer for {@link DefaultPort}.
+ */
+public final class DefaultPortSerializer extends
+ Serializer<DefaultPort> {
+
+ /**
+ * Default constructor.
+ */
+ public DefaultPortSerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output, DefaultPort object) {
+ kryo.writeClassAndObject(output, object.element());
+ kryo.writeObject(output, object.number());
+ output.writeBoolean(object.isEnabled());
+ }
+
+ @Override
+ public DefaultPort read(Kryo kryo, Input input,
+ Class<DefaultPort> type) {
+ Element element = (Element) kryo.readClassAndObject(input);
+ PortNumber number = kryo.readObject(input, PortNumber.class);
+ boolean isEnabled = input.readBoolean();
+
+ return new DefaultPort(element, number, isEnabled);
+ }
+}
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java b/core/store/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java
new file mode 100644
index 0000000..709dce0
--- /dev/null
+++ b/core/store/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java
@@ -0,0 +1,28 @@
+package org.onlab.onos.store.serializers;
+
+import java.net.URI;
+
+import org.onlab.onos.net.DeviceId;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+//TODO move to util, etc.
+/**
+* Kryo Serializer for {@link DeviceId}.
+*/
+public final class DeviceIdSerializer extends Serializer<DeviceId> {
+
+ @Override
+ public void write(Kryo kryo, Output output, DeviceId object) {
+ kryo.writeObject(output, object.uri());
+ }
+
+ @Override
+ public DeviceId read(Kryo kryo, Input input, Class<DeviceId> type) {
+ final URI uri = kryo.readObject(input, URI.class);
+ return DeviceId.deviceId(uri);
+ }
+}
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/IpPrefixSerializer.java b/core/store/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
similarity index 95%
rename from core/store/src/main/java/org/onlab/onos/store/device/impl/IpPrefixSerializer.java
rename to core/store/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
index d6296a3..8ac6679 100644
--- a/core/store/src/main/java/org/onlab/onos/store/device/impl/IpPrefixSerializer.java
+++ b/core/store/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.store.device.impl;
+package org.onlab.onos.store.serializers;
import org.onlab.packet.IpPrefix;
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/PortNumberSerializer.java b/core/store/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java
similarity index 94%
rename from core/store/src/main/java/org/onlab/onos/store/device/impl/PortNumberSerializer.java
rename to core/store/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java
index ae11867..e89c379 100644
--- a/core/store/src/main/java/org/onlab/onos/store/device/impl/PortNumberSerializer.java
+++ b/core/store/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.store.device.impl;
+package org.onlab.onos.store.serializers;
import org.onlab.onos.net.PortNumber;
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/ProviderIdSerializer.java b/core/store/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java
similarity index 95%
rename from core/store/src/main/java/org/onlab/onos/store/device/impl/ProviderIdSerializer.java
rename to core/store/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java
index 82b7a70..3abb784 100644
--- a/core/store/src/main/java/org/onlab/onos/store/device/impl/ProviderIdSerializer.java
+++ b/core/store/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.store.device.impl;
+package org.onlab.onos.store.serializers;
import org.onlab.onos.net.provider.ProviderId;
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/package-info.java b/core/store/src/main/java/org/onlab/onos/store/serializers/package-info.java
new file mode 100644
index 0000000..c66304f
--- /dev/null
+++ b/core/store/src/main/java/org/onlab/onos/store/serializers/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Various Kryo serializers for use in distributed stores.
+ */
+package org.onlab.onos.store.serializers;
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostStore.java
index 4a4d6d3..6568d43 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostStore.java
@@ -24,15 +24,16 @@
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.host.PortAddresses;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
+import org.slf4j.Logger;
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
@@ -50,6 +51,9 @@
// Hosts tracked by their location
private final Multimap<ConnectPoint, Host> locations = HashMultimap.create();
+ private final Map<ConnectPoint, PortAddresses> portAddresses =
+ new ConcurrentHashMap<>();
+
@Activate
public void activate() {
log.info("Started");
@@ -192,4 +196,24 @@
return hostset;
}
+ @Override
+ public void updateAddressBindings(PortAddresses addresses) {
+ portAddresses.put(addresses.connectPoint(), addresses);
+ }
+
+ @Override
+ public void removeAddressBindings(ConnectPoint connectPoint) {
+ portAddresses.remove(connectPoint);
+ }
+
+ @Override
+ public Set<PortAddresses> getAddressBindings() {
+ return new HashSet<>(portAddresses.values());
+ }
+
+ @Override
+ public PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint) {
+ return portAddresses.get(connectPoint);
+ }
+
}
diff --git a/pom.xml b/pom.xml
index 21a8aef..dcd2a6b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -172,6 +172,11 @@
</dependency>
<dependency>
<groupId>org.onlab.onos</groupId>
+ <artifactId>onlab-osgi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
<artifactId>onlab-junit</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
diff --git a/tools/dev/bash_profile b/tools/dev/bash_profile
index 8304bb2..328f5f4 100644
--- a/tools/dev/bash_profile
+++ b/tools/dev/bash_profile
@@ -30,6 +30,7 @@
# Short-hand for ONOS build from the top of the source tree.
alias ob='o && mvn clean install javadoc:aggregate'
+alias ot='onos-test'
# Short-hand for tailing the ONOS (karaf) log
alias tl='$ONOS_ROOT/tools/dev/watchLog'
@@ -46,7 +47,8 @@
# Test related conveniences
# SSH to a specified ONOS instance
-alias sshctl=onos-ssh
+alias sshctl='onos-ssh'
+alias sshnet='onos-ssh $OCN'
# Applies the settings in the specified cell file or lists current cell definition
# if no cell file is given.
@@ -62,6 +64,7 @@
env | egrep "ONOS_CELL"
env | egrep "OCI"
env | egrep "OC[0-9]+" | sort
+ env | egrep "OCN"
fi
}
diff --git a/tools/test/bin/onos-config b/tools/test/bin/onos-config
index dd03e2d..e9f3f0a 100755
--- a/tools/test/bin/onos-config
+++ b/tools/test/bin/onos-config
@@ -8,25 +8,4 @@
remote=$ONOS_USER@${1:-$OCI}
-LOG=$ONOS_INSTALL_DIR/config.log
-onos=$ONOS_INSTALL_DIR/bin/onos
-
-ssh $remote "
- # Wait until we reach the run-level 100
- echo 'Waiting for cluster bootstrap...'
- running=""
- while [ -z \$running ]; do
- $onos bundle:list 2>>$LOG | grep -q 'START LEVEL 100' && running=1 || sleep 2
- done
-
- echo 'Installing ONOS bundles...'
- $onos cluster:feature-install default onos-api 1>>$LOG 2>&1
- # $onos cluster:feature-install default onos-core 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-core-trivial 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-openflow 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-cli 1>>$LOG 2>&1
- # $onos cluster:feature-install default onos-gui 1>>$LOG 2>&1
- # $onos cluster:feature-install default onos-rest 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-app-tvue 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-app-fwd 1>>$LOG 2>&1
-"
+echo "Deprecated!"
\ No newline at end of file
diff --git a/tools/test/bin/onos-log b/tools/test/bin/onos-log
index 698cc2f..1a205f4 100755
--- a/tools/test/bin/onos-log
+++ b/tools/test/bin/onos-log
@@ -14,6 +14,7 @@
ssh $remote "
while true; do
+ echo ==================================================================
[ ! -f $LOG ] && sleep 2 && continue
tail -n 512 --follow=name $LOG --sleep-interval 2
done
diff --git a/tools/test/bin/onos-test b/tools/test/bin/onos-test
new file mode 100755
index 0000000..d549721
--- /dev/null
+++ b/tools/test/bin/onos-test
@@ -0,0 +1,13 @@
+#!/bin/bash
+#-------------------------------------------------------------------------------
+# Launches the ONOS tests on the current cell environment.
+#-------------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+nodes=$(env | sort | egrep "OC[0-9]+" | cut -d= -f2)
+
+onos-package
+for node in $nodes; do onos-install -f $node; done
+for node in $nodes; do onos-wait-for-start $node; done
diff --git a/tools/test/bin/onos-verify-cell b/tools/test/bin/onos-verify-cell
index 8e7fe99..9a5f5a9 100755
--- a/tools/test/bin/onos-verify-cell
+++ b/tools/test/bin/onos-verify-cell
@@ -6,6 +6,6 @@
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
-for node in $(env | sort | egrep "OC[0-9]+" | cut -d= -f2); do
+for node in $(env | sort | egrep "OC[0-9N]+" | cut -d= -f2); do
printf "%s: " $node; ssh -n -o PasswordAuthentication=no $ONOS_USER@$node date
done
\ No newline at end of file
diff --git a/tools/test/cells/local b/tools/test/cells/local
index 37911dd..3d71a1e 100644
--- a/tools/test/cells/local
+++ b/tools/test/cells/local
@@ -1,7 +1,8 @@
-# Default virtual box ONOS instances 1,2 & 3
+# Default virtual box ONOS instances 1,2 & ONOS mininet box
export OC1="192.168.56.101"
export OC2="192.168.56.102"
-export OC3="192.168.56.103"
+
+export OCN="192.168.56.103"
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java b/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
index b53b5fa..bc401fb 100644
--- a/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
+++ b/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
@@ -2,18 +2,37 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
/**
* Default implementation of the service directory using OSGi framework utilities.
*/
public class DefaultServiceDirectory implements ServiceDirectory {
+
+ /**
+ * Returns the reference to the implementation of the specified service.
+ *
+ * @param serviceClass service class
+ * @param <T> type of service
+ * @return service implementation
+ */
+ public static <T> T getService(Class<T> serviceClass) {
+ BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext();
+ if (bc != null) {
+ ServiceReference<T> reference = bc.getServiceReference(serviceClass);
+ if (reference != null) {
+ T impl = bc.getService(reference);
+ if (impl != null) {
+ return impl;
+ }
+ }
+ }
+ throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found");
+ }
+
@Override
public <T> T get(Class<T> serviceClass) {
- BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext();
- T impl = bc.getService(bc.getServiceReference(serviceClass));
- if (impl == null) {
- throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found");
- }
- return impl;
+ return getService(serviceClass);
}
+
}