tom

Cleaned up some of the host-related abstractions and filled in more of the host …

…manager implementation.
1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 +import org.onlab.packet.IPv4;
4 +import org.onlab.packet.MACAddress;
5 +
6 +import java.util.Set;
7 +
3 /** 8 /**
4 * Abstraction of an end-station host on the network, essentially a NIC. 9 * Abstraction of an end-station host on the network, essentially a NIC.
5 */ 10 */
6 public interface Host extends Element { 11 public interface Host extends Element {
7 12
8 - // MAC, IP(s), optional VLAN ID 13 + /**
14 + * Host identification.
15 + *
16 + * @return host id
17 + */
18 + HostId id();
19 +
20 + /**
21 + * Returns the host MAC address.
22 + *
23 + * @return mac address
24 + */
25 + MACAddress mac();
9 26
27 + /**
28 + * Returns set of IP addresses currently bound to the host MAC address.
29 + *
30 + * @return set of IP addresses; empty if no IP address is bound
31 + */
32 + Set<IPv4> ipAddresses();
10 33
11 /** 34 /**
12 * Returns the most recent host location where the host attaches to the 35 * Returns the most recent host location where the host attaches to the
...@@ -16,6 +39,6 @@ public interface Host extends Element { ...@@ -16,6 +39,6 @@ public interface Host extends Element {
16 */ 39 */
17 HostLocation location(); 40 HostLocation location();
18 41
19 - // list of recent locations? 42 + // TODO: explore capturing list of recent locations to aid in mobility
20 43
21 } 44 }
......
1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 +import org.onlab.packet.MACAddress;
4 +
3 import java.net.URI; 5 import java.net.URI;
4 6
5 /** 7 /**
...@@ -16,6 +18,7 @@ public final class HostId extends ElementId { ...@@ -16,6 +18,7 @@ public final class HostId extends ElementId {
16 * Creates a device id using the supplied URI. 18 * Creates a device id using the supplied URI.
17 * 19 *
18 * @param uri device URI 20 * @param uri device URI
21 + * @return host identifier
19 */ 22 */
20 public static HostId hostId(URI uri) { 23 public static HostId hostId(URI uri) {
21 return new HostId(uri); 24 return new HostId(uri);
...@@ -25,9 +28,23 @@ public final class HostId extends ElementId { ...@@ -25,9 +28,23 @@ public final class HostId extends ElementId {
25 * Creates a device id using the supplied URI string. 28 * Creates a device id using the supplied URI string.
26 * 29 *
27 * @param string device URI string 30 * @param string device URI string
31 + * @return host identifier
28 */ 32 */
29 public static HostId hostId(String string) { 33 public static HostId hostId(String string) {
30 return hostId(URI.create(string)); 34 return hostId(URI.create(string));
31 } 35 }
32 36
37 + /**
38 + * Creates a device id using the supplied MAC &amp; VLAN ID.
39 + *
40 + * @param mac mac address
41 + * @param vlanId vlan identifier
42 + * @return host identifier
43 + */
44 + // FIXME: replace vlanId long with a rich data-type, e.g. VLanId or something like that
45 + public static HostId hostId(MACAddress mac, long vlanId) {
46 + // FIXME: use more efficient means of encoding
47 + return hostId("nic" + ":" + mac + "/" + vlanId);
48 + }
49 +
33 } 50 }
......
...@@ -23,6 +23,11 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { ...@@ -23,6 +23,11 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> {
23 HOST_REMOVED, 23 HOST_REMOVED,
24 24
25 /** 25 /**
26 + * Signifies that host data changed, e.g. IP address
27 + */
28 + HOST_UPDATED,
29 +
30 + /**
26 * Signifies that a host location has changed. 31 * Signifies that a host location has changed.
27 */ 32 */
28 HOST_MOVED 33 HOST_MOVED
......
1 package org.onlab.onos.net.host; 1 package org.onlab.onos.net.host;
2 2
3 +import org.onlab.onos.net.HostId;
3 import org.onlab.onos.net.provider.ProviderService; 4 import org.onlab.onos.net.provider.ProviderService;
4 5
5 /** 6 /**
...@@ -11,15 +12,16 @@ public interface HostProviderService extends ProviderService<HostProvider> { ...@@ -11,15 +12,16 @@ public interface HostProviderService extends ProviderService<HostProvider> {
11 * Notifies the core when a host has been detected on a network along with 12 * Notifies the core when a host has been detected on a network along with
12 * information that identifies the hoot location. 13 * information that identifies the hoot location.
13 * 14 *
15 + * @param hostId id of the host that been detected
14 * @param hostDescription description of host and its location 16 * @param hostDescription description of host and its location
15 */ 17 */
16 - void hostDetected(HostDescription hostDescription); 18 + void hostDetected(HostId hostId, HostDescription hostDescription);
17 19
18 /** 20 /**
19 * Notifies the core when a host is no longer detected on a network. 21 * Notifies the core when a host is no longer detected on a network.
20 * 22 *
21 - * @param hostDescription description of host 23 + * @param hostId id of the host that vanished
22 */ 24 */
23 - void hostVanished(HostDescription hostDescription); 25 + void hostVanished(HostId hostId);
24 26
25 } 27 }
......
...@@ -2,8 +2,10 @@ package org.onlab.onos.net.host; ...@@ -2,8 +2,10 @@ package org.onlab.onos.net.host;
2 2
3 import org.onlab.onos.net.ConnectPoint; 3 import org.onlab.onos.net.ConnectPoint;
4 import org.onlab.onos.net.DeviceId; 4 import org.onlab.onos.net.DeviceId;
5 -import org.onlab.onos.net.ElementId;
6 import org.onlab.onos.net.Host; 5 import org.onlab.onos.net.Host;
6 +import org.onlab.onos.net.HostId;
7 +import org.onlab.packet.IPv4;
8 +import org.onlab.packet.MACAddress;
7 9
8 import java.util.Set; 10 import java.util.Set;
9 11
...@@ -13,6 +15,13 @@ import java.util.Set; ...@@ -13,6 +15,13 @@ import java.util.Set;
13 public interface HostService { 15 public interface HostService {
14 16
15 /** 17 /**
18 + * Returns the number of end-station hosts known to the system.
19 + *
20 + * @return number of end-station hosts
21 + */
22 + public int getHostCount();
23 +
24 + /**
16 * Returns a collection of all end-station hosts. 25 * Returns a collection of all end-station hosts.
17 * 26 *
18 * @return collection of hosts 27 * @return collection of hosts
...@@ -25,12 +34,32 @@ public interface HostService { ...@@ -25,12 +34,32 @@ public interface HostService {
25 * @param hostId host identifier 34 * @param hostId host identifier
26 * @return host or null if one with the given identifier is not known 35 * @return host or null if one with the given identifier is not known
27 */ 36 */
28 - Host getHost(ElementId hostId); // TODO: change to HostId 37 + Host getHost(HostId hostId);
38 +
39 + /**
40 + * Returns the set of hosts that belong to the specified VLAN.
41 + *
42 + * @param vlanId vlan identifier
43 + * @return set of hosts in the given vlan id
44 + */
45 + // FIXME: change long to VLanId
46 + Set<Host> getHostsByVlan(long vlanId);
29 47
30 - // TODO: determine which ones make sense or which we care to support 48 + /**
31 - // Set<Host> getHostsByVlan(VlanId vlan); 49 + * Returns the set of hosts that have the specified MAC address.
32 - // Set<Host> getHostsByMac(MacAddress mac); 50 + *
33 - // Set<Host> getHostsByIp(IpAddress ip); 51 + * @param mac mac address
52 + * @return set of hosts with the given mac
53 + */
54 + Set<Host> getHostsByMac(MACAddress mac);
55 +
56 + /**
57 + * Returns the set of hosts that have the specified IP address.
58 + *
59 + * @param ip ip address
60 + * @return set of hosts with the given IP
61 + */
62 + Set<Host> getHostsByIp(IPv4 ip);
34 63
35 /** 64 /**
36 * Returns the set of hosts whose most recent location is the specified 65 * Returns the set of hosts whose most recent location is the specified
......
...@@ -110,21 +110,6 @@ public class SimpleDeviceManager ...@@ -110,21 +110,6 @@ public class SimpleDeviceManager
110 } 110 }
111 111
112 @Override 112 @Override
113 - public void addListener(DeviceListener listener) {
114 - listenerRegistry.addListener(listener);
115 - }
116 -
117 - @Override
118 - public void removeListener(DeviceListener listener) {
119 - listenerRegistry.removeListener(listener);
120 - }
121 -
122 - @Override
123 - protected DeviceProviderService createProviderService(DeviceProvider provider) {
124 - return new InternalDeviceProviderService(provider);
125 - }
126 -
127 - @Override
128 public void setRole(DeviceId deviceId, MastershipRole newRole) { 113 public void setRole(DeviceId deviceId, MastershipRole newRole) {
129 checkNotNull(deviceId, DEVICE_ID_NULL); 114 checkNotNull(deviceId, DEVICE_ID_NULL);
130 checkNotNull(newRole, ROLE_NULL); 115 checkNotNull(newRole, ROLE_NULL);
...@@ -149,6 +134,21 @@ public class SimpleDeviceManager ...@@ -149,6 +134,21 @@ public class SimpleDeviceManager
149 } 134 }
150 } 135 }
151 136
137 + @Override
138 + public void addListener(DeviceListener listener) {
139 + listenerRegistry.addListener(listener);
140 + }
141 +
142 + @Override
143 + public void removeListener(DeviceListener listener) {
144 + listenerRegistry.removeListener(listener);
145 + }
146 +
147 + @Override
148 + protected DeviceProviderService createProviderService(DeviceProvider provider) {
149 + return new InternalDeviceProviderService(provider);
150 + }
151 +
152 // Personalized device provider service issued to the supplied provider. 152 // Personalized device provider service issued to the supplied provider.
153 private class InternalDeviceProviderService extends AbstractProviderService<DeviceProvider> 153 private class InternalDeviceProviderService extends AbstractProviderService<DeviceProvider>
154 implements DeviceProviderService { 154 implements DeviceProviderService {
......
...@@ -28,8 +28,7 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -28,8 +28,7 @@ import static com.google.common.base.Preconditions.checkArgument;
28 import static org.onlab.onos.net.device.DeviceEvent.Type.*; 28 import static org.onlab.onos.net.device.DeviceEvent.Type.*;
29 29
30 /** 30 /**
31 - * Manages inventory of infrastructure devices using trivial in-memory 31 +
32 - * implementation.
33 */ 32 */
34 class SimpleDeviceStore { 33 class SimpleDeviceStore {
35 34
......
...@@ -8,16 +8,26 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -8,16 +8,26 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
8 import org.apache.felix.scr.annotations.Service; 8 import org.apache.felix.scr.annotations.Service;
9 import org.onlab.onos.event.AbstractListenerRegistry; 9 import org.onlab.onos.event.AbstractListenerRegistry;
10 import org.onlab.onos.event.EventDeliveryService; 10 import org.onlab.onos.event.EventDeliveryService;
11 +import org.onlab.onos.net.ConnectPoint;
12 +import org.onlab.onos.net.DeviceId;
13 +import org.onlab.onos.net.Host;
14 +import org.onlab.onos.net.HostId;
11 import org.onlab.onos.net.host.HostDescription; 15 import org.onlab.onos.net.host.HostDescription;
12 import org.onlab.onos.net.host.HostEvent; 16 import org.onlab.onos.net.host.HostEvent;
13 import org.onlab.onos.net.host.HostListener; 17 import org.onlab.onos.net.host.HostListener;
14 import org.onlab.onos.net.host.HostProvider; 18 import org.onlab.onos.net.host.HostProvider;
15 import org.onlab.onos.net.host.HostProviderRegistry; 19 import org.onlab.onos.net.host.HostProviderRegistry;
16 import org.onlab.onos.net.host.HostProviderService; 20 import org.onlab.onos.net.host.HostProviderService;
21 +import org.onlab.onos.net.host.HostService;
17 import org.onlab.onos.net.provider.AbstractProviderRegistry; 22 import org.onlab.onos.net.provider.AbstractProviderRegistry;
18 import org.onlab.onos.net.provider.AbstractProviderService; 23 import org.onlab.onos.net.provider.AbstractProviderService;
24 +import org.onlab.packet.IPv4;
25 +import org.onlab.packet.MACAddress;
19 import org.slf4j.Logger; 26 import org.slf4j.Logger;
20 27
28 +import java.util.Set;
29 +
30 +import static com.google.common.base.Preconditions.checkNotNull;
21 import static org.slf4j.LoggerFactory.getLogger; 31 import static org.slf4j.LoggerFactory.getLogger;
22 32
23 /** 33 /**
...@@ -27,13 +37,16 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -27,13 +37,16 @@ import static org.slf4j.LoggerFactory.getLogger;
27 @Service 37 @Service
28 public class SimpleHostManager 38 public class SimpleHostManager
29 extends AbstractProviderRegistry<HostProvider, HostProviderService> 39 extends AbstractProviderRegistry<HostProvider, HostProviderService>
30 - implements HostProviderRegistry { 40 + implements HostService, HostProviderRegistry {
31 41
42 + public static final String HOST_ID_NULL = "Host ID cannot be null";
32 private final Logger log = getLogger(getClass()); 43 private final Logger log = getLogger(getClass());
33 44
34 private final AbstractListenerRegistry<HostEvent, HostListener> 45 private final AbstractListenerRegistry<HostEvent, HostListener>
35 listenerRegistry = new AbstractListenerRegistry<>(); 46 listenerRegistry = new AbstractListenerRegistry<>();
36 47
48 + private final SimpleHostStore store = new SimpleHostStore();
49 +
37 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 50 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
38 private EventDeliveryService eventDispatcher; 51 private EventDeliveryService eventDispatcher;
39 52
...@@ -55,8 +68,64 @@ public class SimpleHostManager ...@@ -55,8 +68,64 @@ public class SimpleHostManager
55 return new InternalHostProviderService(provider); 68 return new InternalHostProviderService(provider);
56 } 69 }
57 70
71 + @Override
72 + public int getHostCount() {
73 + return store.getHostCount();
74 + }
75 +
76 + @Override
77 + public Iterable<Host> getHosts() {
78 + return store.getHosts();
79 + }
80 +
81 + @Override
82 + public Host getHost(HostId hostId) {
83 + checkNotNull(hostId, HOST_ID_NULL);
84 + return store.getHost(hostId);
85 + }
86 +
87 + @Override
88 + public Set<Host> getHostsByVlan(long vlanId) {
89 + return store.getHosts(vlanId);
90 + }
91 +
92 + @Override
93 + public Set<Host> getHostsByMac(MACAddress mac) {
94 + checkNotNull(mac, "MAC address cannot be null");
95 + return store.getHosts(mac);
96 + }
97 +
98 + @Override
99 + public Set<Host> getHostsByIp(IPv4 ip) {
100 + checkNotNull(ip, "IP address cannot be null");
101 + return store.getHosts(ip);
102 + }
103 +
104 + @Override
105 + public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
106 + checkNotNull(connectPoint, "Connection point cannot be null");
107 + return store.getConnectedHosts(connectPoint);
108 + }
109 +
110 + @Override
111 + public Set<Host> getConnectedHosts(DeviceId deviceId) {
112 + checkNotNull(deviceId, "Device ID cannot be null");
113 + return store.getConnectedHosts(deviceId);
114 + }
115 +
116 + @Override
117 + public void addListener(HostListener listener) {
118 + listenerRegistry.addListener(listener);
119 + }
120 +
121 + @Override
122 + public void removeListener(HostListener listener) {
123 + listenerRegistry.removeListener(listener);
124 + }
125 +
58 // Personalized host provider service issued to the supplied provider. 126 // Personalized host provider service issued to the supplied provider.
59 - private class InternalHostProviderService extends AbstractProviderService<HostProvider> 127 + private class InternalHostProviderService
128 + extends AbstractProviderService<HostProvider>
60 implements HostProviderService { 129 implements HostProviderService {
61 130
62 InternalHostProviderService(HostProvider provider) { 131 InternalHostProviderService(HostProvider provider) {
...@@ -64,13 +133,34 @@ public class SimpleHostManager ...@@ -64,13 +133,34 @@ public class SimpleHostManager
64 } 133 }
65 134
66 @Override 135 @Override
67 - public void hostDetected(HostDescription hostDescription) { 136 + public void hostDetected(HostId hostId, HostDescription hostDescription) {
68 - log.info("Host {} detected", hostDescription); 137 + checkNotNull(hostId, HOST_ID_NULL);
138 + checkValidity();
139 + HostEvent event = store.createOrUpdateHost(provider().id(), hostId,
140 + hostDescription);
141 + if (event != null) {
142 + log.info("Host {} detected", hostId);
143 + post(event);
144 + }
69 } 145 }
70 146
71 @Override 147 @Override
72 - public void hostVanished(HostDescription hostDescription) { 148 + public void hostVanished(HostId hostId) {
73 - log.info("Host {} vanished", hostDescription); 149 + checkNotNull(hostId, HOST_ID_NULL);
150 + checkValidity();
151 + HostEvent event = store.removeHost(hostId);
152 + if (event != null) {
153 + log.info("Host {} vanished", hostId);
154 + post(event);
155 + }
74 } 156 }
75 } 157 }
158 +
159 + // Posts the specified event to the local event dispatcher.
160 + private void post(HostEvent event) {
161 + if (event != null && eventDispatcher != null) {
162 + eventDispatcher.post(event);
163 + }
164 + }
165 +
76 } 166 }
......
1 +package org.onlab.onos.net.trivial.impl;
2 +
3 +import org.onlab.onos.net.ConnectPoint;
4 +import org.onlab.onos.net.DeviceId;
5 +import org.onlab.onos.net.Host;
6 +import org.onlab.onos.net.HostId;
7 +import org.onlab.onos.net.host.HostDescription;
8 +import org.onlab.onos.net.host.HostEvent;
9 +import org.onlab.onos.net.provider.ProviderId;
10 +import org.onlab.packet.IPv4;
11 +import org.onlab.packet.MACAddress;
12 +
13 +import java.util.Map;
14 +import java.util.Set;
15 +import java.util.concurrent.ConcurrentHashMap;
16 +
17 +/**
18 + * Manages inventory of end-station hosts using trivial in-memory
19 + * implementation.
20 + */
21 +public class SimpleHostStore {
22 +
23 + private final Map<HostId, Host> hosts = new ConcurrentHashMap<>();
24 +
25 + /**
26 + * Creates a new host or updates the existing one based on the specified
27 + * description.
28 + *
29 + * @param providerId provider identification
30 + * @param hostId host identification
31 + * @param hostDescription host description data
32 + * @return appropriate event or null if no change resulted
33 + */
34 + HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
35 + HostDescription hostDescription) {
36 + return null;
37 + }
38 +
39 + /**
40 + * Removes the specified host from the inventory.
41 + *
42 + * @param hostId host identification
43 + * @return remove even or null if host was not found
44 + */
45 + HostEvent removeHost(HostId hostId) {
46 + return null;
47 + }
48 +
49 + /**
50 + * Returns the number of hosts in the store.
51 + *
52 + * @return host count
53 + */
54 + int getHostCount() {
55 + return hosts.size();
56 + }
57 +
58 + /**
59 + * Returns a collection of all hosts in the store.
60 + *
61 + * @return iterable collection of all hosts
62 + */
63 + Iterable<Host> getHosts() {
64 + return null;
65 + }
66 +
67 + /**
68 + * Returns the host with the specified identifer.
69 + *
70 + * @param hostId host identification
71 + * @return host or null if not found
72 + */
73 + Host getHost(HostId hostId) {
74 + return null;
75 + }
76 +
77 + /**
78 + * Returns the set of all hosts within the specified VLAN.
79 + *
80 + * @param vlanId vlan id
81 + * @return set of hosts in the vlan
82 + */
83 + Set<Host> getHosts(long vlanId) {
84 + return null;
85 + }
86 +
87 + /**
88 + * Returns the set of hosts with the specified MAC address.
89 + *
90 + * @param mac mac address
91 + * @return set of hosts with the given mac
92 + */
93 + Set<Host> getHosts(MACAddress mac) {
94 + return null;
95 + }
96 +
97 + /**
98 + * Returns the set of hosts with the specified IP address.
99 + *
100 + * @param ip ip address
101 + * @return set of hosts with the given IP
102 + */
103 + Set<Host> getHosts(IPv4 ip) {
104 + return null;
105 + }
106 +
107 + /**
108 + * Returns the set of hosts whose location falls on the given connection point.
109 + *
110 + * @param connectPoint connection point
111 + * @return set of hosts
112 + */
113 + Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
114 + return null;
115 + }
116 +
117 + /**
118 + * Returns the set of hosts whose location falls on the given device.
119 + *
120 + * @param deviceId infrastructure device identifier
121 + * @return set of hosts
122 + */
123 + public Set<Host> getConnectedHosts(DeviceId deviceId) {
124 + return null;
125 + }
126 +
127 +}
...@@ -66,11 +66,6 @@ implements LinkService, LinkAdminService, LinkProviderRegistry { ...@@ -66,11 +66,6 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
66 } 66 }
67 67
68 @Override 68 @Override
69 - protected LinkProviderService createProviderService(LinkProvider provider) {
70 - return new InternalLinkProviderService(provider);
71 - }
72 -
73 - @Override
74 public int getLinkCount() { 69 public int getLinkCount() {
75 return store.getLinkCount(); 70 return store.getLinkCount();
76 } 71 }
...@@ -145,6 +140,11 @@ implements LinkService, LinkAdminService, LinkProviderRegistry { ...@@ -145,6 +140,11 @@ implements LinkService, LinkAdminService, LinkProviderRegistry {
145 listenerRegistry.removeListener(listener); 140 listenerRegistry.removeListener(listener);
146 } 141 }
147 142
143 + @Override
144 + protected LinkProviderService createProviderService(LinkProvider provider) {
145 + return new InternalLinkProviderService(provider);
146 + }
147 +
148 // Personalized link provider service issued to the supplied provider. 148 // Personalized link provider service issued to the supplied provider.
149 private class InternalLinkProviderService extends AbstractProviderService<LinkProvider> 149 private class InternalLinkProviderService extends AbstractProviderService<LinkProvider>
150 implements LinkProviderService { 150 implements LinkProviderService {
......