blob: 4035bdd87fbc432702d186befbf3203b9709e5ab [file] [log] [blame]
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07001/*
2 * Copyright 2021-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.opencord.olt.impl;
18
19import com.esotericsoftware.kryo.Kryo;
20import com.esotericsoftware.kryo.io.Input;
21import com.esotericsoftware.kryo.io.Output;
22import com.esotericsoftware.kryo.Serializer;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.PortNumber;
26import org.opencord.sadis.UniTagInformation;
27
28/**
29 * ServiceKeySerializer is a custom serializer to store a ServiceKey in an Atomix ditributed map.
30 */
31class ServiceKeySerializer extends Serializer<ServiceKey> {
32
33 ServiceKeySerializer() {
34 // non-null, immutable
35 super(false, true);
36 }
37
38 @Override
39 public void write(Kryo kryo, Output output, ServiceKey object) {
40 kryo.writeClassAndObject(output, object.getPort().connectPoint().port());
41 output.writeString(object.getPort().name());
42 output.writeString(object.getPort().connectPoint().deviceId().toString());
43 kryo.writeClassAndObject(output, object.getService());
44 }
45
46 @Override
47 public ServiceKey read(Kryo kryo, Input input, Class<ServiceKey> type) {
48 PortNumber port = (PortNumber) kryo.readClassAndObject(input);
49 final String portName = input.readString();
50 final String devId = input.readString();
51
52 UniTagInformation uti = (UniTagInformation) kryo.readClassAndObject(input);
53 ConnectPoint cp = new ConnectPoint(DeviceId.deviceId(devId), port);
54 AccessDevicePort adp = new AccessDevicePort(cp, portName);
55
56 return new ServiceKey(adp, uti);
57 }
58}