Showing
18 changed files
with
377 additions
and
45 deletions
1 | +package org.onlab.onos.net; | ||
2 | + | ||
3 | +/** | ||
4 | + * Abstraction of a network connection point expressed as a pair of the | ||
5 | + * device identifier and the device port number. | ||
6 | + */ | ||
7 | +public interface ConnectPoint { | ||
8 | + | ||
9 | + /** | ||
10 | + * Returns the connection device identifier. | ||
11 | + * | ||
12 | + * @return device id | ||
13 | + */ | ||
14 | + DeviceId deviceId(); | ||
15 | + | ||
16 | + /** | ||
17 | + * Returns the connection port number. | ||
18 | + * | ||
19 | + * @return port number | ||
20 | + */ | ||
21 | + PortNumber port(); | ||
22 | + | ||
23 | +} |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | +import org.onlab.onos.net.provider.Provided; | ||
4 | + | ||
3 | /** | 5 | /** |
4 | * Representation of an network infrastructure device. | 6 | * Representation of an network infrastructure device. |
5 | */ | 7 | */ |
6 | -public class Device { | 8 | +public interface Device extends Provided { |
7 | 9 | ||
8 | // type, e.g. switch, router, firewall, ips, controller | 10 | // type, e.g. switch, router, firewall, ips, controller |
9 | 11 | ... | ... |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | import java.net.URI; | 3 | import java.net.URI; |
4 | +import java.util.Objects; | ||
5 | + | ||
6 | +import static com.google.common.base.Objects.toStringHelper; | ||
4 | 7 | ||
5 | /** | 8 | /** |
6 | - * Immutable representaion of a device identity. | 9 | + * Immutable representation of a device identity. |
7 | */ | 10 | */ |
8 | public class DeviceId { | 11 | public class DeviceId { |
9 | 12 | ||
... | @@ -22,4 +25,25 @@ public class DeviceId { | ... | @@ -22,4 +25,25 @@ public class DeviceId { |
22 | return uri; | 25 | return uri; |
23 | } | 26 | } |
24 | 27 | ||
28 | + @Override | ||
29 | + public int hashCode() { | ||
30 | + return Objects.hash(uri); | ||
31 | + } | ||
32 | + | ||
33 | + @Override | ||
34 | + public boolean equals(Object obj) { | ||
35 | + if (this == obj) { | ||
36 | + return true; | ||
37 | + } | ||
38 | + if (obj == null || getClass() != obj.getClass()) { | ||
39 | + return false; | ||
40 | + } | ||
41 | + final DeviceId other = (DeviceId) obj; | ||
42 | + return Objects.equals(this.uri, other.uri); | ||
43 | + } | ||
44 | + @Override | ||
45 | + public String toString() { | ||
46 | + return toStringHelper(this).add("uri", uri).toString(); | ||
47 | + } | ||
48 | + | ||
25 | } | 49 | } | ... | ... |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | +import org.onlab.onos.net.provider.Provided; | ||
4 | + | ||
3 | /** | 5 | /** |
4 | * Abstraction of an end-station host on the network, essentially a NIC. | 6 | * Abstraction of an end-station host on the network, essentially a NIC. |
5 | */ | 7 | */ |
6 | -public class Host { | 8 | +public interface Host extends Provided { |
7 | 9 | ||
8 | // MAC, IP(s), optional VLAN ID | 10 | // MAC, IP(s), optional VLAN ID |
9 | 11 | ... | ... |
1 | +package org.onlab.onos.net; | ||
2 | + | ||
3 | +import org.onlab.onos.net.provider.Provided; | ||
4 | + | ||
5 | +/** | ||
6 | + * Abstraction of a network infrastructure link. | ||
7 | + */ | ||
8 | +public interface Link extends Provided { // TODO: Also should extend graph Edge | ||
9 | + | ||
10 | + /** | ||
11 | + * Returns the link source connection point. | ||
12 | + * | ||
13 | + * @return link source connection point | ||
14 | + */ | ||
15 | + ConnectPoint src(); | ||
16 | + | ||
17 | + /** | ||
18 | + * Returns the link destination connection point. | ||
19 | + * | ||
20 | + * @return link destination connection point | ||
21 | + */ | ||
22 | + ConnectPoint dst(); | ||
23 | + | ||
24 | +} |
... | @@ -12,16 +12,24 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { | ... | @@ -12,16 +12,24 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
12 | * Type of device events. | 12 | * Type of device events. |
13 | */ | 13 | */ |
14 | public enum Type { | 14 | public enum Type { |
15 | - /** Signifies that a new device has been detected. */ | 15 | + /** |
16 | + * Signifies that a new device has been detected. | ||
17 | + */ | ||
16 | DEVICE_ADDED, | 18 | DEVICE_ADDED, |
17 | 19 | ||
18 | - /** Signifies that a device has been removed. */ | 20 | + /** |
21 | + * Signifies that a device has been removed. | ||
22 | + */ | ||
19 | DEVICE_REMOVED, | 23 | DEVICE_REMOVED, |
20 | 24 | ||
21 | - /** Signifies that a device has been administratively suspended. */ | 25 | + /** |
26 | + * Signifies that a device has been administratively suspended. | ||
27 | + */ | ||
22 | DEVICE_SUSPENDED, | 28 | DEVICE_SUSPENDED, |
23 | 29 | ||
24 | - /** Signifies that a device has come online or has gone offline. */ | 30 | + /** |
31 | + * Signifies that a device has come online or has gone offline. | ||
32 | + */ | ||
25 | DEVICE_AVAILABILITY_CHANGED, | 33 | DEVICE_AVAILABILITY_CHANGED, |
26 | 34 | ||
27 | /** | 35 | /** |
... | @@ -32,25 +40,25 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { | ... | @@ -32,25 +40,25 @@ public class DeviceEvent extends AbstractEvent<DeviceEvent.Type, Device> { |
32 | } | 40 | } |
33 | 41 | ||
34 | /** | 42 | /** |
35 | - * Creates an event of a given type and for the specified subject and the | 43 | + * Creates an event of a given type and for the specified device and the |
36 | * current time. | 44 | * current time. |
37 | * | 45 | * |
38 | - * @param type event type | 46 | + * @param type device event type |
39 | - * @param subject event subject | 47 | + * @param device event device subject |
40 | */ | 48 | */ |
41 | - public DeviceEvent(Type type, Device subject) { | 49 | + public DeviceEvent(Type type, Device device) { |
42 | - super(type, subject); | 50 | + super(type, device); |
43 | } | 51 | } |
44 | 52 | ||
45 | /** | 53 | /** |
46 | - * Creates an event of a given type and for the specified subject and time. | 54 | + * Creates an event of a given type and for the specified device and time. |
47 | * | 55 | * |
48 | - * @param type event type | 56 | + * @param type device event type |
49 | - * @param subject event subject | 57 | + * @param device event device subject |
50 | - * @param time occurrence time | 58 | + * @param time occurrence time |
51 | */ | 59 | */ |
52 | - public DeviceEvent(Type type, Device subject, long time) { | 60 | + public DeviceEvent(Type type, Device device, long time) { |
53 | - super(type, subject, time); | 61 | + super(type, device, time); |
54 | } | 62 | } |
55 | 63 | ||
56 | } | 64 | } | ... | ... |
1 | package org.onlab.onos.net.device; | 1 | package org.onlab.onos.net.device; |
2 | 2 | ||
3 | +import org.onlab.onos.event.EventListener; | ||
4 | + | ||
3 | /** | 5 | /** |
4 | - * Entity capable of receiving device related events. | 6 | + * Entity capable of receiving infrastructure device related events. |
5 | */ | 7 | */ |
6 | -public interface DeviceListener { | 8 | +public interface DeviceListener extends EventListener<DeviceEvent> { |
7 | } | 9 | } | ... | ... |
1 | +package org.onlab.onos.net.host; | ||
2 | + | ||
3 | +import org.onlab.onos.event.AbstractEvent; | ||
4 | +import org.onlab.onos.net.Host; | ||
5 | + | ||
6 | +/** | ||
7 | + * Describes end-station host event. | ||
8 | + */ | ||
9 | +public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { | ||
10 | + | ||
11 | + /** | ||
12 | + * Type of host events. | ||
13 | + */ | ||
14 | + public enum Type { | ||
15 | + /** | ||
16 | + * Signifies that a new host has been detected. | ||
17 | + */ | ||
18 | + HOST_ADDED, | ||
19 | + | ||
20 | + /** | ||
21 | + * Signifies that a host has been removed. | ||
22 | + */ | ||
23 | + HOST_REMOVED, | ||
24 | + | ||
25 | + /** | ||
26 | + * Signifies that a host location has changed. | ||
27 | + */ | ||
28 | + HOST_MOVED | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Creates an event of a given type and for the specified host and the | ||
33 | + * current time. | ||
34 | + * | ||
35 | + * @param type host event type | ||
36 | + * @param host event host subject | ||
37 | + */ | ||
38 | + public HostEvent(Type type, Host host) { | ||
39 | + super(type, host); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * Creates an event of a given type and for the specified host and time. | ||
44 | + * | ||
45 | + * @param type host event type | ||
46 | + * @param host event host subject | ||
47 | + * @param time occurrence time | ||
48 | + */ | ||
49 | + public HostEvent(Type type, Host host, long time) { | ||
50 | + super(type, host, time); | ||
51 | + } | ||
52 | + | ||
53 | +} |
1 | +package org.onlab.onos.net.link; | ||
2 | + | ||
3 | +import org.onlab.onos.event.AbstractEvent; | ||
4 | +import org.onlab.onos.net.Link; | ||
5 | + | ||
6 | +/** | ||
7 | + * Describes infrastructure link event. | ||
8 | + */ | ||
9 | +public class LinkEvent extends AbstractEvent<LinkEvent.Type, Link> { | ||
10 | + | ||
11 | + /** | ||
12 | + * Type of link events. | ||
13 | + */ | ||
14 | + public enum Type { | ||
15 | + /** | ||
16 | + * Signifies that a new link has been detected. | ||
17 | + */ | ||
18 | + LINK_ADDED, | ||
19 | + | ||
20 | + /** | ||
21 | + * Signifies that a link has been removed. | ||
22 | + */ | ||
23 | + LINK_REMOVED | ||
24 | + } | ||
25 | + | ||
26 | + /** | ||
27 | + * Creates an event of a given type and for the specified link and the | ||
28 | + * current time. | ||
29 | + * | ||
30 | + * @param type link event type | ||
31 | + * @param link event link subject | ||
32 | + */ | ||
33 | + public LinkEvent(Type type, Link link) { | ||
34 | + super(type, link); | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Creates an event of a given type and for the specified link and time. | ||
39 | + * | ||
40 | + * @param type link event type | ||
41 | + * @param link event link subject | ||
42 | + * @param time occurrence time | ||
43 | + */ | ||
44 | + public LinkEvent(Type type, Link link, long time) { | ||
45 | + super(type, link, time); | ||
46 | + } | ||
47 | + | ||
48 | +} |
1 | +package org.onlab.onos.net.provider; | ||
2 | + | ||
3 | +import java.util.HashMap; | ||
4 | +import java.util.Map; | ||
5 | + | ||
6 | +import static com.google.common.base.Preconditions.checkArgument; | ||
7 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
8 | + | ||
9 | +/** | ||
10 | + * Base implementation of provider broker. | ||
11 | + * | ||
12 | + * @param <P> type of the information provider | ||
13 | + * @param <S> type of the provider service | ||
14 | + */ | ||
15 | +public abstract class AbstractProviderBroker<P extends Provider, S extends ProviderService> | ||
16 | + implements ProviderBroker<P, S> { | ||
17 | + | ||
18 | + private final Map<ProviderId, S> services = new HashMap<>(); | ||
19 | + | ||
20 | + /** | ||
21 | + * Creates a new provider service bound to the specified provider. | ||
22 | + * | ||
23 | + * @param provider provider | ||
24 | + * @return provider service | ||
25 | + */ | ||
26 | + protected abstract S createProviderService(P provider); | ||
27 | + | ||
28 | + @Override | ||
29 | + public synchronized S register(P provider) { | ||
30 | + checkNotNull(provider, "Provider cannot be null"); | ||
31 | + checkArgument(!services.containsKey(provider), "Provider %s already registered", provider.id()); | ||
32 | + S service = createProviderService(provider); | ||
33 | + services.put(provider.id(), service); | ||
34 | + return service; | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public synchronized void unregister(P provider) { | ||
39 | + checkNotNull(provider, "Provider cannot be null"); | ||
40 | + S service = services.get(provider); | ||
41 | + checkArgument(service != null, "Provider %s not registered", provider.id()); | ||
42 | + if (service instanceof AbstractProviderService) { | ||
43 | + ((AbstractProviderService) service).invalidate(); | ||
44 | + } | ||
45 | + services.remove(provider); | ||
46 | + } | ||
47 | +} |
1 | +package org.onlab.onos.net.provider; | ||
2 | + | ||
3 | +import static com.google.common.base.Preconditions.checkState; | ||
4 | + | ||
5 | +/** | ||
6 | + * Base implementation of a provider service, which tracks the provider to | ||
7 | + * which it is issued and can be invalidated. | ||
8 | + * | ||
9 | + * @param <P> type of the information provider | ||
10 | + */ | ||
11 | +public abstract class AbstractProviderService<P extends Provider> implements ProviderService<P> { | ||
12 | + | ||
13 | + private boolean isValid = true; | ||
14 | + private final P provider; | ||
15 | + | ||
16 | + /** | ||
17 | + * Creates a provider service on behalf of the specified provider. | ||
18 | + * | ||
19 | + * @param provider provider to which this service is being issued | ||
20 | + */ | ||
21 | + protected AbstractProviderService(P provider) { | ||
22 | + this.provider = provider; | ||
23 | + } | ||
24 | + | ||
25 | + /** | ||
26 | + * Invalidates this provider service. | ||
27 | + */ | ||
28 | + public void invalidate() { | ||
29 | + isValid = false; | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * Checks the validity of this provider service. | ||
34 | + * | ||
35 | + * @throws java.lang.IllegalStateException if the service is no longer valid | ||
36 | + */ | ||
37 | + public void checkValidity() { | ||
38 | + checkState(isValid, "Provider service is no longer valid"); | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public P provider() { | ||
43 | + return provider; | ||
44 | + } | ||
45 | + | ||
46 | +} |
1 | +package org.onlab.onos.net.provider; | ||
2 | + | ||
3 | +/** | ||
4 | + * Abstraction of an entity supplied by a provider. | ||
5 | + */ | ||
6 | +public interface Provided { | ||
7 | + | ||
8 | + /** | ||
9 | + * Returns the identifier of the provider which supplied the entity. | ||
10 | + * | ||
11 | + * @return provider identification | ||
12 | + */ | ||
13 | + ProviderId id(); | ||
14 | + | ||
15 | +} |
... | @@ -5,6 +5,11 @@ package org.onlab.onos.net.provider; | ... | @@ -5,6 +5,11 @@ package org.onlab.onos.net.provider; |
5 | */ | 5 | */ |
6 | public interface Provider { | 6 | public interface Provider { |
7 | 7 | ||
8 | + /** | ||
9 | + * Returns the provider identifier. | ||
10 | + * | ||
11 | + * @return provider identification | ||
12 | + */ | ||
8 | ProviderId id(); | 13 | ProviderId id(); |
9 | 14 | ||
10 | } | 15 | } | ... | ... |
... | @@ -3,10 +3,10 @@ package org.onlab.onos.net.provider; | ... | @@ -3,10 +3,10 @@ package org.onlab.onos.net.provider; |
3 | /** | 3 | /** |
4 | * Broker used for registering/unregistering information providers with the core. | 4 | * Broker used for registering/unregistering information providers with the core. |
5 | * | 5 | * |
6 | - * @param <T> type of the information provider | 6 | + * @param <P> type of the information provider |
7 | * @param <S> type of the provider service | 7 | * @param <S> type of the provider service |
8 | */ | 8 | */ |
9 | -public interface ProviderBroker<T extends Provider, S extends ProviderService> { | 9 | +public interface ProviderBroker<P extends Provider, S extends ProviderService<P>> { |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * Registers the supplied provider with the core. | 12 | * Registers the supplied provider with the core. |
... | @@ -14,14 +14,15 @@ public interface ProviderBroker<T extends Provider, S extends ProviderService> { | ... | @@ -14,14 +14,15 @@ public interface ProviderBroker<T extends Provider, S extends ProviderService> { |
14 | * @param provider provider to be registered | 14 | * @param provider provider to be registered |
15 | * @return provider service for injecting information into core | 15 | * @return provider service for injecting information into core |
16 | */ | 16 | */ |
17 | - S register(T provider); | 17 | + S register(P provider); |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * Unregisters the supplied provider. As a result the previously issued | 20 | * Unregisters the supplied provider. As a result the previously issued |
21 | - * provider service will be invalidated. | 21 | + * provider service will be invalidated and any subsequent invocations |
22 | + * of its methods may throw {@link java.lang.IllegalStateException}. | ||
22 | * | 23 | * |
23 | * @param provider provider to be unregistered | 24 | * @param provider provider to be unregistered |
24 | */ | 25 | */ |
25 | - void unregister(T provider); | 26 | + void unregister(P provider); |
26 | 27 | ||
27 | } | 28 | } | ... | ... |
1 | package org.onlab.onos.net.provider; | 1 | package org.onlab.onos.net.provider; |
2 | 2 | ||
3 | +import java.util.Objects; | ||
4 | + | ||
5 | +import static com.google.common.base.Objects.toStringHelper; | ||
6 | + | ||
3 | /** | 7 | /** |
4 | * Notion of provider identity. | 8 | * Notion of provider identity. |
5 | */ | 9 | */ |
... | @@ -7,37 +11,37 @@ public class ProviderId { | ... | @@ -7,37 +11,37 @@ public class ProviderId { |
7 | 11 | ||
8 | private final String id; | 12 | private final String id; |
9 | 13 | ||
14 | + /** | ||
15 | + * Creates a new provider identifier from the specified string. | ||
16 | + * The providers are expected to follow the reverse DNS convention, e.g. | ||
17 | + * {@code org.onlab.onos.provider.of.device} | ||
18 | + * | ||
19 | + * @param id string identifier | ||
20 | + */ | ||
10 | public ProviderId(String id) { | 21 | public ProviderId(String id) { |
11 | this.id = id; | 22 | this.id = id; |
12 | } | 23 | } |
13 | 24 | ||
14 | @Override | 25 | @Override |
15 | - public boolean equals(Object o) { | 26 | + public int hashCode() { |
16 | - if (this == o) { | 27 | + return Objects.hash(id); |
28 | + } | ||
29 | + | ||
30 | + @Override | ||
31 | + public boolean equals(Object obj) { | ||
32 | + if (this == obj) { | ||
17 | return true; | 33 | return true; |
18 | } | 34 | } |
19 | - if (o == null || getClass() != o.getClass()) { | 35 | + if (obj == null || getClass() != obj.getClass()) { |
20 | - return false; | ||
21 | - } | ||
22 | - | ||
23 | - ProviderId that = (ProviderId) o; | ||
24 | - | ||
25 | - if (!id.equals(that.id)) { | ||
26 | return false; | 36 | return false; |
27 | } | 37 | } |
28 | - | 38 | + final ProviderId other = (ProviderId) obj; |
29 | - return true; | 39 | + return Objects.equals(this.id, other.id); |
30 | - } | ||
31 | - | ||
32 | - @Override | ||
33 | - public int hashCode() { | ||
34 | - return id.hashCode(); | ||
35 | } | 40 | } |
36 | 41 | ||
37 | @Override | 42 | @Override |
38 | public String toString() { | 43 | public String toString() { |
39 | - return "ProviderId{" + | 44 | + return toStringHelper(this).add("id", id).toString(); |
40 | - "id='" + id + '\'' + | ||
41 | - '}'; | ||
42 | } | 45 | } |
46 | + | ||
43 | } | 47 | } | ... | ... |
... | @@ -3,6 +3,16 @@ package org.onlab.onos.net.provider; | ... | @@ -3,6 +3,16 @@ package org.onlab.onos.net.provider; |
3 | /** | 3 | /** |
4 | * Abstraction of a service through which providers can inject information | 4 | * Abstraction of a service through which providers can inject information |
5 | * about the network environment into the core. | 5 | * about the network environment into the core. |
6 | + * | ||
7 | + * @param <P> type of the information provider | ||
6 | */ | 8 | */ |
7 | -public interface ProviderService { | 9 | +public interface ProviderService<P extends Provider> { |
10 | + | ||
11 | + /** | ||
12 | + * Returns the provider to which this service has been issued. | ||
13 | + * | ||
14 | + * @return provider to which this service has been assigned | ||
15 | + */ | ||
16 | + P provider(); | ||
17 | + | ||
8 | } | 18 | } | ... | ... |
-
Please register or login to post a comment