diff options
Diffstat (limited to 'framework/src/onos/core/store/serializers')
32 files changed, 0 insertions, 2618 deletions
diff --git a/framework/src/onos/core/store/serializers/pom.xml b/framework/src/onos/core/store/serializers/pom.xml deleted file mode 100644 index 6fe4c160..00000000 --- a/framework/src/onos/core/store/serializers/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright 2014 Open Networking Laboratory - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<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.onosproject</groupId> - <artifactId>onos-core-store</artifactId> - <version>1.4.0-rc1</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-core-serializers</artifactId> - <packaging>bundle</packaging> - - <description>Serializers for ONOS classes</description> - - <dependencies> - <dependency> - <groupId>com.esotericsoftware</groupId> - <artifactId>kryo</artifactId> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava-testlib</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-incubator-api</artifactId> - </dependency> - </dependencies> - -</project> diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/AnnotationsSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/AnnotationsSerializer.java deleted file mode 100644 index ed02c3e3..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/AnnotationsSerializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.net.DefaultAnnotations; - -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.Serializer; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; - -import java.util.HashMap; - -public class AnnotationsSerializer extends Serializer<DefaultAnnotations> { - - public AnnotationsSerializer() { - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, DefaultAnnotations object) { - kryo.writeObject(output, object.asMap()); - } - - @Override - public DefaultAnnotations read(Kryo kryo, Input input, Class<DefaultAnnotations> type) { - DefaultAnnotations.Builder b = DefaultAnnotations.builder(); - HashMap<String, String> map = kryo.readObject(input, HashMap.class); - map.forEach((k, v) -> b.set(k, v)); - - return b.build(); - } - -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ArraysAsListSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ArraysAsListSerializer.java deleted file mode 100644 index 99c35310..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ArraysAsListSerializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.store.serializers; - -import java.util.ArrayList; -import java.util.List; - -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 java.util.Arrays#asList(Object...)}. - */ -public final class ArraysAsListSerializer extends Serializer<List<?>> { - - @Override - public void write(Kryo kryo, Output output, List<?> object) { - output.writeInt(object.size(), true); - for (Object elm : object) { - kryo.writeClassAndObject(output, elm); - } - } - - @Override - public List<?> read(Kryo kryo, Input input, Class<List<?>> type) { - final int size = input.readInt(true); - List<Object> list = new ArrayList<>(size); - for (int i = 0; i < size; ++i) { - list.add(kryo.readClassAndObject(input)); - } - return list; - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ConnectPointSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ConnectPointSerializer.java deleted file mode 100644 index f1027d5e..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ConnectPointSerializer.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.ElementId; -import org.onosproject.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> { - - /** - * Creates {@link ConnectPointSerializer} serializer instance. - */ - 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/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultApplicationIdSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultApplicationIdSerializer.java deleted file mode 100644 index 0b1ad957..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultApplicationIdSerializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.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.onosproject.core.DefaultApplicationId; - -/** - * Kryo Serializer for {@link org.onosproject.core.DefaultApplicationId}. - */ -public final class DefaultApplicationIdSerializer extends Serializer<DefaultApplicationId> { - - /** - * Creates {@link org.onosproject.core.DefaultApplicationId} serializer instance. - */ - public DefaultApplicationIdSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, DefaultApplicationId object) { - kryo.writeObject(output, object.id()); - kryo.writeObject(output, object.name()); - } - - @Override - public DefaultApplicationId read(Kryo kryo, Input input, Class<DefaultApplicationId> type) { - short id = kryo.readObject(input, Short.class); - String name = kryo.readObject(input, String.class); - return new DefaultApplicationId(id, name); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultLinkSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultLinkSerializer.java deleted file mode 100644 index 6cc90667..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultLinkSerializer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.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.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.Link.State; -import org.onosproject.net.Link.Type; -import org.onosproject.net.provider.ProviderId; - -/** - * Kryo Serializer for {@link DefaultLink}. - */ -public class DefaultLinkSerializer extends Serializer<DefaultLink> { - - /** - * Creates {@link DefaultLink} serializer instance. - */ - 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()); - kryo.writeClassAndObject(output, object.state()); - output.writeBoolean(object.isDurable()); - } - - @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); - State state = (State) kryo.readClassAndObject(input); - boolean isDurable = input.readBoolean(); - return new DefaultLink(providerId, src, dst, linkType, state, isDurable); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultOutboundPacketSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultOutboundPacketSerializer.java deleted file mode 100644 index 9d12e458..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultOutboundPacketSerializer.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import java.nio.ByteBuffer; - -import org.onosproject.net.DeviceId; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.packet.DefaultOutboundPacket; - -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.Serializer; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; - -/** - * Serializer for a default outbound packet. - */ -public class DefaultOutboundPacketSerializer extends Serializer<DefaultOutboundPacket> { - - /** - * Creates {@link DefaultOutboundPacket} serializer instance. - */ - public DefaultOutboundPacketSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public DefaultOutboundPacket read(Kryo kryo, Input input, - Class<DefaultOutboundPacket> type) { - DeviceId sendThrough = (DeviceId) kryo.readClassAndObject(input); - TrafficTreatment treatment = (TrafficTreatment) kryo.readClassAndObject(input); - byte[] data = (byte[]) kryo.readClassAndObject(input); - return new DefaultOutboundPacket(sendThrough, treatment, ByteBuffer.wrap(data)); - } - - @Override - public void write(Kryo kryo, Output output, DefaultOutboundPacket object) { - kryo.writeClassAndObject(output, object.sendThrough()); - kryo.writeClassAndObject(output, object.treatment()); - kryo.writeClassAndObject(output, object.data().array()); - } - -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultPortSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultPortSerializer.java deleted file mode 100644 index 60d09fbe..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultPortSerializer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.net.Annotations; -import org.onosproject.net.DefaultPort; -import org.onosproject.net.Element; -import org.onosproject.net.Port; -import org.onosproject.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> { - - /** - * Creates {@link DefaultPort} serializer instance. - */ - public DefaultPortSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, DefaultPort object) { - kryo.writeClassAndObject(output, object.element()); - kryo.writeObject(output, object.number()); - output.writeBoolean(object.isEnabled()); - kryo.writeObject(output, object.type()); - output.writeLong(object.portSpeed()); - kryo.writeClassAndObject(output, object.annotations()); - } - - @Override - public DefaultPort read(Kryo kryo, Input input, Class<DefaultPort> aClass) { - Element element = (Element) kryo.readClassAndObject(input); - PortNumber number = kryo.readObject(input, PortNumber.class); - boolean isEnabled = input.readBoolean(); - Port.Type type = kryo.readObject(input, Port.Type.class); - long portSpeed = input.readLong(); - Annotations annotations = (Annotations) kryo.readClassAndObject(input); - - return new DefaultPort(element, number, isEnabled, type, portSpeed, annotations); - } - -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DeviceIdSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DeviceIdSerializer.java deleted file mode 100644 index a74a7695..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DeviceIdSerializer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.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> { - - /** - * Creates {@link DeviceId} serializer instance. - */ - public DeviceIdSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, DeviceId object) { - output.writeString(object.toString()); - } - - @Override - public DeviceId read(Kryo kryo, Input input, Class<DeviceId> type) { - final String str = input.readString(); - return DeviceId.deviceId(str); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ExtensionInstructionSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ExtensionInstructionSerializer.java deleted file mode 100644 index e688a80c..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ExtensionInstructionSerializer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.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.osgi.DefaultServiceDirectory; -import org.onosproject.net.DeviceId; -import org.onosproject.net.behaviour.ExtensionTreatmentResolver; -import org.onosproject.net.driver.DefaultDriverData; -import org.onosproject.net.driver.DefaultDriverHandler; -import org.onosproject.net.driver.DriverHandler; -import org.onosproject.net.driver.DriverService; -import org.onosproject.net.flow.instructions.ExtensionTreatment; -import org.onosproject.net.flow.instructions.ExtensionTreatmentType; -import org.onosproject.net.flow.instructions.Instructions; - -/** - * Created by jono on 10/29/15. - */ -public class ExtensionInstructionSerializer extends - Serializer<Instructions.ExtensionInstructionWrapper> { - - public ExtensionInstructionSerializer() { - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, Instructions.ExtensionInstructionWrapper object) { - kryo.writeClassAndObject(output, object.extensionInstruction().type()); - kryo.writeClassAndObject(output, object.deviceId()); - - kryo.writeClassAndObject(output, object.extensionInstruction().serialize()); - - } - - @Override - public Instructions.ExtensionInstructionWrapper read(Kryo kryo, Input input, - Class<Instructions.ExtensionInstructionWrapper> type) { - ExtensionTreatmentType exType = (ExtensionTreatmentType) kryo.readClassAndObject(input); - DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); - - DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); - DriverHandler handler = new DefaultDriverHandler( - new DefaultDriverData(driverService.getDriver(deviceId), deviceId)); - - ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); - - ExtensionTreatment instruction = resolver.getExtensionInstruction(exType); - - byte[] bytes = (byte[]) kryo.readClassAndObject(input); - - instruction.deserialize(bytes); - - return Instructions.extension(instruction, deviceId); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/HostLocationSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/HostLocationSerializer.java deleted file mode 100644 index 270eb218..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/HostLocationSerializer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.net.DeviceId; -import org.onosproject.net.HostLocation; -import org.onosproject.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 HostLocation}. -*/ -public class HostLocationSerializer extends Serializer<HostLocation> { - - /** - * Creates {@link HostLocation} serializer instance. - */ - public HostLocationSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, HostLocation object) { - kryo.writeClassAndObject(output, object.deviceId()); - kryo.writeClassAndObject(output, object.port()); - output.writeLong(object.time()); - } - - @Override - public HostLocation read(Kryo kryo, Input input, Class<HostLocation> type) { - DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); - PortNumber portNumber = (PortNumber) kryo.readClassAndObject(input); - long time = input.readLong(); - return new HostLocation(deviceId, portNumber, time); - } - -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableListSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableListSerializer.java deleted file mode 100644 index 95166c3b..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableListSerializer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.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 com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; - -/** - * Creates {@link ImmutableList} serializer instance. - */ -public class ImmutableListSerializer extends Serializer<ImmutableList<?>> { - - /** - * Creates {@link ImmutableList} serializer instance. - */ - public ImmutableListSerializer() { - // non-null, immutable - super(false, true); - } - @Override - public void write(Kryo kryo, Output output, ImmutableList<?> object) { - output.writeInt(object.size()); - for (Object e : object) { - kryo.writeClassAndObject(output, e); - } - } - - @Override - public ImmutableList<?> read(Kryo kryo, Input input, - Class<ImmutableList<?>> type) { - final int size = input.readInt(); - Builder<Object> builder = ImmutableList.builder(); - for (int i = 0; i < size; ++i) { - builder.add(kryo.readClassAndObject(input)); - } - return builder.build(); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableMapSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableMapSerializer.java deleted file mode 100644 index 4d6af788..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableMapSerializer.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.Serializer; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; -import com.esotericsoftware.kryo.serializers.MapSerializer; -import com.google.common.collect.ImmutableMap; - -/** -* Kryo Serializer for {@link ImmutableMap}. -*/ -public class ImmutableMapSerializer extends Serializer<ImmutableMap<?, ?>> { - - private final MapSerializer mapSerializer = new MapSerializer(); - - /** - * Creates {@link ImmutableMap} serializer instance. - */ - public ImmutableMapSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, ImmutableMap<?, ?> object) { - // wrapping with unmodifiableMap proxy - // to avoid Kryo from writing only the reference marker of this instance, - // which will be embedded right before this method call. - kryo.writeObject(output, Collections.unmodifiableMap(object), mapSerializer); - } - - @Override - public ImmutableMap<?, ?> read(Kryo kryo, Input input, - Class<ImmutableMap<?, ?>> type) { - Map<?, ?> map = kryo.readObject(input, HashMap.class, mapSerializer); - return ImmutableMap.copyOf(map); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableSetSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableSetSerializer.java deleted file mode 100644 index cb9b0543..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableSetSerializer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import java.util.ArrayList; -import java.util.List; - -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.Serializer; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; -import com.esotericsoftware.kryo.serializers.CollectionSerializer; -import com.google.common.collect.ImmutableSet; - -/** -* Kryo Serializer for {@link ImmutableSet}. -*/ -public class ImmutableSetSerializer extends Serializer<ImmutableSet<?>> { - - private final CollectionSerializer serializer = new CollectionSerializer(); - - /** - * Creates {@link ImmutableSet} serializer instance. - */ - public ImmutableSetSerializer() { - // non-null, immutable - super(false, true); - serializer.setElementsCanBeNull(false); - } - - @Override - public void write(Kryo kryo, Output output, ImmutableSet<?> object) { - kryo.writeObject(output, object.asList(), serializer); - } - - @Override - public ImmutableSet<?> read(Kryo kryo, Input input, - Class<ImmutableSet<?>> type) { - List<?> elms = kryo.readObject(input, ArrayList.class, serializer); - return ImmutableSet.copyOf(elms); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip4AddressSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip4AddressSerializer.java deleted file mode 100644 index 2370ad92..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip4AddressSerializer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onlab.packet.Ip4Address; -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 Ip4Address}. - */ -public class Ip4AddressSerializer extends Serializer<Ip4Address> { - - /** - * Creates {@link Ip4Address} serializer instance. - */ - public Ip4AddressSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, Ip4Address object) { - byte[] octs = object.toOctets(); - // It is always Ip4Address.BYTE_LENGTH - output.writeInt(octs.length); - output.writeBytes(octs); - } - - @Override - public Ip4Address read(Kryo kryo, Input input, Class<Ip4Address> type) { - final int octLen = input.readInt(); - byte[] octs = new byte[octLen]; - input.readBytes(octs); - return Ip4Address.valueOf(octs); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip4PrefixSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip4PrefixSerializer.java deleted file mode 100644 index 029ffb1a..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip4PrefixSerializer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onlab.packet.Ip4Prefix; - -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 Ip4Prefix}. - */ -public final class Ip4PrefixSerializer extends Serializer<Ip4Prefix> { - - /** - * Creates {@link Ip4Prefix} serializer instance. - */ - public Ip4PrefixSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, - Ip4Prefix object) { - byte[] octs = object.address().toOctets(); - // It is always Ip4Address.BYTE_LENGTH - output.writeInt(octs.length); - output.writeBytes(octs); - output.writeInt(object.prefixLength()); - } - - @Override - public Ip4Prefix read(Kryo kryo, Input input, - Class<Ip4Prefix> type) { - int octLen = input.readInt(); - byte[] octs = new byte[octLen]; - input.readBytes(octs); - int prefLen = input.readInt(); - return Ip4Prefix.valueOf(octs, prefLen); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip6AddressSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip6AddressSerializer.java deleted file mode 100644 index f8101f98..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip6AddressSerializer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onlab.packet.Ip6Address; -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 Ip6Address}. - */ -public class Ip6AddressSerializer extends Serializer<Ip6Address> { - - /** - * Creates {@link Ip6Address} serializer instance. - */ - public Ip6AddressSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, Ip6Address object) { - byte[] octs = object.toOctets(); - // It is always Ip6Address.BYTE_LENGTH - output.writeInt(octs.length); - output.writeBytes(octs); - } - - @Override - public Ip6Address read(Kryo kryo, Input input, Class<Ip6Address> type) { - final int octLen = input.readInt(); - byte[] octs = new byte[octLen]; - input.readBytes(octs); - return Ip6Address.valueOf(octs); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip6PrefixSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip6PrefixSerializer.java deleted file mode 100644 index 91ba5a29..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip6PrefixSerializer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onlab.packet.Ip6Prefix; - -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 Ip6Prefix}. - */ -public final class Ip6PrefixSerializer extends Serializer<Ip6Prefix> { - - /** - * Creates {@link Ip6Prefix} serializer instance. - */ - public Ip6PrefixSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, - Ip6Prefix object) { - byte[] octs = object.address().toOctets(); - // It is always Ip6Address.BYTE_LENGTH - output.writeInt(octs.length); - output.writeBytes(octs); - output.writeInt(object.prefixLength()); - } - - @Override - public Ip6Prefix read(Kryo kryo, Input input, - Class<Ip6Prefix> type) { - int octLen = input.readInt(); - byte[] octs = new byte[octLen]; - input.readBytes(octs); - int prefLen = input.readInt(); - return Ip6Prefix.valueOf(octs, prefLen); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/IpAddressSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/IpAddressSerializer.java deleted file mode 100644 index cb85fec8..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/IpAddressSerializer.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onlab.packet.IpAddress; -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 IpAddress}. - */ -public class IpAddressSerializer extends Serializer<IpAddress> { - - /** - * Creates {@link IpAddress} serializer instance. - */ - public IpAddressSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, IpAddress object) { - byte[] octs = object.toOctets(); - output.writeInt(octs.length); - output.writeBytes(octs); - } - - @Override - public IpAddress read(Kryo kryo, Input input, Class<IpAddress> type) { - final int octLen = input.readInt(); - byte[] octs = new byte[octLen]; - input.readBytes(octs); - // Use the address size to decide whether it is IPv4 or IPv6 address - if (octLen == IpAddress.INET_BYTE_LENGTH) { - return IpAddress.valueOf(IpAddress.Version.INET, octs); - } - if (octLen == IpAddress.INET6_BYTE_LENGTH) { - return IpAddress.valueOf(IpAddress.Version.INET6, octs); - } - return null; // Shouldn't be reached - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/IpPrefixSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/IpPrefixSerializer.java deleted file mode 100644 index cf0a20b9..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/IpPrefixSerializer.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onlab.packet.IpAddress; -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> { - - /** - * Creates {@link IpPrefix} serializer instance. - */ - public IpPrefixSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, - IpPrefix object) { - byte[] octs = object.address().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.readBytes(octs); - int prefLen = input.readInt(); - // Use the address size to decide whether it is IPv4 or IPv6 address - if (octLen == IpAddress.INET_BYTE_LENGTH) { - return IpPrefix.valueOf(IpAddress.Version.INET, octs, prefLen); - } - if (octLen == IpAddress.INET6_BYTE_LENGTH) { - return IpPrefix.valueOf(IpAddress.Version.INET6, octs, prefLen); - } - return null; // Shouldn't be reached - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java deleted file mode 100644 index 1b883a30..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java +++ /dev/null @@ -1,497 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import org.onlab.packet.ChassisId; -import org.onlab.packet.EthType; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.Ip4Prefix; -import org.onlab.packet.Ip6Address; -import org.onlab.packet.Ip6Prefix; -import org.onlab.packet.IpAddress; -import org.onlab.packet.IpPrefix; -import org.onlab.packet.MacAddress; -import org.onlab.packet.TpPort; -import org.onlab.packet.VlanId; -import org.onlab.util.Bandwidth; -import org.onlab.util.Frequency; -import org.onlab.util.KryoNamespace; -import org.onosproject.app.ApplicationState; -import org.onosproject.cluster.ControllerNode; -import org.onosproject.cluster.DefaultControllerNode; -import org.onosproject.cluster.Leadership; -import org.onosproject.cluster.LeadershipEvent; -import org.onosproject.cluster.NodeId; -import org.onosproject.cluster.RoleInfo; -import org.onosproject.core.ApplicationRole; -import org.onosproject.core.DefaultApplication; -import org.onosproject.core.DefaultApplicationId; -import org.onosproject.core.DefaultGroupId; -import org.onosproject.core.Version; -import org.onosproject.incubator.net.domain.IntentDomainId; -import org.onosproject.mastership.MastershipTerm; -import org.onosproject.net.Annotations; -import org.onosproject.net.ChannelSpacing; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultDevice; -import org.onosproject.net.DefaultEdgeLink; -import org.onosproject.net.DefaultHost; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.DefaultPort; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Element; -import org.onosproject.net.GridType; -import org.onosproject.net.HostId; -import org.onosproject.net.HostLocation; -import org.onosproject.net.IndexedLambda; -import org.onosproject.net.Link; -import org.onosproject.net.LinkKey; -import org.onosproject.net.OchPort; -import org.onosproject.net.OchSignal; -import org.onosproject.net.OchSignalType; -import org.onosproject.net.OduCltPort; -import org.onosproject.net.OduSignalId; -import org.onosproject.net.OduSignalType; -import org.onosproject.net.OmsPort; -import org.onosproject.net.Port; -import org.onosproject.net.PortNumber; -import org.onosproject.net.TributarySlot; -import org.onosproject.net.device.DefaultDeviceDescription; -import org.onosproject.net.device.DefaultPortDescription; -import org.onosproject.net.device.DefaultPortStatistics; -import org.onosproject.net.device.OchPortDescription; -import org.onosproject.net.device.OduCltPortDescription; -import org.onosproject.net.device.OmsPortDescription; -import org.onosproject.net.device.PortStatistics; -import org.onosproject.net.flow.CompletedBatchOperation; -import org.onosproject.net.flow.DefaultFlowEntry; -import org.onosproject.net.flow.DefaultFlowRule; -import org.onosproject.net.flow.DefaultTableStatisticsEntry; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.FlowEntry; -import org.onosproject.net.flow.FlowId; -import org.onosproject.net.flow.FlowRuleBatchEntry; -import org.onosproject.net.flow.FlowRuleBatchEvent; -import org.onosproject.net.flow.FlowRuleBatchOperation; -import org.onosproject.net.flow.FlowRuleBatchRequest; -import org.onosproject.net.flow.FlowRuleEvent; -import org.onosproject.net.flow.FlowRuleExtPayLoad; -import org.onosproject.net.flow.StoredFlowEntry; -import org.onosproject.net.flow.TableStatisticsEntry; -import org.onosproject.net.flow.criteria.Criterion; -import org.onosproject.net.flow.criteria.EthCriterion; -import org.onosproject.net.flow.criteria.EthTypeCriterion; -import org.onosproject.net.flow.criteria.IPCriterion; -import org.onosproject.net.flow.criteria.IPDscpCriterion; -import org.onosproject.net.flow.criteria.IPEcnCriterion; -import org.onosproject.net.flow.criteria.IPProtocolCriterion; -import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion; -import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion; -import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion; -import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion; -import org.onosproject.net.flow.criteria.IcmpCodeCriterion; -import org.onosproject.net.flow.criteria.IcmpTypeCriterion; -import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; -import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; -import org.onosproject.net.flow.criteria.IndexedLambdaCriterion; -import org.onosproject.net.flow.criteria.LambdaCriterion; -import org.onosproject.net.flow.criteria.MetadataCriterion; -import org.onosproject.net.flow.criteria.MplsCriterion; -import org.onosproject.net.flow.criteria.OchSignalCriterion; -import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; -import org.onosproject.net.flow.criteria.OduSignalIdCriterion; -import org.onosproject.net.flow.criteria.OduSignalTypeCriterion; -import org.onosproject.net.flow.criteria.PortCriterion; -import org.onosproject.net.flow.criteria.SctpPortCriterion; -import org.onosproject.net.flow.criteria.TcpPortCriterion; -import org.onosproject.net.flow.criteria.TunnelIdCriterion; -import org.onosproject.net.flow.criteria.UdpPortCriterion; -import org.onosproject.net.flow.criteria.VlanIdCriterion; -import org.onosproject.net.flow.criteria.VlanPcpCriterion; -import org.onosproject.net.flow.instructions.ExtensionTreatmentType; -import org.onosproject.net.flow.instructions.Instructions; -import org.onosproject.net.flow.instructions.L0ModificationInstruction; -import org.onosproject.net.flow.instructions.L1ModificationInstruction; -import org.onosproject.net.flow.instructions.L2ModificationInstruction; -import org.onosproject.net.flow.instructions.L3ModificationInstruction; -import org.onosproject.net.flow.instructions.L4ModificationInstruction; -import org.onosproject.net.host.DefaultHostDescription; -import org.onosproject.net.host.HostDescription; -import org.onosproject.net.intent.ConnectivityIntent; -import org.onosproject.net.intent.FlowRuleIntent; -import org.onosproject.net.intent.HostToHostIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentId; -import org.onosproject.net.intent.IntentOperation; -import org.onosproject.net.intent.IntentState; -import org.onosproject.net.intent.Key; -import org.onosproject.net.intent.LinkCollectionIntent; -import org.onosproject.net.intent.MplsIntent; -import org.onosproject.net.intent.MplsPathIntent; -import org.onosproject.net.intent.MultiPointToSinglePointIntent; -import org.onosproject.net.intent.OpticalCircuitIntent; -import org.onosproject.net.intent.OpticalConnectivityIntent; -import org.onosproject.net.intent.OpticalPathIntent; -import org.onosproject.net.intent.PathIntent; -import org.onosproject.net.intent.PointToPointIntent; -import org.onosproject.net.intent.SinglePointToMultiPointIntent; -import org.onosproject.net.intent.constraint.AnnotationConstraint; -import org.onosproject.net.intent.constraint.BandwidthConstraint; -import org.onosproject.net.intent.constraint.BooleanConstraint; -import org.onosproject.net.intent.constraint.LambdaConstraint; -import org.onosproject.net.intent.constraint.LatencyConstraint; -import org.onosproject.net.intent.constraint.LinkTypeConstraint; -import org.onosproject.net.intent.constraint.ObstacleConstraint; -import org.onosproject.net.intent.constraint.PartialFailureConstraint; -import org.onosproject.net.intent.constraint.WaypointConstraint; -import org.onosproject.net.link.DefaultLinkDescription; -import org.onosproject.net.meter.MeterId; -import org.onosproject.net.newresource.ResourceAllocation; -import org.onosproject.net.newresource.ResourcePath; -import org.onosproject.net.packet.DefaultOutboundPacket; -import org.onosproject.net.packet.DefaultPacketRequest; -import org.onosproject.net.packet.PacketPriority; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.BandwidthResource; -import org.onosproject.net.resource.link.BandwidthResourceAllocation; -import org.onosproject.net.resource.link.BandwidthResourceRequest; -import org.onosproject.net.resource.link.DefaultLinkResourceAllocations; -import org.onosproject.net.resource.link.DefaultLinkResourceRequest; -import org.onosproject.net.resource.link.LambdaResource; -import org.onosproject.net.resource.link.LambdaResourceAllocation; -import org.onosproject.net.resource.link.LambdaResourceRequest; -import org.onosproject.net.resource.link.LinkResourceRequest; -import org.onosproject.net.resource.link.MplsLabel; -import org.onosproject.net.resource.link.MplsLabelResourceAllocation; -import org.onosproject.net.resource.link.MplsLabelResourceRequest; -import org.onosproject.store.Timestamp; -import org.onosproject.store.service.MapEvent; -import org.onosproject.store.service.SetEvent; -import org.onosproject.store.service.Versioned; - -import java.net.URI; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -public final class KryoNamespaces { - - public static final KryoNamespace BASIC = KryoNamespace.newBuilder() - .nextId(KryoNamespace.FLOATING_ID) - .register(byte[].class) - .register(AtomicBoolean.class) - .register(AtomicInteger.class) - .register(AtomicLong.class) - .register(new ImmutableListSerializer(), - ImmutableList.class, - ImmutableList.of(1).getClass(), - ImmutableList.of(1, 2).getClass()) - .register(new ImmutableSetSerializer(), - ImmutableSet.class, - ImmutableSet.of().getClass(), - ImmutableSet.of(1).getClass(), - ImmutableSet.of(1, 2).getClass()) - .register(new ImmutableMapSerializer(), - ImmutableMap.class, - ImmutableMap.of().getClass(), - ImmutableMap.of("a", 1).getClass(), - ImmutableMap.of("R", 2, "D", 2).getClass()) - .register(HashMap.class) - .register(ConcurrentHashMap.class) - .register(CopyOnWriteArraySet.class) - .register(ArrayList.class, - LinkedList.class, - HashSet.class - ) - .register(Maps.immutableEntry("a", "b").getClass()) - .register(new ArraysAsListSerializer(), Arrays.asList().getClass()) - .register(Collections.singletonList(1).getClass()) - .register(Duration.class) - .register(Collections.emptySet().getClass()) - .register(Optional.class) - .register(Collections.emptyList().getClass()) - .register(Collections.unmodifiableSet(Collections.emptySet()).getClass()) - .register(Collections.singleton(Object.class).getClass()) - .build(); - - /** - * KryoNamespace which can serialize ON.lab misc classes. - */ - public static final KryoNamespace MISC = KryoNamespace.newBuilder() - .nextId(KryoNamespace.FLOATING_ID) - .register(new IpPrefixSerializer(), IpPrefix.class) - .register(new Ip4PrefixSerializer(), Ip4Prefix.class) - .register(new Ip6PrefixSerializer(), Ip6Prefix.class) - .register(new IpAddressSerializer(), IpAddress.class) - .register(new Ip4AddressSerializer(), Ip4Address.class) - .register(new Ip6AddressSerializer(), Ip6Address.class) - .register(new MacAddressSerializer(), MacAddress.class) - .register(VlanId.class) - .register(Frequency.class) - .register(Bandwidth.class) - .build(); - - /** - * Kryo registration Id for user custom registration. - */ - public static final int BEGIN_USER_CUSTOM_ID = 300; - - // TODO: Populate other classes - /** - * KryoNamespace which can serialize API bundle classes. - */ - public static final KryoNamespace API = KryoNamespace.newBuilder() - .nextId(KryoNamespace.INITIAL_ID) - .register(BASIC) - .nextId(KryoNamespace.INITIAL_ID + 30) - .register(MISC) - .nextId(KryoNamespace.INITIAL_ID + 30 + 10) - .register( - Instructions.MeterInstruction.class, - MeterId.class, - Version.class, - ControllerNode.State.class, - ApplicationState.class, - ApplicationRole.class, - DefaultApplication.class, - Device.Type.class, - Port.Type.class, - ChassisId.class, - DefaultControllerNode.class, - DefaultDevice.class, - DefaultDeviceDescription.class, - DefaultHost.class, - DefaultLinkDescription.class, - Port.class, - DefaultPortDescription.class, - Element.class, - Link.Type.class, - Link.State.class, - Timestamp.class, - Leadership.class, - LeadershipEvent.class, - LeadershipEvent.Type.class, - HostId.class, - HostDescription.class, - DefaultHostDescription.class, - DefaultFlowEntry.class, - StoredFlowEntry.class, - DefaultFlowRule.class, - DefaultFlowEntry.class, - DefaultPacketRequest.class, - PacketPriority.class, - FlowEntry.FlowEntryState.class, - FlowId.class, - DefaultTrafficSelector.class, - PortCriterion.class, - MetadataCriterion.class, - EthCriterion.class, - EthType.class, - EthTypeCriterion.class, - VlanIdCriterion.class, - VlanPcpCriterion.class, - IPDscpCriterion.class, - IPEcnCriterion.class, - IPProtocolCriterion.class, - IPCriterion.class, - TpPort.class, - TcpPortCriterion.class, - UdpPortCriterion.class, - SctpPortCriterion.class, - IcmpTypeCriterion.class, - IcmpCodeCriterion.class, - IPv6FlowLabelCriterion.class, - Icmpv6TypeCriterion.class, - Icmpv6CodeCriterion.class, - IPv6NDTargetAddressCriterion.class, - IPv6NDLinkLayerAddressCriterion.class, - MplsCriterion.class, - TunnelIdCriterion.class, - IPv6ExthdrFlagsCriterion.class, - LambdaCriterion.class, - IndexedLambdaCriterion.class, - OchSignalCriterion.class, - OchSignalTypeCriterion.class, - OduSignalIdCriterion.class, - OduSignalTypeCriterion.class, - Criterion.class, - Criterion.Type.class, - DefaultTrafficTreatment.class, - Instructions.DropInstruction.class, - Instructions.NoActionInstruction.class, - Instructions.OutputInstruction.class, - Instructions.GroupInstruction.class, - Instructions.TableTypeTransition.class, - L0ModificationInstruction.class, - L0ModificationInstruction.L0SubType.class, - L0ModificationInstruction.ModLambdaInstruction.class, - L0ModificationInstruction.ModOchSignalInstruction.class, - L1ModificationInstruction.class, - L1ModificationInstruction.L1SubType.class, - L1ModificationInstruction.ModOduSignalIdInstruction.class, - L2ModificationInstruction.class, - L2ModificationInstruction.L2SubType.class, - L2ModificationInstruction.ModEtherInstruction.class, - L2ModificationInstruction.PushHeaderInstructions.class, - L2ModificationInstruction.ModVlanIdInstruction.class, - L2ModificationInstruction.ModVlanPcpInstruction.class, - L2ModificationInstruction.PopVlanInstruction.class, - L2ModificationInstruction.ModMplsLabelInstruction.class, - L2ModificationInstruction.ModMplsBosInstruction.class, - L2ModificationInstruction.ModMplsTtlInstruction.class, - L2ModificationInstruction.ModTunnelIdInstruction.class, - L3ModificationInstruction.class, - L3ModificationInstruction.L3SubType.class, - L3ModificationInstruction.ModIPInstruction.class, - L3ModificationInstruction.ModIPv6FlowLabelInstruction.class, - L3ModificationInstruction.ModTtlInstruction.class, - L4ModificationInstruction.class, - L4ModificationInstruction.L4SubType.class, - L4ModificationInstruction.ModTransportPortInstruction.class, - RoleInfo.class, - FlowRuleBatchEvent.class, - FlowRuleBatchEvent.Type.class, - FlowRuleBatchRequest.class, - FlowRuleBatchOperation.class, - FlowRuleEvent.class, - FlowRuleEvent.Type.class, - CompletedBatchOperation.class, - FlowRuleBatchEntry.class, - FlowRuleBatchEntry.FlowRuleOperation.class, - IntentId.class, - IntentState.class, - //Key.class, is abstract - Key.of(1L, new DefaultApplicationId(0, "bar")).getClass(), //LongKey.class - Key.of("foo", new DefaultApplicationId(0, "bar")).getClass(), //StringKey.class - Intent.class, - ConnectivityIntent.class, - PathIntent.class, - DefaultPath.class, - DefaultEdgeLink.class, - HostToHostIntent.class, - PointToPointIntent.class, - MultiPointToSinglePointIntent.class, - SinglePointToMultiPointIntent.class, - FlowRuleIntent.class, - LinkCollectionIntent.class, - OpticalConnectivityIntent.class, - OpticalPathIntent.class, - OpticalCircuitIntent.class, - LinkResourceRequest.class, - DefaultLinkResourceRequest.class, - BandwidthResourceRequest.class, - LambdaResourceRequest.class, - LambdaResource.class, - BandwidthResource.class, - DefaultLinkResourceAllocations.class, - BandwidthResourceAllocation.class, - LambdaResourceAllocation.class, - ResourcePath.class, - ResourcePath.Discrete.class, - ResourcePath.Continuous.class, - ResourceAllocation.class, - // Constraints - LambdaConstraint.class, - BandwidthConstraint.class, - LinkTypeConstraint.class, - LatencyConstraint.class, - WaypointConstraint.class, - ObstacleConstraint.class, - AnnotationConstraint.class, - BooleanConstraint.class, - PartialFailureConstraint.class, - IntentOperation.class, - FlowRuleExtPayLoad.class, - Frequency.class, - DefaultAnnotations.class, - PortStatistics.class, - DefaultPortStatistics.class, - IntentDomainId.class, - TableStatisticsEntry.class, - DefaultTableStatisticsEntry.class - ) - .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class) - .register(new UriSerializer(), URI.class) - .register(new NodeIdSerializer(), NodeId.class) - .register(new ProviderIdSerializer(), ProviderId.class) - .register(new DeviceIdSerializer(), DeviceId.class) - .register(new PortNumberSerializer(), PortNumber.class) - .register(new DefaultPortSerializer(), DefaultPort.class) - .register(new LinkKeySerializer(), LinkKey.class) - .register(new ConnectPointSerializer(), ConnectPoint.class) - .register(new DefaultLinkSerializer(), DefaultLink.class) - .register(new MastershipTermSerializer(), MastershipTerm.class) - .register(new HostLocationSerializer(), HostLocation.class) - .register(new DefaultOutboundPacketSerializer(), DefaultOutboundPacket.class) - .register(new AnnotationsSerializer(), DefaultAnnotations.class) - .register(new ExtensionInstructionSerializer(), Instructions.ExtensionInstructionWrapper.class) - .register(ExtensionTreatmentType.class) - .register(Versioned.class) - .register(MapEvent.class) - .register(MapEvent.Type.class) - .register(SetEvent.class) - .register(SetEvent.Type.class) - .register(DefaultGroupId.class) - .register(Annotations.class) - .register(OmsPort.class) - .register(OchPort.class) - .register(OduSignalType.class) - .register(OchSignalType.class) - .register(GridType.class) - .register(ChannelSpacing.class) - .register(OduCltPort.class) - .register(OduCltPort.SignalType.class) - .register(IndexedLambda.class) - .register(OchSignal.class) - .register(OduSignalId.class) - .register(OduCltPortDescription.class) - .register(OchPortDescription.class) - .register(OmsPortDescription.class) - .register(TributarySlot.class) - .register( - MplsIntent.class, - MplsPathIntent.class, - MplsLabelResourceAllocation.class, - MplsLabelResourceRequest.class, - MplsLabel.class, - org.onlab.packet.MplsLabel.class, - org.onlab.packet.MPLS.class - ) - - .build(); - - - // not to be instantiated - private KryoNamespaces() {} -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoSerializer.java deleted file mode 100644 index dbad6d0d..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoSerializer.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; - -import org.onlab.util.KryoNamespace; - -import com.google.common.base.MoreObjects; - -/** - * StoreSerializer implementation using Kryo. - */ -public class KryoSerializer implements StoreSerializer { - - protected KryoNamespace serializerPool; - - public KryoSerializer() { - setupKryoPool(); - } - - /** - * Sets up the common serializers pool. - */ - protected void setupKryoPool() { - serializerPool = KryoNamespace.newBuilder() - .register(KryoNamespaces.API) - .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID) - .build(); - } - - @Override - public byte[] encode(final Object obj) { - return serializerPool.serialize(obj); - } - - @Override - public <T> T decode(final byte[] bytes) { - if (bytes == null) { - return null; - } - return serializerPool.deserialize(bytes); - } - - @Override - public void encode(Object obj, ByteBuffer buffer) { - serializerPool.serialize(obj, buffer); - } - - @Override - public <T> T decode(ByteBuffer buffer) { - return serializerPool.deserialize(buffer); - } - - @Override - public void encode(Object obj, OutputStream stream) { - serializerPool.serialize(obj, stream); - } - - @Override - public <T> T decode(InputStream stream) { - return serializerPool.deserialize(stream); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("serializerPool", serializerPool) - .toString(); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/LinkKeySerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/LinkKeySerializer.java deleted file mode 100644 index 4bef3369..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/LinkKeySerializer.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.net.ConnectPoint; -import org.onosproject.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> { - - /** - * Creates {@link LinkKey} serializer instance. - */ - 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 LinkKey.linkKey(src, dst); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/MacAddressSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/MacAddressSerializer.java deleted file mode 100644 index 881e0ec0..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/MacAddressSerializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onlab.packet.MacAddress; - -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 MacAddress}. - */ -public class MacAddressSerializer extends Serializer<MacAddress> { - - /** - * Creates {@link MacAddress} serializer instance. - */ - public MacAddressSerializer() { - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, MacAddress object) { - output.writeBytes(object.toBytes()); - } - - @Override - public MacAddress read(Kryo kryo, Input input, Class<MacAddress> type) { - return MacAddress.valueOf(input.readBytes(MacAddress.MAC_ADDRESS_LENGTH)); - } - -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/MastershipTermSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/MastershipTermSerializer.java deleted file mode 100644 index 43bce71c..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/MastershipTermSerializer.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.cluster.NodeId; -import org.onosproject.mastership.MastershipTerm; - -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 org.onosproject.mastership.MastershipTerm}. - */ -public class MastershipTermSerializer extends Serializer<MastershipTerm> { - - /** - * Creates {@link MastershipTerm} serializer instance. - */ - public MastershipTermSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public MastershipTerm read(Kryo kryo, Input input, Class<MastershipTerm> type) { - final NodeId node = (NodeId) kryo.readClassAndObject(input); - final long term = input.readLong(); - return MastershipTerm.of(node, term); - } - - @Override - public void write(Kryo kryo, Output output, MastershipTerm object) { - kryo.writeClassAndObject(output, object.master()); - output.writeLong(object.termNumber()); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/NodeIdSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/NodeIdSerializer.java deleted file mode 100644 index da8939b0..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/NodeIdSerializer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.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.onosproject.cluster.NodeId; - -/** - * Kryo Serializer for {@link org.onosproject.cluster.NodeId}. - */ -public final class NodeIdSerializer extends Serializer<NodeId> { - - /** - * Creates {@link NodeId} serializer instance. - */ - public NodeIdSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, NodeId object) { - output.writeString(object.toString()); - } - - @Override - public NodeId read(Kryo kryo, Input input, Class<NodeId> type) { - final String id = input.readString(); - return new NodeId(id); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/PortNumberSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/PortNumberSerializer.java deleted file mode 100644 index 74db644d..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/PortNumberSerializer.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.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> { - - /** - * Creates {@link PortNumber} serializer instance. - */ - public PortNumberSerializer() { - // non-null, immutable - super(false, true); - } - - @Override - public void write(Kryo kryo, Output output, PortNumber object) { - output.writeBoolean(object.hasName()); - output.writeLong(object.toLong()); - if (object.hasName()) { - output.writeString(object.name()); - } - } - - @Override - public PortNumber read(Kryo kryo, Input input, Class<PortNumber> type) { - if (input.readBoolean()) { - return PortNumber.portNumber(input.readLong(), input.readString()); - } else { - return PortNumber.portNumber(input.readLong()); - } - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ProviderIdSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ProviderIdSerializer.java deleted file mode 100644 index 7f9b6ffc..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ProviderIdSerializer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import org.onosproject.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> { - - /** - * Creates {@link ProviderId} serializer instance. - */ - 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()); - output.writeBoolean(object.isAncillary()); - } - - @Override - public ProviderId read(Kryo kryo, Input input, Class<ProviderId> type) { - String scheme = input.readString(); - String id = input.readString(); - boolean isAncillary = input.readBoolean(); - return new ProviderId(scheme, id, isAncillary); - } - -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/StoreSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/StoreSerializer.java deleted file mode 100644 index f0149fc5..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/StoreSerializer.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; - -// TODO: To be replaced with SerializationService from IOLoop activity -/** - * Service to serialize Objects into byte array. - */ -public interface StoreSerializer { - - /** - * Serializes the specified object into bytes. - * - * @param obj object to be serialized - * @return serialized bytes - */ - byte[] encode(final Object obj); - - /** - * Serializes the specified object into bytes. - * - * @param obj object to be serialized - * @param buffer to write serialized bytes - */ - void encode(final Object obj, ByteBuffer buffer); - - /** - * Serializes the specified object into bytes. - * - * @param obj object to be serialized - * @param stream to write serialized bytes - */ - void encode(final Object obj, final OutputStream stream); - - /** - * Deserializes the specified bytes into an object. - * - * @param bytes bytes to be deserialized - * @return deserialized object - * @param <T> decoded type - */ - <T> T decode(final byte[] bytes); - - /** - * Deserializes the specified bytes into an object. - * - * @param buffer bytes to be deserialized - * @return deserialized object - * @param <T> decoded type - */ - <T> T decode(final ByteBuffer buffer); - - /** - * Deserializes the specified bytes into an object. - * - * @param stream stream containing the bytes to be deserialized - * @return deserialized object - * @param <T> decoded type - */ - <T> T decode(final InputStream stream); -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/UriSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/UriSerializer.java deleted file mode 100644 index 1d146a55..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/UriSerializer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.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 java.net.URI; - -/** - * Serializer for {@link URI}. - */ -public class UriSerializer extends Serializer<URI> { - - /** - * Creates {@link URI} serializer instance. - */ - public UriSerializer() { - super(false); - } - - @Override - public void write(Kryo kryo, Output output, URI object) { - output.writeString(object.toString()); - } - - @Override - public URI read(Kryo kryo, Input input, Class<URI> type) { - return URI.create(input.readString()); - } -} diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/package-info.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/package-info.java deleted file mode 100644 index 9471b43e..00000000 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Various Kryo serializers for use in distributed stores. - */ -package org.onosproject.store.serializers; diff --git a/framework/src/onos/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java b/framework/src/onos/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java deleted file mode 100644 index 7df518e2..00000000 --- a/framework/src/onos/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java +++ /dev/null @@ -1,471 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.store.serializers; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.testing.EqualsTester; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onlab.packet.VlanId; -import org.onlab.util.Bandwidth; -import org.onlab.util.Frequency; -import org.onosproject.cluster.NodeId; -import org.onosproject.cluster.RoleInfo; -import org.onosproject.core.DefaultApplicationId; -import org.onosproject.core.DefaultGroupId; -import org.onosproject.mastership.MastershipTerm; -import org.onosproject.net.Annotations; -import org.onosproject.net.ChannelSpacing; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultDevice; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPort; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.GridType; -import org.onosproject.net.HostLocation; -import org.onosproject.net.IndexedLambda; -import org.onosproject.net.Link; -import org.onosproject.net.Link.Type; -import org.onosproject.net.LinkKey; -import org.onosproject.net.OchPort; -import org.onosproject.net.OchSignal; -import org.onosproject.net.OduCltPort; -import org.onosproject.net.OmsPort; -import org.onosproject.net.PortNumber; -import org.onosproject.net.OduSignalType; -import org.onosproject.net.SparseAnnotations; -import org.onosproject.net.flow.DefaultFlowRule; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.FlowId; -import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleBatchEntry; -import org.onosproject.net.intent.IntentId; -import org.onosproject.net.newresource.ResourcePath; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.BandwidthResource; -import org.onosproject.net.resource.link.BandwidthResourceAllocation; -import org.onosproject.net.resource.link.DefaultLinkResourceAllocations; -import org.onosproject.net.resource.link.DefaultLinkResourceRequest; -import org.onosproject.net.resource.link.LambdaResource; -import org.onosproject.net.resource.link.LambdaResourceAllocation; -import org.onosproject.net.resource.link.LinkResourceRequest; -import org.onosproject.net.resource.ResourceAllocation; -import org.onosproject.net.intent.constraint.AnnotationConstraint; -import org.onosproject.net.intent.constraint.BandwidthConstraint; -import org.onosproject.net.intent.constraint.LambdaConstraint; -import org.onosproject.net.intent.constraint.LatencyConstraint; -import org.onosproject.net.intent.constraint.LinkTypeConstraint; -import org.onosproject.net.intent.constraint.ObstacleConstraint; -import org.onosproject.net.intent.constraint.WaypointConstraint; -import org.onlab.packet.ChassisId; -import org.onlab.packet.IpAddress; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.Ip6Address; -import org.onlab.packet.IpPrefix; -import org.onlab.packet.Ip4Prefix; -import org.onlab.packet.Ip6Prefix; -import org.onlab.packet.MacAddress; -import org.onlab.util.KryoNamespace; - -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.time.Duration; - -import static java.util.Arrays.asList; -import static org.junit.Assert.*; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.PortNumber.portNumber; - -public class KryoSerializerTest { - - private static final ProviderId PID = new ProviderId("of", "foo"); - private static final ProviderId PIDA = new ProviderId("of", "foo", true); - private static final DeviceId DID1 = deviceId("of:foo"); - private static final DeviceId DID2 = deviceId("of:bar"); - private static final PortNumber P1 = portNumber(1); - private static final PortNumber P2 = portNumber(2); - private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1); - private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2); - private static final String MFR = "whitebox"; - private static final String HW = "1.1.x"; - private static final String SW1 = "3.8.1"; - private static final String SW2 = "3.9.5"; - private static final String SN = "43311-12345"; - private static final ChassisId CID = new ChassisId(); - private static final Device DEV1 = new DefaultDevice(PID, DID1, Device.Type.SWITCH, MFR, HW, - SW1, SN, CID); - private static final SparseAnnotations A1 = DefaultAnnotations.builder() - .set("A1", "a1") - .set("B1", "b1") - .build(); - private static final SparseAnnotations A1_2 = DefaultAnnotations.builder() - .remove("A1") - .set("B3", "b3") - .build(); - private static final OchSignal OCH_SIGNAL1 = (OchSignal) org.onosproject.net.Lambda.ochSignal( - GridType.DWDM, ChannelSpacing.CHL_100GHZ, -8, 4); - private static final VlanId VLAN1 = VlanId.vlanId((short) 100); - - private KryoSerializer serializer; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - serializer = new KryoSerializer() { - - @Override - protected void setupKryoPool() { - serializerPool = KryoNamespace.newBuilder() - .register(KryoNamespaces.API) - .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID) - .build(); - } - }; - } - - @After - public void tearDown() throws Exception { - } - - private <T> void testSerializedEquals(T original) { - ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); - serializer.encode(original, buffer); - buffer.flip(); - T copy = serializer.decode(buffer); - - T copy2 = serializer.decode(serializer.encode(original)); - - new EqualsTester() - .addEqualityGroup(original, copy, copy2) - .testEquals(); - } - - private <T> void testSerializable(T original) { - byte[] bs = serializer.encode(original); - T copy = serializer.decode(bs); - assertNotNull(copy); - } - - - @Test - public void testConnectPoint() { - testSerializedEquals(new ConnectPoint(DID1, P1)); - } - - @Test - public void testDefaultLink() { - testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT)); - testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1)); - } - - @Test - public void testDefaultPort() { - testSerializedEquals(new DefaultPort(DEV1, P1, true)); - testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2)); - } - - @Test - public void testOmsPort() { - testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300), - Frequency.ofGHz(100))); - testSerializedEquals(new OmsPort(DEV1, P1, true, Frequency.ofGHz(190_100), Frequency.ofGHz(197_300), - Frequency.ofGHz(100), A1_2)); - } - - @Test - public void testOchPort() { - testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1)); - testSerializedEquals(new OchPort(DEV1, P1, true, OduSignalType.ODU0, false, OCH_SIGNAL1, A1_2)); - } - - @Test - public void testOduCltPort() { - testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE)); - testSerializedEquals(new OduCltPort(DEV1, P1, true, OduCltPort.SignalType.CLT_10GBE, A1_2)); - } - - @Test - public void testDeviceId() { - testSerializedEquals(DID1); - } - - @Test - public void testImmutableMap() { - testSerializedEquals(ImmutableMap.of(DID1, DEV1, DID2, DEV1)); - testSerializedEquals(ImmutableMap.of(DID1, DEV1)); - testSerializedEquals(ImmutableMap.of()); - } - - @Test - public void testImmutableSet() { - testSerializedEquals(ImmutableSet.of(DID1, DID2)); - testSerializedEquals(ImmutableSet.of(DID1)); - testSerializedEquals(ImmutableSet.of()); - } - - @Test - public void testImmutableList() { - testSerializedEquals(ImmutableList.of(DID1, DID2)); - testSerializedEquals(ImmutableList.of(DID1)); - testSerializedEquals(ImmutableList.of()); - } - - @Test - public void testFlowRuleBatchEntry() { - final FlowRule rule1 = - DefaultFlowRule.builder() - .forDevice(DID1) - .withSelector(DefaultTrafficSelector.emptySelector()) - .withTreatment(DefaultTrafficTreatment.emptyTreatment()) - .withPriority(0) - .fromApp(new DefaultApplicationId(1, "1")) - .makeTemporary(1) - .build(); - - final FlowRuleBatchEntry entry1 = - new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1); - final FlowRuleBatchEntry entry2 = - new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L); - - testSerializedEquals(entry1); - testSerializedEquals(entry2); - } - - @Test - public void testIpPrefix() { - testSerializedEquals(IpPrefix.valueOf("192.168.0.1/24")); - } - - @Test - public void testIp4Prefix() { - testSerializedEquals(Ip4Prefix.valueOf("192.168.0.1/24")); - } - - @Test - public void testIp6Prefix() { - testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120")); - } - - @Test - public void testIpAddress() { - testSerializedEquals(IpAddress.valueOf("192.168.0.1")); - } - - @Test - public void testIp4Address() { - testSerializedEquals(Ip4Address.valueOf("192.168.0.1")); - } - - @Test - public void testIp6Address() { - testSerializedEquals(Ip6Address.valueOf("1111:2222::")); - } - - @Test - public void testMacAddress() { - testSerializedEquals(MacAddress.valueOf("12:34:56:78:90:ab")); - } - - @Test - public void testLinkKey() { - testSerializedEquals(LinkKey.linkKey(CP1, CP2)); - } - - @Test - public void testNodeId() { - testSerializedEquals(new NodeId("SomeNodeIdentifier")); - } - - @Test - public void testPortNumber() { - testSerializedEquals(P1); - } - - @Test - public void testProviderId() { - testSerializedEquals(PID); - testSerializedEquals(PIDA); - } - - @Test - public void testMastershipTerm() { - testSerializedEquals(MastershipTerm.of(new NodeId("foo"), 2)); - testSerializedEquals(MastershipTerm.of(null, 0)); - } - - @Test - public void testHostLocation() { - testSerializedEquals(new HostLocation(CP1, 1234L)); - } - - @Test - public void testFlowId() { - testSerializedEquals(FlowId.valueOf(0x12345678L)); - } - - @Test - public void testRoleInfo() { - testSerializedEquals(new RoleInfo(new NodeId("master"), - asList(new NodeId("stby1"), new NodeId("stby2")))); - } - - @Test - public void testIndexedLambda() { - testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L)); - } - - @Test - public void testOchSignal() { - testSerializedEquals(org.onosproject.net.Lambda.ochSignal( - GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1 - )); - } - - @Test - public void testDefaultLinkResourceRequest() { - testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of()) - .addLambdaRequest() - .addBandwidthRequest(32.195) - .build() - ); - } - - @Test - public void testDefaultLinkResourceAllocations() { - LinkResourceRequest request = DefaultLinkResourceRequest - .builder(IntentId.valueOf(2501), ImmutableList.of()) - .addLambdaRequest() - .addBandwidthRequest(32.195) - .build(); - Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); - allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT), - ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))), - new LambdaResourceAllocation(LambdaResource.valueOf(1)))); - testSerializable(new DefaultLinkResourceAllocations(request, allocations)); - } - - @Test - public void testResourcePath() { - testSerializedEquals(ResourcePath.discrete(DID1, P1, VLAN1)); - } - - @Test - public void testResourceAllocation() { - testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation( - ResourcePath.discrete(DID1, P1, VLAN1), - IntentId.valueOf(30))); - } - - @Test - public void testFrequency() { - testSerializedEquals(Frequency.ofGHz(100)); - } - - @Test - public void testBandwidth() { - testSerializedEquals(Bandwidth.mbps(1000.0)); - } - - @Test - public void testLambdaConstraint() { - testSerializable(new LambdaConstraint(new IndexedLambda(1))); - } - - @Test - public void testBandwidthConstraint() { - testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0))); - } - - @Test - public void testLinkTypeConstraint() { - testSerializable(new LinkTypeConstraint(true, Link.Type.DIRECT)); - } - - @Test - public void testLatencyConstraint() { - testSerializable(new LatencyConstraint(Duration.ofSeconds(10))); - } - - @Test - public void testWaypointConstraint() { - testSerializable(new WaypointConstraint(deviceId("of:1"), deviceId("of:2"))); - } - - @Test - public void testObstacleConstraint() { - testSerializable(new ObstacleConstraint(deviceId("of:1"), deviceId("of:2"))); - } - - @Test - public void testArraysAsList() { - testSerializedEquals(Arrays.asList(1, 2, 3)); - } - - @Test - public void testAnnotationConstraint() { - testSerializable(new AnnotationConstraint("distance", 100.0)); - } - - @Test - public void testDefaultGroupId() { - testSerializedEquals(new DefaultGroupId(99)); - } - - @Test - public void testEmptySet() { - testSerializedEquals(Collections.emptySet()); - } - - @Test - public void testAnnotations() { - // Annotations does not have equals defined, manually test equality - final byte[] a1Bytes = serializer.encode(A1); - SparseAnnotations copiedA1 = serializer.decode(a1Bytes); - assertAnnotationsEquals(copiedA1, A1); - - final byte[] a12Bytes = serializer.encode(A1_2); - SparseAnnotations copiedA12 = serializer.decode(a12Bytes); - assertAnnotationsEquals(copiedA12, A1_2); - } - - // code clone - protected static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) { - SparseAnnotations expected = DefaultAnnotations.builder().build(); - for (SparseAnnotations a : annotations) { - expected = DefaultAnnotations.union(expected, a); - } - assertEquals(expected.keys(), actual.keys()); - for (String key : expected.keys()) { - assertEquals(expected.value(key), actual.value(key)); - } - } - -} |