Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
diff --git a/cli/src/main/java/org/onlab/onos/cli/GreetCommand.java b/cli/src/main/java/org/onlab/onos/cli/GreetCommand.java
index dd8ae81..46d4b2c 100644
--- a/cli/src/main/java/org/onlab/onos/cli/GreetCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/GreetCommand.java
@@ -3,7 +3,7 @@
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.onlab.onos.net.GreetService;
+import org.onlab.onos.GreetService;
/**
* Simple command example to demonstrate use of Karaf shell extensions; shows
diff --git a/cli/src/main/java/org/onlab/onos/cli/NameCompleter.java b/cli/src/main/java/org/onlab/onos/cli/NameCompleter.java
index bdf3f72..bcf0707 100644
--- a/cli/src/main/java/org/onlab/onos/cli/NameCompleter.java
+++ b/cli/src/main/java/org/onlab/onos/cli/NameCompleter.java
@@ -2,7 +2,7 @@
import org.apache.karaf.shell.console.Completer;
import org.apache.karaf.shell.console.completer.StringsCompleter;
-import org.onlab.onos.net.GreetService;
+import org.onlab.onos.GreetService;
import java.util.Iterator;
import java.util.List;
diff --git a/net/api/src/main/java/org/onlab/onos/net/GreetService.java b/net/api/src/main/java/org/onlab/onos/GreetService.java
similarity index 93%
rename from net/api/src/main/java/org/onlab/onos/net/GreetService.java
rename to net/api/src/main/java/org/onlab/onos/GreetService.java
index 09f0d96..c196147 100644
--- a/net/api/src/main/java/org/onlab/onos/net/GreetService.java
+++ b/net/api/src/main/java/org/onlab/onos/GreetService.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net;
+package org.onlab.onos;
/**
* Example of a simple service that provides greetings and it
diff --git a/net/api/src/main/java/org/onlab/onos/event/EventDispatchService.java b/net/api/src/main/java/org/onlab/onos/event/EventDispatchService.java
new file mode 100644
index 0000000..8df68bb
--- /dev/null
+++ b/net/api/src/main/java/org/onlab/onos/event/EventDispatchService.java
@@ -0,0 +1,8 @@
+package org.onlab.onos.event;
+
+/**
+ * Abstraction of an entity capable of accepting events to be posted and
+ * then dispatching them to the appropriate event sink.
+ */
+public interface EventDispatchService extends EventDispatcher, EventSinkBroker {
+}
diff --git a/net/api/src/main/java/org/onlab/onos/event/EventDispatcher.java b/net/api/src/main/java/org/onlab/onos/event/EventDispatcher.java
index 8236d899..847df88 100644
--- a/net/api/src/main/java/org/onlab/onos/event/EventDispatcher.java
+++ b/net/api/src/main/java/org/onlab/onos/event/EventDispatcher.java
@@ -6,13 +6,13 @@
* Similarly, whether the events are accepted and dispatched synchronously
* or asynchronously is unspecified as well.
*/
-public interface EventDispatcher<E extends Event> {
+public interface EventDispatcher {
/**
* Posts the specified event for dispatching.
*
* @param event event to be posted
*/
- void post(E event);
+ void post(Event event);
}
diff --git a/net/api/src/main/java/org/onlab/onos/net/device/DeviceProviderService.java b/net/api/src/main/java/org/onlab/onos/net/device/DeviceProviderService.java
index 9d8eb6a..f304398 100644
--- a/net/api/src/main/java/org/onlab/onos/net/device/DeviceProviderService.java
+++ b/net/api/src/main/java/org/onlab/onos/net/device/DeviceProviderService.java
@@ -34,17 +34,17 @@
* determine what has changed.
* <p/>
*
- * @param deviceId identity of the device
- * @param ports list of device ports
+ * @param deviceId identity of the device
+ * @param portDescriptions list of device ports
*/
- void updatePorts(DeviceId deviceId, List<PortDescription> ports);
+ void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions);
/**
* Used to notify the core about port status change of a single port.
*
- * @param deviceId identity of the device
- * @param port description of the port that changed
+ * @param deviceId identity of the device
+ * @param portDescription description of the port that changed
*/
- void portStatusChanged(DeviceId deviceId, PortDescription port);
+ void portStatusChanged(DeviceId deviceId, PortDescription portDescription);
}
diff --git a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/GreetManager.java b/net/core/trivial/src/main/java/org/onlab/onos/impl/GreetManager.java
similarity index 93%
rename from net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/GreetManager.java
rename to net/core/trivial/src/main/java/org/onlab/onos/impl/GreetManager.java
index 2b01396..4f4ba68 100644
--- a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/GreetManager.java
+++ b/net/core/trivial/src/main/java/org/onlab/onos/impl/GreetManager.java
@@ -1,11 +1,11 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.impl;
import com.google.common.collect.ImmutableSet;
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.GreetService;
+import org.onlab.onos.GreetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SomeOtherComponent.java b/net/core/trivial/src/main/java/org/onlab/onos/impl/SomeOtherComponent.java
similarity index 92%
rename from net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SomeOtherComponent.java
rename to net/core/trivial/src/main/java/org/onlab/onos/impl/SomeOtherComponent.java
index e040643..6cb0bfe 100644
--- a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SomeOtherComponent.java
+++ b/net/core/trivial/src/main/java/org/onlab/onos/impl/SomeOtherComponent.java
@@ -1,11 +1,11 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.impl;
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.onlab.onos.net.GreetService;
+import org.onlab.onos.GreetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DeviceStore.java b/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DeviceStore.java
new file mode 100644
index 0000000..f907e35
--- /dev/null
+++ b/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DeviceStore.java
@@ -0,0 +1,69 @@
+package org.onlab.onos.net.trivial.impl;
+
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.device.DeviceDescription;
+import org.onlab.onos.net.device.DeviceEvent;
+import org.onlab.onos.net.device.PortDescription;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Manages inventory of infrastructure devices.
+ */
+public class DeviceStore {
+
+ private final Map<DeviceId, Device> devices = new ConcurrentHashMap<>();
+
+ /**
+ * Creates a new infrastructure device, or updates an existing one using
+ * the supplied device description.
+ *
+ * @param deviceId device identifier
+ * @param deviceDescription device description
+ * @return ready to send event describing what occurred; null if no change
+ */
+ public DeviceEvent createOrUpdateDevice(DeviceId deviceId,
+ DeviceDescription deviceDescription) {
+ return null;
+ }
+
+ /**
+ * Removes the specified infrastructure device.
+ *
+ * @param deviceId device identifier
+ * @return ready to send event describing what occurred; null if no change
+ */
+ public DeviceEvent removeDevice(DeviceId deviceId) {
+ return null;
+ }
+
+ /**
+ * Updates the ports of the specified infrastructure device using the given
+ * list of port descriptions. The list is assumed to be comprehensive.
+ *
+ * @param deviceId device identifier
+ * @param portDescriptions list of port descriptions
+ * @return ready to send events describing what occurred; empty list if no change
+ */
+ public List<DeviceEvent> updatePorts(DeviceId deviceId,
+ List<PortDescription> portDescriptions) {
+ return new ArrayList<>();
+ }
+
+ /**
+ * Updates the port status of the specified infrastructure device using the
+ * given port description.
+ *
+ * @param deviceId device identifier
+ * @param portDescription port description
+ * @return ready to send event describing what occurred; null if no change
+ */
+ public DeviceEvent updatePortStatus(DeviceId deviceId,
+ PortDescription portDescription) {
+ return null;
+ }
+}
diff --git a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java b/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
index ce7c6c4..7038284 100644
--- a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
+++ b/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
@@ -4,12 +4,20 @@
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.event.AbstractListenerManager;
+import org.onlab.onos.event.EventDispatchService;
+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.DeviceListener;
import org.onlab.onos.net.device.DeviceProvider;
import org.onlab.onos.net.device.DeviceProviderBroker;
import org.onlab.onos.net.device.DeviceProviderService;
+import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.AbstractProviderBroker;
import org.onlab.onos.net.provider.AbstractProviderService;
@@ -18,47 +26,86 @@
import java.util.List;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Provides basic implementation of the device SB & NB APIs.
*/
@Component(immediate = true)
@Service
-public class SimpleDeviceManager implements DeviceProviderBroker {
+public class SimpleDeviceManager
+ extends AbstractProviderBroker<DeviceProvider, DeviceProviderService>
+ implements DeviceService, DeviceProviderBroker {
+
+ public static final String DEVICE_ID_NULL = "Device ID cannot be null";
+ public static final String PORT_NUMBER_NULL = "Port number cannot be null";
+ public static final String DEVICE_DESCRIPTION_NULL = "Device description cannot be null";
+ public static final String PORT_DESCRIPTION_NULL = "Port description cannot be null";
private Logger log = LoggerFactory.getLogger(SimpleDeviceManager.class);
- private final DeviceProviderBroker broker = new InternalBroker();
+ private final AbstractListenerManager<DeviceEvent, DeviceListener>
+ listenerManager = new AbstractListenerManager<>();
+
+ private EventDispatchService eventDispatcher;
+
+ private final DeviceStore store = new DeviceStore();
@Activate
public void activate() {
+// eventDispatcher.addSink(DeviceEvent.class, listenerManager);
log.info("Started");
}
@Deactivate
public void deactivate() {
+// eventDispatcher.removeSink(DeviceEvent.class);
log.info("Stopped");
}
@Override
- public DeviceProviderService register(DeviceProvider provider) {
- log.info("Registering provider {}", provider.id());
- return broker.register(provider);
+ public MastershipRole getRole(DeviceId deviceId) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ return null;
}
@Override
- public void unregister(DeviceProvider provider) {
- log.info("Unregistering provider {}", provider.id());
- broker.unregister(provider);
+ public Iterable<Device> getDevices() {
+ return null;
}
- // Internal delegate for tracking various providers and issuing them a
- // personalized provider service.
- private class InternalBroker extends AbstractProviderBroker<DeviceProvider, DeviceProviderService>
- implements DeviceProviderBroker {
- @Override
- protected DeviceProviderService createProviderService(DeviceProvider provider) {
- return new InternalDeviceProviderService(provider);
- }
+ @Override
+ public Device getDevice(DeviceId deviceId) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ return null;
+ }
+
+ @Override
+ public List<Port> getPorts(DeviceId deviceId) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ return null;
+ }
+
+ @Override
+ public Port getPort(DeviceId deviceId, PortNumber portNumber) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ checkNotNull(portNumber, PORT_NUMBER_NULL);
+ return null;
+ }
+
+ @Override
+ public void addListener(DeviceListener listener) {
+ listenerManager.addListener(listener);
+ }
+
+ @Override
+ public void removeListener(DeviceListener listener) {
+ listenerManager.removeListener(listener);
+ }
+
+ @Override
+ protected DeviceProviderService createProviderService(DeviceProvider provider) {
+ return new InternalDeviceProviderService(provider);
}
// Personalized device provider service issued to the supplied provider.
@@ -71,26 +118,49 @@
@Override
public MastershipRole deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL);
log.info("Device {} connected: {}", deviceId, deviceDescription);
+ DeviceEvent event = store.createOrUpdateDevice(deviceId, deviceDescription);
+ post(event);
return MastershipRole.MASTER;
}
@Override
public void deviceDisconnected(DeviceId deviceId) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
log.info("Device {} disconnected", deviceId);
-
+ DeviceEvent event = store.removeDevice(deviceId);
+ post(event);
}
@Override
- public void updatePorts(DeviceId deviceId, List<PortDescription> ports) {
+ public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ checkNotNull(portDescriptions, "Port descriptions list cannot be null");
// FIXME: fix the interface to accept DeviceId separately
- log.info("Device {} ports updated: {}", ports);
-
+ log.info("Device {} ports updated: {}", portDescriptions);
+ List<DeviceEvent> events = store.updatePorts(deviceId, portDescriptions);
+ for (DeviceEvent event : events) {
+ post(event);
+ }
}
@Override
- public void portStatusChanged(DeviceId deviceId, PortDescription port) {
- log.info("Device {} port status changed: {}", deviceId, port);
+ public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) {
+ checkNotNull(deviceId, DEVICE_ID_NULL);
+ checkNotNull(portDescription, PORT_DESCRIPTION_NULL);
+ log.info("Device {} port status changed: {}", deviceId, portDescription);
+ DeviceEvent event = store.updatePortStatus(deviceId, portDescription);
+ post(event);
}
}
+
+ // Posts the specified event to a local event dispatcher
+ private void post(DeviceEvent event) {
+ if (event != null && eventDispatcher != null) {
+ eventDispatcher.post(event);
+ }
+ }
+
}
diff --git a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostManager.java b/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostManager.java
index 8e16877..81397cf 100644
--- a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostManager.java
+++ b/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostManager.java
@@ -36,13 +36,11 @@
@Override
public HostProviderService register(HostProvider provider) {
- log.info("Registering provider {}", provider.id());
return broker.register(provider);
}
@Override
public void unregister(HostProvider provider) {
- log.info("Unregistering provider {}", provider.id());
broker.unregister(provider);
}
diff --git a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java b/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java
index 1f97ef8..6283e0b 100644
--- a/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java
+++ b/net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java
@@ -36,13 +36,11 @@
@Override
public LinkProviderService register(LinkProvider provider) {
- log.info("Registering provider {}", provider.id());
return broker.register(provider);
}
@Override
public void unregister(LinkProvider provider) {
- log.info("Unregistering provider {}", provider.id());
broker.unregister(provider);
}
diff --git a/net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/GreetManagerTest.java b/net/core/trivial/src/test/java/org/onlab/onos/impl/GreetManagerTest.java
similarity index 89%
rename from net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/GreetManagerTest.java
rename to net/core/trivial/src/test/java/org/onlab/onos/impl/GreetManagerTest.java
index 3bbffde..c498660 100644
--- a/net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/GreetManagerTest.java
+++ b/net/core/trivial/src/test/java/org/onlab/onos/impl/GreetManagerTest.java
@@ -1,7 +1,7 @@
-package org.onlab.onos.net.trivial.impl;
+package org.onlab.onos.impl;
import org.junit.Test;
-import org.onlab.onos.net.GreetService;
+import org.onlab.onos.GreetService;
import java.util.Iterator;
diff --git a/web/api/src/main/java/org/onlab/onos/rest/GreetResource.java b/web/api/src/main/java/org/onlab/onos/rest/GreetResource.java
index a379c62..ca099ac 100644
--- a/web/api/src/main/java/org/onlab/onos/rest/GreetResource.java
+++ b/web/api/src/main/java/org/onlab/onos/rest/GreetResource.java
@@ -2,7 +2,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onlab.onos.net.GreetService;
+import org.onlab.onos.GreetService;
import org.onlab.rest.BaseResource;
import javax.ws.rs.DefaultValue;
diff --git a/web/api/src/test/java/org/onlab/onos/rest/GreetResourceTest.java b/web/api/src/test/java/org/onlab/onos/rest/GreetResourceTest.java
index 24b9925..fcdb606 100644
--- a/web/api/src/test/java/org/onlab/onos/rest/GreetResourceTest.java
+++ b/web/api/src/test/java/org/onlab/onos/rest/GreetResourceTest.java
@@ -4,8 +4,8 @@
import com.sun.jersey.test.framework.JerseyTest;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onlab.onos.net.GreetService;
-import org.onlab.onos.net.trivial.impl.GreetManager;
+import org.onlab.onos.GreetService;
+import org.onlab.onos.impl.GreetManager;
import org.onlab.osgi.ServiceDirectory;
import org.onlab.osgi.TestServiceDirectory;
diff --git a/web/gui/src/main/java/org/onlab/onos/gui/GreetResource.java b/web/gui/src/main/java/org/onlab/onos/gui/GreetResource.java
index 7e1e7d4..f184efd 100644
--- a/web/gui/src/main/java/org/onlab/onos/gui/GreetResource.java
+++ b/web/gui/src/main/java/org/onlab/onos/gui/GreetResource.java
@@ -1,6 +1,6 @@
package org.onlab.onos.gui;
-import org.onlab.onos.net.GreetService;
+import org.onlab.onos.GreetService;
import org.onlab.rest.BaseResource;
import javax.ws.rs.DefaultValue;
diff --git a/web/pom.xml b/web/pom.xml
index 33dac46..5eb67bb 100644
--- a/web/pom.xml
+++ b/web/pom.xml
@@ -100,9 +100,8 @@
com.sun.jersey.server.impl.container.servlet,
com.fasterxml.jackson.databind,
com.fasterxml.jackson.databind.node,
- org.onlab.osgi.*,
org.onlab.rest.*,
- org.onlab.onos.net.*
+ org.onlab.onos.*
</Import-Package>
<Web-ContextPath>${web.context}</Web-ContextPath>
</instructions>