Initial implementation of the intent domain manager
Change-Id: I9721449599a4a67bfad7469173c3b47a681873f6
Showing
14 changed files
with
388 additions
and
28 deletions
| ... | @@ -70,7 +70,7 @@ import static org.onosproject.security.AppGuard.checkPermission; | ... | @@ -70,7 +70,7 @@ import static org.onosproject.security.AppGuard.checkPermission; |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | /** | 72 | /** |
| 73 | - * An implementation of Intent Manager. | 73 | + * An implementation of intent service. |
| 74 | */ | 74 | */ |
| 75 | @Component(immediate = true) | 75 | @Component(immediate = true) |
| 76 | @Service | 76 | @Service | ... | ... |
| ... | @@ -41,6 +41,10 @@ | ... | @@ -41,6 +41,10 @@ |
| 41 | <artifactId>guava-testlib</artifactId> | 41 | <artifactId>guava-testlib</artifactId> |
| 42 | <scope>test</scope> | 42 | <scope>test</scope> |
| 43 | </dependency> | 43 | </dependency> |
| 44 | + <dependency> | ||
| 45 | + <groupId>org.onosproject</groupId> | ||
| 46 | + <artifactId>onos-incubator-api</artifactId> | ||
| 47 | + </dependency> | ||
| 44 | </dependencies> | 48 | </dependencies> |
| 45 | 49 | ||
| 46 | </project> | 50 | </project> | ... | ... |
| ... | @@ -45,6 +45,7 @@ import org.onosproject.core.DefaultApplication; | ... | @@ -45,6 +45,7 @@ import org.onosproject.core.DefaultApplication; |
| 45 | import org.onosproject.core.DefaultApplicationId; | 45 | import org.onosproject.core.DefaultApplicationId; |
| 46 | import org.onosproject.core.DefaultGroupId; | 46 | import org.onosproject.core.DefaultGroupId; |
| 47 | import org.onosproject.core.Version; | 47 | import org.onosproject.core.Version; |
| 48 | +import org.onosproject.incubator.net.domain.IntentDomainId; | ||
| 48 | import org.onosproject.mastership.MastershipTerm; | 49 | import org.onosproject.mastership.MastershipTerm; |
| 49 | import org.onosproject.net.Annotations; | 50 | import org.onosproject.net.Annotations; |
| 50 | import org.onosproject.net.ChannelSpacing; | 51 | import org.onosproject.net.ChannelSpacing; |
| ... | @@ -416,7 +417,8 @@ public final class KryoNamespaces { | ... | @@ -416,7 +417,8 @@ public final class KryoNamespaces { |
| 416 | Frequency.class, | 417 | Frequency.class, |
| 417 | DefaultAnnotations.class, | 418 | DefaultAnnotations.class, |
| 418 | PortStatistics.class, | 419 | PortStatistics.class, |
| 419 | - DefaultPortStatistics.class | 420 | + DefaultPortStatistics.class, |
| 421 | + IntentDomainId.class | ||
| 420 | ) | 422 | ) |
| 421 | .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class) | 423 | .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class) |
| 422 | .register(new URISerializer(), URI.class) | 424 | .register(new URISerializer(), URI.class) | ... | ... |
| ... | @@ -16,8 +16,14 @@ | ... | @@ -16,8 +16,14 @@ |
| 16 | package org.onosproject.incubator.net.config; | 16 | package org.onosproject.incubator.net.config; |
| 17 | 17 | ||
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import com.google.common.annotations.Beta; | 21 | import com.google.common.annotations.Beta; |
| 22 | +import com.google.common.collect.Lists; | ||
| 23 | + | ||
| 24 | +import java.util.Collection; | ||
| 25 | +import java.util.List; | ||
| 26 | +import java.util.function.Function; | ||
| 21 | 27 | ||
| 22 | import static com.google.common.base.Preconditions.checkNotNull; | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 23 | 29 | ||
| ... | @@ -259,4 +265,39 @@ public abstract class Config<S> { | ... | @@ -259,4 +265,39 @@ public abstract class Config<S> { |
| 259 | return this; | 265 | return this; |
| 260 | } | 266 | } |
| 261 | 267 | ||
| 268 | + /** | ||
| 269 | + * Gets the specified array property as a list of items. | ||
| 270 | + * | ||
| 271 | + * @param name property name | ||
| 272 | + * @param function mapper from string to item | ||
| 273 | + * @param <T> type of item | ||
| 274 | + * @return list of items | ||
| 275 | + */ | ||
| 276 | + protected <T> List<T> getList(String name, Function<String, T> function) { | ||
| 277 | + List<T> list = Lists.newArrayList(); | ||
| 278 | + ArrayNode arrayNode = (ArrayNode) node.path(name); | ||
| 279 | + arrayNode.forEach(i -> list.add(function.apply(i.asText()))); | ||
| 280 | + return list; | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + /** | ||
| 284 | + * Sets the specified property as an array of items in a given collection or | ||
| 285 | + * clears it if null is given. | ||
| 286 | + * | ||
| 287 | + * @param name propertyName | ||
| 288 | + * @param collection collection of items | ||
| 289 | + * @param <T> type of items | ||
| 290 | + * @return self | ||
| 291 | + */ | ||
| 292 | + protected <T> Config<S> setOrClear(String name, Collection<T> collection) { | ||
| 293 | + if (collection == null) { | ||
| 294 | + node.remove(name); | ||
| 295 | + } else { | ||
| 296 | + ArrayNode arrayNode = mapper.createArrayNode(); | ||
| 297 | + collection.forEach(i -> arrayNode.add(i.toString())); | ||
| 298 | + node.set(name, arrayNode); | ||
| 299 | + } | ||
| 300 | + return this; | ||
| 301 | + } | ||
| 302 | + | ||
| 262 | } | 303 | } | ... | ... |
| ... | @@ -18,6 +18,7 @@ package org.onosproject.incubator.net.config.basics; | ... | @@ -18,6 +18,7 @@ package org.onosproject.incubator.net.config.basics; |
| 18 | import org.onosproject.core.ApplicationId; | 18 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.core.CoreService; | 19 | import org.onosproject.core.CoreService; |
| 20 | import org.onosproject.incubator.net.config.SubjectFactory; | 20 | import org.onosproject.incubator.net.config.SubjectFactory; |
| 21 | +import org.onosproject.incubator.net.domain.IntentDomainId; | ||
| 21 | import org.onosproject.net.ConnectPoint; | 22 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.HostId; | 24 | import org.onosproject.net.HostId; |
| ... | @@ -80,6 +81,14 @@ public final class SubjectFactories { | ... | @@ -80,6 +81,14 @@ public final class SubjectFactories { |
| 80 | } | 81 | } |
| 81 | }; | 82 | }; |
| 82 | 83 | ||
| 84 | + public static final SubjectFactory<IntentDomainId> INTENT_DOMAIN_SUBJECT_FACTORY = | ||
| 85 | + new SubjectFactory<IntentDomainId>(IntentDomainId.class, "domains") { | ||
| 86 | + @Override | ||
| 87 | + public IntentDomainId createSubject(String key) { | ||
| 88 | + return IntentDomainId.valueOf(key); | ||
| 89 | + } | ||
| 90 | + }; | ||
| 91 | + | ||
| 83 | /** | 92 | /** |
| 84 | * Provides reference to the core service, which is required for | 93 | * Provides reference to the core service, which is required for |
| 85 | * application subject factory. | 94 | * application subject factory. | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.incubator.net.domain; | 16 | package org.onosproject.incubator.net.domain; |
| 17 | 17 | ||
| 18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
| 19 | +import com.google.common.base.MoreObjects; | ||
| 19 | import org.onlab.graph.Vertex; | 20 | import org.onlab.graph.Vertex; |
| 20 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
| 21 | 22 | ||
| ... | @@ -30,23 +31,39 @@ public class DomainVertex implements Vertex { | ... | @@ -30,23 +31,39 @@ public class DomainVertex implements Vertex { |
| 30 | // FIXME we will want to add a type enum or subclasses for the two different types | 31 | // FIXME we will want to add a type enum or subclasses for the two different types |
| 31 | 32 | ||
| 32 | // A domain vertex is either an intent domain or a device: | 33 | // A domain vertex is either an intent domain or a device: |
| 33 | - private final IntentDomainId id; | 34 | + private final IntentDomainId domainId; |
| 34 | // ----- or ----- | 35 | // ----- or ----- |
| 35 | private final DeviceId deviceId; | 36 | private final DeviceId deviceId; |
| 36 | 37 | ||
| 37 | // Serialization constructor | 38 | // Serialization constructor |
| 38 | private DomainVertex() { | 39 | private DomainVertex() { |
| 39 | - this.id = null; | 40 | + this.domainId = null; |
| 40 | this.deviceId = null; | 41 | this.deviceId = null; |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | - DomainVertex(IntentDomainId id) { | 44 | + public DomainVertex(IntentDomainId id) { |
| 44 | - this.id = checkNotNull(id, "Intent domain ID cannot be null."); | 45 | + this.domainId = checkNotNull(id, "Intent domain ID cannot be null."); |
| 45 | this.deviceId = null; | 46 | this.deviceId = null; |
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | - DomainVertex(DeviceId id) { | 49 | + public DomainVertex(DeviceId id) { |
| 49 | - this.id = null; | 50 | + this.domainId = null; |
| 50 | this.deviceId = checkNotNull(id, "Device ID cannot be null."); | 51 | this.deviceId = checkNotNull(id, "Device ID cannot be null."); |
| 51 | } | 52 | } |
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public String toString() { | ||
| 56 | + if (domainId != null) { | ||
| 57 | + return MoreObjects.toStringHelper(this) | ||
| 58 | + .add("domainId", domainId) | ||
| 59 | + .toString(); | ||
| 60 | + } else if (deviceId != null) { | ||
| 61 | + return MoreObjects.toStringHelper(this) | ||
| 62 | + .add("deviceId", deviceId) | ||
| 63 | + .toString(); | ||
| 64 | + } else { | ||
| 65 | + return MoreObjects.toStringHelper(this) | ||
| 66 | + .toString(); | ||
| 67 | + } | ||
| 68 | + } | ||
| 52 | } | 69 | } | ... | ... |
| ... | @@ -19,7 +19,6 @@ import com.google.common.annotations.Beta; | ... | @@ -19,7 +19,6 @@ import com.google.common.annotations.Beta; |
| 19 | import org.onosproject.net.ConnectPoint; | 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
| 21 | 21 | ||
| 22 | -import java.util.Objects; | ||
| 23 | import java.util.Set; | 22 | import java.util.Set; |
| 24 | 23 | ||
| 25 | /** | 24 | /** |
| ... | @@ -37,7 +36,7 @@ public class IntentDomain { | ... | @@ -37,7 +36,7 @@ public class IntentDomain { |
| 37 | 36 | ||
| 38 | private IntentDomainProvider provider; | 37 | private IntentDomainProvider provider; |
| 39 | 38 | ||
| 40 | - IntentDomain(IntentDomainId id, String name, | 39 | + public IntentDomain(IntentDomainId id, String name, |
| 41 | Set<DeviceId> internalDevices, | 40 | Set<DeviceId> internalDevices, |
| 42 | Set<ConnectPoint> edgePorts) { | 41 | Set<ConnectPoint> edgePorts) { |
| 43 | this.id = id; | 42 | this.id = id; |
| ... | @@ -88,7 +87,7 @@ public class IntentDomain { | ... | @@ -88,7 +87,7 @@ public class IntentDomain { |
| 88 | * | 87 | * |
| 89 | * @return intent domain provider | 88 | * @return intent domain provider |
| 90 | */ | 89 | */ |
| 91 | - IntentDomainProvider provider() { | 90 | + public IntentDomainProvider provider() { |
| 92 | return provider; | 91 | return provider; |
| 93 | } | 92 | } |
| 94 | 93 | ||
| ... | @@ -115,17 +114,11 @@ public class IntentDomain { | ... | @@ -115,17 +114,11 @@ public class IntentDomain { |
| 115 | } | 114 | } |
| 116 | 115 | ||
| 117 | /** | 116 | /** |
| 118 | - * Unsets the provider for the intent domain if the given provider matches | 117 | + * Unsets the provider for the intent domain. |
| 119 | - * the existing provider. | ||
| 120 | - * | ||
| 121 | - * @param provider provider to unset | ||
| 122 | */ | 118 | */ |
| 123 | - public void unsetProvider(IntentDomainProvider provider) { | 119 | + public void unsetProvider() { |
| 124 | - // TODO consider checkState depending on caller | ||
| 125 | - if (Objects.equals(this.provider, provider)) { | ||
| 126 | this.provider = null; | 120 | this.provider = null; |
| 127 | } | 121 | } |
| 128 | - } | ||
| 129 | 122 | ||
| 130 | //TODO add remaining setters (we will probably want to link this to the network config) | 123 | //TODO add remaining setters (we will probably want to link this to the network config) |
| 131 | } | 124 | } | ... | ... |
| ... | @@ -22,7 +22,7 @@ import org.onosproject.core.ApplicationId; | ... | @@ -22,7 +22,7 @@ import org.onosproject.core.ApplicationId; |
| 22 | * Administrative interface for the intent domain service. | 22 | * Administrative interface for the intent domain service. |
| 23 | */ | 23 | */ |
| 24 | @Beta | 24 | @Beta |
| 25 | -public interface IntentDomainAdminService { | 25 | +public interface IntentDomainAdminService extends IntentDomainService { |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * Register an application that provides intent domain service. | 28 | * Register an application that provides intent domain service. | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.incubator.net.domain; | 16 | package org.onosproject.incubator.net.domain; |
| 17 | 17 | ||
| 18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
| 19 | +import com.google.common.collect.ImmutableSet; | ||
| 19 | import org.onosproject.incubator.net.config.Config; | 20 | import org.onosproject.incubator.net.config.Config; |
| 20 | import org.onosproject.net.ConnectPoint; | 21 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.DeviceId; | 22 | import org.onosproject.net.DeviceId; |
| ... | @@ -27,10 +28,13 @@ import java.util.Set; | ... | @@ -27,10 +28,13 @@ import java.util.Set; |
| 27 | * set of edge ports, and the application bound to control the domain. | 28 | * set of edge ports, and the application bound to control the domain. |
| 28 | */ | 29 | */ |
| 29 | @Beta | 30 | @Beta |
| 30 | -public abstract class IntentDomainConfig extends Config<IntentDomainId> { | 31 | +public class IntentDomainConfig extends Config<IntentDomainId> { |
| 31 | 32 | ||
| 32 | - private static final String DOMAIN_NAME = "domainName"; | 33 | + private static final String DOMAIN_NAME = "name"; |
| 33 | private static final String APPLICATION_NAME = "applicationName"; | 34 | private static final String APPLICATION_NAME = "applicationName"; |
| 35 | + private static final String INTERNAL_DEVICES = "internalDevices"; | ||
| 36 | + private static final String EDGE_PORTS = "edgePorts"; | ||
| 37 | + | ||
| 34 | 38 | ||
| 35 | /** | 39 | /** |
| 36 | * Returns the friendly name for the domain. | 40 | * Returns the friendly name for the domain. |
| ... | @@ -57,7 +61,7 @@ public abstract class IntentDomainConfig extends Config<IntentDomainId> { | ... | @@ -57,7 +61,7 @@ public abstract class IntentDomainConfig extends Config<IntentDomainId> { |
| 57 | * @return domain name | 61 | * @return domain name |
| 58 | */ | 62 | */ |
| 59 | public String applicationName() { | 63 | public String applicationName() { |
| 60 | - return get(APPLICATION_NAME, null); //TODO maybe not null? | 64 | + return get(APPLICATION_NAME, "FIXME"); //TODO maybe not null? |
| 61 | } | 65 | } |
| 62 | 66 | ||
| 63 | /** | 67 | /** |
| ... | @@ -70,8 +74,42 @@ public abstract class IntentDomainConfig extends Config<IntentDomainId> { | ... | @@ -70,8 +74,42 @@ public abstract class IntentDomainConfig extends Config<IntentDomainId> { |
| 70 | return (IntentDomainConfig) setOrClear(APPLICATION_NAME, applicationName); | 74 | return (IntentDomainConfig) setOrClear(APPLICATION_NAME, applicationName); |
| 71 | } | 75 | } |
| 72 | 76 | ||
| 73 | - //TODO sets | 77 | + /** |
| 74 | - abstract Set<DeviceId> internalDevices(); | 78 | + * Returns the set of internal devices. |
| 75 | - abstract Set<ConnectPoint> edgePorts(); | 79 | + * |
| 80 | + * @return set of internal devices | ||
| 81 | + */ | ||
| 82 | + public Set<DeviceId> internalDevices() { | ||
| 83 | + return ImmutableSet.copyOf(getList(INTERNAL_DEVICES, DeviceId::deviceId)); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Sets the set of internal devices. | ||
| 88 | + * | ||
| 89 | + * @param devices set of devices; null to clear | ||
| 90 | + * @return self | ||
| 91 | + */ | ||
| 92 | + public IntentDomainConfig internalDevices(Set<DeviceId> devices) { | ||
| 93 | + return (IntentDomainConfig) setOrClear(INTERNAL_DEVICES, devices); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * Returns the set of edge ports. | ||
| 98 | + * | ||
| 99 | + * @return set of edge ports | ||
| 100 | + */ | ||
| 101 | + public Set<ConnectPoint> edgePorts() { | ||
| 102 | + return ImmutableSet.copyOf(getList(EDGE_PORTS, ConnectPoint::deviceConnectPoint)); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * Sets the set of edge ports. | ||
| 107 | + * | ||
| 108 | + * @param connectPoints set of edge ports; null to clear | ||
| 109 | + * @return self | ||
| 110 | + */ | ||
| 111 | + public IntentDomainConfig edgePorts(Set<ConnectPoint> connectPoints) { | ||
| 112 | + return (IntentDomainConfig) setOrClear(EDGE_PORTS, connectPoints); | ||
| 113 | + } | ||
| 76 | 114 | ||
| 77 | } | 115 | } | ... | ... |
| ... | @@ -26,7 +26,7 @@ public abstract class IntentPrimitive { | ... | @@ -26,7 +26,7 @@ public abstract class IntentPrimitive { |
| 26 | 26 | ||
| 27 | private final ApplicationId appId; | 27 | private final ApplicationId appId; |
| 28 | 28 | ||
| 29 | - IntentPrimitive(ApplicationId appId) { | 29 | + public IntentPrimitive(ApplicationId appId) { |
| 30 | this.appId = appId; | 30 | this.appId = appId; |
| 31 | } | 31 | } |
| 32 | } | 32 | } | ... | ... |
| ... | @@ -26,7 +26,7 @@ import com.google.common.annotations.Beta; | ... | @@ -26,7 +26,7 @@ import com.google.common.annotations.Beta; |
| 26 | * also be automatically cancelled by a provider after a short timeout. | 26 | * also be automatically cancelled by a provider after a short timeout. |
| 27 | */ | 27 | */ |
| 28 | @Beta | 28 | @Beta |
| 29 | -class RequestContext { | 29 | +public class RequestContext { |
| 30 | IntentDomain domain; | 30 | IntentDomain domain; |
| 31 | IntentResource resource; | 31 | IntentResource resource; |
| 32 | //TODO other common parameters: | 32 | //TODO other common parameters: | ... | ... |
| ... | @@ -29,6 +29,8 @@ import org.onosproject.incubator.net.config.basics.BasicHostConfig; | ... | @@ -29,6 +29,8 @@ import org.onosproject.incubator.net.config.basics.BasicHostConfig; |
| 29 | import org.onosproject.incubator.net.config.basics.BasicLinkConfig; | 29 | import org.onosproject.incubator.net.config.basics.BasicLinkConfig; |
| 30 | import org.onosproject.incubator.net.config.basics.BasicPortConfig; | 30 | import org.onosproject.incubator.net.config.basics.BasicPortConfig; |
| 31 | import org.onosproject.incubator.net.config.basics.SubjectFactories; | 31 | import org.onosproject.incubator.net.config.basics.SubjectFactories; |
| 32 | +import org.onosproject.incubator.net.domain.IntentDomainConfig; | ||
| 33 | +import org.onosproject.incubator.net.domain.IntentDomainId; | ||
| 32 | import org.onosproject.net.ConnectPoint; | 34 | import org.onosproject.net.ConnectPoint; |
| 33 | import org.onosproject.net.DeviceId; | 35 | import org.onosproject.net.DeviceId; |
| 34 | import org.onosproject.net.HostId; | 36 | import org.onosproject.net.HostId; |
| ... | @@ -80,6 +82,14 @@ public class BasicNetworkConfigs { | ... | @@ -80,6 +82,14 @@ public class BasicNetworkConfigs { |
| 80 | public BasicLinkConfig createConfig() { | 82 | public BasicLinkConfig createConfig() { |
| 81 | return new BasicLinkConfig(); | 83 | return new BasicLinkConfig(); |
| 82 | } | 84 | } |
| 85 | + }, | ||
| 86 | + new ConfigFactory<IntentDomainId, IntentDomainConfig>(INTENT_DOMAIN_SUBJECT_FACTORY, | ||
| 87 | + IntentDomainConfig.class, | ||
| 88 | + "basic") { | ||
| 89 | + @Override | ||
| 90 | + public IntentDomainConfig createConfig() { | ||
| 91 | + return new IntentDomainConfig(); | ||
| 92 | + } | ||
| 83 | } | 93 | } |
| 84 | ); | 94 | ); |
| 85 | 95 | ... | ... |
incubator/net/src/main/java/org/onosproject/incubator/net/domain/impl/IntentDomainManager.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.net.domain.impl; | ||
| 17 | + | ||
| 18 | +import com.google.common.collect.HashMultimap; | ||
| 19 | +import com.google.common.collect.ImmutableSet; | ||
| 20 | +import com.google.common.collect.Maps; | ||
| 21 | +import com.google.common.collect.Multimap; | ||
| 22 | +import com.google.common.collect.Multimaps; | ||
| 23 | +import com.google.common.collect.Sets; | ||
| 24 | +import org.apache.felix.scr.annotations.Activate; | ||
| 25 | +import org.apache.felix.scr.annotations.Component; | ||
| 26 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 27 | +import org.apache.felix.scr.annotations.Reference; | ||
| 28 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 29 | +import org.apache.felix.scr.annotations.Service; | ||
| 30 | +import org.onlab.graph.AdjacencyListsGraph; | ||
| 31 | +import org.onlab.graph.Graph; | ||
| 32 | +import org.onosproject.core.ApplicationId; | ||
| 33 | +import org.onosproject.core.CoreService; | ||
| 34 | +import org.onosproject.incubator.net.config.NetworkConfigEvent; | ||
| 35 | +import org.onosproject.incubator.net.config.NetworkConfigListener; | ||
| 36 | +import org.onosproject.incubator.net.config.NetworkConfigService; | ||
| 37 | +import org.onosproject.incubator.net.domain.DomainEdge; | ||
| 38 | +import org.onosproject.incubator.net.domain.DomainVertex; | ||
| 39 | +import org.onosproject.incubator.net.domain.IntentDomain; | ||
| 40 | +import org.onosproject.incubator.net.domain.IntentDomainAdminService; | ||
| 41 | +import org.onosproject.incubator.net.domain.IntentDomainConfig; | ||
| 42 | +import org.onosproject.incubator.net.domain.IntentDomainId; | ||
| 43 | +import org.onosproject.incubator.net.domain.IntentDomainListener; | ||
| 44 | +import org.onosproject.incubator.net.domain.IntentDomainProvider; | ||
| 45 | +import org.onosproject.incubator.net.domain.IntentDomainService; | ||
| 46 | +import org.onosproject.net.ConnectPoint; | ||
| 47 | +import org.onosproject.net.DeviceId; | ||
| 48 | +import org.slf4j.Logger; | ||
| 49 | +import org.slf4j.LoggerFactory; | ||
| 50 | + | ||
| 51 | +import java.util.Map; | ||
| 52 | +import java.util.Set; | ||
| 53 | +import java.util.concurrent.ConcurrentMap; | ||
| 54 | +import java.util.stream.Collectors; | ||
| 55 | + | ||
| 56 | +/** | ||
| 57 | + * Implementation of the intent domain service. | ||
| 58 | + */ | ||
| 59 | +@Component(immediate = true) | ||
| 60 | +@Service | ||
| 61 | +public class IntentDomainManager | ||
| 62 | + implements IntentDomainService, IntentDomainAdminService { | ||
| 63 | + | ||
| 64 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 65 | + | ||
| 66 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 67 | + protected CoreService coreService; | ||
| 68 | + | ||
| 69 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 70 | + protected NetworkConfigService configService; | ||
| 71 | + | ||
| 72 | + private NetworkConfigListener cfgListener = new InternalConfigListener(); | ||
| 73 | + | ||
| 74 | + private final ConcurrentMap<IntentDomainId, IntentDomain> domains = Maps.newConcurrentMap(); | ||
| 75 | + | ||
| 76 | + private final Multimap<String, IntentDomainId> appToDomain = | ||
| 77 | + Multimaps.synchronizedSetMultimap(HashMultimap.<String, IntentDomainId>create()); | ||
| 78 | + | ||
| 79 | + private Graph<DomainVertex, DomainEdge> graph; | ||
| 80 | + | ||
| 81 | + @Activate | ||
| 82 | + protected void activate() { | ||
| 83 | + configService.addListener(cfgListener); | ||
| 84 | + configService.getSubjects(IntentDomainId.class, IntentDomainConfig.class) | ||
| 85 | + .forEach(this::processConfig); | ||
| 86 | + graph = buildGraph(); | ||
| 87 | + log.debug("Graph: {}", graph); | ||
| 88 | + log.info("Started"); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + private void processConfig(IntentDomainId intentDomainId) { | ||
| 92 | + IntentDomainConfig cfg = configService.getConfig(intentDomainId, | ||
| 93 | + IntentDomainConfig.class); | ||
| 94 | + | ||
| 95 | + domains.put(intentDomainId, createDomain(intentDomainId, cfg)); | ||
| 96 | + appToDomain.put(cfg.applicationName(), intentDomainId); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + private IntentDomain createDomain(IntentDomainId id, IntentDomainConfig cfg) { | ||
| 100 | + return new IntentDomain(id, cfg.domainName(), cfg.internalDevices(), cfg.edgePorts()); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + private Graph<DomainVertex, DomainEdge> buildGraph() { | ||
| 104 | + Set<DomainVertex> vertices = Sets.newHashSet(); | ||
| 105 | + Set<DomainEdge> edges = Sets.newHashSet(); | ||
| 106 | + | ||
| 107 | + Map<DeviceId, DomainVertex> deviceVertices = Maps.newHashMap(); | ||
| 108 | + domains.forEach((id, domain) -> { | ||
| 109 | + DomainVertex domainVertex = new DomainVertex(id); | ||
| 110 | + | ||
| 111 | + // Add vertex for domain | ||
| 112 | + vertices.add(domainVertex); | ||
| 113 | + | ||
| 114 | + // Add vertices for connection devices | ||
| 115 | + domain.edgePorts().stream() | ||
| 116 | + .map(ConnectPoint::deviceId) | ||
| 117 | + .collect(Collectors.toSet()) | ||
| 118 | + .forEach(did -> deviceVertices.putIfAbsent(did, new DomainVertex(did))); | ||
| 119 | + | ||
| 120 | + // Add bi-directional edges between each domain and connection device | ||
| 121 | + domain.edgePorts().forEach(cp -> { | ||
| 122 | + DomainVertex deviceVertex = deviceVertices.get(cp.deviceId()); | ||
| 123 | + edges.add(new DomainEdge(domainVertex, deviceVertex, cp)); | ||
| 124 | + edges.add(new DomainEdge(deviceVertex, domainVertex, cp)); | ||
| 125 | + }); | ||
| 126 | + }); | ||
| 127 | + | ||
| 128 | + vertices.addAll(deviceVertices.values()); | ||
| 129 | + //FIXME verify graph integrity... | ||
| 130 | + return new AdjacencyListsGraph<>(vertices, edges); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + @Deactivate | ||
| 134 | + protected void deactivate() { | ||
| 135 | + configService.removeListener(cfgListener); | ||
| 136 | + log.info("Stopped"); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + @Override | ||
| 140 | + public IntentDomain getDomain(IntentDomainId id) { | ||
| 141 | + return domains.get(id); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + @Override | ||
| 145 | + public Set<IntentDomain> getDomains() { | ||
| 146 | + return ImmutableSet.copyOf(domains.values()); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + @Override | ||
| 150 | + public Set<IntentDomain> getDomains(DeviceId deviceId) { | ||
| 151 | + return domains.values().stream() | ||
| 152 | + .filter(domain -> | ||
| 153 | + domain.internalDevices().contains(deviceId) || | ||
| 154 | + domain.edgePorts().stream() | ||
| 155 | + .map(ConnectPoint::deviceId) | ||
| 156 | + .anyMatch(d -> d.equals(deviceId))) | ||
| 157 | + .collect(Collectors.toSet()); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + @Override | ||
| 161 | + public Graph<DomainVertex, DomainEdge> getDomainGraph() { | ||
| 162 | + return graph; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + @Override | ||
| 166 | + public void addListener(IntentDomainListener listener) { | ||
| 167 | + //TODO slide in AbstractListenerManager | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + @Override | ||
| 171 | + public void removeListener(IntentDomainListener listener) { | ||
| 172 | + //TODO slide in AbstractListenerManager | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + @Override | ||
| 176 | + public void registerApplication(ApplicationId applicationId, IntentDomainProvider provider) { | ||
| 177 | + appToDomain.get(applicationId.name()).forEach(d -> domains.get(d).setProvider(provider)); | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + @Override | ||
| 181 | + public void unregisterApplication(ApplicationId applicationId) { | ||
| 182 | + appToDomain.get(applicationId.name()).forEach(d -> domains.get(d).unsetProvider()); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + private class InternalConfigListener implements NetworkConfigListener { | ||
| 186 | + @Override | ||
| 187 | + public void event(NetworkConfigEvent event) { | ||
| 188 | + switch (event.type()) { | ||
| 189 | + case CONFIG_ADDED: | ||
| 190 | + case CONFIG_UPDATED: | ||
| 191 | + processConfig((IntentDomainId) event.subject()); | ||
| 192 | + graph = buildGraph(); | ||
| 193 | + log.debug("Graph: {}", graph); | ||
| 194 | + break; | ||
| 195 | + | ||
| 196 | + case CONFIG_REGISTERED: | ||
| 197 | + case CONFIG_UNREGISTERED: | ||
| 198 | + case CONFIG_REMOVED: | ||
| 199 | + default: | ||
| 200 | + //TODO | ||
| 201 | + break; | ||
| 202 | + } | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + @Override | ||
| 206 | + public boolean isRelevant(NetworkConfigEvent event) { | ||
| 207 | + return event.configClass().equals(IntentDomainConfig.class); | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | +} |
| 1 | +{ | ||
| 2 | + "domains" : { | ||
| 3 | + "cord" : { | ||
| 4 | + "basic" : { | ||
| 5 | + "name" : "Core Fabric", | ||
| 6 | + "applicationName" : "org.onosproject.testdomain", | ||
| 7 | + "internalDevices" : [ "of:1" ], | ||
| 8 | + "edgePorts" : [ "of:12/1", "of:14/1" ] | ||
| 9 | + } | ||
| 10 | + }, | ||
| 11 | + "mpls" : { | ||
| 12 | + "basic" : { | ||
| 13 | + "name" : "MPLS Core", | ||
| 14 | + "applicationName" : "org.onosproject.testdomain", | ||
| 15 | + "internalDevices" : [ "of:2" ], | ||
| 16 | + "edgePorts" : [ "of:12/2", "of:23/2" ] | ||
| 17 | + } | ||
| 18 | + }, | ||
| 19 | + "dc" : { | ||
| 20 | + "basic" : { | ||
| 21 | + "name" : "Data Center Fabric", | ||
| 22 | + "applicationName" : "org.onosproject.testdomain", | ||
| 23 | + "internalDevices" : [ "of:3" ], | ||
| 24 | + "edgePorts" : [ "of:23/3", "of:34/3" ] | ||
| 25 | + } | ||
| 26 | + }, | ||
| 27 | + "optical" : { | ||
| 28 | + "basic" : { | ||
| 29 | + "name" : "Optical Core", | ||
| 30 | + "applicationName" : "org.onosproject.testdomain", | ||
| 31 | + "internalDevices" : [ "of:4" ], | ||
| 32 | + "edgePorts" : [ "of:14/4", "of:34/4" ] | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment