Brian O'Connor
Committed by Gerrit Code Review

ONOS-3124 Sketch of simplified intent domain service

Change-Id: I6d8304214897ba75a299bfd9bd90b4591ae8eb04
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.incubator.net.domain.IntentDomainId;
import org.onosproject.incubator.net.domain.IntentDomainService;
import org.onosproject.incubator.net.domain.TunnelPrimitive;
import org.onosproject.net.ConnectPoint;
import java.util.NoSuchElementException;
/**
* Installs intent domain tunnel primitive.
*/
@Command(scope = "onos", name = "add-domain-tunnel",
description = "Installs intent domain tunnel primitive")
public class AddTunnelCommand extends AbstractShellCommand {
@Argument(index = 0, name = "one",
description = "Port one",
required = true, multiValued = false)
String oneString = null;
@Argument(index = 1, name = "two",
description = "Port two",
required = true, multiValued = false)
String twoString = null;
@Override
protected void execute() {
IntentDomainService service = get(IntentDomainService.class);
ConnectPoint one = ConnectPoint.deviceConnectPoint(oneString);
ConnectPoint two = ConnectPoint.deviceConnectPoint(twoString);
TunnelPrimitive tunnel = new TunnelPrimitive(appId(), one, two);
// get the first domain (there should only be one)
final IntentDomainId domainId;
try {
domainId = service.getDomains().iterator().next().id();
} catch (NoSuchElementException | NullPointerException e) {
print("No domains found");
return;
}
service.request(domainId, tunnel).forEach(r -> service.submit(domainId, r));
print("Intent domain tunnel submitted:\n%s", tunnel);
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.domain;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import org.onlab.graph.AbstractEdge;
import org.onosproject.net.ConnectPoint;
import java.util.Objects;
/**
* Representation of a connection between an intent domain and a device. This
* must happen using a connect point that is part of both the domain and the
* device.
*/
@Beta
public class DomainEdge extends AbstractEdge<DomainVertex> {
ConnectPoint connectPoint;
public DomainEdge(DomainVertex src, DomainVertex dst, ConnectPoint connectPoint) {
super(src, dst);
this.connectPoint = connectPoint;
}
@Override
public int hashCode() {
return 43 * super.hashCode() + connectPoint.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DomainEdge) {
final DomainEdge other = (DomainEdge) obj;
return super.equals(other) &&
Objects.equals(this.connectPoint, other.connectPoint);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("src", src())
.add("dst", dst())
.add("connectPoint", connectPoint)
.toString();
}
/**
* Returns the connect point associated with the domain edge.
*
* @return this edges connect point
*/
public ConnectPoint connectPoint() {
return connectPoint;
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.domain;
import org.onosproject.core.ApplicationId;
import org.onosproject.incubator.net.tunnel.DomainTunnelId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Path;
/**
* A variant of intent resource specialized for use on the intra-domain level. It contains a lower level path.
*/
public class DomainIntentResource extends IntentResource {
private final Path domainPath;
private final DomainTunnelId domainTunnelId;
private final IntentDomainId intentDomainId;
/**
* Constructor for a domain intent resource.
*
* @param primitive the primitive associated with this resource
* @param domainTunnelId the id of this tunnel (used as a sorting mechanism)
* @param domainId the ID of the intent domain containing this tunnel
* @param appId the id of the application which created this tunnel
* @param ingress the fist connect point associated with this tunnel (order is irrelevant as long as it is
* consistent with the path)
* @param egress the second connect point associated with this tunnel (order is irrelevant as long as it is
* consistent with the path)
* @param path the path followed through the domain
*/
public DomainIntentResource(IntentPrimitive primitive, DomainTunnelId domainTunnelId, IntentDomainId domainId,
ApplicationId appId, ConnectPoint ingress, ConnectPoint egress, Path path) {
super(primitive, appId, ingress, egress);
this.domainPath = path;
this.domainTunnelId = domainTunnelId;
this.intentDomainId = domainId;
}
/**
* Returns the domain path associated with this resource at creation.
*
* @return this resource's domain level path or if this resource backs a network tunnel then null.
*/
public Path path() {
return domainPath;
}
/**
* Returns the tunnel ID associated with this domain at creation.
*
* @return this resource's tunnel ID.
*/
public DomainTunnelId tunnelId() {
return domainTunnelId;
}
/**
* Returns the domain ID associated with this resource at creation.
*
* @return this resource's domain ID.
*/
public IntentDomainId domainId() {
return intentDomainId;
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.domain;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import org.onlab.graph.Vertex;
import org.onosproject.net.DeviceId;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Representation of the intent domain or a device that is part of the intent
* domain graph.
*/
@Beta
public class DomainVertex implements Vertex {
// FIXME we will want to add a type enum or subclasses for the two different types
// A domain vertex is either an intent domain or a device:
private final IntentDomainId domainId;
// ----- or -----
private final DeviceId deviceId;
// Serialization constructor
private DomainVertex() {
this.domainId = null;
this.deviceId = null;
}
public DomainVertex(IntentDomainId id) {
this.domainId = checkNotNull(id, "Intent domain ID cannot be null.");
this.deviceId = null;
}
public DomainVertex(DeviceId id) {
this.domainId = null;
this.deviceId = checkNotNull(id, "Device ID cannot be null.");
}
@Override
public String toString() {
if (domainId != null) {
return MoreObjects.toStringHelper(this)
.add("domainId", domainId)
.toString();
} else if (deviceId != null) {
return MoreObjects.toStringHelper(this)
.add("deviceId", deviceId)
.toString();
} else {
return MoreObjects.toStringHelper(this)
.toString();
}
}
/**
* Returns the device ID of this vertex if it is a device, returns null if it is a domain.
*
* @return the device ID of this vertex if applicable, else null
*/
public DeviceId deviceId() {
return deviceId;
}
/**
* Returns the domain ID of this vertex if it is a domain, returns null if it is a device.
*
* @return the domain ID of this vertex if applicable, else null
*/
public IntentDomainId domainId() {
return domainId;
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.domain;
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.config.Config;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import java.util.Set;
/**
* Configuration for an intent domain including a name, set of internal devices,
* set of edge ports, and the application bound to control the domain.
*/
@Beta
public class IntentDomainConfig extends Config<IntentDomainId> {
private static final String DOMAIN_NAME = "name";
private static final String APPLICATION_NAME = "applicationName";
private static final String INTERNAL_DEVICES = "internalDevices";
private static final String EDGE_PORTS = "edgePorts";
/**
* Returns the friendly name for the domain.
*
* @return domain name
*/
public String domainName() {
return get(DOMAIN_NAME, subject.toString());
}
/**
* Sets the friendly name for the domain.
*
* @param domainName new name for the domain; null to clear
* @return self
*/
public IntentDomainConfig domainName(String domainName) {
return (IntentDomainConfig) setOrClear(DOMAIN_NAME, domainName);
}
/**
* Returns the friendly name for the domain.
*
* @return domain name
*/
public String applicationName() {
return get(APPLICATION_NAME, "FIXME"); //TODO maybe not null?
}
/**
* Sets the friendly name for the domain.
*
* @param applicationName new name for the domain; null to clear
* @return self
*/
public IntentDomainConfig applicationName(String applicationName) {
return (IntentDomainConfig) setOrClear(APPLICATION_NAME, applicationName);
}
/**
* Returns the set of internal devices.
*
* @return set of internal devices
*/
public Set<DeviceId> internalDevices() {
return ImmutableSet.copyOf(getList(INTERNAL_DEVICES, DeviceId::deviceId));
}
/**
* Sets the set of internal devices.
*
* @param devices set of devices; null to clear
* @return self
*/
public IntentDomainConfig internalDevices(Set<DeviceId> devices) {
return (IntentDomainConfig) setOrClear(INTERNAL_DEVICES, devices);
}
/**
* Returns the set of edge ports.
*
* @return set of edge ports
*/
public Set<ConnectPoint> edgePorts() {
return ImmutableSet.copyOf(getList(EDGE_PORTS, ConnectPoint::deviceConnectPoint));
}
/**
* Sets the set of edge ports.
*
* @param connectPoints set of edge ports; null to clear
* @return self
*/
public IntentDomainConfig edgePorts(Set<ConnectPoint> connectPoints) {
return (IntentDomainConfig) setOrClear(EDGE_PORTS, connectPoints);
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.domain;
import org.onosproject.event.AbstractEvent;
/**
* Describes an intent domain event.
*/
public class IntentDomainEvent
extends AbstractEvent<IntentDomainEvent.Type, IntentDomain> {
public enum Type {
DOMAIN_ADDED,
DOMAIN_MODIFIED,
DOMAIN_REMOVED
}
protected IntentDomainEvent(Type type, IntentDomain subject) {
super(type, subject);
}
}
......@@ -16,12 +16,12 @@
package org.onosproject.incubator.net.domain;
import com.google.common.annotations.Beta;
import org.onosproject.event.EventListener;
/**
* Listener for intent domain events.
*/
@Beta
public interface IntentDomainListener {
//TODO create event types
//extends EventListener<IntentDomainEvent>
public interface IntentDomainListener
extends EventListener<IntentDomainEvent> {
}
\ No newline at end of file
......
......@@ -16,6 +16,7 @@
package org.onosproject.incubator.net.domain;
import com.google.common.annotations.Beta;
import org.onosproject.net.provider.Provider;
import java.util.List;
import java.util.Set;
......@@ -24,7 +25,7 @@ import java.util.Set;
* FIXME.
*/
@Beta
public interface IntentDomainProvider {
public interface IntentDomainProvider extends Provider {
/**
* Requests that the provider attempt to satisfy the intent primitive.
......@@ -37,7 +38,7 @@ public interface IntentDomainProvider {
* @return intent resources that specify paths that satisfy the request.
*/
//TODO Consider an iterable and/or holds (only hold one or two reservation(s) at a time)
List<DomainIntentResource> request(IntentDomain domain, IntentPrimitive primitive);
List<IntentResource> request(IntentDomain domain, IntentPrimitive primitive);
/**
* Request that the provider attempt to modify an existing resource to satisfy
......@@ -48,14 +49,14 @@ public interface IntentDomainProvider {
* @param newResource the resource to be applied
* @return request contexts that contain resources to satisfy the intent
*/
DomainIntentResource modify(DomainIntentResource oldResource, DomainIntentResource newResource);
IntentResource modify(IntentResource oldResource, IntentResource newResource);
/**
* Requests that the provider release an intent resource.
*
* @param resource intent resource
*/
void release(DomainIntentResource resource);
void release(IntentResource resource);
/**
* Requests that the provider apply the path from the intent resource.
......@@ -63,7 +64,7 @@ public interface IntentDomainProvider {
* @param domainIntentResource request context
* @return intent resource that satisfies the intent
*/
DomainIntentResource apply(DomainIntentResource domainIntentResource);
IntentResource apply(IntentResource domainIntentResource);
/**
* Requests that the provider cancel the path. Requests that are not applied
......@@ -71,14 +72,14 @@ public interface IntentDomainProvider {
*
* @param domainIntentResource the intent resource whose path should be cancelled.
*/
void cancel(DomainIntentResource domainIntentResource);
void cancel(IntentResource domainIntentResource);
/**
* Returns all intent resources held by the provider.
*
* @return set of intent resources
*/
Set<DomainIntentResource> getResources();
Set<IntentResource> getResources();
}
......
......@@ -15,39 +15,11 @@
*/
package org.onosproject.incubator.net.domain;
import com.google.common.annotations.Beta;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.provider.ProviderRegistry;
/**
* Administrative interface for the intent domain service.
* Abstraction of a intent domain provider registry.
*/
@Beta
public interface IntentDomainAdminService extends IntentDomainService {
/**
* Register an application that provides intent domain service.
*
* @param applicationId application id
* @param provider intent domain provider
*/
void registerApplication(ApplicationId applicationId, IntentDomainProvider provider);
/**
* Unregisters an application that provides intent domain service.
*
* @param applicationId application id
*/
void unregisterApplication(ApplicationId applicationId);
/* TODO we may be able to accomplish the following through network config:
void createDomain(String domainId);
void removeDomain(String domainId);
void addInternalDeviceToDomain(IntentDomain domain, DeviceId deviceId);
void addPortToDomain(IntentDomain domain, ConnectPoint port);
void bindApplicationToDomain(String domain, IntentDomain implementation);
void unbindApplicationToDomain(String domain, IntentDomain implementation);
*/
public interface IntentDomainProviderRegistry
extends ProviderRegistry<IntentDomainProvider, IntentDomainProviderService> {
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.domain;
import org.onosproject.net.provider.ProviderService;
/**
* Service through which intent domain providers can report intent domain updates.
*/
public interface IntentDomainProviderService
extends ProviderService<IntentDomainProvider> {
}
......@@ -16,9 +16,10 @@
package org.onosproject.incubator.net.domain;
import com.google.common.annotations.Beta;
import org.onlab.graph.Graph;
import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
import java.util.List;
import java.util.Set;
/**
......@@ -26,7 +27,8 @@ import java.util.Set;
* domain providers.
*/
@Beta
public interface IntentDomainService {
public interface IntentDomainService
extends ListenerService<IntentDomainEvent, IntentDomainListener> {
/**
* Returns the intent domain for the given id.
......@@ -52,25 +54,21 @@ public interface IntentDomainService {
Set<IntentDomain> getDomains(DeviceId deviceId);
/**
* Returns the graph of intent domains and connection devices.
* Requests an intent primitive from the intent domain.
*
* @return graph of network domains
* @param domainId id of target domain
* @param primitive intent primitive
* @return set of intent resources that satisfy the primitive
*/
Graph<DomainVertex, DomainEdge> getDomainGraph();
List<IntentResource> request(IntentDomainId domainId, IntentPrimitive primitive);
/**
* Adds the specified listener for intent domain events.
* Submits an intent resource to the intent domain for installation.
*
* @param listener listener to be added
* @param domainId id of target domain
* @param resource intent resource
*/
void addListener(IntentDomainListener listener);
/**
* Removes the specified listener for intent domain events.
*
* @param listener listener to be removed
*/
void removeListener(IntentDomainListener listener);
void submit(IntentDomainId domainId, IntentResource resource);
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.domain;
import org.onosproject.core.ApplicationId;
import org.onosproject.incubator.net.tunnel.NetworkTunnelId;
import org.onosproject.net.ConnectPoint;
/**
* A variant of intent resource specialized for use on the inter-domain level. It contains a higher level path.
*/
public class NetworkIntentResource extends IntentResource {
private final org.onlab.graph.Path<DomainVertex, DomainEdge> netPath;
private NetworkTunnelId networkTunnelId;
/**
* Constructor for a network intent resource.
*
* @param primitive the primitive associated with this resource
* @param networkTunnelId the id of this tunnel (used as a sorting mechanism)
* @param appId the id of the application which created this tunnel
* @param ingress the fist connect point associated with this tunnel (order is irrelevant as long as it is
* consistent with the path)
* @param egress the second connect point associated with this tunnel (order is irrelevant as long as it is
* consistent with the path)
* @param path the path followed through the graph of domain vertices and domain edges
*/
public NetworkIntentResource(IntentPrimitive primitive, NetworkTunnelId networkTunnelId, ApplicationId appId,
ConnectPoint ingress, ConnectPoint egress,
org.onlab.graph.Path<DomainVertex, DomainEdge> path) {
super(primitive, appId, ingress, egress);
this.networkTunnelId = networkTunnelId;
this.netPath = path;
}
/**
* Returns the network path associated with this resource at creation.
*
* @return this resource's network lever path or if this resource backs a domain level tunnel then null.
*/
public org.onlab.graph.Path<DomainVertex, DomainEdge> path() {
return netPath;
}
/**
* Returns ths network ID associated with this network tunnel at creation.
*
* @return thsi resource's tunnel ID.
*/
public NetworkTunnelId tunnelId() {
return this.networkTunnelId;
}
}
......@@ -21,8 +21,6 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.incubator.net.domain.IntentDomainConfig;
import org.onosproject.incubator.net.domain.IntentDomainId;
import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigRegistry;
import org.slf4j.Logger;
......@@ -30,8 +28,6 @@ import org.slf4j.LoggerFactory;
import java.util.Set;
import static org.onosproject.incubator.net.config.basics.ExtraSubjectFactories.INTENT_DOMAIN_SUBJECT_FACTORY;
/**
* Component for registration of builtin basic network configurations.
*/
......@@ -40,16 +36,7 @@ public class ExtraNetworkConfigs {
private final Logger log = LoggerFactory.getLogger(getClass());
private final Set<ConfigFactory> factories = ImmutableSet.of(
new ConfigFactory<IntentDomainId, IntentDomainConfig>(INTENT_DOMAIN_SUBJECT_FACTORY,
IntentDomainConfig.class,
"basic") {
@Override
public IntentDomainConfig createConfig() {
return new IntentDomainConfig();
}
}
);
private final Set<ConfigFactory> factories = ImmutableSet.of();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigRegistry registry;
......
......@@ -15,40 +15,30 @@
*/
package org.onosproject.incubator.net.domain.impl;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.graph.AdjacencyListsGraph;
import org.onlab.graph.Graph;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.incubator.net.domain.DomainEdge;
import org.onosproject.incubator.net.domain.DomainVertex;
import org.onosproject.incubator.net.domain.IntentDomain;
import org.onosproject.incubator.net.domain.IntentDomainAdminService;
import org.onosproject.incubator.net.domain.IntentDomainConfig;
import org.onosproject.incubator.net.domain.IntentDomainEvent;
import org.onosproject.incubator.net.domain.IntentDomainId;
import org.onosproject.incubator.net.domain.IntentDomainListener;
import org.onosproject.incubator.net.domain.IntentDomainProvider;
import org.onosproject.incubator.net.domain.IntentDomainProviderRegistry;
import org.onosproject.incubator.net.domain.IntentDomainProviderService;
import org.onosproject.incubator.net.domain.IntentDomainService;
import org.onosproject.incubator.net.domain.IntentPrimitive;
import org.onosproject.incubator.net.domain.IntentResource;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
......@@ -59,80 +49,21 @@ import java.util.stream.Collectors;
@Component(immediate = true)
@Service
public class IntentDomainManager
implements IntentDomainService, IntentDomainAdminService {
extends AbstractListenerProviderRegistry<IntentDomainEvent, IntentDomainListener,
IntentDomainProvider, IntentDomainProviderService>
implements IntentDomainService, IntentDomainProviderRegistry {
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigService configService;
private NetworkConfigListener cfgListener = new InternalConfigListener();
private final ConcurrentMap<IntentDomainId, IntentDomain> domains = Maps.newConcurrentMap();
private final Multimap<String, IntentDomainId> appToDomain =
Multimaps.synchronizedSetMultimap(HashMultimap.<String, IntentDomainId>create());
private Graph<DomainVertex, DomainEdge> graph;
@Activate
protected void activate() {
configService.addListener(cfgListener);
configService.getSubjects(IntentDomainId.class, IntentDomainConfig.class)
.forEach(this::processConfig);
graph = buildGraph();
log.debug("Graph: {}", graph);
log.info("Started");
}
private void processConfig(IntentDomainId intentDomainId) {
IntentDomainConfig cfg = configService.getConfig(intentDomainId,
IntentDomainConfig.class);
domains.put(intentDomainId, createDomain(intentDomainId, cfg));
appToDomain.put(cfg.applicationName(), intentDomainId);
}
private IntentDomain createDomain(IntentDomainId id, IntentDomainConfig cfg) {
return new IntentDomain(id, cfg.domainName(), cfg.internalDevices(), cfg.edgePorts());
}
private Graph<DomainVertex, DomainEdge> buildGraph() {
Set<DomainVertex> vertices = Sets.newHashSet();
Set<DomainEdge> edges = Sets.newHashSet();
Map<DeviceId, DomainVertex> deviceVertices = Maps.newHashMap();
domains.forEach((id, domain) -> {
DomainVertex domainVertex = new DomainVertex(id);
// Add vertex for domain
vertices.add(domainVertex);
// Add vertices for connection devices
domain.edgePorts().stream()
.map(ConnectPoint::deviceId)
.collect(Collectors.toSet())
.forEach(did -> deviceVertices.putIfAbsent(did, new DomainVertex(did)));
// Add bi-directional edges between each domain and connection device
domain.edgePorts().forEach(cp -> {
DomainVertex deviceVertex = deviceVertices.get(cp.deviceId());
edges.add(new DomainEdge(domainVertex, deviceVertex, cp));
edges.add(new DomainEdge(deviceVertex, domainVertex, cp));
});
});
vertices.addAll(deviceVertices.values());
//FIXME verify graph integrity...
return new AdjacencyListsGraph<>(vertices, edges);
}
@Deactivate
protected void deactivate() {
configService.removeListener(cfgListener);
log.info("Stopped");
}
......@@ -151,60 +82,34 @@ public class IntentDomainManager
return domains.values().stream()
.filter(domain ->
domain.internalDevices().contains(deviceId) ||
domain.edgePorts().stream()
.map(ConnectPoint::deviceId)
.anyMatch(d -> d.equals(deviceId)))
domain.edgePorts().stream()
.map(ConnectPoint::deviceId)
.anyMatch(d -> d.equals(deviceId)))
.collect(Collectors.toSet());
}
@Override
public Graph<DomainVertex, DomainEdge> getDomainGraph() {
return graph;
}
@Override
public void addListener(IntentDomainListener listener) {
//TODO slide in AbstractListenerManager
}
@Override
public void removeListener(IntentDomainListener listener) {
//TODO slide in AbstractListenerManager
public List<IntentResource> request(IntentDomainId domainId, IntentPrimitive primitive) {
IntentDomain domain = getDomain(domainId);
return domain.provider().request(domain, primitive);
}
@Override
public void registerApplication(ApplicationId applicationId, IntentDomainProvider provider) {
appToDomain.get(applicationId.name()).forEach(d -> domains.get(d).setProvider(provider));
public void submit(IntentDomainId domainId, IntentResource resource) {
getDomain(domainId).provider().apply(resource);
}
@Override
public void unregisterApplication(ApplicationId applicationId) {
appToDomain.get(applicationId.name()).forEach(d -> domains.get(d).unsetProvider());
protected IntentDomainProviderService createProviderService(IntentDomainProvider provider) {
return new InternalDomainProviderService(provider);
}
private class InternalConfigListener implements NetworkConfigListener {
@Override
public void event(NetworkConfigEvent event) {
switch (event.type()) {
case CONFIG_ADDED:
case CONFIG_UPDATED:
processConfig((IntentDomainId) event.subject());
graph = buildGraph();
log.debug("Graph: {}", graph);
break;
case CONFIG_REGISTERED:
case CONFIG_UNREGISTERED:
case CONFIG_REMOVED:
default:
//TODO
break;
}
}
private class InternalDomainProviderService
extends AbstractProviderService<IntentDomainProvider>
implements IntentDomainProviderService {
@Override
public boolean isRelevant(NetworkConfigEvent event) {
return event.configClass().equals(IntentDomainConfig.class);
InternalDomainProviderService(IntentDomainProvider provider) {
super(provider);
}
}
}
......