Committed by
Gerrit Code Review
ONOS-3124 Sketch of simplified intent domain service
Change-Id: I6d8304214897ba75a299bfd9bd90b4591ae8eb04
Showing
14 changed files
with
180 additions
and
621 deletions
| 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.cli.net; | ||
| 17 | + | ||
| 18 | +import org.apache.karaf.shell.commands.Argument; | ||
| 19 | +import org.apache.karaf.shell.commands.Command; | ||
| 20 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | +import org.onosproject.incubator.net.domain.IntentDomainId; | ||
| 22 | +import org.onosproject.incubator.net.domain.IntentDomainService; | ||
| 23 | +import org.onosproject.incubator.net.domain.TunnelPrimitive; | ||
| 24 | +import org.onosproject.net.ConnectPoint; | ||
| 25 | + | ||
| 26 | +import java.util.NoSuchElementException; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Installs intent domain tunnel primitive. | ||
| 30 | + */ | ||
| 31 | +@Command(scope = "onos", name = "add-domain-tunnel", | ||
| 32 | + description = "Installs intent domain tunnel primitive") | ||
| 33 | +public class AddTunnelCommand extends AbstractShellCommand { | ||
| 34 | + | ||
| 35 | + @Argument(index = 0, name = "one", | ||
| 36 | + description = "Port one", | ||
| 37 | + required = true, multiValued = false) | ||
| 38 | + String oneString = null; | ||
| 39 | + | ||
| 40 | + @Argument(index = 1, name = "two", | ||
| 41 | + description = "Port two", | ||
| 42 | + required = true, multiValued = false) | ||
| 43 | + String twoString = null; | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + protected void execute() { | ||
| 47 | + IntentDomainService service = get(IntentDomainService.class); | ||
| 48 | + | ||
| 49 | + ConnectPoint one = ConnectPoint.deviceConnectPoint(oneString); | ||
| 50 | + ConnectPoint two = ConnectPoint.deviceConnectPoint(twoString); | ||
| 51 | + | ||
| 52 | + TunnelPrimitive tunnel = new TunnelPrimitive(appId(), one, two); | ||
| 53 | + | ||
| 54 | + // get the first domain (there should only be one) | ||
| 55 | + final IntentDomainId domainId; | ||
| 56 | + try { | ||
| 57 | + domainId = service.getDomains().iterator().next().id(); | ||
| 58 | + } catch (NoSuchElementException | NullPointerException e) { | ||
| 59 | + print("No domains found"); | ||
| 60 | + return; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + service.request(domainId, tunnel).forEach(r -> service.submit(domainId, r)); | ||
| 64 | + | ||
| 65 | + print("Intent domain tunnel submitted:\n%s", tunnel); | ||
| 66 | + } | ||
| 67 | +} |
| 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; | ||
| 17 | - | ||
| 18 | -import com.google.common.annotations.Beta; | ||
| 19 | -import com.google.common.base.MoreObjects; | ||
| 20 | -import org.onlab.graph.AbstractEdge; | ||
| 21 | -import org.onosproject.net.ConnectPoint; | ||
| 22 | - | ||
| 23 | -import java.util.Objects; | ||
| 24 | - | ||
| 25 | -/** | ||
| 26 | - * Representation of a connection between an intent domain and a device. This | ||
| 27 | - * must happen using a connect point that is part of both the domain and the | ||
| 28 | - * device. | ||
| 29 | - */ | ||
| 30 | -@Beta | ||
| 31 | -public class DomainEdge extends AbstractEdge<DomainVertex> { | ||
| 32 | - | ||
| 33 | - ConnectPoint connectPoint; | ||
| 34 | - | ||
| 35 | - public DomainEdge(DomainVertex src, DomainVertex dst, ConnectPoint connectPoint) { | ||
| 36 | - super(src, dst); | ||
| 37 | - this.connectPoint = connectPoint; | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - @Override | ||
| 41 | - public int hashCode() { | ||
| 42 | - return 43 * super.hashCode() + connectPoint.hashCode(); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - @Override | ||
| 46 | - public boolean equals(Object obj) { | ||
| 47 | - if (this == obj) { | ||
| 48 | - return true; | ||
| 49 | - } | ||
| 50 | - if (obj instanceof DomainEdge) { | ||
| 51 | - final DomainEdge other = (DomainEdge) obj; | ||
| 52 | - return super.equals(other) && | ||
| 53 | - Objects.equals(this.connectPoint, other.connectPoint); | ||
| 54 | - } | ||
| 55 | - return false; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - @Override | ||
| 59 | - public String toString() { | ||
| 60 | - return MoreObjects.toStringHelper(this) | ||
| 61 | - .add("src", src()) | ||
| 62 | - .add("dst", dst()) | ||
| 63 | - .add("connectPoint", connectPoint) | ||
| 64 | - .toString(); | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - /** | ||
| 68 | - * Returns the connect point associated with the domain edge. | ||
| 69 | - * | ||
| 70 | - * @return this edges connect point | ||
| 71 | - */ | ||
| 72 | - public ConnectPoint connectPoint() { | ||
| 73 | - return connectPoint; | ||
| 74 | - } | ||
| 75 | -} |
incubator/api/src/main/java/org/onosproject/incubator/net/domain/DomainIntentResource.java
deleted
100644 → 0
| 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 | - | ||
| 17 | -package org.onosproject.incubator.net.domain; | ||
| 18 | - | ||
| 19 | -import org.onosproject.core.ApplicationId; | ||
| 20 | -import org.onosproject.incubator.net.tunnel.DomainTunnelId; | ||
| 21 | -import org.onosproject.net.ConnectPoint; | ||
| 22 | -import org.onosproject.net.Path; | ||
| 23 | - | ||
| 24 | -/** | ||
| 25 | - * A variant of intent resource specialized for use on the intra-domain level. It contains a lower level path. | ||
| 26 | - */ | ||
| 27 | -public class DomainIntentResource extends IntentResource { | ||
| 28 | - | ||
| 29 | - private final Path domainPath; | ||
| 30 | - | ||
| 31 | - private final DomainTunnelId domainTunnelId; | ||
| 32 | - | ||
| 33 | - private final IntentDomainId intentDomainId; | ||
| 34 | - | ||
| 35 | - /** | ||
| 36 | - * Constructor for a domain intent resource. | ||
| 37 | - * | ||
| 38 | - * @param primitive the primitive associated with this resource | ||
| 39 | - * @param domainTunnelId the id of this tunnel (used as a sorting mechanism) | ||
| 40 | - * @param domainId the ID of the intent domain containing this tunnel | ||
| 41 | - * @param appId the id of the application which created this tunnel | ||
| 42 | - * @param ingress the fist connect point associated with this tunnel (order is irrelevant as long as it is | ||
| 43 | - * consistent with the path) | ||
| 44 | - * @param egress the second connect point associated with this tunnel (order is irrelevant as long as it is | ||
| 45 | - * consistent with the path) | ||
| 46 | - * @param path the path followed through the domain | ||
| 47 | - */ | ||
| 48 | - public DomainIntentResource(IntentPrimitive primitive, DomainTunnelId domainTunnelId, IntentDomainId domainId, | ||
| 49 | - ApplicationId appId, ConnectPoint ingress, ConnectPoint egress, Path path) { | ||
| 50 | - super(primitive, appId, ingress, egress); | ||
| 51 | - | ||
| 52 | - this.domainPath = path; | ||
| 53 | - this.domainTunnelId = domainTunnelId; | ||
| 54 | - this.intentDomainId = domainId; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - /** | ||
| 58 | - * Returns the domain path associated with this resource at creation. | ||
| 59 | - * | ||
| 60 | - * @return this resource's domain level path or if this resource backs a network tunnel then null. | ||
| 61 | - */ | ||
| 62 | - public Path path() { | ||
| 63 | - return domainPath; | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - /** | ||
| 67 | - * Returns the tunnel ID associated with this domain at creation. | ||
| 68 | - * | ||
| 69 | - * @return this resource's tunnel ID. | ||
| 70 | - */ | ||
| 71 | - public DomainTunnelId tunnelId() { | ||
| 72 | - return domainTunnelId; | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - /** | ||
| 76 | - * Returns the domain ID associated with this resource at creation. | ||
| 77 | - * | ||
| 78 | - * @return this resource's domain ID. | ||
| 79 | - */ | ||
| 80 | - public IntentDomainId domainId() { | ||
| 81 | - return intentDomainId; | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | -} |
incubator/api/src/main/java/org/onosproject/incubator/net/domain/DomainVertex.java
deleted
100644 → 0
| 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; | ||
| 17 | - | ||
| 18 | -import com.google.common.annotations.Beta; | ||
| 19 | -import com.google.common.base.MoreObjects; | ||
| 20 | -import org.onlab.graph.Vertex; | ||
| 21 | -import org.onosproject.net.DeviceId; | ||
| 22 | - | ||
| 23 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
| 24 | - | ||
| 25 | -/** | ||
| 26 | - * Representation of the intent domain or a device that is part of the intent | ||
| 27 | - * domain graph. | ||
| 28 | - */ | ||
| 29 | -@Beta | ||
| 30 | -public class DomainVertex implements Vertex { | ||
| 31 | - // FIXME we will want to add a type enum or subclasses for the two different types | ||
| 32 | - | ||
| 33 | - // A domain vertex is either an intent domain or a device: | ||
| 34 | - private final IntentDomainId domainId; | ||
| 35 | - // ----- or ----- | ||
| 36 | - | ||
| 37 | - private final DeviceId deviceId; | ||
| 38 | - | ||
| 39 | - // Serialization constructor | ||
| 40 | - private DomainVertex() { | ||
| 41 | - this.domainId = null; | ||
| 42 | - this.deviceId = null; | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - public DomainVertex(IntentDomainId id) { | ||
| 46 | - this.domainId = checkNotNull(id, "Intent domain ID cannot be null."); | ||
| 47 | - this.deviceId = null; | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - public DomainVertex(DeviceId id) { | ||
| 51 | - this.domainId = null; | ||
| 52 | - this.deviceId = checkNotNull(id, "Device ID cannot be null."); | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - @Override | ||
| 56 | - public String toString() { | ||
| 57 | - if (domainId != null) { | ||
| 58 | - return MoreObjects.toStringHelper(this) | ||
| 59 | - .add("domainId", domainId) | ||
| 60 | - .toString(); | ||
| 61 | - } else if (deviceId != null) { | ||
| 62 | - return MoreObjects.toStringHelper(this) | ||
| 63 | - .add("deviceId", deviceId) | ||
| 64 | - .toString(); | ||
| 65 | - } else { | ||
| 66 | - return MoreObjects.toStringHelper(this) | ||
| 67 | - .toString(); | ||
| 68 | - } | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - /** | ||
| 72 | - * Returns the device ID of this vertex if it is a device, returns null if it is a domain. | ||
| 73 | - * | ||
| 74 | - * @return the device ID of this vertex if applicable, else null | ||
| 75 | - */ | ||
| 76 | - public DeviceId deviceId() { | ||
| 77 | - return deviceId; | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - /** | ||
| 81 | - * Returns the domain ID of this vertex if it is a domain, returns null if it is a device. | ||
| 82 | - * | ||
| 83 | - * @return the domain ID of this vertex if applicable, else null | ||
| 84 | - */ | ||
| 85 | - public IntentDomainId domainId() { | ||
| 86 | - return domainId; | ||
| 87 | - } | ||
| 88 | -} |
incubator/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainConfig.java
deleted
100644 → 0
| 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; | ||
| 17 | - | ||
| 18 | -import com.google.common.annotations.Beta; | ||
| 19 | -import com.google.common.collect.ImmutableSet; | ||
| 20 | -import org.onosproject.net.config.Config; | ||
| 21 | -import org.onosproject.net.ConnectPoint; | ||
| 22 | -import org.onosproject.net.DeviceId; | ||
| 23 | - | ||
| 24 | -import java.util.Set; | ||
| 25 | - | ||
| 26 | -/** | ||
| 27 | - * Configuration for an intent domain including a name, set of internal devices, | ||
| 28 | - * set of edge ports, and the application bound to control the domain. | ||
| 29 | - */ | ||
| 30 | -@Beta | ||
| 31 | -public class IntentDomainConfig extends Config<IntentDomainId> { | ||
| 32 | - | ||
| 33 | - private static final String DOMAIN_NAME = "name"; | ||
| 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 | - | ||
| 38 | - | ||
| 39 | - /** | ||
| 40 | - * Returns the friendly name for the domain. | ||
| 41 | - * | ||
| 42 | - * @return domain name | ||
| 43 | - */ | ||
| 44 | - public String domainName() { | ||
| 45 | - return get(DOMAIN_NAME, subject.toString()); | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - /** | ||
| 49 | - * Sets the friendly name for the domain. | ||
| 50 | - * | ||
| 51 | - * @param domainName new name for the domain; null to clear | ||
| 52 | - * @return self | ||
| 53 | - */ | ||
| 54 | - public IntentDomainConfig domainName(String domainName) { | ||
| 55 | - return (IntentDomainConfig) setOrClear(DOMAIN_NAME, domainName); | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - /** | ||
| 59 | - * Returns the friendly name for the domain. | ||
| 60 | - * | ||
| 61 | - * @return domain name | ||
| 62 | - */ | ||
| 63 | - public String applicationName() { | ||
| 64 | - return get(APPLICATION_NAME, "FIXME"); //TODO maybe not null? | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - /** | ||
| 68 | - * Sets the friendly name for the domain. | ||
| 69 | - * | ||
| 70 | - * @param applicationName new name for the domain; null to clear | ||
| 71 | - * @return self | ||
| 72 | - */ | ||
| 73 | - public IntentDomainConfig applicationName(String applicationName) { | ||
| 74 | - return (IntentDomainConfig) setOrClear(APPLICATION_NAME, applicationName); | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - /** | ||
| 78 | - * Returns the set of internal devices. | ||
| 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 | - } | ||
| 114 | - | ||
| 115 | -} |
| 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; | ||
| 17 | + | ||
| 18 | +import org.onosproject.event.AbstractEvent; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * Describes an intent domain event. | ||
| 22 | + */ | ||
| 23 | +public class IntentDomainEvent | ||
| 24 | + extends AbstractEvent<IntentDomainEvent.Type, IntentDomain> { | ||
| 25 | + | ||
| 26 | + public enum Type { | ||
| 27 | + DOMAIN_ADDED, | ||
| 28 | + DOMAIN_MODIFIED, | ||
| 29 | + DOMAIN_REMOVED | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + protected IntentDomainEvent(Type type, IntentDomain subject) { | ||
| 33 | + super(type, subject); | ||
| 34 | + } | ||
| 35 | +} |
| ... | @@ -16,12 +16,12 @@ | ... | @@ -16,12 +16,12 @@ |
| 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 org.onosproject.event.EventListener; | ||
| 19 | 20 | ||
| 20 | /** | 21 | /** |
| 21 | * Listener for intent domain events. | 22 | * Listener for intent domain events. |
| 22 | */ | 23 | */ |
| 23 | @Beta | 24 | @Beta |
| 24 | -public interface IntentDomainListener { | 25 | +public interface IntentDomainListener |
| 25 | - //TODO create event types | 26 | + extends EventListener<IntentDomainEvent> { |
| 26 | - //extends EventListener<IntentDomainEvent> | ||
| 27 | } | 27 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -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 org.onosproject.net.provider.Provider; | ||
| 19 | 20 | ||
| 20 | import java.util.List; | 21 | import java.util.List; |
| 21 | import java.util.Set; | 22 | import java.util.Set; |
| ... | @@ -24,7 +25,7 @@ import java.util.Set; | ... | @@ -24,7 +25,7 @@ import java.util.Set; |
| 24 | * FIXME. | 25 | * FIXME. |
| 25 | */ | 26 | */ |
| 26 | @Beta | 27 | @Beta |
| 27 | -public interface IntentDomainProvider { | 28 | +public interface IntentDomainProvider extends Provider { |
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 30 | * Requests that the provider attempt to satisfy the intent primitive. | 31 | * Requests that the provider attempt to satisfy the intent primitive. |
| ... | @@ -37,7 +38,7 @@ public interface IntentDomainProvider { | ... | @@ -37,7 +38,7 @@ public interface IntentDomainProvider { |
| 37 | * @return intent resources that specify paths that satisfy the request. | 38 | * @return intent resources that specify paths that satisfy the request. |
| 38 | */ | 39 | */ |
| 39 | //TODO Consider an iterable and/or holds (only hold one or two reservation(s) at a time) | 40 | //TODO Consider an iterable and/or holds (only hold one or two reservation(s) at a time) |
| 40 | - List<DomainIntentResource> request(IntentDomain domain, IntentPrimitive primitive); | 41 | + List<IntentResource> request(IntentDomain domain, IntentPrimitive primitive); |
| 41 | 42 | ||
| 42 | /** | 43 | /** |
| 43 | * Request that the provider attempt to modify an existing resource to satisfy | 44 | * Request that the provider attempt to modify an existing resource to satisfy |
| ... | @@ -48,14 +49,14 @@ public interface IntentDomainProvider { | ... | @@ -48,14 +49,14 @@ public interface IntentDomainProvider { |
| 48 | * @param newResource the resource to be applied | 49 | * @param newResource the resource to be applied |
| 49 | * @return request contexts that contain resources to satisfy the intent | 50 | * @return request contexts that contain resources to satisfy the intent |
| 50 | */ | 51 | */ |
| 51 | - DomainIntentResource modify(DomainIntentResource oldResource, DomainIntentResource newResource); | 52 | + IntentResource modify(IntentResource oldResource, IntentResource newResource); |
| 52 | 53 | ||
| 53 | /** | 54 | /** |
| 54 | * Requests that the provider release an intent resource. | 55 | * Requests that the provider release an intent resource. |
| 55 | * | 56 | * |
| 56 | * @param resource intent resource | 57 | * @param resource intent resource |
| 57 | */ | 58 | */ |
| 58 | - void release(DomainIntentResource resource); | 59 | + void release(IntentResource resource); |
| 59 | 60 | ||
| 60 | /** | 61 | /** |
| 61 | * Requests that the provider apply the path from the intent resource. | 62 | * Requests that the provider apply the path from the intent resource. |
| ... | @@ -63,7 +64,7 @@ public interface IntentDomainProvider { | ... | @@ -63,7 +64,7 @@ public interface IntentDomainProvider { |
| 63 | * @param domainIntentResource request context | 64 | * @param domainIntentResource request context |
| 64 | * @return intent resource that satisfies the intent | 65 | * @return intent resource that satisfies the intent |
| 65 | */ | 66 | */ |
| 66 | - DomainIntentResource apply(DomainIntentResource domainIntentResource); | 67 | + IntentResource apply(IntentResource domainIntentResource); |
| 67 | 68 | ||
| 68 | /** | 69 | /** |
| 69 | * Requests that the provider cancel the path. Requests that are not applied | 70 | * Requests that the provider cancel the path. Requests that are not applied |
| ... | @@ -71,14 +72,14 @@ public interface IntentDomainProvider { | ... | @@ -71,14 +72,14 @@ public interface IntentDomainProvider { |
| 71 | * | 72 | * |
| 72 | * @param domainIntentResource the intent resource whose path should be cancelled. | 73 | * @param domainIntentResource the intent resource whose path should be cancelled. |
| 73 | */ | 74 | */ |
| 74 | - void cancel(DomainIntentResource domainIntentResource); | 75 | + void cancel(IntentResource domainIntentResource); |
| 75 | 76 | ||
| 76 | /** | 77 | /** |
| 77 | * Returns all intent resources held by the provider. | 78 | * Returns all intent resources held by the provider. |
| 78 | * | 79 | * |
| 79 | * @return set of intent resources | 80 | * @return set of intent resources |
| 80 | */ | 81 | */ |
| 81 | - Set<DomainIntentResource> getResources(); | 82 | + Set<IntentResource> getResources(); |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | 85 | ... | ... |
| ... | @@ -15,39 +15,11 @@ | ... | @@ -15,39 +15,11 @@ |
| 15 | */ | 15 | */ |
| 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 org.onosproject.net.provider.ProviderRegistry; |
| 19 | -import org.onosproject.core.ApplicationId; | ||
| 20 | 19 | ||
| 21 | /** | 20 | /** |
| 22 | - * Administrative interface for the intent domain service. | 21 | + * Abstraction of a intent domain provider registry. |
| 23 | - */ | ||
| 24 | -@Beta | ||
| 25 | -public interface IntentDomainAdminService extends IntentDomainService { | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * Register an application that provides intent domain service. | ||
| 29 | - * | ||
| 30 | - * @param applicationId application id | ||
| 31 | - * @param provider intent domain provider | ||
| 32 | - */ | ||
| 33 | - void registerApplication(ApplicationId applicationId, IntentDomainProvider provider); | ||
| 34 | - | ||
| 35 | - /** | ||
| 36 | - * Unregisters an application that provides intent domain service. | ||
| 37 | - * | ||
| 38 | - * @param applicationId application id | ||
| 39 | - */ | ||
| 40 | - void unregisterApplication(ApplicationId applicationId); | ||
| 41 | - | ||
| 42 | - /* TODO we may be able to accomplish the following through network config: | ||
| 43 | - void createDomain(String domainId); | ||
| 44 | - void removeDomain(String domainId); | ||
| 45 | - | ||
| 46 | - void addInternalDeviceToDomain(IntentDomain domain, DeviceId deviceId); | ||
| 47 | - void addPortToDomain(IntentDomain domain, ConnectPoint port); | ||
| 48 | - | ||
| 49 | - void bindApplicationToDomain(String domain, IntentDomain implementation); | ||
| 50 | - void unbindApplicationToDomain(String domain, IntentDomain implementation); | ||
| 51 | */ | 22 | */ |
| 23 | +public interface IntentDomainProviderRegistry | ||
| 24 | + extends ProviderRegistry<IntentDomainProvider, IntentDomainProviderService> { | ||
| 52 | } | 25 | } |
| 53 | - | ... | ... |
incubator/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProviderService.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; | ||
| 17 | + | ||
| 18 | +import org.onosproject.net.provider.ProviderService; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * Service through which intent domain providers can report intent domain updates. | ||
| 22 | + */ | ||
| 23 | +public interface IntentDomainProviderService | ||
| 24 | + extends ProviderService<IntentDomainProvider> { | ||
| 25 | + | ||
| 26 | +} |
| ... | @@ -16,9 +16,10 @@ | ... | @@ -16,9 +16,10 @@ |
| 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 org.onlab.graph.Graph; | 19 | +import org.onosproject.event.ListenerService; |
| 20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
| 21 | 21 | ||
| 22 | +import java.util.List; | ||
| 22 | import java.util.Set; | 23 | import java.util.Set; |
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| ... | @@ -26,7 +27,8 @@ import java.util.Set; | ... | @@ -26,7 +27,8 @@ import java.util.Set; |
| 26 | * domain providers. | 27 | * domain providers. |
| 27 | */ | 28 | */ |
| 28 | @Beta | 29 | @Beta |
| 29 | -public interface IntentDomainService { | 30 | +public interface IntentDomainService |
| 31 | + extends ListenerService<IntentDomainEvent, IntentDomainListener> { | ||
| 30 | 32 | ||
| 31 | /** | 33 | /** |
| 32 | * Returns the intent domain for the given id. | 34 | * Returns the intent domain for the given id. |
| ... | @@ -52,25 +54,21 @@ public interface IntentDomainService { | ... | @@ -52,25 +54,21 @@ public interface IntentDomainService { |
| 52 | Set<IntentDomain> getDomains(DeviceId deviceId); | 54 | Set<IntentDomain> getDomains(DeviceId deviceId); |
| 53 | 55 | ||
| 54 | /** | 56 | /** |
| 55 | - * Returns the graph of intent domains and connection devices. | 57 | + * Requests an intent primitive from the intent domain. |
| 56 | * | 58 | * |
| 57 | - * @return graph of network domains | 59 | + * @param domainId id of target domain |
| 60 | + * @param primitive intent primitive | ||
| 61 | + * @return set of intent resources that satisfy the primitive | ||
| 58 | */ | 62 | */ |
| 59 | - Graph<DomainVertex, DomainEdge> getDomainGraph(); | 63 | + List<IntentResource> request(IntentDomainId domainId, IntentPrimitive primitive); |
| 60 | 64 | ||
| 61 | /** | 65 | /** |
| 62 | - * Adds the specified listener for intent domain events. | 66 | + * Submits an intent resource to the intent domain for installation. |
| 63 | * | 67 | * |
| 64 | - * @param listener listener to be added | 68 | + * @param domainId id of target domain |
| 69 | + * @param resource intent resource | ||
| 65 | */ | 70 | */ |
| 66 | - void addListener(IntentDomainListener listener); | 71 | + void submit(IntentDomainId domainId, IntentResource resource); |
| 67 | - | ||
| 68 | - /** | ||
| 69 | - * Removes the specified listener for intent domain events. | ||
| 70 | - * | ||
| 71 | - * @param listener listener to be removed | ||
| 72 | - */ | ||
| 73 | - void removeListener(IntentDomainListener listener); | ||
| 74 | } | 72 | } |
| 75 | 73 | ||
| 76 | 74 | ... | ... |
incubator/api/src/main/java/org/onosproject/incubator/net/domain/NetworkIntentResource.java
deleted
100644 → 0
| 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 | - | ||
| 17 | -package org.onosproject.incubator.net.domain; | ||
| 18 | - | ||
| 19 | -import org.onosproject.core.ApplicationId; | ||
| 20 | -import org.onosproject.incubator.net.tunnel.NetworkTunnelId; | ||
| 21 | -import org.onosproject.net.ConnectPoint; | ||
| 22 | - | ||
| 23 | -/** | ||
| 24 | - * A variant of intent resource specialized for use on the inter-domain level. It contains a higher level path. | ||
| 25 | - */ | ||
| 26 | -public class NetworkIntentResource extends IntentResource { | ||
| 27 | - | ||
| 28 | - private final org.onlab.graph.Path<DomainVertex, DomainEdge> netPath; | ||
| 29 | - | ||
| 30 | - private NetworkTunnelId networkTunnelId; | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * Constructor for a network intent resource. | ||
| 34 | - * | ||
| 35 | - * @param primitive the primitive associated with this resource | ||
| 36 | - * @param networkTunnelId the id of this tunnel (used as a sorting mechanism) | ||
| 37 | - * @param appId the id of the application which created this tunnel | ||
| 38 | - * @param ingress the fist connect point associated with this tunnel (order is irrelevant as long as it is | ||
| 39 | - * consistent with the path) | ||
| 40 | - * @param egress the second connect point associated with this tunnel (order is irrelevant as long as it is | ||
| 41 | - * consistent with the path) | ||
| 42 | - * @param path the path followed through the graph of domain vertices and domain edges | ||
| 43 | - */ | ||
| 44 | - public NetworkIntentResource(IntentPrimitive primitive, NetworkTunnelId networkTunnelId, ApplicationId appId, | ||
| 45 | - ConnectPoint ingress, ConnectPoint egress, | ||
| 46 | - org.onlab.graph.Path<DomainVertex, DomainEdge> path) { | ||
| 47 | - super(primitive, appId, ingress, egress); | ||
| 48 | - | ||
| 49 | - this.networkTunnelId = networkTunnelId; | ||
| 50 | - this.netPath = path; | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - /** | ||
| 54 | - * Returns the network path associated with this resource at creation. | ||
| 55 | - * | ||
| 56 | - * @return this resource's network lever path or if this resource backs a domain level tunnel then null. | ||
| 57 | - */ | ||
| 58 | - public org.onlab.graph.Path<DomainVertex, DomainEdge> path() { | ||
| 59 | - return netPath; | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - /** | ||
| 63 | - * Returns ths network ID associated with this network tunnel at creation. | ||
| 64 | - * | ||
| 65 | - * @return thsi resource's tunnel ID. | ||
| 66 | - */ | ||
| 67 | - public NetworkTunnelId tunnelId() { | ||
| 68 | - return this.networkTunnelId; | ||
| 69 | - } | ||
| 70 | -} |
| ... | @@ -21,8 +21,6 @@ import org.apache.felix.scr.annotations.Component; | ... | @@ -21,8 +21,6 @@ import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; | 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; | 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | -import org.onosproject.incubator.net.domain.IntentDomainConfig; | ||
| 25 | -import org.onosproject.incubator.net.domain.IntentDomainId; | ||
| 26 | import org.onosproject.net.config.ConfigFactory; | 24 | import org.onosproject.net.config.ConfigFactory; |
| 27 | import org.onosproject.net.config.NetworkConfigRegistry; | 25 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 28 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
| ... | @@ -30,8 +28,6 @@ import org.slf4j.LoggerFactory; | ... | @@ -30,8 +28,6 @@ import org.slf4j.LoggerFactory; |
| 30 | 28 | ||
| 31 | import java.util.Set; | 29 | import java.util.Set; |
| 32 | 30 | ||
| 33 | -import static org.onosproject.incubator.net.config.basics.ExtraSubjectFactories.INTENT_DOMAIN_SUBJECT_FACTORY; | ||
| 34 | - | ||
| 35 | /** | 31 | /** |
| 36 | * Component for registration of builtin basic network configurations. | 32 | * Component for registration of builtin basic network configurations. |
| 37 | */ | 33 | */ |
| ... | @@ -40,16 +36,7 @@ public class ExtraNetworkConfigs { | ... | @@ -40,16 +36,7 @@ public class ExtraNetworkConfigs { |
| 40 | 36 | ||
| 41 | private final Logger log = LoggerFactory.getLogger(getClass()); | 37 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 42 | 38 | ||
| 43 | - private final Set<ConfigFactory> factories = ImmutableSet.of( | 39 | + private final Set<ConfigFactory> factories = ImmutableSet.of(); |
| 44 | - new ConfigFactory<IntentDomainId, IntentDomainConfig>(INTENT_DOMAIN_SUBJECT_FACTORY, | ||
| 45 | - IntentDomainConfig.class, | ||
| 46 | - "basic") { | ||
| 47 | - @Override | ||
| 48 | - public IntentDomainConfig createConfig() { | ||
| 49 | - return new IntentDomainConfig(); | ||
| 50 | - } | ||
| 51 | - } | ||
| 52 | - ); | ||
| 53 | 40 | ||
| 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 41 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 55 | protected NetworkConfigRegistry registry; | 42 | protected NetworkConfigRegistry registry; | ... | ... |
| ... | @@ -15,40 +15,30 @@ | ... | @@ -15,40 +15,30 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.incubator.net.domain.impl; | 16 | package org.onosproject.incubator.net.domain.impl; |
| 17 | 17 | ||
| 18 | -import com.google.common.collect.HashMultimap; | ||
| 19 | import com.google.common.collect.ImmutableSet; | 18 | import com.google.common.collect.ImmutableSet; |
| 20 | import com.google.common.collect.Maps; | 19 | 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; | 20 | import org.apache.felix.scr.annotations.Activate; |
| 25 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
| 26 | import org.apache.felix.scr.annotations.Deactivate; | 22 | 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; | 23 | 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.net.config.NetworkConfigEvent; | ||
| 35 | -import org.onosproject.net.config.NetworkConfigListener; | ||
| 36 | -import org.onosproject.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; | 24 | import org.onosproject.incubator.net.domain.IntentDomain; |
| 40 | -import org.onosproject.incubator.net.domain.IntentDomainAdminService; | 25 | +import org.onosproject.incubator.net.domain.IntentDomainEvent; |
| 41 | -import org.onosproject.incubator.net.domain.IntentDomainConfig; | ||
| 42 | import org.onosproject.incubator.net.domain.IntentDomainId; | 26 | import org.onosproject.incubator.net.domain.IntentDomainId; |
| 43 | import org.onosproject.incubator.net.domain.IntentDomainListener; | 27 | import org.onosproject.incubator.net.domain.IntentDomainListener; |
| 44 | import org.onosproject.incubator.net.domain.IntentDomainProvider; | 28 | import org.onosproject.incubator.net.domain.IntentDomainProvider; |
| 29 | +import org.onosproject.incubator.net.domain.IntentDomainProviderRegistry; | ||
| 30 | +import org.onosproject.incubator.net.domain.IntentDomainProviderService; | ||
| 45 | import org.onosproject.incubator.net.domain.IntentDomainService; | 31 | import org.onosproject.incubator.net.domain.IntentDomainService; |
| 32 | +import org.onosproject.incubator.net.domain.IntentPrimitive; | ||
| 33 | +import org.onosproject.incubator.net.domain.IntentResource; | ||
| 46 | import org.onosproject.net.ConnectPoint; | 34 | import org.onosproject.net.ConnectPoint; |
| 47 | import org.onosproject.net.DeviceId; | 35 | import org.onosproject.net.DeviceId; |
| 36 | +import org.onosproject.net.provider.AbstractListenerProviderRegistry; | ||
| 37 | +import org.onosproject.net.provider.AbstractProviderService; | ||
| 48 | import org.slf4j.Logger; | 38 | import org.slf4j.Logger; |
| 49 | import org.slf4j.LoggerFactory; | 39 | import org.slf4j.LoggerFactory; |
| 50 | 40 | ||
| 51 | -import java.util.Map; | 41 | +import java.util.List; |
| 52 | import java.util.Set; | 42 | import java.util.Set; |
| 53 | import java.util.concurrent.ConcurrentMap; | 43 | import java.util.concurrent.ConcurrentMap; |
| 54 | import java.util.stream.Collectors; | 44 | import java.util.stream.Collectors; |
| ... | @@ -59,80 +49,21 @@ import java.util.stream.Collectors; | ... | @@ -59,80 +49,21 @@ import java.util.stream.Collectors; |
| 59 | @Component(immediate = true) | 49 | @Component(immediate = true) |
| 60 | @Service | 50 | @Service |
| 61 | public class IntentDomainManager | 51 | public class IntentDomainManager |
| 62 | - implements IntentDomainService, IntentDomainAdminService { | 52 | + extends AbstractListenerProviderRegistry<IntentDomainEvent, IntentDomainListener, |
| 53 | + IntentDomainProvider, IntentDomainProviderService> | ||
| 54 | + implements IntentDomainService, IntentDomainProviderRegistry { | ||
| 63 | 55 | ||
| 64 | private final Logger log = LoggerFactory.getLogger(getClass()); | 56 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 65 | 57 | ||
| 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(); | 58 | private final ConcurrentMap<IntentDomainId, IntentDomain> domains = Maps.newConcurrentMap(); |
| 75 | 59 | ||
| 76 | - private final Multimap<String, IntentDomainId> appToDomain = | ||
| 77 | - Multimaps.synchronizedSetMultimap(HashMultimap.<String, IntentDomainId>create()); | ||
| 78 | - | ||
| 79 | - private Graph<DomainVertex, DomainEdge> graph; | ||
| 80 | - | ||
| 81 | @Activate | 60 | @Activate |
| 82 | protected void activate() { | 61 | 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"); | 62 | log.info("Started"); |
| 89 | } | 63 | } |
| 90 | 64 | ||
| 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 | 65 | @Deactivate |
| 134 | protected void deactivate() { | 66 | protected void deactivate() { |
| 135 | - configService.removeListener(cfgListener); | ||
| 136 | log.info("Stopped"); | 67 | log.info("Stopped"); |
| 137 | } | 68 | } |
| 138 | 69 | ||
| ... | @@ -158,53 +89,27 @@ public class IntentDomainManager | ... | @@ -158,53 +89,27 @@ public class IntentDomainManager |
| 158 | } | 89 | } |
| 159 | 90 | ||
| 160 | @Override | 91 | @Override |
| 161 | - public Graph<DomainVertex, DomainEdge> getDomainGraph() { | 92 | + public List<IntentResource> request(IntentDomainId domainId, IntentPrimitive primitive) { |
| 162 | - return graph; | 93 | + IntentDomain domain = getDomain(domainId); |
| 94 | + return domain.provider().request(domain, primitive); | ||
| 163 | } | 95 | } |
| 164 | 96 | ||
| 165 | @Override | 97 | @Override |
| 166 | - public void addListener(IntentDomainListener listener) { | 98 | + public void submit(IntentDomainId domainId, IntentResource resource) { |
| 167 | - //TODO slide in AbstractListenerManager | 99 | + getDomain(domainId).provider().apply(resource); |
| 168 | } | 100 | } |
| 169 | 101 | ||
| 170 | @Override | 102 | @Override |
| 171 | - public void removeListener(IntentDomainListener listener) { | 103 | + protected IntentDomainProviderService createProviderService(IntentDomainProvider provider) { |
| 172 | - //TODO slide in AbstractListenerManager | 104 | + return new InternalDomainProviderService(provider); |
| 173 | } | 105 | } |
| 174 | 106 | ||
| 175 | - @Override | 107 | + private class InternalDomainProviderService |
| 176 | - public void registerApplication(ApplicationId applicationId, IntentDomainProvider provider) { | 108 | + extends AbstractProviderService<IntentDomainProvider> |
| 177 | - appToDomain.get(applicationId.name()).forEach(d -> domains.get(d).setProvider(provider)); | 109 | + implements IntentDomainProviderService { |
| 178 | - } | ||
| 179 | 110 | ||
| 180 | - @Override | 111 | + InternalDomainProviderService(IntentDomainProvider provider) { |
| 181 | - public void unregisterApplication(ApplicationId applicationId) { | 112 | + super(provider); |
| 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 | } | 113 | } |
| 209 | } | 114 | } |
| 210 | } | 115 | } | ... | ... |
-
Please register or login to post a comment