Committed by
Gerrit Code Review
Managers refactored to use ConfigOperators:
o Device, Host, and LinkManagers now use respecive ConfigOperator implementations to combine Descriptions with Network Configs. This refactors work done in 3a0cdd57. o Touchups on ConfigOperator impls Change-Id: I735e7e6bfa0c47c8727433aab804cb2782eebfff
Showing
5 changed files
with
15 additions
and
119 deletions
... | @@ -17,6 +17,7 @@ package org.onosproject.net.device.impl; | ... | @@ -17,6 +17,7 @@ package org.onosproject.net.device.impl; |
17 | 17 | ||
18 | import static org.slf4j.LoggerFactory.getLogger; | 18 | import static org.slf4j.LoggerFactory.getLogger; |
19 | 19 | ||
20 | +import org.onosproject.incubator.net.config.ConfigOperator; | ||
20 | import org.onosproject.incubator.net.config.basics.BasicDeviceConfig; | 21 | import org.onosproject.incubator.net.config.basics.BasicDeviceConfig; |
21 | import org.onosproject.net.AnnotationKeys; | 22 | import org.onosproject.net.AnnotationKeys; |
22 | import org.onosproject.net.DefaultAnnotations; | 23 | import org.onosproject.net.DefaultAnnotations; |
... | @@ -30,7 +31,7 @@ import org.slf4j.Logger; | ... | @@ -30,7 +31,7 @@ import org.slf4j.Logger; |
30 | * Implementations of merge policies for various sources of device configuration | 31 | * Implementations of merge policies for various sources of device configuration |
31 | * information. This includes applications, provides, and network configurations. | 32 | * information. This includes applications, provides, and network configurations. |
32 | */ | 33 | */ |
33 | -public final class BasicDeviceOperator { | 34 | +public final class BasicDeviceOperator implements ConfigOperator { |
34 | 35 | ||
35 | protected static final double DEFAULT_COORD = -1.0; | 36 | protected static final double DEFAULT_COORD = -1.0; |
36 | private static final Logger log = getLogger(BasicDeviceOperator.class); | 37 | private static final Logger log = getLogger(BasicDeviceOperator.class); | ... | ... |
... | @@ -37,14 +37,12 @@ import org.onosproject.mastership.MastershipListener; | ... | @@ -37,14 +37,12 @@ import org.onosproject.mastership.MastershipListener; |
37 | import org.onosproject.mastership.MastershipService; | 37 | import org.onosproject.mastership.MastershipService; |
38 | import org.onosproject.mastership.MastershipTerm; | 38 | import org.onosproject.mastership.MastershipTerm; |
39 | import org.onosproject.mastership.MastershipTermService; | 39 | import org.onosproject.mastership.MastershipTermService; |
40 | -import org.onosproject.net.DefaultAnnotations; | ||
41 | import org.onosproject.net.Device; | 40 | import org.onosproject.net.Device; |
42 | import org.onosproject.net.Device.Type; | 41 | import org.onosproject.net.Device.Type; |
43 | import org.onosproject.net.DeviceId; | 42 | import org.onosproject.net.DeviceId; |
44 | import org.onosproject.net.MastershipRole; | 43 | import org.onosproject.net.MastershipRole; |
45 | import org.onosproject.net.Port; | 44 | import org.onosproject.net.Port; |
46 | import org.onosproject.net.PortNumber; | 45 | import org.onosproject.net.PortNumber; |
47 | -import org.onosproject.net.SparseAnnotations; | ||
48 | import org.onosproject.net.device.DefaultDeviceDescription; | 46 | import org.onosproject.net.device.DefaultDeviceDescription; |
49 | import org.onosproject.net.device.DefaultPortDescription; | 47 | import org.onosproject.net.device.DefaultPortDescription; |
50 | import org.onosproject.net.device.DeviceAdminService; | 48 | import org.onosproject.net.device.DeviceAdminService; |
... | @@ -334,17 +332,8 @@ public class DeviceManager | ... | @@ -334,17 +332,8 @@ public class DeviceManager |
334 | BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class); | 332 | BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class); |
335 | checkState(cfg == null || cfg.isAllowed(), "Device " + deviceId + " is not allowed"); | 333 | checkState(cfg == null || cfg.isAllowed(), "Device " + deviceId + " is not allowed"); |
336 | log.info("Device {} connected", deviceId); | 334 | log.info("Device {} connected", deviceId); |
337 | - if (cfg != null) { | 335 | + |
338 | - SparseAnnotations finalSparse = processAnnotations(cfg, deviceDescription, deviceId); | 336 | + return BasicDeviceOperator.combine(cfg, deviceDescription); |
339 | - if (cfg.type() != Type.SWITCH) { | ||
340 | - deviceDescription = new DefaultDeviceDescription(deviceDescription, | ||
341 | - cfg.type(), finalSparse); | ||
342 | - } else { | ||
343 | - deviceDescription = new DefaultDeviceDescription(deviceDescription, | ||
344 | - deviceDescription.type(), finalSparse); | ||
345 | - } | ||
346 | - } | ||
347 | - return deviceDescription; | ||
348 | } | 337 | } |
349 | 338 | ||
350 | @Override | 339 | @Override |
... | @@ -500,37 +489,6 @@ public class DeviceManager | ... | @@ -500,37 +489,6 @@ public class DeviceManager |
500 | deviceId, portStatistics); | 489 | deviceId, portStatistics); |
501 | post(event); | 490 | post(event); |
502 | } | 491 | } |
503 | - | ||
504 | - // supplements or replaces deviceDescription annotations with | ||
505 | - // BasicDeviceConfig annotations | ||
506 | - private SparseAnnotations processAnnotations(BasicDeviceConfig cfg, DeviceDescription deviceDescription, | ||
507 | - DeviceId deviceId) { | ||
508 | - SparseAnnotations originalAnnotations = deviceDescription.annotations(); | ||
509 | - DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); | ||
510 | - if (cfg.driver() != deviceId.toString()) { | ||
511 | - newBuilder.set(cfg.DRIVER, cfg.driver()); | ||
512 | - } | ||
513 | - if (cfg.type() != Type.SWITCH) { | ||
514 | - newBuilder.set(cfg.TYPE, cfg.type().toString()); | ||
515 | - } | ||
516 | - if (cfg.name() != null) { | ||
517 | - newBuilder.set(cfg.NAME, cfg.name()); | ||
518 | - } | ||
519 | - if (cfg.latitude() != -1) { | ||
520 | - newBuilder.set(cfg.LATITUDE, Double.toString(cfg.latitude())); | ||
521 | - } | ||
522 | - if (cfg.longitude() != -1) { | ||
523 | - newBuilder.set(cfg.LONGITUDE, Double.toString(cfg.longitude())); | ||
524 | - } | ||
525 | - if (cfg.rackAddress() != null) { | ||
526 | - newBuilder.set(cfg.RACK_ADDRESS, cfg.rackAddress()); | ||
527 | - } | ||
528 | - if (cfg.owner() != null) { | ||
529 | - newBuilder.set(cfg.OWNER, cfg.owner()); | ||
530 | - } | ||
531 | - DefaultAnnotations newAnnotations = newBuilder.build(); | ||
532 | - return DefaultAnnotations.union(originalAnnotations, newAnnotations); | ||
533 | - } | ||
534 | } | 492 | } |
535 | 493 | ||
536 | // Applies the specified role to the device; ignores NONE | 494 | // Applies the specified role to the device; ignores NONE | ... | ... |
... | @@ -31,13 +31,10 @@ import org.onosproject.incubator.net.config.NetworkConfigListener; | ... | @@ -31,13 +31,10 @@ import org.onosproject.incubator.net.config.NetworkConfigListener; |
31 | import org.onosproject.incubator.net.config.NetworkConfigService; | 31 | import org.onosproject.incubator.net.config.NetworkConfigService; |
32 | import org.onosproject.incubator.net.config.basics.BasicHostConfig; | 32 | import org.onosproject.incubator.net.config.basics.BasicHostConfig; |
33 | import org.onosproject.net.ConnectPoint; | 33 | import org.onosproject.net.ConnectPoint; |
34 | -import org.onosproject.net.DefaultAnnotations; | ||
35 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
36 | import org.onosproject.net.Host; | 35 | import org.onosproject.net.Host; |
37 | import org.onosproject.net.HostId; | 36 | import org.onosproject.net.HostId; |
38 | -import org.onosproject.net.SparseAnnotations; | ||
39 | import org.onosproject.net.device.DeviceService; | 37 | import org.onosproject.net.device.DeviceService; |
40 | -import org.onosproject.net.host.DefaultHostDescription; | ||
41 | import org.onosproject.net.host.HostAdminService; | 38 | import org.onosproject.net.host.HostAdminService; |
42 | import org.onosproject.net.host.HostDescription; | 39 | import org.onosproject.net.host.HostDescription; |
43 | import org.onosproject.net.host.HostEvent; | 40 | import org.onosproject.net.host.HostEvent; |
... | @@ -246,14 +243,8 @@ public class HostManager | ... | @@ -246,14 +243,8 @@ public class HostManager |
246 | private HostDescription validateHost(HostDescription hostDescription, HostId hostId) { | 243 | private HostDescription validateHost(HostDescription hostDescription, HostId hostId) { |
247 | BasicHostConfig cfg = networkConfigService.getConfig(hostId, BasicHostConfig.class); | 244 | BasicHostConfig cfg = networkConfigService.getConfig(hostId, BasicHostConfig.class); |
248 | checkState(cfg == null || cfg.isAllowed(), "Host {} is not allowed", hostId); | 245 | checkState(cfg == null || cfg.isAllowed(), "Host {} is not allowed", hostId); |
249 | - if (cfg != null) { | 246 | + |
250 | - SparseAnnotations finalSparse = processAnnotations(cfg, hostDescription); | 247 | + return BasicHostOperator.combine(cfg, hostDescription); |
251 | - hostDescription = new DefaultHostDescription(hostId.mac(), | ||
252 | - hostDescription.vlan(), | ||
253 | - hostDescription.location(), | ||
254 | - finalSparse); | ||
255 | - } | ||
256 | - return hostDescription; | ||
257 | } | 248 | } |
258 | 249 | ||
259 | @Override | 250 | @Override |
... | @@ -267,30 +258,6 @@ public class HostManager | ... | @@ -267,30 +258,6 @@ public class HostManager |
267 | } | 258 | } |
268 | } | 259 | } |
269 | 260 | ||
270 | - // Supplements or replaces hostDescriptions's annotations with BasicHostConfig's | ||
271 | - // annotations | ||
272 | - private SparseAnnotations processAnnotations(BasicHostConfig cfg, HostDescription hostDescription) { | ||
273 | - SparseAnnotations originalAnnotations = hostDescription.annotations(); | ||
274 | - DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); | ||
275 | - if (cfg.name() != null) { | ||
276 | - newBuilder.set(cfg.NAME, cfg.name()); | ||
277 | - } | ||
278 | - if (cfg.latitude() != -1) { | ||
279 | - newBuilder.set(cfg.LATITUDE, Double.toString(cfg.latitude())); | ||
280 | - } | ||
281 | - if (cfg.longitude() != -1) { | ||
282 | - newBuilder.set(cfg.LONGITUDE, Double.toString(cfg.longitude())); | ||
283 | - } | ||
284 | - if (cfg.rackAddress() != null) { | ||
285 | - newBuilder.set(cfg.RACK_ADDRESS, cfg.rackAddress()); | ||
286 | - } | ||
287 | - if (cfg.owner() != null) { | ||
288 | - newBuilder.set(cfg.OWNER, cfg.owner()); | ||
289 | - } | ||
290 | - DefaultAnnotations newAnnotations = newBuilder.build(); | ||
291 | - return DefaultAnnotations.union(originalAnnotations, newAnnotations); | ||
292 | - } | ||
293 | - | ||
294 | // Store delegate to re-post events emitted from the store. | 261 | // Store delegate to re-post events emitted from the store. |
295 | private class InternalStoreDelegate implements HostStoreDelegate { | 262 | private class InternalStoreDelegate implements HostStoreDelegate { |
296 | @Override | 263 | @Override | ... | ... |
... | @@ -20,6 +20,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -20,6 +20,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
20 | import java.time.Duration; | 20 | import java.time.Duration; |
21 | 21 | ||
22 | import org.onosproject.net.AnnotationKeys; | 22 | import org.onosproject.net.AnnotationKeys; |
23 | +import org.onosproject.incubator.net.config.ConfigOperator; | ||
23 | import org.onosproject.incubator.net.config.basics.BasicLinkConfig; | 24 | import org.onosproject.incubator.net.config.basics.BasicLinkConfig; |
24 | import org.onosproject.net.DefaultAnnotations; | 25 | import org.onosproject.net.DefaultAnnotations; |
25 | import org.onosproject.net.Link; | 26 | import org.onosproject.net.Link; |
... | @@ -32,8 +33,10 @@ import org.slf4j.Logger; | ... | @@ -32,8 +33,10 @@ import org.slf4j.Logger; |
32 | * Implementations of merge policies for various sources of link configuration | 33 | * Implementations of merge policies for various sources of link configuration |
33 | * information. This includes applications, provides, and network configurations. | 34 | * information. This includes applications, provides, and network configurations. |
34 | */ | 35 | */ |
35 | -public final class BasicLinkOperator { | 36 | +public final class BasicLinkOperator implements ConfigOperator { |
36 | 37 | ||
38 | + private static final long DEF_BANDWIDTH = -1L; | ||
39 | + private static final Duration DEF_DURATION = Duration.ofNanos(-1L); | ||
37 | private static final Logger log = getLogger(BasicLinkOperator.class); | 40 | private static final Logger log = getLogger(BasicLinkOperator.class); |
38 | 41 | ||
39 | private BasicLinkOperator() { | 42 | private BasicLinkOperator() { |
... | @@ -72,10 +75,10 @@ public final class BasicLinkOperator { | ... | @@ -72,10 +75,10 @@ public final class BasicLinkOperator { |
72 | */ | 75 | */ |
73 | public static SparseAnnotations combine(BasicLinkConfig cfg, SparseAnnotations an) { | 76 | public static SparseAnnotations combine(BasicLinkConfig cfg, SparseAnnotations an) { |
74 | DefaultAnnotations.Builder b = DefaultAnnotations.builder(); | 77 | DefaultAnnotations.Builder b = DefaultAnnotations.builder(); |
75 | - if (cfg.latency() != Duration.ofNanos(-1)) { | 78 | + if (cfg.latency() != DEF_DURATION) { |
76 | b.set(AnnotationKeys.LATENCY, cfg.latency().toString()); | 79 | b.set(AnnotationKeys.LATENCY, cfg.latency().toString()); |
77 | } | 80 | } |
78 | - if (cfg.bandwidth() != -1) { | 81 | + if (cfg.bandwidth() != DEF_BANDWIDTH) { |
79 | b.set(AnnotationKeys.BANDWIDTH, String.valueOf(cfg.bandwidth())); | 82 | b.set(AnnotationKeys.BANDWIDTH, String.valueOf(cfg.bandwidth())); |
80 | } | 83 | } |
81 | return DefaultAnnotations.union(an, b.build()); | 84 | return DefaultAnnotations.union(an, b.build()); | ... | ... |
... | @@ -31,17 +31,14 @@ import org.onosproject.incubator.net.config.NetworkConfigListener; | ... | @@ -31,17 +31,14 @@ import org.onosproject.incubator.net.config.NetworkConfigListener; |
31 | import org.onosproject.incubator.net.config.NetworkConfigService; | 31 | import org.onosproject.incubator.net.config.NetworkConfigService; |
32 | import org.onosproject.incubator.net.config.basics.BasicLinkConfig; | 32 | import org.onosproject.incubator.net.config.basics.BasicLinkConfig; |
33 | import org.onosproject.net.ConnectPoint; | 33 | import org.onosproject.net.ConnectPoint; |
34 | -import org.onosproject.net.DefaultAnnotations; | ||
35 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
36 | import org.onosproject.net.Link; | 35 | import org.onosproject.net.Link; |
37 | import org.onosproject.net.Link.State; | 36 | import org.onosproject.net.Link.State; |
38 | import org.onosproject.net.LinkKey; | 37 | import org.onosproject.net.LinkKey; |
39 | import org.onosproject.net.MastershipRole; | 38 | import org.onosproject.net.MastershipRole; |
40 | -import org.onosproject.net.SparseAnnotations; | ||
41 | import org.onosproject.net.device.DeviceEvent; | 39 | import org.onosproject.net.device.DeviceEvent; |
42 | import org.onosproject.net.device.DeviceListener; | 40 | import org.onosproject.net.device.DeviceListener; |
43 | import org.onosproject.net.device.DeviceService; | 41 | import org.onosproject.net.device.DeviceService; |
44 | -import org.onosproject.net.link.DefaultLinkDescription; | ||
45 | import org.onosproject.net.link.LinkAdminService; | 42 | import org.onosproject.net.link.LinkAdminService; |
46 | import org.onosproject.net.link.LinkDescription; | 43 | import org.onosproject.net.link.LinkDescription; |
47 | import org.onosproject.net.link.LinkEvent; | 44 | import org.onosproject.net.link.LinkEvent; |
... | @@ -55,7 +52,6 @@ import org.onosproject.net.link.LinkStoreDelegate; | ... | @@ -55,7 +52,6 @@ import org.onosproject.net.link.LinkStoreDelegate; |
55 | import org.onosproject.net.provider.AbstractProviderService; | 52 | import org.onosproject.net.provider.AbstractProviderService; |
56 | import org.slf4j.Logger; | 53 | import org.slf4j.Logger; |
57 | 54 | ||
58 | -import java.time.Duration; | ||
59 | import java.util.Set; | 55 | import java.util.Set; |
60 | 56 | ||
61 | import static com.google.common.base.Preconditions.checkNotNull; | 57 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -206,6 +202,7 @@ public class LinkManager | ... | @@ -206,6 +202,7 @@ public class LinkManager |
206 | removeLinks(getDeviceLinks(deviceId), false); | 202 | removeLinks(getDeviceLinks(deviceId), false); |
207 | } | 203 | } |
208 | 204 | ||
205 | + @Override | ||
209 | public void removeLink(ConnectPoint src, ConnectPoint dst) { | 206 | public void removeLink(ConnectPoint src, ConnectPoint dst) { |
210 | post(store.removeLink(src, dst)); | 207 | post(store.removeLink(src, dst)); |
211 | } | 208 | } |
... | @@ -264,38 +261,8 @@ public class LinkManager | ... | @@ -264,38 +261,8 @@ public class LinkManager |
264 | 261 | ||
265 | checkState(cfg == null || cfg.isAllowed(), "Link " + linkDescription.toString() + " is not allowed"); | 262 | checkState(cfg == null || cfg.isAllowed(), "Link " + linkDescription.toString() + " is not allowed"); |
266 | checkState(cfgTwo == null || cfgTwo.isAllowed(), "Link " + linkDescription.toString() + " is not allowed"); | 263 | checkState(cfgTwo == null || cfgTwo.isAllowed(), "Link " + linkDescription.toString() + " is not allowed"); |
267 | - if (cfg != null) { | 264 | + |
268 | - SparseAnnotations finalSparse = processAnnotations(cfg, linkDescription); | 265 | + return BasicLinkOperator.combine(cfg, linkDescription); |
269 | - // check whether config has a specified type | ||
270 | - if (cfg.type() != Link.Type.DIRECT) { | ||
271 | - linkDescription = new DefaultLinkDescription(linkDescription.src(), | ||
272 | - linkDescription.dst(), | ||
273 | - cfg.type(), finalSparse); | ||
274 | - } else { | ||
275 | - linkDescription = new DefaultLinkDescription(linkDescription.src(), | ||
276 | - linkDescription.dst(), | ||
277 | - linkDescription.type(), finalSparse); | ||
278 | - } | ||
279 | - } | ||
280 | - return linkDescription; | ||
281 | - } | ||
282 | - | ||
283 | - // supplements or replaces linkDescriptions's annotations with BasicLinkConfig's | ||
284 | - // annotations | ||
285 | - private SparseAnnotations processAnnotations(BasicLinkConfig cfg, LinkDescription linkDescription) { | ||
286 | - SparseAnnotations originalAnnotations = linkDescription.annotations(); | ||
287 | - DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); | ||
288 | - if (cfg.type() != Link.Type.DIRECT) { | ||
289 | - newBuilder.set(cfg.TYPE, cfg.type().toString()); | ||
290 | - } | ||
291 | - if (cfg.latency() != Duration.ofNanos(-1)) { | ||
292 | - newBuilder.set(cfg.LATENCY, cfg.latency().toString()); | ||
293 | - } | ||
294 | - if (cfg.bandwidth() != -1) { | ||
295 | - newBuilder.set(cfg.BANDWIDTH, String.valueOf(cfg.bandwidth())); | ||
296 | - } | ||
297 | - DefaultAnnotations newAnnotations = newBuilder.build(); | ||
298 | - return DefaultAnnotations.union(originalAnnotations, newAnnotations); | ||
299 | } | 266 | } |
300 | 267 | ||
301 | @Override | 268 | @Override | ... | ... |
-
Please register or login to post a comment