Showing
22 changed files
with
267 additions
and
180 deletions
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | -import com.google.common.collect.ImmutableSet; | ||
4 | - | ||
5 | -import java.util.HashMap; | ||
6 | -import java.util.Map; | ||
7 | -import java.util.Set; | ||
8 | - | ||
9 | import static com.google.common.base.Preconditions.checkArgument; | 3 | import static com.google.common.base.Preconditions.checkArgument; |
10 | 4 | ||
11 | /** | 5 | /** |
... | @@ -13,13 +7,13 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -13,13 +7,13 @@ import static com.google.common.base.Preconditions.checkArgument; |
13 | */ | 7 | */ |
14 | public class AbstractAnnotated implements Annotated { | 8 | public class AbstractAnnotated implements Annotated { |
15 | 9 | ||
16 | - private static final Map<String, String> EMPTY = new HashMap<>(); | 10 | + private static final Annotations EMPTY = DefaultAnnotations.builder().build(); |
17 | 11 | ||
18 | - private final Map<String, String> annotations; | 12 | + private final Annotations annotations; |
19 | 13 | ||
20 | // For serialization | 14 | // For serialization |
21 | protected AbstractAnnotated() { | 15 | protected AbstractAnnotated() { |
22 | - this.annotations = EMPTY; | 16 | + this.annotations = null; |
23 | } | 17 | } |
24 | 18 | ||
25 | /** | 19 | /** |
... | @@ -27,19 +21,14 @@ public class AbstractAnnotated implements Annotated { | ... | @@ -27,19 +21,14 @@ public class AbstractAnnotated implements Annotated { |
27 | * | 21 | * |
28 | * @param annotations optional key/value annotations map | 22 | * @param annotations optional key/value annotations map |
29 | */ | 23 | */ |
30 | - protected AbstractAnnotated(Map<String, String>[] annotations) { | 24 | + protected AbstractAnnotated(Annotations... annotations) { |
31 | checkArgument(annotations.length <= 1, "Only one set of annotations is expected"); | 25 | checkArgument(annotations.length <= 1, "Only one set of annotations is expected"); |
32 | this.annotations = annotations.length == 1 ? annotations[0] : EMPTY; | 26 | this.annotations = annotations.length == 1 ? annotations[0] : EMPTY; |
33 | } | 27 | } |
34 | 28 | ||
35 | @Override | 29 | @Override |
36 | - public Set<String> annotationKeys() { | 30 | + public Annotations annotations() { |
37 | - return ImmutableSet.copyOf(annotations.keySet()); | 31 | + return annotations; |
38 | - } | ||
39 | - | ||
40 | - @Override | ||
41 | - public String annotation(String key) { | ||
42 | - return annotations.get(key); | ||
43 | } | 32 | } |
44 | 33 | ||
45 | } | 34 | } | ... | ... |
1 | +package org.onlab.onos.net; | ||
2 | + | ||
3 | +import static com.google.common.base.Preconditions.checkArgument; | ||
4 | + | ||
5 | +/** | ||
6 | + * Base implementation of an annotated model description. | ||
7 | + */ | ||
8 | +public class AbstractDescription implements Annotated { | ||
9 | + | ||
10 | + private static final SparseAnnotations EMPTY = DefaultAnnotations.builder().build(); | ||
11 | + | ||
12 | + private final SparseAnnotations annotations; | ||
13 | + | ||
14 | + // For serialization | ||
15 | + protected AbstractDescription() { | ||
16 | + this.annotations = null; | ||
17 | + } | ||
18 | + | ||
19 | + /** | ||
20 | + * Creates a new entity, annotated with the specified annotations. | ||
21 | + * | ||
22 | + * @param annotations optional key/value annotations map | ||
23 | + */ | ||
24 | + protected AbstractDescription(SparseAnnotations... annotations) { | ||
25 | + checkArgument(annotations.length <= 1, "Only one set of annotations is expected"); | ||
26 | + this.annotations = annotations.length == 1 ? annotations[0] : EMPTY; | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + public SparseAnnotations annotations() { | ||
31 | + return annotations; | ||
32 | + } | ||
33 | + | ||
34 | +} |
... | @@ -17,11 +17,13 @@ public class AbstractElement extends AbstractModel implements Element { | ... | @@ -17,11 +17,13 @@ public class AbstractElement extends AbstractModel implements Element { |
17 | /** | 17 | /** |
18 | * Creates a network element attributed to the specified provider. | 18 | * Creates a network element attributed to the specified provider. |
19 | * | 19 | * |
20 | - * @param providerId identity of the provider | 20 | + * @param providerId identity of the provider |
21 | - * @param id element identifier | 21 | + * @param id element identifier |
22 | + * @param annotations optional key/value annotations | ||
22 | */ | 23 | */ |
23 | - protected AbstractElement(ProviderId providerId, ElementId id) { | 24 | + protected AbstractElement(ProviderId providerId, ElementId id, |
24 | - super(providerId); | 25 | + Annotations... annotations) { |
26 | + super(providerId, annotations); | ||
25 | this.id = id; | 27 | this.id = id; |
26 | } | 28 | } |
27 | 29 | ... | ... |
... | @@ -2,8 +2,6 @@ package org.onlab.onos.net; | ... | @@ -2,8 +2,6 @@ package org.onlab.onos.net; |
2 | 2 | ||
3 | import org.onlab.onos.net.provider.ProviderId; | 3 | import org.onlab.onos.net.provider.ProviderId; |
4 | 4 | ||
5 | -import java.util.Map; | ||
6 | - | ||
7 | /** | 5 | /** |
8 | * Base implementation of a network model entity. | 6 | * Base implementation of a network model entity. |
9 | */ | 7 | */ |
... | @@ -23,9 +21,7 @@ public class AbstractModel extends AbstractAnnotated implements Provided { | ... | @@ -23,9 +21,7 @@ public class AbstractModel extends AbstractAnnotated implements Provided { |
23 | * @param providerId identity of the provider | 21 | * @param providerId identity of the provider |
24 | * @param annotations optional key/value annotations | 22 | * @param annotations optional key/value annotations |
25 | */ | 23 | */ |
26 | - @SafeVarargs | 24 | + protected AbstractModel(ProviderId providerId, Annotations... annotations) { |
27 | - protected AbstractModel(ProviderId providerId, | ||
28 | - Map<String, String>... annotations) { | ||
29 | super(annotations); | 25 | super(annotations); |
30 | this.providerId = providerId; | 26 | this.providerId = providerId; |
31 | } | 27 | } | ... | ... |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | -import java.util.Set; | ||
4 | - | ||
5 | /** | 3 | /** |
6 | * Represents an entity that carries arbitrary annotations. | 4 | * Represents an entity that carries arbitrary annotations. |
7 | */ | 5 | */ |
8 | public interface Annotated { | 6 | public interface Annotated { |
9 | 7 | ||
10 | /** | 8 | /** |
11 | - * Returns the set of annotation keys currently available. | 9 | + * Returns the key/value annotations. |
12 | - * | ||
13 | - * @return set of annotation keys | ||
14 | - */ | ||
15 | - Set<String> annotationKeys(); | ||
16 | - | ||
17 | - /** | ||
18 | - * Returns the annotation value for the specified key. | ||
19 | * | 10 | * |
20 | - * @param key annotation key | 11 | + * @return key/value annotations |
21 | - * @return annotation value; null if there is no annotation | ||
22 | */ | 12 | */ |
23 | - String annotation(String key); | 13 | + Annotations annotations(); |
24 | 14 | ||
25 | } | 15 | } | ... | ... |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | -import com.google.common.collect.ImmutableMap; | ||
4 | - | ||
5 | -import java.util.Map; | ||
6 | -import java.util.Objects; | ||
7 | import java.util.Set; | 3 | import java.util.Set; |
8 | 4 | ||
9 | /** | 5 | /** |
10 | - * Represents a set of simple annotations that can be used to add arbitrary | 6 | + * Represents an set of simply key/value string annotations. |
11 | - * attributes to various parts of the data model. | ||
12 | */ | 7 | */ |
13 | -public final class Annotations { | 8 | +public interface Annotations { |
14 | - | ||
15 | - private final Map<String, String> map; | ||
16 | - | ||
17 | - /** | ||
18 | - * Creates a new set of annotations using the specified immutable map. | ||
19 | - * | ||
20 | - * @param map immutable map of key/value pairs | ||
21 | - */ | ||
22 | - private Annotations(ImmutableMap<String, String> map) { | ||
23 | - this.map = map; | ||
24 | - } | ||
25 | 9 | ||
26 | /** | 10 | /** |
27 | - * Creates a new annotations builder. | 11 | + * Returns the set of keys for available annotations. |
28 | - * | ||
29 | - * @return new annotations builder | ||
30 | - */ | ||
31 | - public static Builder builder() { | ||
32 | - return new Builder(); | ||
33 | - } | ||
34 | - | ||
35 | - /** | ||
36 | - * Returns the set of keys for available annotations. Note that this set | ||
37 | - * includes keys for any attributes tagged for removal. | ||
38 | * | 12 | * |
39 | * @return annotation keys | 13 | * @return annotation keys |
40 | */ | 14 | */ |
41 | - public Set<String> keys() { | 15 | + public Set<String> keys(); |
42 | - return map.keySet(); | ||
43 | - } | ||
44 | 16 | ||
45 | /** | 17 | /** |
46 | * Returns the value of the specified annotation. | 18 | * Returns the value of the specified annotation. |
... | @@ -48,66 +20,6 @@ public final class Annotations { | ... | @@ -48,66 +20,6 @@ public final class Annotations { |
48 | * @param key annotation key | 20 | * @param key annotation key |
49 | * @return annotation value | 21 | * @return annotation value |
50 | */ | 22 | */ |
51 | - public String value(String key) { | 23 | + public String value(String key); |
52 | - String value = map.get(key); | ||
53 | - return Objects.equals(Builder.REMOVED, value) ? null : value; | ||
54 | - } | ||
55 | - | ||
56 | - /** | ||
57 | - * Indicates whether the specified key has been tagged as removed. This is | ||
58 | - * used to for merging sparse annotation sets. | ||
59 | - * | ||
60 | - * @param key annotation key | ||
61 | - * @return true if the previous annotation has been tagged for removal | ||
62 | - */ | ||
63 | - public boolean isRemoved(String key) { | ||
64 | - return Objects.equals(Builder.REMOVED, map.get(key)); | ||
65 | - } | ||
66 | - | ||
67 | - /** | ||
68 | - * Facility for gradually building model annotations. | ||
69 | - */ | ||
70 | - public static final class Builder { | ||
71 | - | ||
72 | - private static final String REMOVED = "~rEmOvEd~"; | ||
73 | - private final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); | ||
74 | - | ||
75 | - // Private construction is forbidden. | ||
76 | - private Builder() { | ||
77 | - } | ||
78 | - | ||
79 | - /** | ||
80 | - * Adds the specified annotation. Any previous value associated with | ||
81 | - * the given annotation key will be overwritten. | ||
82 | - * | ||
83 | - * @param key annotation key | ||
84 | - * @param value annotation value | ||
85 | - * @return self | ||
86 | - */ | ||
87 | - public Builder set(String key, String value) { | ||
88 | - builder.put(key, value); | ||
89 | - return this; | ||
90 | - } | ||
91 | - | ||
92 | - /** | ||
93 | - * Adds the specified annotation. Any previous value associated with | ||
94 | - * the given annotation key will be tagged for removal. | ||
95 | - * | ||
96 | - * @param key annotation key | ||
97 | - * @return self | ||
98 | - */ | ||
99 | - public Builder remove(String key) { | ||
100 | - builder.put(key, REMOVED); | ||
101 | - return this; | ||
102 | - } | ||
103 | 24 | ||
104 | - /** | ||
105 | - * Returns immutable annotations built from the accrued key/values pairs. | ||
106 | - * | ||
107 | - * @return annotations | ||
108 | - */ | ||
109 | - public Annotations build() { | ||
110 | - return new Annotations(builder.build()); | ||
111 | - } | ||
112 | - } | ||
113 | } | 25 | } | ... | ... |
1 | +package org.onlab.onos.net; | ||
2 | + | ||
3 | +import java.util.HashMap; | ||
4 | +import java.util.Map; | ||
5 | +import java.util.Objects; | ||
6 | +import java.util.Set; | ||
7 | + | ||
8 | +/** | ||
9 | + * Represents a set of simple annotations that can be used to add arbitrary | ||
10 | + * attributes to various parts of the data model. | ||
11 | + */ | ||
12 | +public final class DefaultAnnotations implements SparseAnnotations { | ||
13 | + | ||
14 | + private final Map<String, String> map; | ||
15 | + | ||
16 | + // For serialization | ||
17 | + private DefaultAnnotations() { | ||
18 | + this.map = null; | ||
19 | + } | ||
20 | + | ||
21 | + /** | ||
22 | + * Creates a new set of annotations using the specified immutable map. | ||
23 | + * | ||
24 | + * @param map immutable map of key/value pairs | ||
25 | + */ | ||
26 | + private DefaultAnnotations(Map<String, String> map) { | ||
27 | + this.map = map; | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * Creates a new annotations builder. | ||
32 | + * | ||
33 | + * @return new annotations builder | ||
34 | + */ | ||
35 | + public static Builder builder() { | ||
36 | + return new Builder(); | ||
37 | + } | ||
38 | + | ||
39 | + | ||
40 | + @Override | ||
41 | + public Set<String> keys() { | ||
42 | + return map.keySet(); | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public String value(String key) { | ||
47 | + String value = map.get(key); | ||
48 | + return Objects.equals(Builder.REMOVED, value) ? null : value; | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public boolean isRemoved(String key) { | ||
53 | + return Objects.equals(Builder.REMOVED, map.get(key)); | ||
54 | + } | ||
55 | + | ||
56 | + /** | ||
57 | + * Facility for gradually building model annotations. | ||
58 | + */ | ||
59 | + public static final class Builder { | ||
60 | + | ||
61 | + private static final String REMOVED = "~rEmOvEd~"; | ||
62 | + | ||
63 | + // FIXME: Figure out whether and how to make this immutable and serializable | ||
64 | +// private final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); | ||
65 | + private final Map<String, String> builder = new HashMap<>(); | ||
66 | + | ||
67 | + // Private construction is forbidden. | ||
68 | + private Builder() { | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * Adds the specified annotation. Any previous value associated with | ||
73 | + * the given annotation key will be overwritten. | ||
74 | + * | ||
75 | + * @param key annotation key | ||
76 | + * @param value annotation value | ||
77 | + * @return self | ||
78 | + */ | ||
79 | + public Builder set(String key, String value) { | ||
80 | + builder.put(key, value); | ||
81 | + return this; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Adds the specified annotation. Any previous value associated with | ||
86 | + * the given annotation key will be tagged for removal. | ||
87 | + * | ||
88 | + * @param key annotation key | ||
89 | + * @return self | ||
90 | + */ | ||
91 | + public Builder remove(String key) { | ||
92 | + builder.put(key, REMOVED); | ||
93 | + return this; | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Returns immutable annotations built from the accrued key/values pairs. | ||
98 | + * | ||
99 | + * @return annotations | ||
100 | + */ | ||
101 | + public DefaultAnnotations build() { | ||
102 | +// return new DefaultAnnotations(builder.build()); | ||
103 | + return new DefaultAnnotations(builder); | ||
104 | + } | ||
105 | + } | ||
106 | +} |
... | @@ -36,11 +36,12 @@ public class DefaultDevice extends AbstractElement implements Device { | ... | @@ -36,11 +36,12 @@ public class DefaultDevice extends AbstractElement implements Device { |
36 | * @param hwVersion device HW version | 36 | * @param hwVersion device HW version |
37 | * @param swVersion device SW version | 37 | * @param swVersion device SW version |
38 | * @param serialNumber device serial number | 38 | * @param serialNumber device serial number |
39 | + * @param annotations optional key/value annotations | ||
39 | */ | 40 | */ |
40 | public DefaultDevice(ProviderId providerId, DeviceId id, Type type, | 41 | public DefaultDevice(ProviderId providerId, DeviceId id, Type type, |
41 | String manufacturer, String hwVersion, String swVersion, | 42 | String manufacturer, String hwVersion, String swVersion, |
42 | - String serialNumber) { | 43 | + String serialNumber, Annotations... annotations) { |
43 | - super(providerId, id); | 44 | + super(providerId, id, annotations); |
44 | this.type = type; | 45 | this.type = type; |
45 | this.manufacturer = manufacturer; | 46 | this.manufacturer = manufacturer; |
46 | this.hwVersion = hwVersion; | 47 | this.hwVersion = hwVersion; | ... | ... |
... | @@ -20,11 +20,13 @@ public class DefaultEdgeLink extends DefaultLink implements EdgeLink { | ... | @@ -20,11 +20,13 @@ public class DefaultEdgeLink extends DefaultLink implements EdgeLink { |
20 | * @param hostLocation location where host attaches to the network | 20 | * @param hostLocation location where host attaches to the network |
21 | * @param isIngress true to indicated host-to-network direction; false | 21 | * @param isIngress true to indicated host-to-network direction; false |
22 | * for network-to-host direction | 22 | * for network-to-host direction |
23 | + * @param annotations optional key/value annotations | ||
23 | */ | 24 | */ |
24 | public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint, | 25 | public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint, |
25 | - HostLocation hostLocation, boolean isIngress) { | 26 | + HostLocation hostLocation, boolean isIngress, |
27 | + Annotations... annotations) { | ||
26 | super(providerId, isIngress ? hostPoint : hostLocation, | 28 | super(providerId, isIngress ? hostPoint : hostLocation, |
27 | - isIngress ? hostLocation : hostPoint, Type.EDGE); | 29 | + isIngress ? hostLocation : hostPoint, Type.EDGE, annotations); |
28 | checkArgument(hostPoint.elementId() instanceof HostId, | 30 | checkArgument(hostPoint.elementId() instanceof HostId, |
29 | "Host point does not refer to a host ID"); | 31 | "Host point does not refer to a host ID"); |
30 | this.hostId = (HostId) hostPoint.elementId(); | 32 | this.hostId = (HostId) hostPoint.elementId(); | ... | ... |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | -import static com.google.common.base.MoreObjects.toStringHelper; | 3 | +import org.onlab.onos.net.provider.ProviderId; |
4 | +import org.onlab.packet.IpPrefix; | ||
5 | +import org.onlab.packet.MacAddress; | ||
6 | +import org.onlab.packet.VlanId; | ||
4 | 7 | ||
5 | import java.util.Collections; | 8 | import java.util.Collections; |
6 | import java.util.HashSet; | 9 | import java.util.HashSet; |
7 | import java.util.Objects; | 10 | import java.util.Objects; |
8 | import java.util.Set; | 11 | import java.util.Set; |
9 | 12 | ||
10 | -import org.onlab.onos.net.provider.ProviderId; | 13 | +import static com.google.common.base.MoreObjects.toStringHelper; |
11 | -import org.onlab.packet.IpPrefix; | ||
12 | -import org.onlab.packet.MacAddress; | ||
13 | -import org.onlab.packet.VlanId; | ||
14 | 14 | ||
15 | /** | 15 | /** |
16 | * A basic implementation of a Host. | 16 | * A basic implementation of a Host. |
... | @@ -22,12 +22,24 @@ public class DefaultHost extends AbstractElement implements Host { | ... | @@ -22,12 +22,24 @@ public class DefaultHost extends AbstractElement implements Host { |
22 | private final HostLocation location; | 22 | private final HostLocation location; |
23 | private final Set<IpPrefix> ips; | 23 | private final Set<IpPrefix> ips; |
24 | 24 | ||
25 | + /** | ||
26 | + * Creates an end-station host using the supplied information. | ||
27 | + * | ||
28 | + * @param providerId provider identity | ||
29 | + * @param id host identifier | ||
30 | + * @param mac host MAC address | ||
31 | + * @param vlan host VLAN identifier | ||
32 | + * @param location host location | ||
33 | + * @param ips host IP addresses | ||
34 | + * @param annotations optional key/value annotations | ||
35 | + */ | ||
25 | public DefaultHost(ProviderId providerId, HostId id, MacAddress mac, | 36 | public DefaultHost(ProviderId providerId, HostId id, MacAddress mac, |
26 | - VlanId vlan, HostLocation loc, Set<IpPrefix> ips) { | 37 | + VlanId vlan, HostLocation location, Set<IpPrefix> ips, |
27 | - super(providerId, id); | 38 | + Annotations... annotations) { |
39 | + super(providerId, id, annotations); | ||
28 | this.mac = mac; | 40 | this.mac = mac; |
29 | this.vlan = vlan; | 41 | this.vlan = vlan; |
30 | - this.location = loc; | 42 | + this.location = location; |
31 | this.ips = new HashSet<IpPrefix>(ips); | 43 | this.ips = new HashSet<IpPrefix>(ips); |
32 | } | 44 | } |
33 | 45 | ... | ... |
... | @@ -22,10 +22,11 @@ public class DefaultLink extends AbstractModel implements Link { | ... | @@ -22,10 +22,11 @@ public class DefaultLink extends AbstractModel implements Link { |
22 | * @param src link source | 22 | * @param src link source |
23 | * @param dst link destination | 23 | * @param dst link destination |
24 | * @param type link type | 24 | * @param type link type |
25 | + * @param annotations optional key/value annotations | ||
25 | */ | 26 | */ |
26 | public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, | 27 | public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, |
27 | - Type type) { | 28 | + Type type, Annotations... annotations) { |
28 | - super(providerId); | 29 | + super(providerId, annotations); |
29 | this.src = src; | 30 | this.src = src; |
30 | this.dst = dst; | 31 | this.dst = dst; |
31 | this.type = type; | 32 | this.type = type; | ... | ... |
... | @@ -24,9 +24,11 @@ public class DefaultPath extends DefaultLink implements Path { | ... | @@ -24,9 +24,11 @@ public class DefaultPath extends DefaultLink implements Path { |
24 | * @param providerId provider identity | 24 | * @param providerId provider identity |
25 | * @param links contiguous links that comprise the path | 25 | * @param links contiguous links that comprise the path |
26 | * @param cost unit-less path cost | 26 | * @param cost unit-less path cost |
27 | + * @param annotations optional key/value annotations | ||
27 | */ | 28 | */ |
28 | - public DefaultPath(ProviderId providerId, List<Link> links, double cost) { | 29 | + public DefaultPath(ProviderId providerId, List<Link> links, double cost, |
29 | - super(providerId, source(links), destination(links), Type.INDIRECT); | 30 | + Annotations... annotations) { |
31 | + super(providerId, source(links), destination(links), Type.INDIRECT, annotations); | ||
30 | this.links = ImmutableList.copyOf(links); | 32 | this.links = ImmutableList.copyOf(links); |
31 | this.cost = cost; | 33 | this.cost = cost; |
32 | } | 34 | } | ... | ... |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | -import static com.google.common.base.MoreObjects.toStringHelper; | ||
4 | - | ||
5 | -import java.util.Map; | ||
6 | import java.util.Objects; | 3 | import java.util.Objects; |
7 | 4 | ||
5 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
6 | + | ||
8 | /** | 7 | /** |
9 | * Default port implementation. | 8 | * Default port implementation. |
10 | */ | 9 | */ |
... | @@ -22,10 +21,8 @@ public class DefaultPort extends AbstractAnnotated implements Port { | ... | @@ -22,10 +21,8 @@ public class DefaultPort extends AbstractAnnotated implements Port { |
22 | * @param isEnabled indicator whether the port is up and active | 21 | * @param isEnabled indicator whether the port is up and active |
23 | * @param annotations optional key/value annotations | 22 | * @param annotations optional key/value annotations |
24 | */ | 23 | */ |
25 | - @SafeVarargs | ||
26 | public DefaultPort(Element element, PortNumber number, | 24 | public DefaultPort(Element element, PortNumber number, |
27 | - boolean isEnabled, | 25 | + boolean isEnabled, Annotations... annotations) { |
28 | - Map<String, String>... annotations) { | ||
29 | super(annotations); | 26 | super(annotations); |
30 | this.element = element; | 27 | this.element = element; |
31 | this.number = number; | 28 | this.number = number; | ... | ... |
... | @@ -4,4 +4,8 @@ package org.onlab.onos.net; | ... | @@ -4,4 +4,8 @@ package org.onlab.onos.net; |
4 | * Base abstraction of a piece of information about network elements. | 4 | * Base abstraction of a piece of information about network elements. |
5 | */ | 5 | */ |
6 | public interface Description extends Annotated { | 6 | public interface Description extends Annotated { |
7 | + | ||
8 | + @Override | ||
9 | + SparseAnnotations annotations(); | ||
10 | + | ||
7 | } | 11 | } | ... | ... |
... | @@ -9,16 +9,23 @@ public class HostLocation extends ConnectPoint { | ... | @@ -9,16 +9,23 @@ public class HostLocation extends ConnectPoint { |
9 | // Note that time is explicitly excluded from the notion of equality. | 9 | // Note that time is explicitly excluded from the notion of equality. |
10 | private final long time; | 10 | private final long time; |
11 | 11 | ||
12 | + /** | ||
13 | + * Creates a new host location using the supplied device & port. | ||
14 | + * | ||
15 | + * @param deviceId device identity | ||
16 | + * @param portNumber device port number | ||
17 | + * @param time time when detected, in millis since start of epoch | ||
18 | + */ | ||
12 | public HostLocation(DeviceId deviceId, PortNumber portNumber, long time) { | 19 | public HostLocation(DeviceId deviceId, PortNumber portNumber, long time) { |
13 | super(deviceId, portNumber); | 20 | super(deviceId, portNumber); |
14 | this.time = time; | 21 | this.time = time; |
15 | } | 22 | } |
16 | 23 | ||
17 | /** | 24 | /** |
18 | - * Returns the timestamp when the location was established, given in | 25 | + * Returns the time when the location was established, given in |
19 | * milliseconds since start of epoch. | 26 | * milliseconds since start of epoch. |
20 | * | 27 | * |
21 | - * @return timestamp in milliseconds since start of epoch | 28 | + * @return time in milliseconds since start of epoch |
22 | */ | 29 | */ |
23 | public long time() { | 30 | public long time() { |
24 | return time; | 31 | return time; | ... | ... |
1 | +package org.onlab.onos.net; | ||
2 | + | ||
3 | +import java.util.Set; | ||
4 | + | ||
5 | +/** | ||
6 | + * Represents an set of simply key/value string annotations. | ||
7 | + */ | ||
8 | +public interface SparseAnnotations extends Annotations { | ||
9 | + | ||
10 | + /** | ||
11 | + * {@inheritDoc} | ||
12 | + * <p/> | ||
13 | + * Note that this set includes keys for any attributes tagged for removal. | ||
14 | + */ | ||
15 | + @Override | ||
16 | + public Set<String> keys(); | ||
17 | + | ||
18 | + /** | ||
19 | + * Indicates whether the specified key has been tagged as removed. This is | ||
20 | + * used to for merging sparse annotation sets. | ||
21 | + * | ||
22 | + * @param key annotation key | ||
23 | + * @return true if the previous annotation has been tagged for removal | ||
24 | + */ | ||
25 | + public boolean isRemoved(String key); | ||
26 | + | ||
27 | +} |
1 | package org.onlab.onos.net.device; | 1 | package org.onlab.onos.net.device; |
2 | 2 | ||
3 | -import org.onlab.onos.net.AbstractAnnotated; | 3 | +import org.onlab.onos.net.AbstractDescription; |
4 | +import org.onlab.onos.net.SparseAnnotations; | ||
4 | 5 | ||
5 | import java.net.URI; | 6 | import java.net.URI; |
6 | -import java.util.Map; | ||
7 | 7 | ||
8 | import static com.google.common.base.MoreObjects.toStringHelper; | 8 | import static com.google.common.base.MoreObjects.toStringHelper; |
9 | import static com.google.common.base.Preconditions.checkNotNull; | 9 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -12,7 +12,7 @@ import static org.onlab.onos.net.Device.Type; | ... | @@ -12,7 +12,7 @@ import static org.onlab.onos.net.Device.Type; |
12 | /** | 12 | /** |
13 | * Default implementation of immutable device description entity. | 13 | * Default implementation of immutable device description entity. |
14 | */ | 14 | */ |
15 | -public class DefaultDeviceDescription extends AbstractAnnotated | 15 | +public class DefaultDeviceDescription extends AbstractDescription |
16 | implements DeviceDescription { | 16 | implements DeviceDescription { |
17 | private final URI uri; | 17 | private final URI uri; |
18 | private final Type type; | 18 | private final Type type; |
... | @@ -32,11 +32,10 @@ public class DefaultDeviceDescription extends AbstractAnnotated | ... | @@ -32,11 +32,10 @@ public class DefaultDeviceDescription extends AbstractAnnotated |
32 | * @param serialNumber device serial number | 32 | * @param serialNumber device serial number |
33 | * @param annotations optional key/value annotations map | 33 | * @param annotations optional key/value annotations map |
34 | */ | 34 | */ |
35 | - @SafeVarargs | ||
36 | public DefaultDeviceDescription(URI uri, Type type, String manufacturer, | 35 | public DefaultDeviceDescription(URI uri, Type type, String manufacturer, |
37 | String hwVersion, String swVersion, | 36 | String hwVersion, String swVersion, |
38 | String serialNumber, | 37 | String serialNumber, |
39 | - Map<String, String>... annotations) { | 38 | + SparseAnnotations... annotations) { |
40 | super(annotations); | 39 | super(annotations); |
41 | this.uri = checkNotNull(uri, "Device URI cannot be null"); | 40 | this.uri = checkNotNull(uri, "Device URI cannot be null"); |
42 | this.type = checkNotNull(type, "Device type cannot be null"); | 41 | this.type = checkNotNull(type, "Device type cannot be null"); | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | import com.google.common.collect.ImmutableSet; | 3 | import com.google.common.collect.ImmutableSet; |
4 | -import org.onlab.onos.net.AbstractAnnotated; | 4 | +import org.onlab.onos.net.AbstractDescription; |
5 | import org.onlab.onos.net.HostLocation; | 5 | import org.onlab.onos.net.HostLocation; |
6 | +import org.onlab.onos.net.SparseAnnotations; | ||
6 | import org.onlab.packet.IpPrefix; | 7 | import org.onlab.packet.IpPrefix; |
7 | import org.onlab.packet.MacAddress; | 8 | import org.onlab.packet.MacAddress; |
8 | import org.onlab.packet.VlanId; | 9 | import org.onlab.packet.VlanId; |
9 | 10 | ||
10 | import java.util.HashSet; | 11 | import java.util.HashSet; |
11 | -import java.util.Map; | ||
12 | import java.util.Set; | 12 | import java.util.Set; |
13 | 13 | ||
14 | import static com.google.common.base.MoreObjects.toStringHelper; | 14 | import static com.google.common.base.MoreObjects.toStringHelper; |
... | @@ -16,7 +16,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -16,7 +16,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
16 | /** | 16 | /** |
17 | * Default implementation of an immutable host description. | 17 | * Default implementation of an immutable host description. |
18 | */ | 18 | */ |
19 | -public class DefaultHostDescription extends AbstractAnnotated | 19 | +public class DefaultHostDescription extends AbstractDescription |
20 | implements HostDescription { | 20 | implements HostDescription { |
21 | 21 | ||
22 | private final MacAddress mac; | 22 | private final MacAddress mac; |
... | @@ -32,10 +32,9 @@ public class DefaultHostDescription extends AbstractAnnotated | ... | @@ -32,10 +32,9 @@ public class DefaultHostDescription extends AbstractAnnotated |
32 | * @param location host location | 32 | * @param location host location |
33 | * @param annotations optional key/value annotations map | 33 | * @param annotations optional key/value annotations map |
34 | */ | 34 | */ |
35 | - @SafeVarargs | ||
36 | public DefaultHostDescription(MacAddress mac, VlanId vlan, | 35 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
37 | HostLocation location, | 36 | HostLocation location, |
38 | - Map<String, String>... annotations) { | 37 | + SparseAnnotations... annotations) { |
39 | this(mac, vlan, location, new HashSet<IpPrefix>(), annotations); | 38 | this(mac, vlan, location, new HashSet<IpPrefix>(), annotations); |
40 | } | 39 | } |
41 | 40 | ||
... | @@ -48,10 +47,9 @@ public class DefaultHostDescription extends AbstractAnnotated | ... | @@ -48,10 +47,9 @@ public class DefaultHostDescription extends AbstractAnnotated |
48 | * @param ips of host IP addresses | 47 | * @param ips of host IP addresses |
49 | * @param annotations optional key/value annotations map | 48 | * @param annotations optional key/value annotations map |
50 | */ | 49 | */ |
51 | - @SafeVarargs | ||
52 | public DefaultHostDescription(MacAddress mac, VlanId vlan, | 50 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
53 | HostLocation location, Set<IpPrefix> ips, | 51 | HostLocation location, Set<IpPrefix> ips, |
54 | - Map<String, String>... annotations) { | 52 | + SparseAnnotations... annotations) { |
55 | super(annotations); | 53 | super(annotations); |
56 | this.mac = mac; | 54 | this.mac = mac; |
57 | this.vlan = vlan; | 55 | this.vlan = vlan; | ... | ... |
1 | package org.onlab.onos.net.link; | 1 | package org.onlab.onos.net.link; |
2 | 2 | ||
3 | +import org.onlab.onos.net.AbstractDescription; | ||
3 | import org.onlab.onos.net.ConnectPoint; | 4 | import org.onlab.onos.net.ConnectPoint; |
4 | import org.onlab.onos.net.Link; | 5 | import org.onlab.onos.net.Link; |
6 | +import org.onlab.onos.net.SparseAnnotations; | ||
5 | 7 | ||
6 | /** | 8 | /** |
7 | * Default implementation of immutable link description entity. | 9 | * Default implementation of immutable link description entity. |
8 | */ | 10 | */ |
9 | -public class DefaultLinkDescription implements LinkDescription { | 11 | +public class DefaultLinkDescription extends AbstractDescription |
12 | + implements LinkDescription { | ||
10 | 13 | ||
11 | private final ConnectPoint src; | 14 | private final ConnectPoint src; |
12 | private final ConnectPoint dst; | 15 | private final ConnectPoint dst; |
... | @@ -18,8 +21,11 @@ public class DefaultLinkDescription implements LinkDescription { | ... | @@ -18,8 +21,11 @@ public class DefaultLinkDescription implements LinkDescription { |
18 | * @param src link source | 21 | * @param src link source |
19 | * @param dst link destination | 22 | * @param dst link destination |
20 | * @param type link type | 23 | * @param type link type |
24 | + * @param annotations optional key/value annotations | ||
21 | */ | 25 | */ |
22 | - public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst, Link.Type type) { | 26 | + public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst, |
27 | + Link.Type type, SparseAnnotations... annotations) { | ||
28 | + super(annotations); | ||
23 | this.src = src; | 29 | this.src = src; |
24 | this.dst = dst; | 30 | this.dst = dst; |
25 | this.type = type; | 31 | this.type = type; | ... | ... |
... | @@ -6,6 +6,7 @@ import org.onlab.packet.IpPrefix; | ... | @@ -6,6 +6,7 @@ import org.onlab.packet.IpPrefix; |
6 | /** | 6 | /** |
7 | * Service for processing arp requests on behalf of applications. | 7 | * Service for processing arp requests on behalf of applications. |
8 | */ | 8 | */ |
9 | +// TODO: move to the peer host package | ||
9 | public interface ProxyArpService { | 10 | public interface ProxyArpService { |
10 | 11 | ||
11 | /** | 12 | /** | ... | ... |
... | @@ -2,18 +2,19 @@ package org.onlab.onos.net.topology; | ... | @@ -2,18 +2,19 @@ package org.onlab.onos.net.topology; |
2 | 2 | ||
3 | import com.google.common.collect.ImmutableSet; | 3 | import com.google.common.collect.ImmutableSet; |
4 | import com.google.common.collect.Maps; | 4 | import com.google.common.collect.Maps; |
5 | -import org.onlab.onos.net.AbstractAnnotated; | 5 | +import org.onlab.onos.net.AbstractDescription; |
6 | import org.onlab.onos.net.ConnectPoint; | 6 | import org.onlab.onos.net.ConnectPoint; |
7 | import org.onlab.onos.net.Device; | 7 | import org.onlab.onos.net.Device; |
8 | import org.onlab.onos.net.DeviceId; | 8 | import org.onlab.onos.net.DeviceId; |
9 | import org.onlab.onos.net.Link; | 9 | import org.onlab.onos.net.Link; |
10 | +import org.onlab.onos.net.SparseAnnotations; | ||
10 | 11 | ||
11 | import java.util.Map; | 12 | import java.util.Map; |
12 | 13 | ||
13 | /** | 14 | /** |
14 | * Default implementation of an immutable topology graph data carrier. | 15 | * Default implementation of an immutable topology graph data carrier. |
15 | */ | 16 | */ |
16 | -public class DefaultGraphDescription extends AbstractAnnotated | 17 | +public class DefaultGraphDescription extends AbstractDescription |
17 | implements GraphDescription { | 18 | implements GraphDescription { |
18 | 19 | ||
19 | private final long nanos; | 20 | private final long nanos; |
... | @@ -32,10 +33,9 @@ public class DefaultGraphDescription extends AbstractAnnotated | ... | @@ -32,10 +33,9 @@ public class DefaultGraphDescription extends AbstractAnnotated |
32 | * @param links collection of infrastructure links | 33 | * @param links collection of infrastructure links |
33 | * @param annotations optional key/value annotations map | 34 | * @param annotations optional key/value annotations map |
34 | */ | 35 | */ |
35 | - @SafeVarargs | ||
36 | public DefaultGraphDescription(long nanos, Iterable<Device> devices, | 36 | public DefaultGraphDescription(long nanos, Iterable<Device> devices, |
37 | Iterable<Link> links, | 37 | Iterable<Link> links, |
38 | - Map<String, String>... annotations) { | 38 | + SparseAnnotations... annotations) { |
39 | super(annotations); | 39 | super(annotations); |
40 | this.nanos = nanos; | 40 | this.nanos = nanos; |
41 | this.vertexes = buildVertexes(devices); | 41 | this.vertexes = buildVertexes(devices); | ... | ... |
1 | package org.onlab.onos.store.serializers; | 1 | package org.onlab.onos.store.serializers; |
2 | 2 | ||
3 | -import java.net.URI; | 3 | +import de.javakaffee.kryoserializers.URISerializer; |
4 | -import java.nio.ByteBuffer; | ||
5 | -import java.util.ArrayList; | ||
6 | -import java.util.HashMap; | ||
7 | - | ||
8 | import org.apache.felix.scr.annotations.Activate; | 4 | import org.apache.felix.scr.annotations.Activate; |
9 | import org.apache.felix.scr.annotations.Component; | 5 | import org.apache.felix.scr.annotations.Component; |
10 | import org.apache.felix.scr.annotations.Deactivate; | 6 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -13,6 +9,7 @@ import org.onlab.onos.cluster.ControllerNode; | ... | @@ -13,6 +9,7 @@ import org.onlab.onos.cluster.ControllerNode; |
13 | import org.onlab.onos.cluster.DefaultControllerNode; | 9 | import org.onlab.onos.cluster.DefaultControllerNode; |
14 | import org.onlab.onos.cluster.NodeId; | 10 | import org.onlab.onos.cluster.NodeId; |
15 | import org.onlab.onos.net.ConnectPoint; | 11 | import org.onlab.onos.net.ConnectPoint; |
12 | +import org.onlab.onos.net.DefaultAnnotations; | ||
16 | import org.onlab.onos.net.DefaultDevice; | 13 | import org.onlab.onos.net.DefaultDevice; |
17 | import org.onlab.onos.net.DefaultLink; | 14 | import org.onlab.onos.net.DefaultLink; |
18 | import org.onlab.onos.net.DefaultPort; | 15 | import org.onlab.onos.net.DefaultPort; |
... | @@ -30,7 +27,10 @@ import org.onlab.util.KryoPool; | ... | @@ -30,7 +27,10 @@ import org.onlab.util.KryoPool; |
30 | import org.slf4j.Logger; | 27 | import org.slf4j.Logger; |
31 | import org.slf4j.LoggerFactory; | 28 | import org.slf4j.LoggerFactory; |
32 | 29 | ||
33 | -import de.javakaffee.kryoserializers.URISerializer; | 30 | +import java.net.URI; |
31 | +import java.nio.ByteBuffer; | ||
32 | +import java.util.ArrayList; | ||
33 | +import java.util.HashMap; | ||
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Serialization service using Kryo. | 36 | * Serialization service using Kryo. |
... | @@ -66,6 +66,7 @@ public class KryoSerializationManager implements KryoSerializationService { | ... | @@ -66,6 +66,7 @@ public class KryoSerializationManager implements KryoSerializationService { |
66 | ControllerNode.State.class, | 66 | ControllerNode.State.class, |
67 | Device.Type.class, | 67 | Device.Type.class, |
68 | 68 | ||
69 | + DefaultAnnotations.class, | ||
69 | DefaultControllerNode.class, | 70 | DefaultControllerNode.class, |
70 | DefaultDevice.class, | 71 | DefaultDevice.class, |
71 | MastershipRole.class, | 72 | MastershipRole.class, | ... | ... |
-
Please register or login to post a comment