aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl')
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java287
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/PathManager.java293
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/TopologyManager.java256
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/package-info.java20
4 files changed, 0 insertions, 856 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java
deleted file mode 100644
index 20a5ad36..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright 2014-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.net.topology.impl;
-
-import static com.google.common.base.Strings.isNullOrEmpty;
-import static java.util.concurrent.Executors.newFixedThreadPool;
-import static org.onlab.util.Tools.get;
-import static org.onlab.util.Tools.groupedThreads;
-import static org.onosproject.core.CoreService.CORE_PROVIDER_ID;
-import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED;
-import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
-import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.List;
-import java.util.Timer;
-import java.util.concurrent.ExecutorService;
-
-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.Modified;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.Service;
-import org.onlab.util.AbstractAccumulator;
-import org.onlab.util.Accumulator;
-import org.onosproject.cfg.ComponentConfigService;
-import org.onosproject.event.Event;
-import org.onosproject.net.device.DeviceEvent;
-import org.onosproject.net.device.DeviceListener;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.link.LinkEvent;
-import org.onosproject.net.link.LinkListener;
-import org.onosproject.net.link.LinkService;
-import org.onosproject.net.provider.AbstractProvider;
-import org.onosproject.net.topology.DefaultGraphDescription;
-import org.onosproject.net.topology.GraphDescription;
-import org.onosproject.net.topology.TopologyProvider;
-import org.onosproject.net.topology.TopologyProviderRegistry;
-import org.onosproject.net.topology.TopologyProviderService;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * Default implementation of a network topology provider that feeds off
- * device and link subsystem events to trigger assembly and computation of
- * new topology snapshots.
- */
-@Component(immediate = true)
-@Service
-public class DefaultTopologyProvider extends AbstractProvider
- implements TopologyProvider {
-
- private static final int MAX_THREADS = 8;
- private static final int DEFAULT_MAX_EVENTS = 1000;
- private static final int DEFAULT_MAX_IDLE_MS = 10;
- private static final int DEFAULT_MAX_BATCH_MS = 50;
-
- // FIXME: Replace with a system-wide timer instance;
- // TODO: Convert to use HashedWheelTimer or produce a variant of that; then decide which we want to adopt
- private static final Timer TIMER = new Timer("onos-topo-event-batching");
-
- @Property(name = "maxEvents", intValue = DEFAULT_MAX_EVENTS,
- label = "Maximum number of events to accumulate")
- private int maxEvents = DEFAULT_MAX_EVENTS;
-
- @Property(name = "maxIdleMs", intValue = DEFAULT_MAX_IDLE_MS,
- label = "Maximum number of millis between events")
- private int maxIdleMs = DEFAULT_MAX_IDLE_MS;
-
- @Property(name = "maxBatchMs", intValue = DEFAULT_MAX_BATCH_MS,
- label = "Maximum number of millis for whole batch")
- private int maxBatchMs = DEFAULT_MAX_BATCH_MS;
-
- private final Logger log = getLogger(getClass());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected TopologyProviderRegistry providerRegistry;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkService linkService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ComponentConfigService cfgService;
-
- private volatile boolean isStarted = false;
-
- private TopologyProviderService providerService;
- private final DeviceListener deviceListener = new InternalDeviceListener();
- private final LinkListener linkListener = new InternalLinkListener();
-
- private Accumulator<Event> accumulator;
- private ExecutorService executor;
-
- /**
- * Creates a provider with the supplier identifier.
- */
- public DefaultTopologyProvider() {
- super(CORE_PROVIDER_ID);
- }
-
- @Activate
- public synchronized void activate(ComponentContext context) {
- cfgService.registerProperties(DefaultTopologyProvider.class);
- executor = newFixedThreadPool(MAX_THREADS, groupedThreads("onos/topo", "build-%d"));
- accumulator = new TopologyChangeAccumulator();
- logConfig("Configured");
-
- modified(context);
-
- providerService = providerRegistry.register(this);
- deviceService.addListener(deviceListener);
- linkService.addListener(linkListener);
-
- isStarted = true;
- triggerRecompute();
- log.info("Started");
- }
-
- @Deactivate
- public synchronized void deactivate(ComponentContext context) {
- cfgService.unregisterProperties(DefaultTopologyProvider.class, false);
- isStarted = false;
-
- deviceService.removeListener(deviceListener);
- linkService.removeListener(linkListener);
- providerRegistry.unregister(this);
- providerService = null;
-
- executor.shutdownNow();
- executor = null;
-
- log.info("Stopped");
- }
-
- @Modified
- public void modified(ComponentContext context) {
- if (context == null) {
- accumulator = new TopologyChangeAccumulator();
- logConfig("Reconfigured");
- return;
- }
-
- Dictionary<?, ?> properties = context.getProperties();
- int newMaxEvents, newMaxBatchMs, newMaxIdleMs;
- try {
- String s = get(properties, "maxEvents");
- newMaxEvents = isNullOrEmpty(s) ? maxEvents : Integer.parseInt(s.trim());
-
- s = get(properties, "maxBatchMs");
- newMaxBatchMs = isNullOrEmpty(s) ? maxBatchMs : Integer.parseInt(s.trim());
-
- s = get(properties, "maxIdleMs");
- newMaxIdleMs = isNullOrEmpty(s) ? maxIdleMs : Integer.parseInt(s.trim());
-
- } catch (NumberFormatException | ClassCastException e) {
- newMaxEvents = DEFAULT_MAX_EVENTS;
- newMaxBatchMs = DEFAULT_MAX_BATCH_MS;
- newMaxIdleMs = DEFAULT_MAX_IDLE_MS;
- }
-
- if (newMaxEvents != maxEvents || newMaxBatchMs != maxBatchMs || newMaxIdleMs != maxIdleMs) {
- maxEvents = newMaxEvents;
- maxBatchMs = newMaxBatchMs;
- maxIdleMs = newMaxIdleMs;
- accumulator = maxEvents > 1 ? new TopologyChangeAccumulator() : null;
- logConfig("Reconfigured");
- }
- }
-
- private void logConfig(String prefix) {
- log.info("{} with maxEvents = {}; maxBatchMs = {}; maxIdleMs = {}; accumulator={}",
- prefix, maxEvents, maxBatchMs, maxIdleMs, accumulator != null);
- }
-
-
- @Override
- public void triggerRecompute() {
- triggerTopologyBuild(Collections.<Event>emptyList());
- }
-
- /**
- * Triggers assembly of topology data citing the specified events as the
- * reason.
- *
- * @param reasons events which triggered the topology change
- */
- private synchronized void triggerTopologyBuild(List<Event> reasons) {
- if (executor != null) {
- executor.execute(new TopologyBuilderTask(reasons));
- }
- }
-
- // Builds the topology using the latest device and link information
- // and citing the specified events as reasons for the change.
- private void buildTopology(List<Event> reasons) {
- if (isStarted) {
- GraphDescription desc =
- new DefaultGraphDescription(System.nanoTime(),
- System.currentTimeMillis(),
- deviceService.getAvailableDevices(),
- linkService.getActiveLinks());
- providerService.topologyChanged(desc, reasons);
- }
- }
-
- private void processEvent(Event event) {
- if (accumulator != null) {
- accumulator.add(event);
- } else {
- triggerTopologyBuild(ImmutableList.of(event));
- }
- }
-
- // Callback for device events
- private class InternalDeviceListener implements DeviceListener {
- @Override
- public void event(DeviceEvent event) {
- DeviceEvent.Type type = event.type();
- if (type == DEVICE_ADDED || type == DEVICE_REMOVED ||
- type == DEVICE_AVAILABILITY_CHANGED) {
- processEvent(event);
- }
- }
- }
-
- // Callback for link events
- private class InternalLinkListener implements LinkListener {
- @Override
- public void event(LinkEvent event) {
- processEvent(event);
- }
- }
-
- // Event accumulator for paced triggering of topology assembly.
- private class TopologyChangeAccumulator extends AbstractAccumulator<Event> {
- TopologyChangeAccumulator() {
- super(TIMER, maxEvents, maxBatchMs, maxIdleMs);
- }
-
- @Override
- public void processItems(List<Event> items) {
- triggerTopologyBuild(items);
- }
- }
-
- // Task for building topology data in a separate thread.
- private class TopologyBuilderTask implements Runnable {
- private final List<Event> reasons;
-
- public TopologyBuilderTask(List<Event> reasons) {
- this.reasons = reasons;
- }
-
- @Override
- public void run() {
- try {
- buildTopology(reasons);
- } catch (Exception e) {
- log.warn("Unable to compute topology", e);
- }
- }
- }
-
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/PathManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/PathManager.java
deleted file mode 100644
index 8347ee38..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/PathManager.java
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Copyright 2014 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.net.topology.impl;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-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.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultEdgeLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.DisjointPath;
-import org.onosproject.net.DefaultDisjointPath;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.EdgeLink;
-import org.onosproject.net.ElementId;
-import org.onosproject.net.Host;
-import org.onosproject.net.HostId;
-import org.onosproject.net.HostLocation;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.host.HostService;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.net.topology.LinkWeight;
-import org.onosproject.net.topology.PathService;
-import org.onosproject.net.topology.Topology;
-import org.onosproject.net.topology.TopologyService;
-import org.slf4j.Logger;
-
-import java.util.List;
-import java.util.Set;
-import java.util.Map;
-
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.slf4j.LoggerFactory.getLogger;
-import static org.onosproject.security.AppGuard.checkPermission;
-import static org.onosproject.security.AppPermission.Type.*;
-
-
-/**
- * Provides implementation of a path selection service atop the current
- * topology and host services.
- */
-@Component(immediate = true)
-@Service
-public class PathManager implements PathService {
-
- private static final String ELEMENT_ID_NULL = "Element ID cannot be null";
-
- private static final ProviderId PID = new ProviderId("core", "org.onosproject.core");
- private static final PortNumber P0 = PortNumber.portNumber(0);
-
- private static final EdgeLink NOT_HOST = new NotHost();
-
- private final Logger log = getLogger(getClass());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected TopologyService topologyService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected HostService hostService;
-
- @Activate
- public void activate() {
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- log.info("Stopped");
- }
-
- @Override
- public Set<Path> getPaths(ElementId src, ElementId dst) {
- checkPermission(TOPOLOGY_READ);
-
- return getPaths(src, dst, null);
- }
-
- @Override
- public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
- checkPermission(TOPOLOGY_READ);
-
- checkNotNull(src, ELEMENT_ID_NULL);
- checkNotNull(dst, ELEMENT_ID_NULL);
-
- // Get the source and destination edge locations
- EdgeLink srcEdge = getEdgeLink(src, true);
- EdgeLink dstEdge = getEdgeLink(dst, false);
-
- // If either edge is null, bail with no paths.
- if (srcEdge == null || dstEdge == null) {
- return ImmutableSet.of();
- }
-
- DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src;
- DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst;
-
- // If the source and destination are on the same edge device, there
- // is just one path, so build it and return it.
- if (srcDevice.equals(dstDevice)) {
- return edgeToEdgePaths(srcEdge, dstEdge);
- }
-
- // Otherwise get all paths between the source and destination edge
- // devices.
- Topology topology = topologyService.currentTopology();
- Set<Path> paths = weight == null ?
- topologyService.getPaths(topology, srcDevice, dstDevice) :
- topologyService.getPaths(topology, srcDevice, dstDevice, weight);
-
- return edgeToEdgePaths(srcEdge, dstEdge, paths);
- }
-
- @Override
- public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst) {
- return getDisjointPaths(src, dst, (LinkWeight) null);
- }
-
- @Override
- public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight) {
- checkNotNull(src, ELEMENT_ID_NULL);
- checkNotNull(dst, ELEMENT_ID_NULL);
-
- // Get the source and destination edge locations
- EdgeLink srcEdge = getEdgeLink(src, true);
- EdgeLink dstEdge = getEdgeLink(dst, false);
-
- // If either edge is null, bail with no paths.
- if (srcEdge == null || dstEdge == null) {
- return ImmutableSet.of();
- }
-
- DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src;
- DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst;
-
- // If the source and destination are on the same edge device, there
- // is just one path, so build it and return it.
- if (srcDevice.equals(dstDevice)) {
- return edgeToEdgePathsDisjoint(srcEdge, dstEdge);
- }
-
- // Otherwise get all paths between the source and destination edge
- // devices.
- Topology topology = topologyService.currentTopology();
- Set<DisjointPath> paths = weight == null ?
- topologyService.getDisjointPaths(topology, srcDevice, dstDevice) :
- topologyService.getDisjointPaths(topology, srcDevice, dstDevice, weight);
-
- return edgeToEdgePathsDisjoint(srcEdge, dstEdge, paths);
- }
-
- @Override
- public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst,
- Map<Link, Object> riskProfile) {
- return getDisjointPaths(src, dst, null, riskProfile);
- }
-
- @Override
- public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight,
- Map<Link, Object> riskProfile) {
- checkNotNull(src, ELEMENT_ID_NULL);
- checkNotNull(dst, ELEMENT_ID_NULL);
-
- // Get the source and destination edge locations
- EdgeLink srcEdge = getEdgeLink(src, true);
- EdgeLink dstEdge = getEdgeLink(dst, false);
-
- // If either edge is null, bail with no paths.
- if (srcEdge == null || dstEdge == null) {
- return ImmutableSet.of();
- }
-
- DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src;
- DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst;
-
- // If the source and destination are on the same edge device, there
- // is just one path, so build it and return it.
- if (srcDevice.equals(dstDevice)) {
- return edgeToEdgePathsDisjoint(srcEdge, dstEdge);
- }
-
- // Otherwise get all paths between the source and destination edge
- // devices.
- Topology topology = topologyService.currentTopology();
- Set<DisjointPath> paths = weight == null ?
- topologyService.getDisjointPaths(topology, srcDevice, dstDevice, riskProfile) :
- topologyService.getDisjointPaths(topology, srcDevice, dstDevice, weight, riskProfile);
-
- return edgeToEdgePathsDisjoint(srcEdge, dstEdge, paths);
- }
-
- // Finds the host edge link if the element ID is a host id of an existing
- // host. Otherwise, if the host does not exist, it returns null and if
- // the element ID is not a host ID, returns NOT_HOST edge link.
- private EdgeLink getEdgeLink(ElementId elementId, boolean isIngress) {
- if (elementId instanceof HostId) {
- // Resolve the host, return null.
- Host host = hostService.getHost((HostId) elementId);
- if (host == null) {
- return null;
- }
- return new DefaultEdgeLink(PID, new ConnectPoint(elementId, P0),
- host.location(), isIngress);
- }
- return NOT_HOST;
- }
-
- // Produces a set of edge-to-edge paths using the set of infrastructure
- // paths and the given edge links.
- private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink) {
- Set<Path> endToEndPaths = Sets.newHashSetWithExpectedSize(1);
- endToEndPaths.add(edgeToEdgePath(srcLink, dstLink, null));
- return endToEndPaths;
- }
-
- // Produces a set of edge-to-edge paths using the set of infrastructure
- // paths and the given edge links.
- private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink, Set<Path> paths) {
- Set<Path> endToEndPaths = Sets.newHashSetWithExpectedSize(paths.size());
- for (Path path : paths) {
- endToEndPaths.add(edgeToEdgePath(srcLink, dstLink, path));
- }
- return endToEndPaths;
- }
-
- private Set<DisjointPath> edgeToEdgePathsDisjoint(EdgeLink srcLink, EdgeLink dstLink) {
- Set<DisjointPath> endToEndPaths = Sets.newHashSetWithExpectedSize(1);
- endToEndPaths.add(edgeToEdgePathD(srcLink, dstLink, null));
- return endToEndPaths;
- }
-
- private Set<DisjointPath> edgeToEdgePathsDisjoint(EdgeLink srcLink, EdgeLink dstLink, Set<DisjointPath> paths) {
- Set<DisjointPath> endToEndPaths = Sets.newHashSetWithExpectedSize(paths.size());
- for (DisjointPath path : paths) {
- endToEndPaths.add(edgeToEdgePathD(srcLink, dstLink, path));
- }
- return endToEndPaths;
- }
-
- // Produces a direct edge-to-edge path.
- private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink, Path path) {
- List<Link> links = Lists.newArrayListWithCapacity(2);
- // Add source and destination edge links only if they are real and
- // add the infrastructure path only if it is not null.
- if (srcLink != NOT_HOST) {
- links.add(srcLink);
- }
- if (path != null) {
- links.addAll(path.links());
- }
- if (dstLink != NOT_HOST) {
- links.add(dstLink);
- }
- return new DefaultPath(PID, links, 2);
- }
-
- // Produces a direct edge-to-edge path.
- private DisjointPath edgeToEdgePathD(EdgeLink srcLink, EdgeLink dstLink, DisjointPath path) {
- return new DefaultDisjointPath(PID, (DefaultPath) edgeToEdgePath(srcLink, dstLink, path.primary()),
- (DefaultPath) edgeToEdgePath(srcLink, dstLink, path.backup()));
- }
-
-
- // Special value for edge link to represent that this is really not an
- // edge link since the src or dst are really an infrastructure device.
- private static class NotHost extends DefaultEdgeLink implements EdgeLink {
- NotHost() {
- super(PID, new ConnectPoint(HostId.NONE, P0),
- new HostLocation(DeviceId.NONE, P0, 0L), false);
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/TopologyManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/TopologyManager.java
deleted file mode 100644
index 4425e1c1..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/TopologyManager.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright 2014 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.net.topology.impl;
-
-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.onosproject.net.DisjointPath;
-import org.onosproject.net.provider.AbstractListenerProviderRegistry;
-import org.onosproject.event.Event;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.provider.AbstractProviderService;
-import org.onosproject.net.topology.ClusterId;
-import org.onosproject.net.topology.GraphDescription;
-import org.onosproject.net.topology.LinkWeight;
-import org.onosproject.net.topology.Topology;
-import org.onosproject.net.topology.TopologyCluster;
-import org.onosproject.net.topology.TopologyEvent;
-import org.onosproject.net.topology.TopologyGraph;
-import org.onosproject.net.topology.TopologyListener;
-import org.onosproject.net.topology.TopologyProvider;
-import org.onosproject.net.topology.TopologyProviderRegistry;
-import org.onosproject.net.topology.TopologyProviderService;
-import org.onosproject.net.topology.TopologyService;
-import org.onosproject.net.topology.TopologyStore;
-import org.onosproject.net.topology.TopologyStoreDelegate;
-import org.slf4j.Logger;
-
-import java.util.List;
-import java.util.Set;
-import java.util.Map;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.security.AppGuard.checkPermission;
-import static org.slf4j.LoggerFactory.getLogger;
-import static org.onosproject.security.AppPermission.Type.*;
-
-
-/**
- * Provides basic implementation of the topology SB &amp; NB APIs.
- */
-@Component(immediate = true)
-@Service
-public class TopologyManager
- extends AbstractListenerProviderRegistry<TopologyEvent, TopologyListener,
- TopologyProvider, TopologyProviderService>
- implements TopologyService, TopologyProviderRegistry {
-
- public static final String TOPOLOGY_NULL = "Topology cannot be null";
- private static final String DEVICE_ID_NULL = "Device ID cannot be null";
- private static final String CLUSTER_ID_NULL = "Cluster ID cannot be null";
- private static final String CLUSTER_NULL = "Topology cluster cannot be null";
- public static final String CONNECTION_POINT_NULL = "Connection point cannot be null";
- public static final String LINK_WEIGHT_NULL = "Link weight cannot be null";
-
- private final Logger log = getLogger(getClass());
-
- private TopologyStoreDelegate delegate = new InternalStoreDelegate();
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected TopologyStore store;
-
- @Activate
- public void activate() {
- store.setDelegate(delegate);
- eventDispatcher.addSink(TopologyEvent.class, listenerRegistry);
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- store.unsetDelegate(delegate);
- eventDispatcher.removeSink(TopologyEvent.class);
- log.info("Stopped");
- }
-
- @Override
- public Topology currentTopology() {
- checkPermission(TOPOLOGY_READ);
- return store.currentTopology();
- }
-
- @Override
- public boolean isLatest(Topology topology) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- return store.isLatest(topology);
- }
-
- @Override
- public Set<TopologyCluster> getClusters(Topology topology) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- return store.getClusters(topology);
- }
-
- @Override
- public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(topology, CLUSTER_ID_NULL);
- return store.getCluster(topology, clusterId);
- }
-
- @Override
- public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(topology, CLUSTER_NULL);
- return store.getClusterDevices(topology, cluster);
- }
-
- @Override
- public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(topology, CLUSTER_NULL);
- return store.getClusterLinks(topology, cluster);
- }
-
- @Override
- public TopologyGraph getGraph(Topology topology) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- return store.getGraph(topology);
- }
-
- @Override
- public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(src, DEVICE_ID_NULL);
- checkNotNull(dst, DEVICE_ID_NULL);
- return store.getPaths(topology, src, dst);
- }
-
- @Override
- public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
- checkPermission(TOPOLOGY_READ);
-
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(src, DEVICE_ID_NULL);
- checkNotNull(dst, DEVICE_ID_NULL);
- checkNotNull(weight, "Link weight cannot be null");
- return store.getPaths(topology, src, dst, weight);
- }
-
- @Override
- public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) {
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(src, DEVICE_ID_NULL);
- checkNotNull(dst, DEVICE_ID_NULL);
- return store.getDisjointPaths(topology, src, dst);
- }
-
- @Override
- public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
- DeviceId dst, LinkWeight weight) {
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(src, DEVICE_ID_NULL);
- checkNotNull(dst, DEVICE_ID_NULL);
- checkNotNull(weight, LINK_WEIGHT_NULL);
- return store.getDisjointPaths(topology, src, dst, weight);
- }
-
- @Override
- public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
- Map<Link, Object> riskProfile) {
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(src, DEVICE_ID_NULL);
- checkNotNull(dst, DEVICE_ID_NULL);
- return store.getDisjointPaths(topology, src, dst, riskProfile);
- }
-
- @Override
- public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src,
- DeviceId dst, LinkWeight weight,
- Map<Link, Object> riskProfile) {
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(src, DEVICE_ID_NULL);
- checkNotNull(dst, DEVICE_ID_NULL);
- checkNotNull(weight, LINK_WEIGHT_NULL);
- return store.getDisjointPaths(topology, src, dst, weight, riskProfile);
- }
-
- @Override
- public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(connectPoint, CONNECTION_POINT_NULL);
- return store.isInfrastructure(topology, connectPoint);
- }
-
- @Override
- public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
- checkPermission(TOPOLOGY_READ);
- checkNotNull(topology, TOPOLOGY_NULL);
- checkNotNull(connectPoint, CONNECTION_POINT_NULL);
- return store.isBroadcastPoint(topology, connectPoint);
- }
-
- // Personalized host provider service issued to the supplied provider.
- @Override
- protected TopologyProviderService createProviderService(TopologyProvider provider) {
- return new InternalTopologyProviderService(provider);
- }
-
- private class InternalTopologyProviderService
- extends AbstractProviderService<TopologyProvider>
- implements TopologyProviderService {
-
- InternalTopologyProviderService(TopologyProvider provider) {
- super(provider);
- }
-
- @Override
- public void topologyChanged(GraphDescription topoDescription,
- List<Event> reasons) {
- checkNotNull(topoDescription, "Topology description cannot be null");
-
- TopologyEvent event = store.updateTopology(provider().id(),
- topoDescription, reasons);
- if (event != null) {
- log.info("Topology {} changed", event.subject());
- post(event);
- }
- }
- }
-
- // Store delegate to re-post events emitted from the store.
- private class InternalStoreDelegate implements TopologyStoreDelegate {
- @Override
- public void notify(TopologyEvent event) {
- post(event);
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/package-info.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/package-info.java
deleted file mode 100644
index 586bbf3b..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/topology/impl/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2014 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.
- */
-
-/**
- * Core subsystem for tracking global &amp; consistent topology graph views.
- */
-package org.onosproject.net.topology.impl;