Sho SHIMIZU
Committed by Gerrit Code Review

Make serialized resources more compact to omit redundant parent resource ID

Change-Id: Icafe92f35bded405dd39e57ad8380bca82a6d720
(cherry picked from commit d68739b5)
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 -package org.onosproject.net.resource;
17 -
18 -import com.google.common.annotations.Beta;
19 -import com.google.common.collect.ImmutableSet;
20 -
21 -import java.util.Objects;
22 -import java.util.Optional;
23 -import java.util.Set;
24 -
25 -import static com.google.common.base.Preconditions.checkArgument;
26 -import static com.google.common.base.Preconditions.checkNotNull;
27 -import static com.google.common.base.Preconditions.checkState;
28 -
29 -/**
30 - * Represents a set of discrete type resources.
31 - * This class is intended to be used by ConsistentResourceStore though it is exposed to the public.
32 - */
33 -@Beta
34 -public final class DiscreteResourceSet {
35 - private final Set<DiscreteResource> values;
36 - private final DiscreteResourceCodec codec;
37 -
38 - private static final DiscreteResourceSet EMPTY = new DiscreteResourceSet(ImmutableSet.of(), NoOpCodec.INSTANCE);
39 -
40 - /**
41 - * Creates an instance with resources and the codec for them.
42 - *
43 - * @param values resources to be contained in the instance
44 - * @param codec codec for the specified resources
45 - * @return an instance
46 - */
47 - public static DiscreteResourceSet of(Set<DiscreteResource> values, DiscreteResourceCodec codec) {
48 - checkNotNull(values);
49 - checkNotNull(codec);
50 - checkArgument(!values.isEmpty());
51 -
52 - return new DiscreteResourceSet(ImmutableSet.copyOf(values), codec);
53 - }
54 -
55 - /**
56 - * Creates the instance representing an empty resource set.
57 - *
58 - * @return an empty resource set
59 - */
60 - public static DiscreteResourceSet empty() {
61 - return EMPTY;
62 - }
63 -
64 - private DiscreteResourceSet(Set<DiscreteResource> values, DiscreteResourceCodec codec) {
65 - this.values = values;
66 - this.codec = codec;
67 - }
68 -
69 - private DiscreteResourceSet() {
70 - this.values = null;
71 - this.codec = null;
72 - }
73 -
74 - /**
75 - * Returns resources contained in this instance.
76 - *
77 - * @return resources
78 - */
79 - public Set<DiscreteResource> values() {
80 - return values;
81 - }
82 -
83 - /**
84 - * Returns the parent resource of the resources contained in this instance.
85 - *
86 - * @return the parent resource of the resources
87 - */
88 - public DiscreteResourceId parent() {
89 - if (values.isEmpty()) {
90 - // Dummy value avoiding null
91 - return ResourceId.ROOT;
92 - }
93 - Optional<DiscreteResourceId> parent = values.iterator().next().id().parent();
94 - checkState(parent.isPresent());
95 -
96 - return parent.get();
97 - }
98 -
99 - /**
100 - * Returns the codec for the resources contained in this instance.
101 - *
102 - * @return the codec for the resources
103 - */
104 - public DiscreteResourceCodec codec() {
105 - return codec;
106 - }
107 -
108 - @Override
109 - public int hashCode() {
110 - return Objects.hash(values, codec);
111 - }
112 -
113 - @Override
114 - public boolean equals(Object obj) {
115 - if (this == obj) {
116 - return true;
117 - }
118 -
119 - if (obj == null || getClass() != obj.getClass()) {
120 - return false;
121 - }
122 -
123 - final DiscreteResourceSet other = (DiscreteResourceSet) obj;
124 - return Objects.equals(this.values, other.values)
125 - && Objects.equals(this.codec, other.codec);
126 - }
127 -
128 - public boolean contains(DiscreteResource resource) {
129 - return values.contains(resource);
130 - }
131 -}
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 -package org.onosproject.net.resource;
17 -
18 -/**
19 - * Represents no-op codec intended to used in an empty discrete resource set only.
20 - * It's not supposed to be used by other classes.
21 - */
22 -public class NoOpCodec implements DiscreteResourceCodec<Object> {
23 - public static final DiscreteResourceCodec INSTANCE = new NoOpCodec();
24 -
25 - @Override
26 - public int encode(Object resource) {
27 - return 0;
28 - }
29 -
30 - @Override
31 - public Object decode(int value) {
32 - return Resource.ROOT;
33 - }
34 -
35 - @Override
36 - public boolean equals(Object obj) {
37 - if (obj == this) {
38 - return true;
39 - }
40 -
41 - if (obj == null || getClass() != obj.getClass()) {
42 - return false;
43 - }
44 -
45 - return true;
46 - }
47 -
48 - @Override
49 - public int hashCode() {
50 - return NoOpCodec.class.hashCode();
51 - }
52 -}
...@@ -76,6 +76,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -76,6 +76,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
76 .register(new EncodableDiscreteResourcesSerializer(), EncodableDiscreteResources.class) 76 .register(new EncodableDiscreteResourcesSerializer(), EncodableDiscreteResources.class)
77 .register(GenericDiscreteResources.class) 77 .register(GenericDiscreteResources.class)
78 .register(EmptyDiscreteResources.class) 78 .register(EmptyDiscreteResources.class)
79 + .register(new EncodedResourcesSerializer(), EncodedDiscreteResources.class)
79 .register(ContinuousResourceAllocation.class) 80 .register(ContinuousResourceAllocation.class)
80 .build()); 81 .build());
81 82
......
...@@ -19,7 +19,6 @@ import com.google.common.collect.Sets; ...@@ -19,7 +19,6 @@ import com.google.common.collect.Sets;
19 import org.onosproject.net.resource.DiscreteResource; 19 import org.onosproject.net.resource.DiscreteResource;
20 import org.onosproject.net.resource.DiscreteResourceCodec; 20 import org.onosproject.net.resource.DiscreteResourceCodec;
21 import org.onosproject.net.resource.DiscreteResourceId; 21 import org.onosproject.net.resource.DiscreteResourceId;
22 -import org.onosproject.net.resource.DiscreteResourceSet;
23 import org.onosproject.net.resource.Resources; 22 import org.onosproject.net.resource.Resources;
24 23
25 import java.util.LinkedHashMap; 24 import java.util.LinkedHashMap;
...@@ -36,7 +35,7 @@ import java.util.stream.Collectors; ...@@ -36,7 +35,7 @@ import java.util.stream.Collectors;
36 final class EncodableDiscreteResources implements DiscreteResources { 35 final class EncodableDiscreteResources implements DiscreteResources {
37 private static final Codecs CODECS = Codecs.getInstance(); 36 private static final Codecs CODECS = Codecs.getInstance();
38 private final DiscreteResource parent; 37 private final DiscreteResource parent;
39 - private final Map<Class<?>, DiscreteResourceSet> values; 38 + private final Map<Class<?>, EncodedDiscreteResources> values;
40 39
41 private static Class<?> getClass(DiscreteResource resource) { 40 private static Class<?> getClass(DiscreteResource resource) {
42 return resource.valueAs(Object.class).map(Object::getClass).get(); 41 return resource.valueAs(Object.class).map(Object::getClass).get();
...@@ -55,16 +54,16 @@ final class EncodableDiscreteResources implements DiscreteResources { ...@@ -55,16 +54,16 @@ final class EncodableDiscreteResources implements DiscreteResources {
55 Map<Class<?>, Set<DiscreteResource>> grouped = resources.stream() 54 Map<Class<?>, Set<DiscreteResource>> grouped = resources.stream()
56 .collect(Collectors.groupingBy(x -> getClass(x), Collectors.toCollection(LinkedHashSet::new))); 55 .collect(Collectors.groupingBy(x -> getClass(x), Collectors.toCollection(LinkedHashSet::new)));
57 56
58 - Map<Class<?>, DiscreteResourceSet> values = new LinkedHashMap<>(); 57 + Map<Class<?>, EncodedDiscreteResources> values = new LinkedHashMap<>();
59 for (Map.Entry<Class<?>, Set<DiscreteResource>> entry : grouped.entrySet()) { 58 for (Map.Entry<Class<?>, Set<DiscreteResource>> entry : grouped.entrySet()) {
60 DiscreteResourceCodec<?> codec = CODECS.getCodec(entry.getKey()); 59 DiscreteResourceCodec<?> codec = CODECS.getCodec(entry.getKey());
61 - values.put(entry.getKey(), DiscreteResourceSet.of(entry.getValue(), codec)); 60 + values.put(entry.getKey(), EncodedDiscreteResources.of(entry.getValue(), codec));
62 } 61 }
63 62
64 return new EncodableDiscreteResources(parent, values); 63 return new EncodableDiscreteResources(parent, values);
65 } 64 }
66 65
67 - private EncodableDiscreteResources(DiscreteResource parent, Map<Class<?>, DiscreteResourceSet> values) { 66 + private EncodableDiscreteResources(DiscreteResource parent, Map<Class<?>, EncodedDiscreteResources> values) {
68 this.parent = parent; 67 this.parent = parent;
69 this.values = values; 68 this.values = values;
70 } 69 }
...@@ -93,10 +92,8 @@ final class EncodableDiscreteResources implements DiscreteResources { ...@@ -93,10 +92,8 @@ final class EncodableDiscreteResources implements DiscreteResources {
93 92
94 @Override 93 @Override
95 public boolean isEmpty() { 94 public boolean isEmpty() {
96 - return !values.values().stream() 95 + return values.values().stream()
97 - .flatMap(x -> x.values().stream()) 96 + .allMatch(x -> x.isEmpty());
98 - .findAny()
99 - .isPresent();
100 } 97 }
101 98
102 @Override 99 @Override
...@@ -120,7 +117,7 @@ final class EncodableDiscreteResources implements DiscreteResources { ...@@ -120,7 +117,7 @@ final class EncodableDiscreteResources implements DiscreteResources {
120 @Override 117 @Override
121 public Set<DiscreteResource> values() { 118 public Set<DiscreteResource> values() {
122 return values.values().stream() 119 return values.values().stream()
123 - .flatMap(x -> x.values().stream()) 120 + .flatMap(x -> x.resources(parent.id()).stream())
124 .collect(Collectors.toCollection(LinkedHashSet::new)); 121 .collect(Collectors.toCollection(LinkedHashSet::new));
125 } 122 }
126 123
...@@ -128,7 +125,7 @@ final class EncodableDiscreteResources implements DiscreteResources { ...@@ -128,7 +125,7 @@ final class EncodableDiscreteResources implements DiscreteResources {
128 return parent; 125 return parent;
129 } 126 }
130 127
131 - Map<Class<?>, DiscreteResourceSet> rawValues() { 128 + Map<Class<?>, EncodedDiscreteResources> rawValues() {
132 return values; 129 return values;
133 } 130 }
134 } 131 }
......
...@@ -20,7 +20,6 @@ import com.esotericsoftware.kryo.Serializer; ...@@ -20,7 +20,6 @@ import com.esotericsoftware.kryo.Serializer;
20 import com.esotericsoftware.kryo.io.Input; 20 import com.esotericsoftware.kryo.io.Input;
21 import com.esotericsoftware.kryo.io.Output; 21 import com.esotericsoftware.kryo.io.Output;
22 import org.onosproject.net.resource.DiscreteResource; 22 import org.onosproject.net.resource.DiscreteResource;
23 -import org.onosproject.net.resource.DiscreteResourceSet;
24 23
25 import java.util.LinkedHashSet; 24 import java.util.LinkedHashSet;
26 import java.util.Set; 25 import java.util.Set;
...@@ -40,11 +39,11 @@ class EncodableDiscreteResourcesSerializer extends Serializer<EncodableDiscreteR ...@@ -40,11 +39,11 @@ class EncodableDiscreteResourcesSerializer extends Serializer<EncodableDiscreteR
40 public EncodableDiscreteResources read(Kryo kryo, Input input, Class<EncodableDiscreteResources> cls) { 39 public EncodableDiscreteResources read(Kryo kryo, Input input, Class<EncodableDiscreteResources> cls) {
41 DiscreteResource parent = kryo.readObject(input, DiscreteResource.class); 40 DiscreteResource parent = kryo.readObject(input, DiscreteResource.class);
42 @SuppressWarnings("unchecked") 41 @SuppressWarnings("unchecked")
43 - Set<DiscreteResourceSet> resources = kryo.readObject(input, LinkedHashSet.class); 42 + Set<EncodedDiscreteResources> resources = kryo.readObject(input, LinkedHashSet.class);
44 43
45 return EncodableDiscreteResources.of(parent, 44 return EncodableDiscreteResources.of(parent,
46 resources.stream() 45 resources.stream()
47 - .flatMap(x -> x.values().stream()) 46 + .flatMap(x -> x.resources(parent.id()).stream())
48 .collect(Collectors.toCollection(LinkedHashSet::new))); 47 .collect(Collectors.toCollection(LinkedHashSet::new)));
49 } 48 }
50 } 49 }
......
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 +package org.onosproject.store.resource.impl;
17 +
18 +import org.onlab.util.Tools;
19 +import org.onosproject.net.resource.DiscreteResource;
20 +import org.onosproject.net.resource.DiscreteResourceCodec;
21 +import org.onosproject.net.resource.DiscreteResourceId;
22 +import org.onosproject.net.resource.Resources;
23 +
24 +import java.util.LinkedHashSet;
25 +import java.util.Set;
26 +import java.util.stream.Collectors;
27 +
28 +/**
29 + * Represents discrete resources encoded by a codec.
30 + */
31 +final class EncodedDiscreteResources {
32 + private final Set<Integer> rawValues;
33 + private final DiscreteResourceCodec codec;
34 +
35 + EncodedDiscreteResources(Set<Integer> rawValues, DiscreteResourceCodec codec) {
36 + this.rawValues = rawValues;
37 + this.codec = codec;
38 + }
39 +
40 + static EncodedDiscreteResources of(Set<DiscreteResource> resources, DiscreteResourceCodec codec) {
41 + Set<Integer> rawValues = resources.stream()
42 + .map(x -> x.valueAs(Object.class))
43 + .flatMap(Tools::stream)
44 + .map(x -> codec.encode(x))
45 + .collect(Collectors.toCollection(LinkedHashSet::new));
46 +
47 + return new EncodedDiscreteResources(rawValues, codec);
48 + }
49 +
50 + Set<Integer> rawValues() {
51 + return rawValues;
52 + }
53 +
54 + DiscreteResourceCodec codec() {
55 + return codec;
56 + }
57 +
58 + Set<DiscreteResource> resources(DiscreteResourceId parent) {
59 + return rawValues.stream()
60 + .map(x -> codec.decode(x))
61 + .map(x -> Resources.discrete(parent, x).resource())
62 + .collect(Collectors.toCollection(LinkedHashSet::new));
63 + }
64 +
65 + @SuppressWarnings("unchecked")
66 + boolean contains(DiscreteResource resource) {
67 + return rawValues.contains(codec.encode(resource));
68 + }
69 +
70 + boolean isEmpty() {
71 + return rawValues.isEmpty();
72 + }
73 +}
...@@ -13,42 +13,33 @@ ...@@ -13,42 +13,33 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.net.resource; 16 +package org.onosproject.store.resource.impl;
17 17
18 import com.esotericsoftware.kryo.Kryo; 18 import com.esotericsoftware.kryo.Kryo;
19 import com.esotericsoftware.kryo.Serializer; 19 import com.esotericsoftware.kryo.Serializer;
20 import com.esotericsoftware.kryo.io.Input; 20 import com.esotericsoftware.kryo.io.Input;
21 import com.esotericsoftware.kryo.io.Output; 21 import com.esotericsoftware.kryo.io.Output;
22 -import com.google.common.annotations.Beta;
23 import com.google.common.collect.DiscreteDomain; 22 import com.google.common.collect.DiscreteDomain;
24 import com.google.common.collect.Range; 23 import com.google.common.collect.Range;
25 import com.google.common.collect.TreeRangeSet; 24 import com.google.common.collect.TreeRangeSet;
26 import org.onlab.util.ClosedOpenRange; 25 import org.onlab.util.ClosedOpenRange;
27 -import org.onlab.util.Tools; 26 +import org.onosproject.net.resource.DiscreteResourceCodec;
28 27
29 import java.util.ArrayList; 28 import java.util.ArrayList;
29 +import java.util.HashSet;
30 +import java.util.LinkedHashSet;
30 import java.util.List; 31 import java.util.List;
31 -import java.util.Set;
32 import java.util.stream.Collectors; 32 import java.util.stream.Collectors;
33 import java.util.stream.IntStream; 33 import java.util.stream.IntStream;
34 34
35 /** 35 /**
36 - * Kryo serializer for {@link DiscreteResourceSet}. 36 + * Kryo Serializer for {@link EncodedDiscreteResources}.
37 */ 37 */
38 -@Beta 38 +final class EncodedResourcesSerializer extends Serializer<EncodedDiscreteResources> {
39 -public final class DiscreteResourceSetSerializer extends Serializer<DiscreteResourceSet> {
40 -
41 - public DiscreteResourceSetSerializer() {
42 - super(false, true);
43 - }
44 -
45 @Override 39 @Override
46 - public void write(Kryo kryo, Output output, DiscreteResourceSet object) { 40 + public void write(Kryo kryo, Output output, EncodedDiscreteResources object) {
47 TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); 41 TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
48 - object.values().stream() 42 + object.rawValues().stream()
49 - .map(x -> x.valueAs(Object.class))
50 - .flatMap(Tools::stream)
51 - .map(x -> object.codec().encode(x))
52 .map(Range::singleton) 43 .map(Range::singleton)
53 .map(x -> x.canonical(DiscreteDomain.integers())) 44 .map(x -> x.canonical(DiscreteDomain.integers()))
54 .forEach(rangeSet::add); 45 .forEach(rangeSet::add);
...@@ -57,26 +48,18 @@ public final class DiscreteResourceSetSerializer extends Serializer<DiscreteReso ...@@ -57,26 +48,18 @@ public final class DiscreteResourceSetSerializer extends Serializer<DiscreteReso
57 .collect(Collectors.toList()); 48 .collect(Collectors.toList());
58 kryo.writeObject(output, ranges); 49 kryo.writeObject(output, ranges);
59 kryo.writeClassAndObject(output, object.codec()); 50 kryo.writeClassAndObject(output, object.codec());
60 - kryo.writeObject(output, object.parent());
61 } 51 }
62 52
63 @Override 53 @Override
64 - public DiscreteResourceSet read(Kryo kryo, Input input, Class<DiscreteResourceSet> type) { 54 + public EncodedDiscreteResources read(Kryo kryo, Input input, Class<EncodedDiscreteResources> cls) {
65 @SuppressWarnings("unchecked") 55 @SuppressWarnings("unchecked")
66 List<ClosedOpenRange> ranges = kryo.readObject(input, ArrayList.class); 56 List<ClosedOpenRange> ranges = kryo.readObject(input, ArrayList.class);
67 DiscreteResourceCodec codec = (DiscreteResourceCodec) kryo.readClassAndObject(input); 57 DiscreteResourceCodec codec = (DiscreteResourceCodec) kryo.readClassAndObject(input);
68 - DiscreteResourceId parent = kryo.readObject(input, DiscreteResourceId.class);
69 58
70 - if (ranges.isEmpty()) { 59 + HashSet<Integer> rawValues = ranges.stream()
71 - return DiscreteResourceSet.empty();
72 - }
73 -
74 - Set<DiscreteResource> resources = ranges.stream()
75 .flatMapToInt(x -> IntStream.range(x.lowerBound(), x.upperBound())) 60 .flatMapToInt(x -> IntStream.range(x.lowerBound(), x.upperBound()))
76 - .mapToObj(x -> codec.decode(x)) 61 + .boxed()
77 - .map(x -> Resources.discrete(parent, x).resource()) 62 + .collect(Collectors.toCollection(LinkedHashSet::new));
78 - .collect(Collectors.toSet()); 63 + return new EncodedDiscreteResources(rawValues, codec);
79 -
80 - return DiscreteResourceSet.of(resources, codec);
81 } 64 }
82 } 65 }
......
...@@ -194,10 +194,7 @@ import org.onosproject.net.resource.ContinuousResourceId; ...@@ -194,10 +194,7 @@ import org.onosproject.net.resource.ContinuousResourceId;
194 import org.onosproject.net.resource.DiscreteResource; 194 import org.onosproject.net.resource.DiscreteResource;
195 import org.onosproject.net.resource.DiscreteResourceCodec; 195 import org.onosproject.net.resource.DiscreteResourceCodec;
196 import org.onosproject.net.resource.DiscreteResourceId; 196 import org.onosproject.net.resource.DiscreteResourceId;
197 -import org.onosproject.net.resource.DiscreteResourceSet;
198 -import org.onosproject.net.resource.DiscreteResourceSetSerializer;
199 import org.onosproject.net.resource.MplsCodec; 197 import org.onosproject.net.resource.MplsCodec;
200 -import org.onosproject.net.resource.NoOpCodec;
201 import org.onosproject.net.resource.ResourceAllocation; 198 import org.onosproject.net.resource.ResourceAllocation;
202 import org.onosproject.net.resource.ResourceConsumerId; 199 import org.onosproject.net.resource.ResourceConsumerId;
203 import org.onosproject.net.packet.DefaultOutboundPacket; 200 import org.onosproject.net.packet.DefaultOutboundPacket;
...@@ -537,11 +534,9 @@ public final class KryoNamespaces { ...@@ -537,11 +534,9 @@ public final class KryoNamespaces {
537 org.onlab.packet.MPLS.class 534 org.onlab.packet.MPLS.class
538 ) 535 )
539 .register(ClosedOpenRange.class) 536 .register(ClosedOpenRange.class)
540 - .register(new DiscreteResourceSetSerializer(), DiscreteResourceSet.class)
541 .register(DiscreteResourceCodec.class) 537 .register(DiscreteResourceCodec.class)
542 .register(VlanCodec.class) 538 .register(VlanCodec.class)
543 .register(MplsCodec.class) 539 .register(MplsCodec.class)
544 - .register(NoOpCodec.class)
545 .build("API"); 540 .build("API");
546 541
547 542
......
...@@ -24,7 +24,6 @@ import org.junit.After; ...@@ -24,7 +24,6 @@ import org.junit.After;
24 import org.junit.Before; 24 import org.junit.Before;
25 import org.junit.BeforeClass; 25 import org.junit.BeforeClass;
26 import org.junit.Test; 26 import org.junit.Test;
27 -import org.onlab.packet.MplsLabel;
28 import org.onlab.packet.VlanId; 27 import org.onlab.packet.VlanId;
29 import org.onlab.util.Bandwidth; 28 import org.onlab.util.Bandwidth;
30 import org.onlab.util.Frequency; 29 import org.onlab.util.Frequency;
...@@ -63,9 +62,6 @@ import org.onosproject.net.flow.FlowId; ...@@ -63,9 +62,6 @@ import org.onosproject.net.flow.FlowId;
63 import org.onosproject.net.flow.FlowRule; 62 import org.onosproject.net.flow.FlowRule;
64 import org.onosproject.net.flow.FlowRuleBatchEntry; 63 import org.onosproject.net.flow.FlowRuleBatchEntry;
65 import org.onosproject.net.intent.IntentId; 64 import org.onosproject.net.intent.IntentId;
66 -import org.onosproject.net.resource.DiscreteResource;
67 -import org.onosproject.net.resource.DiscreteResourceSet;
68 -import org.onosproject.net.resource.MplsCodec;
69 import org.onosproject.net.resource.ResourceAllocation; 65 import org.onosproject.net.resource.ResourceAllocation;
70 import org.onosproject.net.resource.ResourceConsumerId; 66 import org.onosproject.net.resource.ResourceConsumerId;
71 import org.onosproject.net.resource.Resources; 67 import org.onosproject.net.resource.Resources;
...@@ -84,15 +80,11 @@ import org.onlab.packet.IpPrefix; ...@@ -84,15 +80,11 @@ import org.onlab.packet.IpPrefix;
84 import org.onlab.packet.Ip4Prefix; 80 import org.onlab.packet.Ip4Prefix;
85 import org.onlab.packet.Ip6Prefix; 81 import org.onlab.packet.Ip6Prefix;
86 import org.onlab.packet.MacAddress; 82 import org.onlab.packet.MacAddress;
87 -import org.onosproject.net.resource.VlanCodec;
88 83
89 import java.nio.ByteBuffer; 84 import java.nio.ByteBuffer;
90 import java.util.Arrays; 85 import java.util.Arrays;
91 import java.util.Collections; 86 import java.util.Collections;
92 import java.time.Duration; 87 import java.time.Duration;
93 -import java.util.Set;
94 -import java.util.stream.Collectors;
95 -import java.util.stream.IntStream;
96 88
97 import static java.util.Arrays.asList; 89 import static java.util.Arrays.asList;
98 import static org.junit.Assert.*; 90 import static org.junit.Assert.*;
...@@ -355,38 +347,6 @@ public class KryoSerializerTest { ...@@ -355,38 +347,6 @@ public class KryoSerializerTest {
355 } 347 }
356 348
357 @Test 349 @Test
358 - public void testVlanIdResourceSet() {
359 - DiscreteResource port = Resources.discrete(DID1, P1).resource();
360 -
361 - Set<DiscreteResource> vlans = IntStream.range(0, 4096)
362 - .mapToObj(x -> VlanId.vlanId((short) x))
363 - .map(x -> Resources.discrete(port.id(), x).resource())
364 - .collect(Collectors.toSet());
365 -
366 - DiscreteResourceSet sut = DiscreteResourceSet.of(vlans, new VlanCodec());
367 - testSerializedEquals(sut);
368 - }
369 -
370 - @Test
371 - public void testMplsLabelResourceSet() {
372 - DiscreteResource port = Resources.discrete(DID1, P1).resource();
373 -
374 - Set<DiscreteResource> labels = IntStream.range(0, 1024)
375 - .mapToObj(MplsLabel::mplsLabel)
376 - .map(x -> Resources.discrete(port.id(), x).resource())
377 - .collect(Collectors.toSet());
378 -
379 - DiscreteResourceSet sut = DiscreteResourceSet.of(labels, new MplsCodec());
380 - testSerializedEquals(sut);
381 - }
382 -
383 - @Test
384 - public void testEmptyResourceSet() {
385 - DiscreteResourceSet sut = DiscreteResourceSet.empty();
386 - testSerializedEquals(sut);
387 - }
388 -
389 - @Test
390 public void testResourceId() { 350 public void testResourceId() {
391 testSerializedEquals(Resources.discrete(DID1, P1).id()); 351 testSerializedEquals(Resources.discrete(DID1, P1).id());
392 } 352 }
......