diff options
author | Ashlee Young <ashlee@onosfw.com> | 2015-09-09 22:15:21 -0700 |
---|---|---|
committer | Ashlee Young <ashlee@onosfw.com> | 2015-09-09 22:15:21 -0700 |
commit | 13d05bc8458758ee39cb829098241e89616717ee (patch) | |
tree | 22a4d1ce65f15952f07a3df5af4b462b4697cb3a /framework/src/onos/core/store/serializers/src/main/java/org/onosproject | |
parent | 6139282e1e93c2322076de4b91b1c85d0bc4a8b3 (diff) |
ONOS checkin based on commit tag e796610b1f721d02f9b0e213cf6f7790c10ecd60
Change-Id: Ife8810491034fe7becdba75dda20de4267bd15cd
Diffstat (limited to 'framework/src/onos/core/store/serializers/src/main/java/org/onosproject')
29 files changed, 1991 insertions, 0 deletions
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 new file mode 100644 index 00000000..febb4adb --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/AnnotationsSerializer.java @@ -0,0 +1,32 @@ +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 new file mode 100644 index 00000000..99c35310 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ArraysAsListSerializer.java @@ -0,0 +1,49 @@ +/* + * 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 new file mode 100644 index 00000000..f1027d5e --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ConnectPointSerializer.java @@ -0,0 +1,51 @@ +/* + * 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 new file mode 100644 index 00000000..0b1ad957 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultApplicationIdSerializer.java @@ -0,0 +1,49 @@ +/* + * 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 new file mode 100644 index 00000000..6cc90667 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultLinkSerializer.java @@ -0,0 +1,61 @@ +/* + * 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 new file mode 100644 index 00000000..9d12e458 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultOutboundPacketSerializer.java @@ -0,0 +1,58 @@ +/* + * 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 new file mode 100644 index 00000000..60d09fbe --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultPortSerializer.java @@ -0,0 +1,65 @@ +/* + * 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 new file mode 100644 index 00000000..a74a7695 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/DeviceIdSerializer.java @@ -0,0 +1,48 @@ +/* + * 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/HostLocationSerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/HostLocationSerializer.java new file mode 100644 index 00000000..270eb218 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/HostLocationSerializer.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 00000000..95166c3b --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableListSerializer.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 00000000..4d6af788 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableMapSerializer.java @@ -0,0 +1,58 @@ +/* + * 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 new file mode 100644 index 00000000..cb9b0543 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableSetSerializer.java @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 00000000..2370ad92 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip4AddressSerializer.java @@ -0,0 +1,52 @@ +/* + * 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 new file mode 100644 index 00000000..029ffb1a --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip4PrefixSerializer.java @@ -0,0 +1,57 @@ +/* + * 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 new file mode 100644 index 00000000..f8101f98 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip6AddressSerializer.java @@ -0,0 +1,52 @@ +/* + * 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 new file mode 100644 index 00000000..91ba5a29 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/Ip6PrefixSerializer.java @@ -0,0 +1,57 @@ +/* + * 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 new file mode 100644 index 00000000..cb85fec8 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/IpAddressSerializer.java @@ -0,0 +1,58 @@ +/* + * 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 new file mode 100644 index 00000000..cf0a20b9 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/IpPrefixSerializer.java @@ -0,0 +1,64 @@ +/* + * 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 new file mode 100644 index 00000000..66ee7be7 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java @@ -0,0 +1,479 @@ +/* + * 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.OduSignalType; +import org.onosproject.net.OmsPort; +import org.onosproject.net.Port; +import org.onosproject.net.PortNumber; +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.DefaultTrafficSelector; +import org.onosproject.net.flow.DefaultTrafficTreatment; +import org.onosproject.net.flow.FlowEntry; +import org.onosproject.net.flow.FlowId; +import org.onosproject.net.flow.FlowRule; +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.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.OpticalSignalTypeCriterion; +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.Instructions; +import org.onosproject.net.flow.instructions.L0ModificationInstruction; +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, + FlowRule.Type.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, + OpticalSignalTypeCriterion.class, + Criterion.class, + Criterion.Type.class, + DefaultTrafficTreatment.class, + Instructions.DropInstruction.class, + Instructions.OutputInstruction.class, + Instructions.GroupInstruction.class, + Instructions.TableTypeTransition.class, + L0ModificationInstruction.class, + L0ModificationInstruction.L0SubType.class, + L0ModificationInstruction.ModLambdaInstruction.class, + L0ModificationInstruction.ModOchSignalInstruction.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.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, + 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 + ) + .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(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(OduCltPortDescription.class) + .register(OchPortDescription.class) + .register(OmsPortDescription.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 new file mode 100644 index 00000000..dbad6d0d --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoSerializer.java @@ -0,0 +1,86 @@ +/* + * 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 new file mode 100644 index 00000000..4bef3369 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/LinkKeySerializer.java @@ -0,0 +1,51 @@ +/* + * 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 new file mode 100644 index 00000000..881e0ec0 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/MacAddressSerializer.java @@ -0,0 +1,47 @@ +/* + * 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 new file mode 100644 index 00000000..43bce71c --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/MastershipTermSerializer.java @@ -0,0 +1,51 @@ +/* + * 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 new file mode 100644 index 00000000..da8939b0 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/NodeIdSerializer.java @@ -0,0 +1,48 @@ +/* + * 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 new file mode 100644 index 00000000..74db644d --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/PortNumberSerializer.java @@ -0,0 +1,56 @@ +/* + * 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 new file mode 100644 index 00000000..7f9b6ffc --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/ProviderIdSerializer.java @@ -0,0 +1,53 @@ +/* + * 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 new file mode 100644 index 00000000..f0149fc5 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/StoreSerializer.java @@ -0,0 +1,78 @@ +/* + * 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 new file mode 100644 index 00000000..43969666 --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/URISerializer.java @@ -0,0 +1,46 @@ +/* + * 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.net.URI; + +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 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 new file mode 100644 index 00000000..9471b43e --- /dev/null +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/package-info.java @@ -0,0 +1,20 @@ +/* + * 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; |