blob: 6e0c85b0367c6f25d3b294337e6e06e335ddaa90 [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;
Gustavo Silva29fb20e2022-05-26 09:59:54 -030026import org.opencord.olt.AccessDevicePort;
27import org.opencord.olt.ServiceKey;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070028import org.opencord.sadis.UniTagInformation;
29
30/**
31 * ServiceKeySerializer is a custom serializer to store a ServiceKey in an Atomix ditributed map.
32 */
33class ServiceKeySerializer extends Serializer<ServiceKey> {
34
35 ServiceKeySerializer() {
36 // non-null, immutable
37 super(false, true);
38 }
39
40 @Override
41 public void write(Kryo kryo, Output output, ServiceKey object) {
42 kryo.writeClassAndObject(output, object.getPort().connectPoint().port());
43 output.writeString(object.getPort().name());
44 output.writeString(object.getPort().connectPoint().deviceId().toString());
45 kryo.writeClassAndObject(output, object.getService());
46 }
47
48 @Override
49 public ServiceKey read(Kryo kryo, Input input, Class<ServiceKey> type) {
50 PortNumber port = (PortNumber) kryo.readClassAndObject(input);
51 final String portName = input.readString();
52 final String devId = input.readString();
53
54 UniTagInformation uti = (UniTagInformation) kryo.readClassAndObject(input);
55 ConnectPoint cp = new ConnectPoint(DeviceId.deviceId(devId), port);
56 AccessDevicePort adp = new AccessDevicePort(cp, portName);
57
58 return new ServiceKey(adp, uti);
59 }
60}