Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
7 changed files
with
118 additions
and
7 deletions
1 | +package org.onlab.onos.net; | ||
2 | + | ||
3 | +import org.onlab.onos.net.provider.ProviderId; | ||
4 | + | ||
5 | +import static com.google.common.base.Preconditions.checkArgument; | ||
6 | + | ||
7 | +/** | ||
8 | + * Default edge link model implementation. | ||
9 | + */ | ||
10 | +public class DefaultEdgeLink extends DefaultLink implements EdgeLink { | ||
11 | + | ||
12 | + private final HostId hostId; | ||
13 | + private final HostLocation hostLocation; | ||
14 | + | ||
15 | + /** | ||
16 | + * Creates an edge link using the supplied information. | ||
17 | + * | ||
18 | + * @param providerId provider identity | ||
19 | + * @param hostPoint host-side connection point | ||
20 | + * @param hostLocation location where host attaches to the network | ||
21 | + * @param isIngress true to indicated host-to-network direction; false | ||
22 | + * for network-to-host direction | ||
23 | + */ | ||
24 | + public DefaultEdgeLink(ProviderId providerId, ConnectPoint hostPoint, | ||
25 | + HostLocation hostLocation, boolean isIngress) { | ||
26 | + super(providerId, isIngress ? hostLocation : hostPoint, | ||
27 | + isIngress ? hostPoint : hostLocation, Type.EDGE); | ||
28 | + checkArgument(hostPoint.elementId() instanceof HostId, | ||
29 | + "Host point does not refer to a host ID"); | ||
30 | + this.hostId = (HostId) hostPoint.elementId(); | ||
31 | + this.hostLocation = hostLocation; | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public HostId hostId() { | ||
36 | + return hostId; | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public ConnectPoint connectPoint() { | ||
41 | + return hostLocation; | ||
42 | + } | ||
43 | +} |
... | @@ -4,14 +4,14 @@ package org.onlab.onos.net; | ... | @@ -4,14 +4,14 @@ package org.onlab.onos.net; |
4 | * Abstraction of a link between an end-station host and the network | 4 | * Abstraction of a link between an end-station host and the network |
5 | * infrastructure. | 5 | * infrastructure. |
6 | */ | 6 | */ |
7 | -public interface HostLinks extends Link { | 7 | +public interface EdgeLink extends Link { |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Returns the host identification. | 10 | * Returns the host identification. |
11 | * | 11 | * |
12 | * @return host identifier | 12 | * @return host identifier |
13 | */ | 13 | */ |
14 | - ElementId hostId(); | 14 | + HostId hostId(); |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * Returns the connection point where the host attaches to the | 17 | * Returns the connection point where the host attaches to the | ... | ... |
1 | +package org.onlab.onos.net; | ||
2 | + | ||
3 | +import java.net.URI; | ||
4 | + | ||
5 | +/** | ||
6 | + * Immutable representation of a host identity. | ||
7 | + */ | ||
8 | +public final class HostId extends ElementId { | ||
9 | + | ||
10 | + // Public construction is prohibited | ||
11 | + private HostId(URI uri) { | ||
12 | + super(uri); | ||
13 | + } | ||
14 | + | ||
15 | + /** | ||
16 | + * Creates a device id using the supplied URI. | ||
17 | + * | ||
18 | + * @param uri device URI | ||
19 | + */ | ||
20 | + public static HostId hostId(URI uri) { | ||
21 | + return new HostId(uri); | ||
22 | + } | ||
23 | + | ||
24 | + /** | ||
25 | + * Creates a device id using the supplied URI string. | ||
26 | + * | ||
27 | + * @param string device URI string | ||
28 | + */ | ||
29 | + public static HostId hostId(String string) { | ||
30 | + return new HostId(URI.create(string)); | ||
31 | + } | ||
32 | + | ||
33 | +} |
... | @@ -20,7 +20,12 @@ public interface Link extends Provided { | ... | @@ -20,7 +20,12 @@ public interface Link extends Provided { |
20 | * links traversing optical paths, tunnels or intervening 'dark' | 20 | * links traversing optical paths, tunnels or intervening 'dark' |
21 | * switches. | 21 | * switches. |
22 | */ | 22 | */ |
23 | - INDIRECT | 23 | + INDIRECT, |
24 | + | ||
25 | + /** | ||
26 | + * Signifies that this link is an edge, i.e. host link. | ||
27 | + */ | ||
28 | + EDGE | ||
24 | } | 29 | } |
25 | 30 | ||
26 | /** | 31 | /** | ... | ... |
... | @@ -27,8 +27,11 @@ import org.onlab.onos.net.provider.AbstractProviderService; | ... | @@ -27,8 +27,11 @@ import org.onlab.onos.net.provider.AbstractProviderService; |
27 | import org.slf4j.Logger; | 27 | import org.slf4j.Logger; |
28 | 28 | ||
29 | import java.util.List; | 29 | import java.util.List; |
30 | +import java.util.concurrent.ExecutorService; | ||
30 | 31 | ||
31 | import static com.google.common.base.Preconditions.checkNotNull; | 32 | import static com.google.common.base.Preconditions.checkNotNull; |
33 | +import static java.util.concurrent.Executors.newSingleThreadExecutor; | ||
34 | +import static org.onlab.util.Tools.namedThreads; | ||
32 | import static org.slf4j.LoggerFactory.getLogger; | 35 | import static org.slf4j.LoggerFactory.getLogger; |
33 | 36 | ||
34 | /** | 37 | /** |
... | @@ -53,6 +56,9 @@ public class SimpleDeviceManager | ... | @@ -53,6 +56,9 @@ public class SimpleDeviceManager |
53 | 56 | ||
54 | private final SimpleDeviceStore store = new SimpleDeviceStore(); | 57 | private final SimpleDeviceStore store = new SimpleDeviceStore(); |
55 | 58 | ||
59 | + private final ExecutorService executor = | ||
60 | + newSingleThreadExecutor(namedThreads("onos-device-%d")); | ||
61 | + | ||
56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 62 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
57 | protected EventDeliveryService eventDispatcher; | 63 | protected EventDeliveryService eventDispatcher; |
58 | 64 | ||
... | @@ -163,6 +169,11 @@ public class SimpleDeviceManager | ... | @@ -163,6 +169,11 @@ public class SimpleDeviceManager |
163 | DeviceEvent event = store.createOrUpdateDevice(provider().id(), | 169 | DeviceEvent event = store.createOrUpdateDevice(provider().id(), |
164 | deviceId, deviceDescription); | 170 | deviceId, deviceDescription); |
165 | post(event); | 171 | post(event); |
172 | + | ||
173 | + // If there was a change of any kind, trigger role selection process. | ||
174 | + if (event != null) { | ||
175 | + triggerRoleSelection(event.subject(), provider()); | ||
176 | + } | ||
166 | } | 177 | } |
167 | 178 | ||
168 | @Override | 179 | @Override |
... | @@ -199,6 +210,22 @@ public class SimpleDeviceManager | ... | @@ -199,6 +210,22 @@ public class SimpleDeviceManager |
199 | } | 210 | } |
200 | } | 211 | } |
201 | 212 | ||
213 | + /** | ||
214 | + * Triggers asynchronous role selection. | ||
215 | + * | ||
216 | + * @param device device | ||
217 | + * @param provider device provider | ||
218 | + */ | ||
219 | + private void triggerRoleSelection(final Device device, | ||
220 | + final DeviceProvider provider) { | ||
221 | + executor.execute(new Runnable() { | ||
222 | + @Override | ||
223 | + public void run() { | ||
224 | + provider.roleChanged(device, store.getRole(device.id())); | ||
225 | + } | ||
226 | + }); | ||
227 | + } | ||
228 | + | ||
202 | // Posts the specified event to the local event dispatcher. | 229 | // Posts the specified event to the local event dispatcher. |
203 | private void post(DeviceEvent event) { | 230 | private void post(DeviceEvent event) { |
204 | if (event != null && eventDispatcher != null) { | 231 | if (event != null && eventDispatcher != null) { | ... | ... |
... | @@ -96,6 +96,9 @@ class SimpleDeviceStore { | ... | @@ -96,6 +96,9 @@ class SimpleDeviceStore { |
96 | synchronized (this) { | 96 | synchronized (this) { |
97 | devices.put(deviceId, device); | 97 | devices.put(deviceId, device); |
98 | availableDevices.add(deviceId); | 98 | availableDevices.add(deviceId); |
99 | + | ||
100 | + // For now claim the device as a master automatically. | ||
101 | + roles.put(deviceId, MastershipRole.MASTER); | ||
99 | } | 102 | } |
100 | return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, null); | 103 | return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, null); |
101 | } | 104 | } | ... | ... |
... | @@ -139,17 +139,17 @@ public class SimpleDeviceManagerTest { | ... | @@ -139,17 +139,17 @@ public class SimpleDeviceManagerTest { |
139 | @Test | 139 | @Test |
140 | public void getRole() { | 140 | public void getRole() { |
141 | connectDevice(DID1, SW1); | 141 | connectDevice(DID1, SW1); |
142 | - assertEquals("incorrect role", MastershipRole.NONE, service.getRole(DID1)); | 142 | + assertEquals("incorrect role", MastershipRole.MASTER, service.getRole(DID1)); |
143 | } | 143 | } |
144 | 144 | ||
145 | @Test | 145 | @Test |
146 | public void setRole() { | 146 | public void setRole() { |
147 | connectDevice(DID1, SW1); | 147 | connectDevice(DID1, SW1); |
148 | - admin.setRole(DID1, MastershipRole.MASTER); | 148 | + admin.setRole(DID1, MastershipRole.STANDBY); |
149 | validateEvents(DEVICE_ADDED, DEVICE_MASTERSHIP_CHANGED); | 149 | validateEvents(DEVICE_ADDED, DEVICE_MASTERSHIP_CHANGED); |
150 | - assertEquals("incorrect role", MastershipRole.MASTER, service.getRole(DID1)); | 150 | + assertEquals("incorrect role", MastershipRole.STANDBY, service.getRole(DID1)); |
151 | assertEquals("incorrect device", DID1, provider.deviceReceived.id()); | 151 | assertEquals("incorrect device", DID1, provider.deviceReceived.id()); |
152 | - assertEquals("incorrect role", MastershipRole.MASTER, provider.roleReceived); | 152 | + assertEquals("incorrect role", MastershipRole.STANDBY, provider.roleReceived); |
153 | } | 153 | } |
154 | 154 | ||
155 | @Test | 155 | @Test | ... | ... |
-
Please register or login to post a comment