Pier Luigi Ventre | d1173a1 | 2016-03-30 15:51:03 +0200 | [diff] [blame] | 1 | /* |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Pier Luigi Ventre | d1173a1 | 2016-03-30 15:51:03 +0200 | [diff] [blame] | 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.onosproject.sdxl2; |
| 18 | |
| 19 | import com.esotericsoftware.kryo.Kryo; |
| 20 | import com.esotericsoftware.kryo.Serializer; |
| 21 | import com.esotericsoftware.kryo.io.Input; |
| 22 | import com.esotericsoftware.kryo.io.Output; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.VlanId; |
| 25 | import org.onosproject.net.ConnectPoint; |
| 26 | |
| 27 | import java.util.List; |
| 28 | |
| 29 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 30 | * Kryo serializer for SDX-L2 connection point. |
Pier Luigi Ventre | d1173a1 | 2016-03-30 15:51:03 +0200 | [diff] [blame] | 31 | */ |
| 32 | public class SdxL2ConnectionPointSerializer extends Serializer<SdxL2ConnectionPoint> { |
| 33 | |
| 34 | /** |
| 35 | * Serialize the object using kryo. |
| 36 | * |
| 37 | * @param kryo the serializer |
| 38 | * @param output the output |
| 39 | * @param object the object to serialize |
| 40 | */ |
| 41 | public void write(Kryo kryo, Output output, SdxL2ConnectionPoint object) { |
| 42 | kryo.writeClassAndObject(output, object.name()); |
| 43 | kryo.writeClassAndObject(output, object.connectPoint()); |
| 44 | kryo.writeClassAndObject(output, object.macAddress()); |
| 45 | kryo.writeClassAndObject(output, object.vlanIds()); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Create an object from one serialized using kryo. |
| 50 | * |
| 51 | * @param kryo the serializer |
| 52 | * @param input the inpunt |
| 53 | * @param type the object to create |
| 54 | * @return the object |
| 55 | */ |
| 56 | public SdxL2ConnectionPoint read(Kryo kryo, Input input, Class<SdxL2ConnectionPoint> type) { |
| 57 | String name = (String) kryo.readClassAndObject(input); |
| 58 | ConnectPoint cp = (ConnectPoint) kryo.readClassAndObject(input); |
| 59 | MacAddress mac = (MacAddress) kryo.readClassAndObject(input); |
| 60 | List<VlanId> vlans = (List<VlanId>) kryo.readClassAndObject(input); |
| 61 | return new SdxL2ConnectionPoint(name, cp, vlans, mac); |
| 62 | } |
| 63 | } |