Bundle restructuring
Change-Id: I5a9efa7f4d03bd78dd17297731c5addea5cf0442
diff --git a/core/store/dist/pom.xml b/core/store/dist/pom.xml
new file mode 100644
index 0000000..900a2ff
--- /dev/null
+++ b/core/store/dist/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-core-store</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-core-dist</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS Gossip based distributed store subsystems</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-core-serializers</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>de.javakaffee</groupId>
+ <artifactId>kryo-serializers</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/package-info.java b/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/package-info.java
new file mode 100644
index 0000000..b2fc91d
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/device/impl/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Implementation of device store using distributed structures.
+ */
+package org.onlab.onos.store.device.impl;
diff --git a/core/store/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
rename to core/store/dist/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/host/impl/DistributedHostStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/host/impl/DistributedHostStore.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/host/impl/DistributedHostStore.java
rename to core/store/dist/src/main/java/org/onlab/onos/store/host/impl/DistributedHostStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/OnosTimestamp.java b/core/store/dist/src/main/java/org/onlab/onos/store/impl/OnosTimestamp.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/impl/OnosTimestamp.java
rename to core/store/dist/src/main/java/org/onlab/onos/store/impl/OnosTimestamp.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/OnosTimestampSerializer.java b/core/store/dist/src/main/java/org/onlab/onos/store/serializers/OnosTimestampSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/OnosTimestampSerializer.java
rename to core/store/dist/src/main/java/org/onlab/onos/store/serializers/OnosTimestampSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java b/core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
similarity index 100%
copy from core/store/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
copy to core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopologyGraph.java b/core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopologyGraph.java
similarity index 100%
copy from core/store/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopologyGraph.java
copy to core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopologyGraph.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java
similarity index 100%
copy from core/store/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java
copy to core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/topology/impl/PathKey.java b/core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/PathKey.java
similarity index 100%
copy from core/store/src/main/java/org/onlab/onos/store/topology/impl/PathKey.java
copy to core/store/dist/src/main/java/org/onlab/onos/store/topology/impl/PathKey.java
diff --git a/core/store/hz/pom.xml b/core/store/hz/pom.xml
new file mode 100644
index 0000000..d17bb4f
--- /dev/null
+++ b/core/store/hz/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-core-store</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-core-hz</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS Hazelcast based distributed store subsystems</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-core-serializers</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>de.javakaffee</groupId>
+ <artifactId>kryo-serializers</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/core/store/src/main/java/org/onlab/onos/store/cluster/impl/DistributedClusterStore.java b/core/store/hz/src/main/java/org/onlab/onos/store/cluster/impl/DistributedClusterStore.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/cluster/impl/DistributedClusterStore.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/cluster/impl/DistributedClusterStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/cluster/impl/DistributedMastershipStore.java b/core/store/hz/src/main/java/org/onlab/onos/store/cluster/impl/DistributedMastershipStore.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/cluster/impl/DistributedMastershipStore.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/cluster/impl/DistributedMastershipStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/cluster/impl/package-info.java b/core/store/hz/src/main/java/org/onlab/onos/store/cluster/impl/package-info.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/cluster/impl/package-info.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/cluster/impl/package-info.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/common/StoreService.java b/core/store/hz/src/main/java/org/onlab/onos/store/common/StoreService.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/common/StoreService.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/common/StoreService.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/common/package-info.java b/core/store/hz/src/main/java/org/onlab/onos/store/common/package-info.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/common/package-info.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/common/package-info.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java b/core/store/hz/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/device/impl/DistributedDeviceStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/device/impl/package-info.java b/core/store/hz/src/main/java/org/onlab/onos/store/device/impl/package-info.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/device/impl/package-info.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/device/impl/package-info.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java b/core/store/hz/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
similarity index 100%
copy from core/store/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
copy to core/store/hz/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/host/impl/DistributedHostStore.java b/core/store/hz/src/main/java/org/onlab/onos/store/host/impl/DistributedHostStore.java
similarity index 100%
copy from core/store/src/main/java/org/onlab/onos/store/host/impl/DistributedHostStore.java
copy to core/store/hz/src/main/java/org/onlab/onos/store/host/impl/DistributedHostStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/AbsentInvalidatingLoadingCache.java b/core/store/hz/src/main/java/org/onlab/onos/store/impl/AbsentInvalidatingLoadingCache.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/impl/AbsentInvalidatingLoadingCache.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/impl/AbsentInvalidatingLoadingCache.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/AbstractDistributedStore.java b/core/store/hz/src/main/java/org/onlab/onos/store/impl/AbstractDistributedStore.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/impl/AbstractDistributedStore.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/impl/AbstractDistributedStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/OptionalCacheLoader.java b/core/store/hz/src/main/java/org/onlab/onos/store/impl/OptionalCacheLoader.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/impl/OptionalCacheLoader.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/impl/OptionalCacheLoader.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java b/core/store/hz/src/main/java/org/onlab/onos/store/impl/StoreManager.java
similarity index 96%
rename from core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/impl/StoreManager.java
index e2692d5..7d542a8 100644
--- a/core/store/src/main/java/org/onlab/onos/store/impl/StoreManager.java
+++ b/core/store/hz/src/main/java/org/onlab/onos/store/impl/StoreManager.java
@@ -35,7 +35,6 @@
import org.onlab.onos.store.serializers.IpPrefixSerializer;
import org.onlab.onos.store.serializers.LinkKeySerializer;
import org.onlab.onos.store.serializers.NodeIdSerializer;
-import org.onlab.onos.store.serializers.OnosTimestampSerializer;
import org.onlab.onos.store.serializers.PortNumberSerializer;
import org.onlab.onos.store.serializers.ProviderIdSerializer;
import org.onlab.packet.IpPrefix;
@@ -102,7 +101,6 @@
.register(DeviceId.class, new DeviceIdSerializer())
.register(PortNumber.class, new PortNumberSerializer())
.register(DefaultPort.class, new DefaultPortSerializer())
- .register(OnosTimestamp.class, new OnosTimestampSerializer())
.register(LinkKey.class, new LinkKeySerializer())
.register(ConnectPoint.class, new ConnectPointSerializer())
.register(DefaultLink.class, new DefaultLinkSerializer())
diff --git a/core/store/src/main/java/org/onlab/onos/store/impl/package-info.java b/core/store/hz/src/main/java/org/onlab/onos/store/impl/package-info.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/impl/package-info.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/impl/package-info.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/link/impl/DistributedLinkStore.java b/core/store/hz/src/main/java/org/onlab/onos/store/link/impl/DistributedLinkStore.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/link/impl/DistributedLinkStore.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/link/impl/DistributedLinkStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/link/impl/package-info.java b/core/store/hz/src/main/java/org/onlab/onos/store/link/impl/package-info.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/link/impl/package-info.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/link/impl/package-info.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java b/core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopology.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopologyGraph.java b/core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopologyGraph.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopologyGraph.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/DefaultTopologyGraph.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java b/core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/topology/impl/PathKey.java b/core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/PathKey.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/topology/impl/PathKey.java
rename to core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/PathKey.java
diff --git a/core/store/src/test/java/org/onlab/onos/store/device/impl/DistributedDeviceStoreTest.java b/core/store/hz/src/test/java/org/onlab/onos/store/device/impl/DistributedDeviceStoreTest.java
similarity index 100%
rename from core/store/src/test/java/org/onlab/onos/store/device/impl/DistributedDeviceStoreTest.java
rename to core/store/hz/src/test/java/org/onlab/onos/store/device/impl/DistributedDeviceStoreTest.java
diff --git a/core/store/src/test/java/org/onlab/onos/store/impl/TestStoreManager.java b/core/store/hz/src/test/java/org/onlab/onos/store/impl/TestStoreManager.java
similarity index 100%
rename from core/store/src/test/java/org/onlab/onos/store/impl/TestStoreManager.java
rename to core/store/hz/src/test/java/org/onlab/onos/store/impl/TestStoreManager.java
diff --git a/core/store/src/test/java/org/onlab/onos/store/link/impl/DistributedLinkStoreTest.java b/core/store/hz/src/test/java/org/onlab/onos/store/link/impl/DistributedLinkStoreTest.java
similarity index 100%
rename from core/store/src/test/java/org/onlab/onos/store/link/impl/DistributedLinkStoreTest.java
rename to core/store/hz/src/test/java/org/onlab/onos/store/link/impl/DistributedLinkStoreTest.java
diff --git a/core/store/pom.xml b/core/store/pom.xml
index 246355c..b94b4fe 100644
--- a/core/store/pom.xml
+++ b/core/store/pom.xml
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -12,34 +10,41 @@
</parent>
<artifactId>onos-core-store</artifactId>
- <packaging>bundle</packaging>
+ <packaging>pom</packaging>
- <description>ONOS distributed store subsystems</description>
+ <description>ONOS Core Store subsystem</description>
+
+ <modules>
+ <module>trivial</module>
+ <module>dist</module>
+ <module>hz</module>
+ <module>serializers</module>
+ </modules>
<dependencies>
<dependency>
- <groupId>org.onlab.onos</groupId>
- <artifactId>onos-api</artifactId>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onlab-misc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onlab-junit</artifactId>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</dependency>
- <dependency>
- <groupId>de.javakaffee</groupId>
- <artifactId>kryo-serializers</artifactId>
- </dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
+ <artifactId>maven-bundle-plugin</artifactId>
</plugin>
</plugins>
</build>
diff --git a/core/store/serializers/pom.xml b/core/store/serializers/pom.xml
new file mode 100644
index 0000000..f222a23
--- /dev/null
+++ b/core/store/serializers/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-core-store</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-core-serializers</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Serializers for ONOS classes</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>de.javakaffee</groupId>
+ <artifactId>kryo-serializers</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/ConnectPointSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ConnectPointSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/ConnectPointSerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ConnectPointSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/DefaultLinkSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultLinkSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/DefaultLinkSerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultLinkSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/LinkKeySerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/LinkKeySerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/LinkKeySerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/LinkKeySerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/NodeIdSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/NodeIdSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/NodeIdSerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/NodeIdSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java
diff --git a/core/store/src/main/java/org/onlab/onos/store/serializers/package-info.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/package-info.java
similarity index 100%
rename from core/store/src/main/java/org/onlab/onos/store/serializers/package-info.java
rename to core/store/serializers/src/main/java/org/onlab/onos/store/serializers/package-info.java
diff --git a/core/store/trivial/pom.xml b/core/store/trivial/pom.xml
new file mode 100644
index 0000000..40016d4
--- /dev/null
+++ b/core/store/trivial/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-core-store</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-core-trivial</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS network control trivial implementations of core subsystems</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopology.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopology.java
new file mode 100644
index 0000000..e65ad08
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopology.java
@@ -0,0 +1,444 @@
+package org.onlab.onos.net.trivial.impl;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import org.onlab.graph.DijkstraGraphSearch;
+import org.onlab.graph.GraphPathSearch;
+import org.onlab.graph.TarjanGraphSearch;
+import org.onlab.onos.net.AbstractModel;
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.DefaultPath;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.Path;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.net.topology.ClusterId;
+import org.onlab.onos.net.topology.DefaultTopologyCluster;
+import org.onlab.onos.net.topology.DefaultTopologyVertex;
+import org.onlab.onos.net.topology.GraphDescription;
+import org.onlab.onos.net.topology.LinkWeight;
+import org.onlab.onos.net.topology.Topology;
+import org.onlab.onos.net.topology.TopologyCluster;
+import org.onlab.onos.net.topology.TopologyEdge;
+import org.onlab.onos.net.topology.TopologyGraph;
+import org.onlab.onos.net.topology.TopologyVertex;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.collect.ImmutableSetMultimap.Builder;
+import static org.onlab.graph.GraphPathSearch.Result;
+import static org.onlab.graph.TarjanGraphSearch.SCCResult;
+import static org.onlab.onos.net.Link.Type.INDIRECT;
+
+/**
+ * Default implementation of the topology descriptor. This carries the
+ * backing topology data.
+ */
+public class DefaultTopology extends AbstractModel implements Topology {
+
+ private static final DijkstraGraphSearch<TopologyVertex, TopologyEdge> DIJKSTRA =
+ new DijkstraGraphSearch<>();
+ private static final TarjanGraphSearch<TopologyVertex, TopologyEdge> TARJAN =
+ new TarjanGraphSearch<>();
+
+ private static final ProviderId PID = new ProviderId("core", "org.onlab.onos.net");
+
+ private final long time;
+ private final TopologyGraph graph;
+
+ private final SCCResult<TopologyVertex, TopologyEdge> clusterResults;
+ private final ImmutableMap<DeviceId, Result<TopologyVertex, TopologyEdge>> results;
+ private final ImmutableSetMultimap<PathKey, Path> paths;
+
+ private final ImmutableMap<ClusterId, TopologyCluster> clusters;
+ private final ImmutableSet<ConnectPoint> infrastructurePoints;
+ private final ImmutableSetMultimap<ClusterId, ConnectPoint> broadcastSets;
+
+ private ImmutableMap<DeviceId, TopologyCluster> clustersByDevice;
+ private ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster;
+ private ImmutableSetMultimap<TopologyCluster, Link> linksByCluster;
+
+
+ /**
+ * Creates a topology descriptor attributed to the specified provider.
+ *
+ * @param providerId identity of the provider
+ * @param description data describing the new topology
+ */
+ DefaultTopology(ProviderId providerId, GraphDescription description) {
+ super(providerId);
+ this.time = description.timestamp();
+
+ // Build the graph
+ this.graph = new DefaultTopologyGraph(description.vertexes(),
+ description.edges());
+
+ this.results = searchForShortestPaths();
+ this.paths = buildPaths();
+
+ this.clusterResults = searchForClusters();
+ this.clusters = buildTopologyClusters();
+
+ buildIndexes();
+
+ this.broadcastSets = buildBroadcastSets();
+ this.infrastructurePoints = findInfrastructurePoints();
+ }
+
+ @Override
+ public long time() {
+ return time;
+ }
+
+ @Override
+ public int clusterCount() {
+ return clusters.size();
+ }
+
+ @Override
+ public int deviceCount() {
+ return graph.getVertexes().size();
+ }
+
+ @Override
+ public int linkCount() {
+ return graph.getEdges().size();
+ }
+
+ @Override
+ public int pathCount() {
+ return paths.size();
+ }
+
+ /**
+ * Returns the backing topology graph.
+ *
+ * @return topology graph
+ */
+ TopologyGraph getGraph() {
+ return graph;
+ }
+
+ /**
+ * Returns the set of topology clusters.
+ *
+ * @return set of clusters
+ */
+ Set<TopologyCluster> getClusters() {
+ return ImmutableSet.copyOf(clusters.values());
+ }
+
+ /**
+ * Returns the specified topology cluster.
+ *
+ * @param clusterId cluster identifier
+ * @return topology cluster
+ */
+ TopologyCluster getCluster(ClusterId clusterId) {
+ return clusters.get(clusterId);
+ }
+
+ /**
+ * Returns the topology cluster that contains the given device.
+ *
+ * @param deviceId device identifier
+ * @return topology cluster
+ */
+ TopologyCluster getCluster(DeviceId deviceId) {
+ return clustersByDevice.get(deviceId);
+ }
+
+ /**
+ * Returns the set of cluster devices.
+ *
+ * @param cluster topology cluster
+ * @return cluster devices
+ */
+ Set<DeviceId> getClusterDevices(TopologyCluster cluster) {
+ return devicesByCluster.get(cluster);
+ }
+
+ /**
+ * Returns the set of cluster links.
+ *
+ * @param cluster topology cluster
+ * @return cluster links
+ */
+ Set<Link> getClusterLinks(TopologyCluster cluster) {
+ return linksByCluster.get(cluster);
+ }
+
+ /**
+ * Indicates whether the given point is an infrastructure link end-point.
+ *
+ * @param connectPoint connection point
+ * @return true if infrastructure
+ */
+ boolean isInfrastructure(ConnectPoint connectPoint) {
+ return infrastructurePoints.contains(connectPoint);
+ }
+
+ /**
+ * Indicates whether the given point is part of a broadcast set.
+ *
+ * @param connectPoint connection point
+ * @return true if in broadcast set
+ */
+ boolean isBroadcastPoint(ConnectPoint connectPoint) {
+ // Any non-infrastructure, i.e. edge points are assumed to be OK.
+ if (!isInfrastructure(connectPoint)) {
+ return true;
+ }
+
+ // Find the cluster to which the device belongs.
+ TopologyCluster cluster = clustersByDevice.get(connectPoint.deviceId());
+ if (cluster == null) {
+ throw new IllegalArgumentException("No cluster found for device " + connectPoint.deviceId());
+ }
+
+ // If the broadcast set is null or empty, or if the point explicitly
+ // belongs to it, return true;
+ Set<ConnectPoint> points = broadcastSets.get(cluster.id());
+ return points == null || points.isEmpty() || points.contains(connectPoint);
+ }
+
+ /**
+ * Returns the size of the cluster broadcast set.
+ *
+ * @param clusterId cluster identifier
+ * @return size of the cluster broadcast set
+ */
+ int broadcastSetSize(ClusterId clusterId) {
+ return broadcastSets.get(clusterId).size();
+ }
+
+ /**
+ * Returns the set of pre-computed shortest paths between source and
+ * destination devices.
+ *
+ * @param src source device
+ * @param dst destination device
+ * @return set of shortest paths
+ */
+ Set<Path> getPaths(DeviceId src, DeviceId dst) {
+ return paths.get(new PathKey(src, dst));
+ }
+
+ /**
+ * Computes on-demand the set of shortest paths between source and
+ * destination devices.
+ *
+ * @param src source device
+ * @param dst destination device
+ * @return set of shortest paths
+ */
+ Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
+ GraphPathSearch.Result<TopologyVertex, TopologyEdge> result =
+ DIJKSTRA.search(graph, new DefaultTopologyVertex(src),
+ new DefaultTopologyVertex(dst), weight);
+ ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
+ for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
+ builder.add(networkPath(path));
+ }
+ return builder.build();
+ }
+
+
+ // Searches the graph for all shortest paths and returns the search results.
+ private ImmutableMap<DeviceId, Result<TopologyVertex, TopologyEdge>> searchForShortestPaths() {
+ ImmutableMap.Builder<DeviceId, Result<TopologyVertex, TopologyEdge>> builder = ImmutableMap.builder();
+
+ // Search graph paths for each source to all destinations.
+ LinkWeight weight = new HopCountLinkWeight(graph.getVertexes().size());
+ for (TopologyVertex src : graph.getVertexes()) {
+ builder.put(src.deviceId(), DIJKSTRA.search(graph, src, null, weight));
+ }
+ return builder.build();
+ }
+
+ // Builds network paths from the graph path search results
+ private ImmutableSetMultimap<PathKey, Path> buildPaths() {
+ Builder<PathKey, Path> builder = ImmutableSetMultimap.builder();
+ for (DeviceId deviceId : results.keySet()) {
+ Result<TopologyVertex, TopologyEdge> result = results.get(deviceId);
+ for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
+ builder.put(new PathKey(path.src().deviceId(), path.dst().deviceId()),
+ networkPath(path));
+ }
+ }
+ return builder.build();
+ }
+
+ // Converts graph path to a network path with the same cost.
+ private Path networkPath(org.onlab.graph.Path<TopologyVertex, TopologyEdge> path) {
+ List<Link> links = new ArrayList<>();
+ for (TopologyEdge edge : path.edges()) {
+ links.add(edge.link());
+ }
+ return new DefaultPath(PID, links, path.cost());
+ }
+
+
+ // Searches for SCC clusters in the network topology graph using Tarjan
+ // algorithm.
+ private SCCResult<TopologyVertex, TopologyEdge> searchForClusters() {
+ return TARJAN.search(graph, new NoIndirectLinksWeight());
+ }
+
+ // Builds the topology clusters and returns the id-cluster bindings.
+ private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() {
+ ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
+ SCCResult<TopologyVertex, TopologyEdge> result =
+ TARJAN.search(graph, new NoIndirectLinksWeight());
+
+ // Extract both vertexes and edges from the results; the lists form
+ // pairs along the same index.
+ List<Set<TopologyVertex>> clusterVertexes = result.clusterVertexes();
+ List<Set<TopologyEdge>> clusterEdges = result.clusterEdges();
+
+ // Scan over the lists and create a cluster from the results.
+ for (int i = 0, n = result.clusterCount(); i < n; i++) {
+ Set<TopologyVertex> vertexSet = clusterVertexes.get(i);
+ Set<TopologyEdge> edgeSet = clusterEdges.get(i);
+
+ ClusterId cid = ClusterId.clusterId(i);
+ DefaultTopologyCluster cluster =
+ new DefaultTopologyCluster(cid, vertexSet.size(), edgeSet.size(),
+ findRoot(vertexSet).deviceId());
+ clusterBuilder.put(cid, cluster);
+ }
+ return clusterBuilder.build();
+ }
+
+ // Finds the vertex whose device id is the lexicographical minimum in the
+ // specified set.
+ private TopologyVertex findRoot(Set<TopologyVertex> vertexSet) {
+ TopologyVertex minVertex = null;
+ for (TopologyVertex vertex : vertexSet) {
+ if (minVertex == null ||
+ minVertex.deviceId().toString()
+ .compareTo(minVertex.deviceId().toString()) < 0) {
+ minVertex = vertex;
+ }
+ }
+ return minVertex;
+ }
+
+ // Processes a map of broadcast sets for each cluster.
+ private ImmutableSetMultimap<ClusterId, ConnectPoint> buildBroadcastSets() {
+ Builder<ClusterId, ConnectPoint> builder = ImmutableSetMultimap.builder();
+ for (TopologyCluster cluster : clusters.values()) {
+ addClusterBroadcastSet(cluster, builder);
+ }
+ return builder.build();
+ }
+
+ // Finds all broadcast points for the cluster. These are those connection
+ // points which lie along the shortest paths between the cluster root and
+ // all other devices within the cluster.
+ private void addClusterBroadcastSet(TopologyCluster cluster,
+ Builder<ClusterId, ConnectPoint> builder) {
+ // Use the graph root search results to build the broadcast set.
+ Result<TopologyVertex, TopologyEdge> result = results.get(cluster.root());
+ for (Map.Entry<TopologyVertex, Set<TopologyEdge>> entry : result.parents().entrySet()) {
+ TopologyVertex vertex = entry.getKey();
+
+ // Ignore any parents that lead outside the cluster.
+ if (clustersByDevice.get(vertex.deviceId()) != cluster) {
+ continue;
+ }
+
+ // Ignore any back-link sets that are empty.
+ Set<TopologyEdge> parents = entry.getValue();
+ if (parents.isEmpty()) {
+ continue;
+ }
+
+ // Use the first back-link source and destinations to add to the
+ // broadcast set.
+ Link link = parents.iterator().next().link();
+ builder.put(cluster.id(), link.src());
+ builder.put(cluster.id(), link.dst());
+ }
+ }
+
+ // Collects and returns an set of all infrastructure link end-points.
+ private ImmutableSet<ConnectPoint> findInfrastructurePoints() {
+ ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
+ for (TopologyEdge edge : graph.getEdges()) {
+ builder.add(edge.link().src());
+ builder.add(edge.link().dst());
+ }
+ return builder.build();
+ }
+
+ // Builds cluster-devices, cluster-links and device-cluster indexes.
+ private void buildIndexes() {
+ // Prepare the index builders
+ ImmutableMap.Builder<DeviceId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
+ ImmutableSetMultimap.Builder<TopologyCluster, DeviceId> devicesBuilder = ImmutableSetMultimap.builder();
+ ImmutableSetMultimap.Builder<TopologyCluster, Link> linksBuilder = ImmutableSetMultimap.builder();
+
+ // Now scan through all the clusters
+ for (TopologyCluster cluster : clusters.values()) {
+ int i = cluster.id().index();
+
+ // Scan through all the cluster vertexes.
+ for (TopologyVertex vertex : clusterResults.clusterVertexes().get(i)) {
+ devicesBuilder.put(cluster, vertex.deviceId());
+ clusterBuilder.put(vertex.deviceId(), cluster);
+ }
+
+ // Scan through all the cluster edges.
+ for (TopologyEdge edge : clusterResults.clusterEdges().get(i)) {
+ linksBuilder.put(cluster, edge.link());
+ }
+ }
+
+ // Finalize all indexes.
+ clustersByDevice = clusterBuilder.build();
+ devicesByCluster = devicesBuilder.build();
+ linksByCluster = linksBuilder.build();
+ }
+
+ // Link weight for measuring link cost as hop count with indirect links
+ // being as expensive as traversing the entire graph to assume the worst.
+ private static class HopCountLinkWeight implements LinkWeight {
+ private final int indirectLinkCost;
+
+ HopCountLinkWeight(int indirectLinkCost) {
+ this.indirectLinkCost = indirectLinkCost;
+ }
+
+ @Override
+ public double weight(TopologyEdge edge) {
+ // To force preference to use direct paths first, make indirect
+ // links as expensive as the linear vertex traversal.
+ return edge.link().type() == INDIRECT ? indirectLinkCost : 1;
+ }
+ }
+
+ // Link weight for preventing traversal over indirect links.
+ private static class NoIndirectLinksWeight implements LinkWeight {
+ @Override
+ public double weight(TopologyEdge edge) {
+ return edge.link().type() == INDIRECT ? -1 : 1;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("time", time)
+ .add("clusters", clusterCount())
+ .add("devices", deviceCount())
+ .add("links", linkCount())
+ .add("pathCount", pathCount())
+ .toString();
+ }
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopologyGraph.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopologyGraph.java
new file mode 100644
index 0000000..401dfd2
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DefaultTopologyGraph.java
@@ -0,0 +1,28 @@
+package org.onlab.onos.net.trivial.impl;
+
+import org.onlab.graph.AdjacencyListsGraph;
+import org.onlab.onos.net.topology.TopologyEdge;
+import org.onlab.onos.net.topology.TopologyGraph;
+import org.onlab.onos.net.topology.TopologyVertex;
+
+import java.util.Set;
+
+/**
+ * Default implementation of an immutable topology graph based on a generic
+ * implementation of adjacency lists graph.
+ */
+public class DefaultTopologyGraph
+ extends AdjacencyListsGraph<TopologyVertex, TopologyEdge>
+ implements TopologyGraph {
+
+ /**
+ * Creates a topology graph comprising of the specified vertexes and edges.
+ *
+ * @param vertexes set of graph vertexes
+ * @param edges set of graph edges
+ */
+ public DefaultTopologyGraph(Set<TopologyVertex> vertexes, Set<TopologyEdge> edges) {
+ super(vertexes, edges);
+ }
+
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/PathKey.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/PathKey.java
new file mode 100644
index 0000000..da3b055
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/PathKey.java
@@ -0,0 +1,40 @@
+package org.onlab.onos.net.trivial.impl;
+
+import org.onlab.onos.net.DeviceId;
+
+import java.util.Objects;
+
+/**
+ * Key for filing pre-computed paths between source and destination devices.
+ */
+class PathKey {
+ private final DeviceId src;
+ private final DeviceId dst;
+
+ /**
+ * Creates a path key from the given source/dest pair.
+ * @param src source device
+ * @param dst destination device
+ */
+ PathKey(DeviceId src, DeviceId dst) {
+ this.src = src;
+ this.dst = dst;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(src, dst);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof PathKey) {
+ final PathKey other = (PathKey) obj;
+ return Objects.equals(this.src, other.src) && Objects.equals(this.dst, other.dst);
+ }
+ return false;
+ }
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleClusterStore.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleClusterStore.java
new file mode 100644
index 0000000..d348d2f
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleClusterStore.java
@@ -0,0 +1,74 @@
+package org.onlab.onos.net.trivial.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.cluster.ClusterEvent;
+import org.onlab.onos.cluster.ClusterStore;
+import org.onlab.onos.cluster.ClusterStoreDelegate;
+import org.onlab.onos.cluster.ControllerNode;
+import org.onlab.onos.cluster.DefaultControllerNode;
+import org.onlab.onos.cluster.NodeId;
+import org.onlab.onos.store.AbstractStore;
+import org.onlab.packet.IpPrefix;
+import org.slf4j.Logger;
+
+import java.util.Set;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Manages inventory of infrastructure DEVICES using trivial in-memory
+ * structures implementation.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleClusterStore
+ extends AbstractStore<ClusterEvent, ClusterStoreDelegate>
+ implements ClusterStore {
+
+ public static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1");
+
+ private final Logger log = getLogger(getClass());
+
+ private ControllerNode instance;
+
+ @Activate
+ public void activate() {
+ instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+
+ @Override
+ public ControllerNode getLocalNode() {
+ return instance;
+ }
+
+ @Override
+ public Set<ControllerNode> getNodes() {
+ return ImmutableSet.of(instance);
+ }
+
+ @Override
+ public ControllerNode getNode(NodeId nodeId) {
+ return instance.id().equals(nodeId) ? instance : null;
+ }
+
+ @Override
+ public ControllerNode.State getState(NodeId nodeId) {
+ return ControllerNode.State.ACTIVE;
+ }
+
+ @Override
+ public void removeNode(NodeId nodeId) {
+ }
+
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
new file mode 100644
index 0000000..15dba06
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
@@ -0,0 +1,263 @@
+package org.onlab.onos.net.trivial.impl;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableList;
+
+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.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.DeviceStoreDelegate;
+import org.onlab.onos.net.device.PortDescription;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.store.AbstractStore;
+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 java.util.concurrent.ConcurrentHashMap;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Predicates.notNull;
+import static org.onlab.onos.net.device.DeviceEvent.Type.*;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Manages inventory of infrastructure devices using trivial in-memory
+ * structures implementation.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleDeviceStore
+ extends AbstractStore<DeviceEvent, DeviceStoreDelegate>
+ implements DeviceStore {
+
+ private final Logger log = getLogger(getClass());
+
+ public static final String DEVICE_NOT_FOUND = "Device with ID %s not found";
+
+ private final Map<DeviceId, DefaultDevice> devices = new ConcurrentHashMap<>();
+ private final Set<DeviceId> availableDevices = new HashSet<>();
+ private final Map<DeviceId, Map<PortNumber, Port>> devicePorts = new HashMap<>();
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public int getDeviceCount() {
+ return devices.size();
+ }
+
+ @Override
+ public Iterable<Device> getDevices() {
+ return Collections.unmodifiableSet(new HashSet<Device>(devices.values()));
+ }
+
+ @Override
+ public Device getDevice(DeviceId deviceId) {
+ return devices.get(deviceId);
+ }
+
+ @Override
+ public DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId,
+ DeviceDescription deviceDescription) {
+ DefaultDevice device = devices.get(deviceId);
+ if (device == null) {
+ return createDevice(providerId, deviceId, deviceDescription);
+ }
+ return updateDevice(providerId, device, deviceDescription);
+ }
+
+ // Creates the device and returns the appropriate event if necessary.
+ private DeviceEvent createDevice(ProviderId providerId, DeviceId deviceId,
+ DeviceDescription desc) {
+ DefaultDevice device = new DefaultDevice(providerId, deviceId, desc.type(),
+ desc.manufacturer(),
+ desc.hwVersion(), desc.swVersion(),
+ desc.serialNumber());
+ synchronized (this) {
+ devices.put(deviceId, device);
+ availableDevices.add(deviceId);
+
+ // For now claim the device as a master automatically.
+ // roles.put(deviceId, MastershipRole.MASTER);
+ }
+ return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, null);
+ }
+
+ // Updates the device and returns the appropriate event if necessary.
+ private DeviceEvent updateDevice(ProviderId providerId, DefaultDevice device,
+ DeviceDescription desc) {
+ // We allow only certain attributes to trigger update
+ if (!Objects.equals(device.hwVersion(), desc.hwVersion()) ||
+ !Objects.equals(device.swVersion(), desc.swVersion())) {
+ DefaultDevice updated = new DefaultDevice(providerId, device.id(),
+ desc.type(),
+ desc.manufacturer(),
+ desc.hwVersion(),
+ desc.swVersion(),
+ desc.serialNumber());
+ synchronized (this) {
+ devices.put(device.id(), updated);
+ availableDevices.add(device.id());
+ }
+ return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, updated, null);
+ }
+
+ // Otherwise merely attempt to change availability
+ synchronized (this) {
+ boolean added = availableDevices.add(device.id());
+ return !added ? null :
+ new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
+ }
+ }
+
+ @Override
+ public DeviceEvent markOffline(DeviceId deviceId) {
+ synchronized (this) {
+ Device device = devices.get(deviceId);
+ boolean removed = device != null && availableDevices.remove(deviceId);
+ return !removed ? null :
+ new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
+ }
+ }
+
+ @Override
+ public List<DeviceEvent> updatePorts(DeviceId deviceId,
+ List<PortDescription> portDescriptions) {
+ List<DeviceEvent> events = new ArrayList<>();
+ synchronized (this) {
+ Device device = devices.get(deviceId);
+ checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
+ Map<PortNumber, Port> ports = getPortMap(deviceId);
+
+ // Add new ports
+ Set<PortNumber> processed = new HashSet<>();
+ for (PortDescription portDescription : portDescriptions) {
+ Port port = ports.get(portDescription.portNumber());
+ events.add(port == null ?
+ createPort(device, portDescription, ports) :
+ updatePort(device, port, portDescription, ports));
+ processed.add(portDescription.portNumber());
+ }
+
+ events.addAll(pruneOldPorts(device, ports, processed));
+ }
+ return FluentIterable.from(events).filter(notNull()).toList();
+ }
+
+ // Creates a new port based on the port description adds it to the map and
+ // Returns corresponding event.
+ private DeviceEvent createPort(Device device, PortDescription portDescription,
+ Map<PortNumber, Port> ports) {
+ DefaultPort port = new DefaultPort(device, portDescription.portNumber(),
+ portDescription.isEnabled());
+ ports.put(port.number(), port);
+ return new DeviceEvent(PORT_ADDED, device, port);
+ }
+
+ // CHecks if the specified port requires update and if so, it replaces the
+ // existing entry in the map and returns corresponding event.
+ private DeviceEvent updatePort(Device device, Port port,
+ PortDescription portDescription,
+ Map<PortNumber, Port> ports) {
+ if (port.isEnabled() != portDescription.isEnabled()) {
+ DefaultPort updatedPort =
+ new DefaultPort(device, portDescription.portNumber(),
+ portDescription.isEnabled());
+ ports.put(port.number(), updatedPort);
+ return new DeviceEvent(PORT_UPDATED, device, port);
+ }
+ return null;
+ }
+
+ // Prunes the specified list of ports based on which ports are in the
+ // processed list and returns list of corresponding events.
+ private List<DeviceEvent> pruneOldPorts(Device device,
+ Map<PortNumber, Port> ports,
+ Set<PortNumber> processed) {
+ List<DeviceEvent> events = new ArrayList<>();
+ Iterator<PortNumber> iterator = ports.keySet().iterator();
+ while (iterator.hasNext()) {
+ PortNumber portNumber = iterator.next();
+ if (!processed.contains(portNumber)) {
+ events.add(new DeviceEvent(PORT_REMOVED, device,
+ ports.get(portNumber)));
+ iterator.remove();
+ }
+ }
+ return events;
+ }
+
+ // Gets the map of ports for the specified device; if one does not already
+ // exist, it creates and registers a new one.
+ private Map<PortNumber, Port> getPortMap(DeviceId deviceId) {
+ Map<PortNumber, Port> ports = devicePorts.get(deviceId);
+ if (ports == null) {
+ ports = new HashMap<>();
+ devicePorts.put(deviceId, ports);
+ }
+ return ports;
+ }
+
+ @Override
+ public DeviceEvent updatePortStatus(DeviceId deviceId,
+ PortDescription portDescription) {
+ synchronized (this) {
+ Device device = devices.get(deviceId);
+ checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
+ Map<PortNumber, Port> ports = getPortMap(deviceId);
+ Port port = ports.get(portDescription.portNumber());
+ return updatePort(device, port, portDescription, ports);
+ }
+ }
+
+ @Override
+ public List<Port> getPorts(DeviceId deviceId) {
+ Map<PortNumber, Port> ports = devicePorts.get(deviceId);
+ return ports == null ? new ArrayList<Port>() : ImmutableList.copyOf(ports.values());
+ }
+
+ @Override
+ public Port getPort(DeviceId deviceId, PortNumber portNumber) {
+ Map<PortNumber, Port> ports = devicePorts.get(deviceId);
+ return ports == null ? null : ports.get(portNumber);
+ }
+
+ @Override
+ public boolean isAvailable(DeviceId deviceId) {
+ return availableDevices.contains(deviceId);
+ }
+
+ @Override
+ public DeviceEvent removeDevice(DeviceId deviceId) {
+ synchronized (this) {
+ Device device = devices.remove(deviceId);
+ return device == null ? null :
+ new DeviceEvent(DEVICE_REMOVED, device, null);
+ }
+ }
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java
new file mode 100644
index 0000000..38e94aa
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java
@@ -0,0 +1,152 @@
+package org.onlab.onos.net.trivial.impl;
+
+import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
+import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collection;
+import java.util.Collections;
+
+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.ApplicationId;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.flow.DefaultFlowRule;
+import org.onlab.onos.net.flow.FlowRule;
+import org.onlab.onos.net.flow.FlowRule.FlowRuleState;
+import org.onlab.onos.net.flow.FlowRuleEvent;
+import org.onlab.onos.net.flow.FlowRuleEvent.Type;
+import org.onlab.onos.net.flow.FlowRuleStore;
+import org.onlab.onos.net.flow.FlowRuleStoreDelegate;
+import org.onlab.onos.store.AbstractStore;
+import org.slf4j.Logger;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Multimap;
+
+/**
+ * Manages inventory of flow rules using trivial in-memory implementation.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleFlowRuleStore
+ extends AbstractStore<FlowRuleEvent, FlowRuleStoreDelegate>
+ implements FlowRuleStore {
+
+ private final Logger log = getLogger(getClass());
+
+ // store entries as a pile of rules, no info about device tables
+ private final Multimap<DeviceId, FlowRule> flowEntries =
+ ArrayListMultimap.<DeviceId, FlowRule>create();
+
+ private final Multimap<ApplicationId, FlowRule> flowEntriesById =
+ ArrayListMultimap.<ApplicationId, FlowRule>create();
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+
+ @Override
+ public synchronized FlowRule getFlowRule(FlowRule rule) {
+ for (FlowRule f : flowEntries.get(rule.deviceId())) {
+ if (f.equals(rule)) {
+ return f;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public synchronized Iterable<FlowRule> getFlowEntries(DeviceId deviceId) {
+ Collection<FlowRule> rules = flowEntries.get(deviceId);
+ if (rules == null) {
+ return Collections.emptyList();
+ }
+ return ImmutableSet.copyOf(rules);
+ }
+
+ @Override
+ public synchronized Iterable<FlowRule> getFlowEntriesByAppId(ApplicationId appId) {
+ Collection<FlowRule> rules = flowEntriesById.get(appId);
+ if (rules == null) {
+ return Collections.emptyList();
+ }
+ return ImmutableSet.copyOf(rules);
+ }
+
+ @Override
+ public synchronized void storeFlowRule(FlowRule rule) {
+ FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_ADD);
+ DeviceId did = f.deviceId();
+ if (!flowEntries.containsEntry(did, f)) {
+ flowEntries.put(did, f);
+ flowEntriesById.put(rule.appId(), f);
+ }
+ }
+
+ @Override
+ public synchronized void deleteFlowRule(FlowRule rule) {
+ FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_REMOVE);
+ DeviceId did = f.deviceId();
+
+ /*
+ * find the rule and mark it for deletion.
+ * Ultimately a flow removed will come remove it.
+ */
+
+ if (flowEntries.containsEntry(did, f)) {
+ //synchronized (flowEntries) {
+ flowEntries.remove(did, f);
+ flowEntries.put(did, f);
+ flowEntriesById.remove(rule.appId(), rule);
+ //}
+ }
+ }
+
+ @Override
+ public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowRule rule) {
+ DeviceId did = rule.deviceId();
+
+ // check if this new rule is an update to an existing entry
+ if (flowEntries.containsEntry(did, rule)) {
+ //synchronized (flowEntries) {
+ // Multimaps support duplicates so we have to remove our rule
+ // and replace it with the current version.
+ flowEntries.remove(did, rule);
+ flowEntries.put(did, rule);
+ //}
+ return new FlowRuleEvent(Type.RULE_UPDATED, rule);
+ }
+
+ flowEntries.put(did, rule);
+ return new FlowRuleEvent(RULE_ADDED, rule);
+ }
+
+ @Override
+ public synchronized FlowRuleEvent removeFlowRule(FlowRule rule) {
+ //synchronized (this) {
+ if (flowEntries.remove(rule.deviceId(), rule)) {
+ return new FlowRuleEvent(RULE_REMOVED, rule);
+ } else {
+ return null;
+ }
+ //}
+ }
+
+
+
+
+
+
+
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostStore.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostStore.java
new file mode 100644
index 0000000..94a3f05
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostStore.java
@@ -0,0 +1,277 @@
+package org.onlab.onos.net.trivial.impl;
+
+import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED;
+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;
+import java.util.Map;
+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;
+import org.onlab.onos.net.Host;
+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.host.HostStoreDelegate;
+import org.onlab.onos.net.host.PortAddresses;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.store.AbstractStore;
+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 com.google.common.collect.Sets;
+
+/**
+ * Manages inventory of end-station hosts using trivial in-memory
+ * implementation.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleHostStore
+ extends AbstractStore<HostEvent, HostStoreDelegate>
+ implements HostStore {
+
+ private final Logger log = getLogger(getClass());
+
+ // Host inventory
+ private final Map<HostId, Host> hosts = new ConcurrentHashMap<>();
+
+ // 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");
+ }
+
+ @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);
+ }
+ return updateHost(providerId, host, hostDescription);
+ }
+
+ // creates a new host and sends HOST_ADDED
+ private HostEvent createHost(ProviderId providerId, HostId hostId,
+ HostDescription descr) {
+ DefaultHost newhost = new DefaultHost(providerId, hostId,
+ descr.hwAddress(),
+ descr.vlan(),
+ descr.location(),
+ descr.ipAddresses());
+ synchronized (this) {
+ hosts.put(hostId, newhost);
+ locations.put(descr.location(), newhost);
+ }
+ return new HostEvent(HOST_ADDED, newhost);
+ }
+
+ // checks for type of update to host, sends appropriate event
+ private HostEvent updateHost(ProviderId providerId, Host host,
+ HostDescription descr) {
+ DefaultHost updated;
+ HostEvent event;
+ if (!host.location().equals(descr.location())) {
+ updated = new DefaultHost(providerId, host.id(),
+ host.mac(),
+ host.vlan(),
+ descr.location(),
+ host.ipAddresses());
+ event = new HostEvent(HOST_MOVED, updated);
+
+ } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) {
+ updated = new DefaultHost(providerId, host.id(),
+ host.mac(),
+ host.vlan(),
+ descr.location(),
+ descr.ipAddresses());
+ event = new HostEvent(HOST_UPDATED, updated);
+ } else {
+ return null;
+ }
+ synchronized (this) {
+ hosts.put(host.id(), updated);
+ locations.remove(host.location(), host);
+ locations.put(updated.location(), updated);
+ }
+ return event;
+ }
+
+ @Override
+ public HostEvent removeHost(HostId hostId) {
+ synchronized (this) {
+ Host host = hosts.remove(hostId);
+ if (host != null) {
+ locations.remove((host.location()), host);
+ return new HostEvent(HOST_REMOVED, host);
+ }
+ return null;
+ }
+ }
+
+ @Override
+ public int getHostCount() {
+ return hosts.size();
+ }
+
+ @Override
+ public Iterable<Host> getHosts() {
+ return Collections.unmodifiableSet(new HashSet<>(hosts.values()));
+ }
+
+ @Override
+ public Host getHost(HostId hostId) {
+ return hosts.get(hostId);
+ }
+
+ @Override
+ public Set<Host> getHosts(VlanId vlanId) {
+ Set<Host> vlanset = new HashSet<>();
+ for (Host h : hosts.values()) {
+ if (h.vlan().equals(vlanId)) {
+ vlanset.add(h);
+ }
+ }
+ return vlanset;
+ }
+
+ @Override
+ public Set<Host> getHosts(MacAddress mac) {
+ Set<Host> macset = new HashSet<>();
+ for (Host h : hosts.values()) {
+ if (h.mac().equals(mac)) {
+ macset.add(h);
+ }
+ }
+ return macset;
+ }
+
+ @Override
+ public Set<Host> getHosts(IpPrefix ip) {
+ Set<Host> ipset = new HashSet<>();
+ for (Host h : hosts.values()) {
+ if (h.ipAddresses().contains(ip)) {
+ ipset.add(h);
+ }
+ }
+ return ipset;
+ }
+
+ @Override
+ public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
+ return ImmutableSet.copyOf(locations.get(connectPoint));
+ }
+
+ @Override
+ public Set<Host> getConnectedHosts(DeviceId deviceId) {
+ Set<Host> hostset = new HashSet<>();
+ for (ConnectPoint p : locations.keySet()) {
+ if (p.deviceId().equals(deviceId)) {
+ hostset.addAll(locations.get(p));
+ }
+ }
+ return hostset;
+ }
+
+ @Override
+ public void updateAddressBindings(PortAddresses addresses) {
+ synchronized (portAddresses) {
+ PortAddresses existing = portAddresses.get(addresses.connectPoint());
+ if (existing == null) {
+ portAddresses.put(addresses.connectPoint(), addresses);
+ } else {
+ Set<IpPrefix> union = Sets.union(existing.ips(), addresses.ips())
+ .immutableCopy();
+
+ MacAddress newMac = (addresses.mac() == null) ? existing.mac()
+ : addresses.mac();
+
+ PortAddresses newAddresses =
+ new PortAddresses(addresses.connectPoint(), union, newMac);
+
+ portAddresses.put(newAddresses.connectPoint(), newAddresses);
+ }
+ }
+ }
+
+ @Override
+ public void removeAddressBindings(PortAddresses addresses) {
+ synchronized (portAddresses) {
+ PortAddresses existing = portAddresses.get(addresses.connectPoint());
+ if (existing != null) {
+ Set<IpPrefix> difference =
+ Sets.difference(existing.ips(), addresses.ips()).immutableCopy();
+
+ // If they removed the existing mac, set the new mac to null.
+ // Otherwise, keep the existing mac.
+ MacAddress newMac = existing.mac();
+ if (addresses.mac() != null && addresses.mac().equals(existing.mac())) {
+ newMac = null;
+ }
+
+ PortAddresses newAddresses =
+ new PortAddresses(addresses.connectPoint(), difference, newMac);
+
+ portAddresses.put(newAddresses.connectPoint(), newAddresses);
+ }
+ }
+ }
+
+ @Override
+ public void clearAddressBindings(ConnectPoint connectPoint) {
+ synchronized (portAddresses) {
+ portAddresses.remove(connectPoint);
+ }
+ }
+
+ @Override
+ public Set<PortAddresses> getAddressBindings() {
+ synchronized (portAddresses) {
+ return new HashSet<>(portAddresses.values());
+ }
+ }
+
+ @Override
+ public PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint) {
+ PortAddresses addresses;
+
+ synchronized (portAddresses) {
+ addresses = portAddresses.get(connectPoint);
+ }
+
+ if (addresses == null) {
+ addresses = new PortAddresses(connectPoint, null, null);
+ }
+
+ return addresses;
+ }
+
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkStore.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkStore.java
new file mode 100644
index 0000000..17bbc88
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkStore.java
@@ -0,0 +1,169 @@
+package org.onlab.onos.net.trivial.impl;
+
+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;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.LinkKey;
+import org.onlab.onos.net.link.LinkDescription;
+import org.onlab.onos.net.link.LinkEvent;
+import org.onlab.onos.net.link.LinkStore;
+import org.onlab.onos.net.link.LinkStoreDelegate;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.store.AbstractStore;
+import org.slf4j.Logger;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+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
+ * implementation.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleLinkStore
+ extends AbstractStore<LinkEvent, LinkStoreDelegate>
+ implements LinkStore {
+
+ private final Logger log = getLogger(getClass());
+
+ // Link inventory
+ private final Map<LinkKey, DefaultLink> links = new ConcurrentHashMap<>();
+
+ // Egress and ingress link sets
+ private final Multimap<DeviceId, Link> srcLinks = HashMultimap.create();
+ private final Multimap<DeviceId, Link> dstLinks = HashMultimap.create();
+
+ 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() {
+ return links.size();
+ }
+
+ @Override
+ public Iterable<Link> getLinks() {
+ return Collections.unmodifiableSet(new HashSet<Link>(links.values()));
+ }
+
+ @Override
+ public Set<Link> getDeviceEgressLinks(DeviceId deviceId) {
+ return ImmutableSet.copyOf(srcLinks.get(deviceId));
+ }
+
+ @Override
+ public Set<Link> getDeviceIngressLinks(DeviceId deviceId) {
+ return ImmutableSet.copyOf(dstLinks.get(deviceId));
+ }
+
+ @Override
+ public Link getLink(ConnectPoint src, ConnectPoint dst) {
+ return links.get(new LinkKey(src, dst));
+ }
+
+ @Override
+ public Set<Link> getEgressLinks(ConnectPoint src) {
+ Set<Link> egress = new HashSet<>();
+ for (Link link : srcLinks.get(src.deviceId())) {
+ if (link.src().equals(src)) {
+ egress.add(link);
+ }
+ }
+ return egress;
+ }
+
+ @Override
+ public Set<Link> getIngressLinks(ConnectPoint dst) {
+ Set<Link> ingress = new HashSet<>();
+ for (Link link : dstLinks.get(dst.deviceId())) {
+ if (link.dst().equals(dst)) {
+ ingress.add(link);
+ }
+ }
+ return ingress;
+ }
+
+ @Override
+ public LinkEvent createOrUpdateLink(ProviderId providerId,
+ LinkDescription linkDescription) {
+ LinkKey key = new LinkKey(linkDescription.src(), linkDescription.dst());
+ DefaultLink link = links.get(key);
+ if (link == null) {
+ return createLink(providerId, key, linkDescription);
+ }
+ return updateLink(providerId, link, key, linkDescription);
+ }
+
+ // Creates and stores the link and returns the appropriate event.
+ private LinkEvent createLink(ProviderId providerId, LinkKey key,
+ LinkDescription linkDescription) {
+ DefaultLink link = new DefaultLink(providerId, key.src(), key.dst(),
+ linkDescription.type());
+ synchronized (this) {
+ links.put(key, link);
+ srcLinks.put(link.src().deviceId(), link);
+ dstLinks.put(link.dst().deviceId(), link);
+ }
+ return new LinkEvent(LINK_ADDED, link);
+ }
+
+ // Updates, if necessary the specified link and returns the appropriate event.
+ private LinkEvent updateLink(ProviderId providerId, DefaultLink link,
+ LinkKey key, LinkDescription linkDescription) {
+ if (link.type() == INDIRECT && linkDescription.type() == DIRECT) {
+ synchronized (this) {
+ srcLinks.remove(link.src().deviceId(), link);
+ dstLinks.remove(link.dst().deviceId(), link);
+
+ DefaultLink updated =
+ new DefaultLink(providerId, link.src(), link.dst(),
+ linkDescription.type());
+ links.put(key, updated);
+ srcLinks.put(link.src().deviceId(), updated);
+ dstLinks.put(link.dst().deviceId(), updated);
+ return new LinkEvent(LINK_UPDATED, updated);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) {
+ synchronized (this) {
+ Link link = links.remove(new LinkKey(src, dst));
+ if (link != null) {
+ srcLinks.remove(link.src().deviceId(), link);
+ dstLinks.remove(link.dst().deviceId(), link);
+ return new LinkEvent(LINK_REMOVED, link);
+ }
+ return null;
+ }
+ }
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleMastershipStore.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleMastershipStore.java
new file mode 100644
index 0000000..61dbe61
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleMastershipStore.java
@@ -0,0 +1,136 @@
+package org.onlab.onos.net.trivial.impl;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+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.cluster.ControllerNode;
+import org.onlab.onos.cluster.DefaultControllerNode;
+import org.onlab.onos.cluster.MastershipEvent;
+import org.onlab.onos.cluster.MastershipStore;
+import org.onlab.onos.cluster.MastershipStoreDelegate;
+import org.onlab.onos.cluster.MastershipTerm;
+import org.onlab.onos.cluster.NodeId;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.store.AbstractStore;
+import org.onlab.packet.IpPrefix;
+import org.slf4j.Logger;
+
+import static org.onlab.onos.cluster.MastershipEvent.Type.*;
+
+/**
+ * Manages inventory of controller mastership over devices using
+ * trivial, non-distributed in-memory structures implementation.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleMastershipStore
+ extends AbstractStore<MastershipEvent, MastershipStoreDelegate>
+ implements MastershipStore {
+
+ private final Logger log = getLogger(getClass());
+
+ public static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1");
+
+ private ControllerNode instance =
+ new DefaultControllerNode(new NodeId("local"), LOCALHOST);
+
+ //devices mapped to their masters, to emulate multiple nodes
+ protected final ConcurrentMap<DeviceId, NodeId> masterMap =
+ new ConcurrentHashMap<>();
+ protected final Map<DeviceId, AtomicInteger> termMap = new HashMap<>();
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
+
+ NodeId node = masterMap.get(deviceId);
+ if (node == null) {
+ synchronized (this) {
+ masterMap.put(deviceId, nodeId);
+ termMap.put(deviceId, new AtomicInteger());
+ }
+ return new MastershipEvent(MASTER_CHANGED, deviceId, nodeId);
+ }
+
+ if (node.equals(nodeId)) {
+ return null;
+ } else {
+ synchronized (this) {
+ masterMap.put(deviceId, nodeId);
+ termMap.get(deviceId).incrementAndGet();
+ return new MastershipEvent(MASTER_CHANGED, deviceId, nodeId);
+ }
+ }
+ }
+
+ @Override
+ public NodeId getMaster(DeviceId deviceId) {
+ return masterMap.get(deviceId);
+ }
+
+ @Override
+ public Set<DeviceId> getDevices(NodeId nodeId) {
+ Set<DeviceId> ids = new HashSet<>();
+ for (Map.Entry<DeviceId, NodeId> d : masterMap.entrySet()) {
+ if (d.getValue().equals(nodeId)) {
+ ids.add(d.getKey());
+ }
+ }
+ return Collections.unmodifiableSet(ids);
+ }
+
+ @Override
+ public MastershipRole requestRole(DeviceId deviceId) {
+ return getRole(instance.id(), deviceId);
+ }
+
+ @Override
+ public MastershipRole getRole(NodeId nodeId, DeviceId deviceId) {
+ NodeId node = masterMap.get(deviceId);
+ MastershipRole role;
+ if (node != null) {
+ if (node.equals(nodeId)) {
+ role = MastershipRole.MASTER;
+ } else {
+ role = MastershipRole.STANDBY;
+ }
+ } else {
+ //masterMap doesn't contain it.
+ role = MastershipRole.MASTER;
+ masterMap.put(deviceId, nodeId);
+ }
+ return role;
+ }
+
+ @Override
+ public MastershipTerm getTermFor(DeviceId deviceId) {
+ if (masterMap.get(deviceId) == null) {
+ return null;
+ }
+ return MastershipTerm.of(
+ masterMap.get(deviceId), termMap.get(deviceId).get());
+ }
+
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyStore.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyStore.java
new file mode 100644
index 0000000..32cc1f7
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleTopologyStore.java
@@ -0,0 +1,140 @@
+package org.onlab.onos.net.trivial.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.Service;
+import org.onlab.onos.event.Event;
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.Path;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.net.topology.ClusterId;
+import org.onlab.onos.net.topology.GraphDescription;
+import org.onlab.onos.net.topology.LinkWeight;
+import org.onlab.onos.net.topology.Topology;
+import org.onlab.onos.net.topology.TopologyCluster;
+import org.onlab.onos.net.topology.TopologyEvent;
+import org.onlab.onos.net.topology.TopologyGraph;
+import org.onlab.onos.net.topology.TopologyStore;
+import org.onlab.onos.net.topology.TopologyStoreDelegate;
+import org.onlab.onos.store.AbstractStore;
+import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.Set;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Manages inventory of topology snapshots using trivial in-memory
+ * structures implementation.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleTopologyStore
+ extends AbstractStore<TopologyEvent, TopologyStoreDelegate>
+ implements TopologyStore {
+
+ private final Logger log = getLogger(getClass());
+
+ private volatile DefaultTopology current;
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+ @Override
+ public Topology currentTopology() {
+ return current;
+ }
+
+ @Override
+ public boolean isLatest(Topology topology) {
+ // Topology is current only if it is the same as our current topology
+ return topology == current;
+ }
+
+ @Override
+ public TopologyGraph getGraph(Topology topology) {
+ return defaultTopology(topology).getGraph();
+ }
+
+ @Override
+ public Set<TopologyCluster> getClusters(Topology topology) {
+ return defaultTopology(topology).getClusters();
+ }
+
+ @Override
+ public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
+ return defaultTopology(topology).getCluster(clusterId);
+ }
+
+ @Override
+ public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
+ return defaultTopology(topology).getClusterDevices(cluster);
+ }
+
+ @Override
+ public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
+ return defaultTopology(topology).getClusterLinks(cluster);
+ }
+
+ @Override
+ public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
+ return defaultTopology(topology).getPaths(src, dst);
+ }
+
+ @Override
+ public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst,
+ LinkWeight weight) {
+ return defaultTopology(topology).getPaths(src, dst, weight);
+ }
+
+ @Override
+ public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
+ return defaultTopology(topology).isInfrastructure(connectPoint);
+ }
+
+ @Override
+ public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
+ return defaultTopology(topology).isBroadcastPoint(connectPoint);
+ }
+
+ @Override
+ public TopologyEvent updateTopology(ProviderId providerId,
+ GraphDescription graphDescription,
+ List<Event> reasons) {
+ // First off, make sure that what we're given is indeed newer than
+ // what we already have.
+ if (current != null && graphDescription.timestamp() < current.time()) {
+ return null;
+ }
+
+ // Have the default topology construct self from the description data.
+ DefaultTopology newTopology =
+ new DefaultTopology(providerId, graphDescription);
+
+ // Promote the new topology to current and return a ready-to-send event.
+ synchronized (this) {
+ current = newTopology;
+ return new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, current);
+ }
+ }
+
+ // Validates the specified topology and returns it as a default
+ private DefaultTopology defaultTopology(Topology topology) {
+ if (topology instanceof DefaultTopology) {
+ return (DefaultTopology) topology;
+ }
+ throw new IllegalArgumentException("Topology class " + topology.getClass() +
+ " not supported");
+ }
+
+}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/package-info.java b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/package-info.java
new file mode 100644
index 0000000..9e3f28f
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/net/trivial/impl/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * Implementations of in-memory stores suitable for unit testing and
+ * experimentation; not for production use.
+ */
+package org.onlab.onos.net.trivial.impl;
diff --git a/core/store/trivial/src/test/java/org/onlab/onos/net/trivial/impl/DefaultTopologyTest.java b/core/store/trivial/src/test/java/org/onlab/onos/net/trivial/impl/DefaultTopologyTest.java
new file mode 100644
index 0000000..57f4d78
--- /dev/null
+++ b/core/store/trivial/src/test/java/org/onlab/onos/net/trivial/impl/DefaultTopologyTest.java
@@ -0,0 +1,130 @@
+package org.onlab.onos.net.trivial.impl;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.DefaultDevice;
+import org.onlab.onos.net.DefaultLink;
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.Path;
+import org.onlab.onos.net.PortNumber;
+import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.net.topology.ClusterId;
+import org.onlab.onos.net.topology.DefaultGraphDescription;
+import org.onlab.onos.net.topology.GraphDescription;
+import org.onlab.onos.net.topology.LinkWeight;
+import org.onlab.onos.net.topology.TopologyCluster;
+import org.onlab.onos.net.topology.TopologyEdge;
+
+import java.util.Set;
+
+import static com.google.common.collect.ImmutableSet.of;
+import static org.junit.Assert.*;
+import static org.onlab.onos.net.DeviceId.deviceId;
+import static org.onlab.onos.net.PortNumber.portNumber;
+
+/**
+ * Test of the default topology implementation.
+ */
+public class DefaultTopologyTest {
+
+ public static final ProviderId PID = new ProviderId("of", "foo.bar");
+
+ public static final DeviceId D1 = deviceId("of:1");
+ public static final DeviceId D2 = deviceId("of:2");
+ public static final DeviceId D3 = deviceId("of:3");
+ public static final DeviceId D4 = deviceId("of:4");
+ public static final DeviceId D5 = deviceId("of:5");
+
+ public static final PortNumber P1 = portNumber(1);
+ public static final PortNumber P2 = portNumber(2);
+
+ public static final LinkWeight WEIGHT = new LinkWeight() {
+ @Override
+ public double weight(TopologyEdge edge) {
+ return edge.src().deviceId().equals(D4) ||
+ edge.dst().deviceId().equals(D4) ? 2.0 : 1.0;
+ }
+ };
+
+ private DefaultTopology dt;
+
+ @Before
+ public void setUp() {
+ long now = System.currentTimeMillis();
+ Set<Device> devices = of(device("1"), device("2"),
+ device("3"), device("4"),
+ device("5"));
+ Set<Link> links = of(link("1", 1, "2", 1), link("2", 1, "1", 1),
+ link("3", 2, "2", 2), link("2", 2, "3", 2),
+ link("1", 3, "4", 3), link("4", 3, "1", 3),
+ link("3", 4, "4", 4), link("4", 4, "3", 4));
+ GraphDescription graphDescription =
+ new DefaultGraphDescription(now, devices, links);
+
+ dt = new DefaultTopology(PID, graphDescription);
+ assertEquals("incorrect supplier", PID, dt.providerId());
+ assertEquals("incorrect time", now, dt.time());
+ assertEquals("incorrect device count", 5, dt.deviceCount());
+ assertEquals("incorrect link count", 8, dt.linkCount());
+ assertEquals("incorrect cluster count", 2, dt.clusterCount());
+ assertEquals("incorrect broadcast set size", 6,
+ dt.broadcastSetSize(ClusterId.clusterId(0)));
+ }
+
+ @Test
+ public void pathRelated() {
+ Set<Path> paths = dt.getPaths(D1, D2);
+ assertEquals("incorrect path count", 1, paths.size());
+
+ paths = dt.getPaths(D1, D3);
+ assertEquals("incorrect path count", 2, paths.size());
+
+ paths = dt.getPaths(D1, D5);
+ assertTrue("no paths expected", paths.isEmpty());
+
+ paths = dt.getPaths(D1, D3, WEIGHT);
+ assertEquals("incorrect path count", 1, paths.size());
+ }
+
+ @Test
+ public void pointRelated() {
+ assertTrue("should be infrastructure point",
+ dt.isInfrastructure(new ConnectPoint(D1, P1)));
+ assertFalse("should not be infrastructure point",
+ dt.isInfrastructure(new ConnectPoint(D1, P2)));
+ }
+
+ @Test
+ public void clusterRelated() {
+ Set<TopologyCluster> clusters = dt.getClusters();
+ assertEquals("incorrect cluster count", 2, clusters.size());
+
+ TopologyCluster c = dt.getCluster(D1);
+ Set<DeviceId> devs = dt.getClusterDevices(c);
+ assertEquals("incorrect cluster device count", 4, devs.size());
+ assertTrue("cluster should contain D2", devs.contains(D2));
+ assertFalse("cluster should not contain D5", devs.contains(D5));
+ }
+
+ // Short-hand for creating a link.
+ public static Link link(String src, int sp, String dst, int dp) {
+ return new DefaultLink(PID, new ConnectPoint(did(src), portNumber(sp)),
+ new ConnectPoint(did(dst), portNumber(dp)),
+ Link.Type.DIRECT);
+ }
+
+ // Crates a new device with the specified id
+ public static Device device(String id) {
+ return new DefaultDevice(PID, did(id), Device.Type.SWITCH,
+ "mfg", "1.0", "1.1", "1234");
+ }
+
+ // Short-hand for producing a device id from a string
+ public static DeviceId did(String id) {
+ return deviceId("of:" + id);
+ }
+
+}