Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.opencord.olt.impl; |
| 18 | |
| 19 | import com.esotericsoftware.kryo.Kryo; |
| 20 | import com.esotericsoftware.kryo.io.Input; |
| 21 | import com.esotericsoftware.kryo.io.Output; |
| 22 | import com.esotericsoftware.kryo.Serializer; |
| 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.net.PortNumber; |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame^] | 26 | import org.opencord.olt.AccessDevicePort; |
| 27 | import org.opencord.olt.ServiceKey; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 28 | import org.opencord.sadis.UniTagInformation; |
| 29 | |
| 30 | /** |
| 31 | * ServiceKeySerializer is a custom serializer to store a ServiceKey in an Atomix ditributed map. |
| 32 | */ |
| 33 | class 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 | } |