Detangling incubator: virtual nets, tunnels, resource labels, oh my
- virtual networking moved to /apps/virtual; with CLI & REST API
- tunnels and labels moved to /apps/tunnel; with CLI & REST API; UI disabled for now
- protobuf/models moved to /core/protobuf/models
- defunct grpc/rpc registry stuff left under /graveyard
- compile dependencies on /incubator moved to respective modules for compilation
- run-time dependencies will need to be re-tested for dependent apps
- /graveyard will be removed in not-too-distant future
Change-Id: I0a0b995c635487edcf95a352f50dd162186b0b39
diff --git a/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java b/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java
index f5791de..a5d06a8 100644
--- a/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java
+++ b/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java
@@ -17,7 +17,7 @@
import com.google.common.collect.ImmutableSet;
import org.onosproject.core.CoreService;
-import org.onosproject.incubator.net.config.basics.PortDescriptionsConfig;
+import org.onosproject.net.config.basics.PortDescriptionsConfig;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.HostId;
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
index 4caf74e..98880db 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
@@ -23,7 +23,7 @@
import org.onlab.util.Tools;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.NodeId;
-import org.onosproject.incubator.net.config.basics.PortDescriptionsConfig;
+import org.onosproject.net.config.basics.PortDescriptionsConfig;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipListener;
import org.onosproject.mastership.MastershipService;
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompiler.java
deleted file mode 100644
index 3222714..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompiler.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * 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.intent.impl.compiler;
-
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.onlab.osgi.DefaultServiceDirectory;
-import org.onlab.osgi.ServiceDirectory;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.incubator.net.tunnel.TunnelId;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.VirtualNetworkIntent;
-import org.onosproject.incubator.net.virtual.VirtualNetworkService;
-import org.onosproject.incubator.net.virtual.VirtualNetworkStore;
-import org.onosproject.incubator.net.virtual.VirtualPort;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.FilteredConnectPoint;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentCompilationException;
-import org.onosproject.net.intent.IntentService;
-import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.net.topology.TopologyService;
-import org.slf4j.Logger;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * An intent compiler for {@link org.onosproject.incubator.net.virtual.VirtualNetworkIntent}.
- */
-@Component(immediate = true)
-public class VirtualNetworkIntentCompiler
- extends ConnectivityIntentCompiler<VirtualNetworkIntent> {
-
- private final Logger log = getLogger(getClass());
-
- private static final String NETWORK_ID = "networkId=";
- protected static final String KEY_FORMAT = "{" + NETWORK_ID + "%s, src=%s, dst=%s}";
-
- protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY)
- protected VirtualNetworkService manager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY)
- protected IntentService intentService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY)
- protected VirtualNetworkStore store;
-
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(VirtualNetworkIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(VirtualNetworkIntent.class);
- }
-
- @Override
- public List<Intent> compile(VirtualNetworkIntent intent, List<Intent> installable) {
-
- log.debug("Compiling intent: " + intent);
- List<Intent> intents = new ArrayList<>();
- Optional<Path> path = getPaths(intent).stream()
- .findFirst();
- if (path != null && path.isPresent()) {
- List<Link> links = path.get().links();
-
- // First create an intent between the intent ingress CP and the first link source CP,
- // only if the two CPs are not the same.
- Link firstLink = links.get(0);
- if (!intent.ingressPoint().equals(firstLink.src())) {
- intents.add(createPtPtIntent(intent, intent.ingressPoint(), firstLink.src()));
- }
-
- // Next create an intent between the intent egress CP and the last link destination CP,
- // only if the two CPs are not the same.
- Link lastLink = links.get(links.size() - 1);
- if (!intent.egressPoint().equals(lastLink.dst())) {
- intents.add(createPtPtIntent(intent, lastLink.dst(), intent.egressPoint()));
- }
-
- // Now loop through all of the virtual links in the path and create an intent.
- // An intent is also created connecting two virtual links.
- final int[] index = {0};
- links.forEach(link -> {
- intents.add(createPtPtIntent(intent, link.src(), link.dst()));
- if (index[0] > 0) {
- Link previousLink = links.get(index[0] - 1);
- intents.add(createPtPtIntent(intent, previousLink.dst(), link.src()));
- }
- index[0]++;
- });
- } else {
- throw new IntentCompilationException("Unable to find a path for intent " + intent);
- }
-
- return intents;
- }
-
- /**
- * Returns the paths for the virtual network intent.
- *
- * @param intent virtual network intent
- * @return set of paths
- */
- private Set<Path> getPaths(VirtualNetworkIntent intent) {
-
- TopologyService topologyService = manager.get(intent.networkId(), TopologyService.class);
- if (topologyService == null) {
- throw new IntentCompilationException("topologyService is null");
- }
- return topologyService.getPaths(topologyService.currentTopology(),
- intent.ingressPoint().deviceId(), intent.egressPoint().deviceId());
- }
-
- /**
- * Encodes the key using the network identifier, application identifier, source and destination
- * connect points.
- *
- * @param networkId virtual network identifier
- * @param applicationId application identifier
- * @param src source connect point
- * @param dst destination connect point
- * @return encoded key
- */
-
- private static Key encodeKey(NetworkId networkId, ApplicationId applicationId, ConnectPoint src, ConnectPoint dst) {
- String key = String.format(KEY_FORMAT, networkId, src, dst);
- return Key.of(key, applicationId);
- }
-
- /**
- * Creates a point-to-point intent using the virtual network intent between the source and destination
- * connect point.
- *
- * @param intent virtual network intent
- * @param src source connect point
- * @param dst destination connect point
- * @return point to point intent
- */
- private Intent createPtPtIntent(VirtualNetworkIntent intent, ConnectPoint src, ConnectPoint dst) {
- ConnectPoint ingressPoint = mapVirtualToPhysicalPort(intent.networkId(), src);
- ConnectPoint egressPoint = mapVirtualToPhysicalPort(intent.networkId(), dst);
- Key intentKey = encodeKey(intent.networkId(), intent.appId(), ingressPoint, egressPoint);
-
- // TODO Currently there can only be one intent between the ingress and egress across
- // all virtual networks. We may want to support multiple intents between the same src/dst pairs.
- PointToPointIntent physicalIntent = PointToPointIntent.builder()
- .key(intentKey)
- .appId(intent.appId())
- .filteredIngressPoint(new FilteredConnectPoint(ingressPoint))
- .filteredEgressPoint(new FilteredConnectPoint(egressPoint))
- .constraints(intent.constraints())
- .selector(intent.selector())
- .treatment(intent.treatment())
- .resourceGroup(intent.resourceGroup())
- .build();
- log.debug("Submitting physical intent: " + physicalIntent);
- intentService.submit(physicalIntent);
-
- // Store the physical intent against this virtual intent.
- store.addTunnelId(intent, TunnelId.valueOf(physicalIntent.key().toString()));
-
- return physicalIntent;
- }
-
- /**
- * Maps the virtual connect point to a physical connect point.
- *
- * @param networkId virtual network identifier
- * @param virtualCp virtual connect point
- * @return physical connect point
- */
- private ConnectPoint mapVirtualToPhysicalPort(NetworkId networkId, ConnectPoint virtualCp) {
- Set<VirtualPort> ports = manager.getVirtualPorts(networkId, virtualCp.deviceId());
- for (VirtualPort port : ports) {
- if (port.element().id().equals(virtualCp.elementId()) &&
- port.number().equals(virtualCp.port())) {
- return new ConnectPoint(port.realizedBy().deviceId(), port.realizedBy().port());
- }
- }
- return null;
- }
-}
-
diff --git a/core/net/src/main/java/org/onosproject/net/statistic/impl/PortStatisticsManager.java b/core/net/src/main/java/org/onosproject/net/statistic/impl/PortStatisticsManager.java
new file mode 100644
index 0000000..da41750
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/statistic/impl/PortStatisticsManager.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.statistic.impl;
+
+import com.google.common.collect.Maps;
+import org.onosproject.net.statistic.PortStatisticsService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortStatistics;
+import org.onosproject.net.statistic.DefaultLoad;
+import org.onosproject.net.statistic.Load;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.onosproject.net.PortNumber.portNumber;
+import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
+import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED;
+import static org.onosproject.net.device.DeviceEvent.Type.PORT_STATS_UPDATED;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Implementation of the port statistics service.
+ */
+@Component(immediate = true, service = PortStatisticsService.class)
+public class PortStatisticsManager implements PortStatisticsService {
+
+ private final Logger log = getLogger(getClass());
+
+ private static final long POLL_FREQUENCY = 10_000; // milliseconds
+ private static final long STALE_LIMIT = (long) (1.5 * POLL_FREQUENCY);
+ private static final int SECOND = 1_000; // milliseconds
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected DeviceService deviceService;
+
+ private final DeviceListener deviceListener = new InternalDeviceListener();
+
+ private Map<ConnectPoint, DataPoint> current = Maps.newConcurrentMap();
+ private Map<ConnectPoint, DataPoint> previous = Maps.newConcurrentMap();
+
+ @Activate
+ public void activate() {
+ deviceService.addListener(deviceListener);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ deviceService.removeListener(deviceListener);
+ log.info("Stopped");
+ }
+
+ @Override
+ public Load load(ConnectPoint connectPoint) {
+ return load(connectPoint, MetricType.BYTES);
+ }
+
+ @Override
+ public Load load(ConnectPoint connectPoint, MetricType metricType) {
+ DataPoint c = current.get(connectPoint);
+ DataPoint p = previous.get(connectPoint);
+ long now = System.currentTimeMillis();
+
+ if (c != null && p != null && (now - c.time < STALE_LIMIT)) {
+ if (c.time > p.time + SECOND) {
+ long cve = getEgressValue(c.stats, metricType);
+ long cvi = getIngressValue(c.stats, metricType);
+ long pve = getEgressValue(p.stats, metricType);
+ long pvi = getIngressValue(p.stats, metricType);
+ //Use max of either Tx or Rx load as the total load of a port
+ Load load = null;
+ if (cve >= pve) {
+ load = new DefaultLoad(cve, pve, (int) (c.time - p.time) / SECOND);
+ }
+ if (cvi >= pvi) {
+ Load rcvLoad = new DefaultLoad(cvi, pvi, (int) (c.time - p.time) / SECOND);
+ load = ((load == null) || (rcvLoad.rate() > load.rate())) ? rcvLoad : load;
+ }
+ return load;
+ }
+ }
+ return null;
+ }
+
+ private long getEgressValue(PortStatistics stats, MetricType metricType) {
+ return metricType == MetricType.BYTES ? stats.bytesSent() : stats.packetsSent();
+ }
+
+ private long getIngressValue(PortStatistics stats, MetricType metricType) {
+ return metricType == MetricType.BYTES ? stats.bytesReceived() : stats.packetsReceived();
+ }
+
+ // Monitors port stats update messages.
+ private class InternalDeviceListener implements DeviceListener {
+ @Override
+ public void event(DeviceEvent event) {
+ DeviceEvent.Type type = event.type();
+ DeviceId deviceId = event.subject().id();
+ if (type == PORT_STATS_UPDATED) {
+ // Update port load
+ updateDeviceData(deviceId);
+
+ } else if (type == DEVICE_REMOVED ||
+ (type == DEVICE_AVAILABILITY_CHANGED &&
+ !deviceService.isAvailable(deviceId))) {
+ // Clean-up all port loads
+ pruneDeviceData(deviceId);
+ }
+ }
+ }
+
+ // Updates the port stats for the specified device
+ private void updateDeviceData(DeviceId deviceId) {
+ deviceService.getPortStatistics(deviceId)
+ .forEach(stats -> updatePortData(deviceId, stats));
+ }
+
+ // Updates the port stats for the specified port
+ private void updatePortData(DeviceId deviceId, PortStatistics stats) {
+ ConnectPoint cp = new ConnectPoint(deviceId, portNumber(stats.port()));
+ DataPoint c = current.get(cp);
+
+ // Create a new data point and make it the current one
+ current.put(cp, new DataPoint(stats));
+
+ // If we have a current data point, demote it to previous
+ if (c != null) {
+ previous.put(cp, c);
+ }
+ }
+
+ // Cleans all port loads for the specified device
+ private void pruneDeviceData(DeviceId deviceId) {
+ pruneMap(current, deviceId);
+ pruneMap(previous, deviceId);
+ }
+
+ private void pruneMap(Map<ConnectPoint, DataPoint> map, DeviceId deviceId) {
+ map.keySet().stream().filter(cp -> deviceId.equals(cp.deviceId()))
+ .collect(Collectors.toSet()).forEach(map::remove);
+ }
+
+ // Auxiliary data point to track when we receive different samples.
+ private class DataPoint {
+ long time;
+ PortStatistics stats;
+
+ DataPoint(PortStatistics stats) {
+ time = System.currentTimeMillis();
+ this.stats = stats;
+ }
+ }
+
+}