Bundle restructuring
Change-Id: I5a9efa7f4d03bd78dd17297731c5addea5cf0442
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/serializers/src/main/java/org/onlab/onos/store/serializers/ConnectPointSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ConnectPointSerializer.java
new file mode 100644
index 0000000..46badcb
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ConnectPointSerializer.java
@@ -0,0 +1,37 @@
+package org.onlab.onos.store.serializers;
+
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.ElementId;
+import org.onlab.onos.net.PortNumber;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+/**
+ * Kryo Serializer for {@link ConnectPointSerializer}.
+ */
+public class ConnectPointSerializer extends Serializer<ConnectPoint> {
+
+ /**
+ * Default constructor.
+ */
+ public ConnectPointSerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output, ConnectPoint object) {
+ kryo.writeClassAndObject(output, object.elementId());
+ kryo.writeClassAndObject(output, object.port());
+ }
+
+ @Override
+ public ConnectPoint read(Kryo kryo, Input input, Class<ConnectPoint> type) {
+ ElementId elementId = (ElementId) kryo.readClassAndObject(input);
+ PortNumber portNumber = (PortNumber) kryo.readClassAndObject(input);
+ return new ConnectPoint(elementId, portNumber);
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultLinkSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultLinkSerializer.java
new file mode 100644
index 0000000..5ee273d
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultLinkSerializer.java
@@ -0,0 +1,42 @@
+package org.onlab.onos.store.serializers;
+
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.DefaultLink;
+import org.onlab.onos.net.Link.Type;
+import org.onlab.onos.net.provider.ProviderId;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+/**
+ * Kryo Serializer for {@link DefaultLink}.
+ */
+public class DefaultLinkSerializer extends Serializer<DefaultLink> {
+
+ /**
+ * Default constructor.
+ */
+ public DefaultLinkSerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output, DefaultLink object) {
+ kryo.writeClassAndObject(output, object.providerId());
+ kryo.writeClassAndObject(output, object.src());
+ kryo.writeClassAndObject(output, object.dst());
+ kryo.writeClassAndObject(output, object.type());
+ }
+
+ @Override
+ public DefaultLink read(Kryo kryo, Input input, Class<DefaultLink> type) {
+ ProviderId providerId = (ProviderId) kryo.readClassAndObject(input);
+ ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input);
+ ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input);
+ Type linkType = (Type) kryo.readClassAndObject(input);
+ return new DefaultLink(providerId, src, dst, linkType);
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java
new file mode 100644
index 0000000..8455e80
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultPortSerializer.java
@@ -0,0 +1,42 @@
+package org.onlab.onos.store.serializers;
+
+import org.onlab.onos.net.DefaultPort;
+import org.onlab.onos.net.Element;
+import org.onlab.onos.net.PortNumber;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+/**
+ * Kryo Serializer for {@link DefaultPort}.
+ */
+public final class DefaultPortSerializer extends
+ Serializer<DefaultPort> {
+
+ /**
+ * Default constructor.
+ */
+ public DefaultPortSerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output, DefaultPort object) {
+ kryo.writeClassAndObject(output, object.element());
+ kryo.writeObject(output, object.number());
+ output.writeBoolean(object.isEnabled());
+ }
+
+ @Override
+ public DefaultPort read(Kryo kryo, Input input,
+ Class<DefaultPort> type) {
+ Element element = (Element) kryo.readClassAndObject(input);
+ PortNumber number = kryo.readObject(input, PortNumber.class);
+ boolean isEnabled = input.readBoolean();
+
+ return new DefaultPort(element, number, isEnabled);
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java
new file mode 100644
index 0000000..c63b676
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DeviceIdSerializer.java
@@ -0,0 +1,27 @@
+package org.onlab.onos.store.serializers;
+
+import java.net.URI;
+
+import org.onlab.onos.net.DeviceId;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+/**
+* Kryo Serializer for {@link DeviceId}.
+*/
+public final class DeviceIdSerializer extends Serializer<DeviceId> {
+
+ @Override
+ public void write(Kryo kryo, Output output, DeviceId object) {
+ kryo.writeObject(output, object.uri());
+ }
+
+ @Override
+ public DeviceId read(Kryo kryo, Input input, Class<DeviceId> type) {
+ final URI uri = kryo.readObject(input, URI.class);
+ return DeviceId.deviceId(uri);
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
new file mode 100644
index 0000000..2dbec57
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
@@ -0,0 +1,41 @@
+package org.onlab.onos.store.serializers;
+
+import org.onlab.packet.IpPrefix;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+/**
+ * Kryo Serializer for {@link IpPrefix}.
+ */
+public final class IpPrefixSerializer extends Serializer<IpPrefix> {
+
+ /**
+ * Default constructor.
+ */
+ public IpPrefixSerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output,
+ IpPrefix object) {
+ byte[] octs = object.toOctets();
+ output.writeInt(octs.length);
+ output.writeBytes(octs);
+ output.writeInt(object.prefixLength());
+ }
+
+ @Override
+ public IpPrefix read(Kryo kryo, Input input,
+ Class<IpPrefix> type) {
+ int octLen = input.readInt();
+ byte[] octs = new byte[octLen];
+ input.read(octs);
+ int prefLen = input.readInt();
+ return IpPrefix.valueOf(octs, prefLen);
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/LinkKeySerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/LinkKeySerializer.java
new file mode 100644
index 0000000..f635f3c
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/LinkKeySerializer.java
@@ -0,0 +1,35 @@
+package org.onlab.onos.store.serializers;
+
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.LinkKey;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+/**
+ * Kryo Serializer for {@link LinkKey}.
+ */
+public class LinkKeySerializer extends Serializer<LinkKey> {
+
+ /**
+ * Default constructor.
+ */
+ public LinkKeySerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output, LinkKey object) {
+ kryo.writeClassAndObject(output, object.src());
+ kryo.writeClassAndObject(output, object.dst());
+ }
+
+ @Override
+ public LinkKey read(Kryo kryo, Input input, Class<LinkKey> type) {
+ ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input);
+ ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input);
+ return new LinkKey(src, dst);
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/NodeIdSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/NodeIdSerializer.java
new file mode 100644
index 0000000..ef9d3f1
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/NodeIdSerializer.java
@@ -0,0 +1,24 @@
+package org.onlab.onos.store.serializers;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+import org.onlab.onos.cluster.NodeId;
+
+/**
+ * Kryo Serializer for {@link org.onlab.onos.cluster.NodeId}.
+ */
+public final class NodeIdSerializer extends Serializer<NodeId> {
+
+ @Override
+ public void write(Kryo kryo, Output output, NodeId object) {
+ kryo.writeObject(output, object.toString());
+ }
+
+ @Override
+ public NodeId read(Kryo kryo, Input input, Class<NodeId> type) {
+ final String id = kryo.readObject(input, String.class);
+ return new NodeId(id);
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java
new file mode 100644
index 0000000..02805bb
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/PortNumberSerializer.java
@@ -0,0 +1,34 @@
+package org.onlab.onos.store.serializers;
+
+import org.onlab.onos.net.PortNumber;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+/**
+ * Serializer for {@link PortNumber}.
+ */
+public final class PortNumberSerializer extends
+ Serializer<PortNumber> {
+
+ /**
+ * Default constructor.
+ */
+ public PortNumberSerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output, PortNumber object) {
+ output.writeLong(object.toLong());
+ }
+
+ @Override
+ public PortNumber read(Kryo kryo, Input input,
+ Class<PortNumber> type) {
+ return PortNumber.portNumber(input.readLong());
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java
new file mode 100644
index 0000000..1a1c6f6
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/ProviderIdSerializer.java
@@ -0,0 +1,36 @@
+package org.onlab.onos.store.serializers;
+
+import org.onlab.onos.net.provider.ProviderId;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+/**
+ * Serializer for {@link ProviderId}.
+ */
+public class ProviderIdSerializer extends Serializer<ProviderId> {
+
+ /**
+ * Default constructor.
+ */
+ public ProviderIdSerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output, ProviderId object) {
+ output.writeString(object.scheme());
+ output.writeString(object.id());
+ }
+
+ @Override
+ public ProviderId read(Kryo kryo, Input input, Class<ProviderId> type) {
+ String scheme = input.readString();
+ String id = input.readString();
+ return new ProviderId(scheme, id);
+ }
+
+}
diff --git a/core/store/serializers/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
new file mode 100644
index 0000000..c66304f
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Various Kryo serializers for use in distributed stores.
+ */
+package org.onlab.onos.store.serializers;