Sho SHIMIZU
Committed by Sho Shimizu

Add DiscreteResourceCodec for PortNumber

Change-Id: Iedda1a0ba46b3d044f127334a8abdb419dabcd9f
(cherry picked from commit cbd103df)
...@@ -17,6 +17,7 @@ package org.onosproject.store.resource.impl; ...@@ -17,6 +17,7 @@ package org.onosproject.store.resource.impl;
17 17
18 import org.onlab.packet.MplsLabel; 18 import org.onlab.packet.MplsLabel;
19 import org.onlab.packet.VlanId; 19 import org.onlab.packet.VlanId;
20 +import org.onosproject.net.PortNumber;
20 import org.onosproject.net.resource.DiscreteResource; 21 import org.onosproject.net.resource.DiscreteResource;
21 import org.onosproject.net.resource.DiscreteResourceCodec; 22 import org.onosproject.net.resource.DiscreteResourceCodec;
22 23
...@@ -46,6 +47,7 @@ final class Codecs { ...@@ -46,6 +47,7 @@ final class Codecs {
46 } 47 }
47 48
48 private void init() { 49 private void init() {
50 + codecs.put(PortNumber.class, new PortNumberCodec());
49 codecs.put(VlanId.class, new VlanIdCodec()); 51 codecs.put(VlanId.class, new VlanIdCodec());
50 codecs.put(MplsLabel.class, new MplsLabelCodec()); 52 codecs.put(MplsLabel.class, new MplsLabelCodec());
51 } 53 }
......
...@@ -78,6 +78,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -78,6 +78,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
78 .register(EmptyDiscreteResources.class) 78 .register(EmptyDiscreteResources.class)
79 .register(new EncodedResourcesSerializer(), EncodedDiscreteResources.class) 79 .register(new EncodedResourcesSerializer(), EncodedDiscreteResources.class)
80 .register(ContinuousResourceAllocation.class) 80 .register(ContinuousResourceAllocation.class)
81 + .register(PortNumberCodec.class)
81 .register(VlanIdCodec.class) 82 .register(VlanIdCodec.class)
82 .register(MplsLabelCodec.class) 83 .register(MplsLabelCodec.class)
83 .build()); 84 .build());
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
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.store.resource.impl;
18 +
19 +import org.onosproject.net.PortNumber;
20 +import org.onosproject.net.resource.DiscreteResourceCodec;
21 +
22 +class PortNumberCodec implements DiscreteResourceCodec<PortNumber> {
23 + @Override
24 + public int encode(PortNumber resource) {
25 + return (int) resource.toLong();
26 + }
27 +
28 + @Override
29 + public PortNumber decode(int value) {
30 + return PortNumber.portNumber(value);
31 + }
32 +
33 + @Override
34 + public boolean equals(Object obj) {
35 + if (obj == this) {
36 + return true;
37 + }
38 +
39 + if (obj == null || getClass() != obj.getClass()) {
40 + return false;
41 + }
42 +
43 + return true;
44 + }
45 +
46 + @Override
47 + public int hashCode() {
48 + return PortNumber.class.hashCode();
49 + }
50 +}