From e63291850fd0795c5700e25e67e5dee89ba54c5f Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Tue, 1 Dec 2015 05:49:27 -0800 Subject: onos commit hash c2999f30c69e50df905a9d175ef80b3f23a98514 Change-Id: I2bb8562c4942b6d6a6d60b663db2e17540477b81 Signed-off-by: Ashlee Young --- .../onosproject/app/impl/ApplicationManager.java | 16 +++++- .../flowobjective/impl/FlowObjectiveManager.java | 31 +++++++++-- .../org/onosproject/net/host/impl/HostMonitor.java | 4 +- .../OpticalConnectivityIntentCompiler.java | 1 + .../newresource/impl/ResourceDeviceListener.java | 64 ++++++++++++++++++++-- .../net/newresource/impl/ResourceLinkListener.java | 9 +-- .../net/newresource/impl/ResourceManager.java | 18 ++---- 7 files changed, 112 insertions(+), 31 deletions(-) (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject') diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java index d09eb1f1..80a5ca77 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java @@ -237,12 +237,22 @@ public class ApplicationManager boolean changed = false; for (String name : app.features()) { Feature feature = featuresService.getFeature(name); + + // If we see an attempt at activation of a non-existent feature + // attempt to install the app artifacts first and then retry. + // This can be triggered by a race condition between different ONOS + // instances "installing" the apps from disk at their own pace. + // Perhaps there is a more elegant solution to be explored in the + // future. + if (feature == null) { + installAppArtifacts(app); + feature = featuresService.getFeature(name); + } + if (feature != null && !featuresService.isInstalled(feature)) { featuresService.installFeature(name); changed = true; - } else if (feature == null && !initializing) { - // Suppress feature-not-found reporting during startup since these - // can arise naturally from the staggered cluster install. + } else if (feature == null) { log.warn("Feature {} not found", name); } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/flowobjective/impl/FlowObjectiveManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/flowobjective/impl/FlowObjectiveManager.java index a76a298f..5ecdc7a2 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/flowobjective/impl/FlowObjectiveManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/flowobjective/impl/FlowObjectiveManager.java @@ -54,6 +54,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -226,10 +227,11 @@ public class FlowObjectiveManager implements FlowObjectiveService { if (fwd.nextId() != null && flowObjectiveStore.getNextGroup(fwd.nextId()) == null) { log.trace("Queuing forwarding objective for nextId {}", fwd.nextId()); - if (pendingForwards.putIfAbsent(fwd.nextId(), - Sets.newHashSet(new PendingNext(deviceId, fwd))) != null) { - Set pending = pendingForwards.get(fwd.nextId()); - pending.add(new PendingNext(deviceId, fwd)); + // TODO: change to computeIfAbsent + Set pnext = pendingForwards.putIfAbsent(fwd.nextId(), + Sets.newHashSet(new PendingNext(deviceId, fwd))); + if (pnext != null) { + pnext.add(new PendingNext(deviceId, fwd)); } return true; } @@ -412,5 +414,26 @@ public class FlowObjectiveManager implements FlowObjectiveService { public ForwardingObjective forwardingObjective() { return fwd; } + + @Override + public int hashCode() { + return Objects.hash(deviceId, fwd); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof PendingNext)) { + return false; + } + final PendingNext other = (PendingNext) obj; + if (this.deviceId.equals(other.deviceId) && + this.fwd.equals(other.fwd)) { + return true; + } + return false; + } } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java index 4dc93a51..5fb1dcf1 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java @@ -168,7 +168,9 @@ public class HostMonitor implements TimerTask { } } - this.timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); + synchronized (this) { + this.timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); + } } /** diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java index a4ed551a..2941ddba 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java @@ -189,6 +189,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler allocations = resourceService.allocate(intent.id(), lambdaResources); if (allocations.isEmpty()) { log.info("Resource allocation for {} failed (resource request: {})", intent, lambdaResources); + return null; } return minLambda; diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java index 066dd33e..4fb0d7ba 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java @@ -15,14 +15,23 @@ */ package org.onosproject.net.newresource.impl; +import com.google.common.collect.Lists; import org.onosproject.net.Device; import org.onosproject.net.Port; +import org.onosproject.net.OchPort; +import org.onosproject.net.TributarySlot; +import org.onosproject.net.OduSignalType; import org.onosproject.net.device.DeviceEvent; import org.onosproject.net.device.DeviceListener; import org.onosproject.net.newresource.ResourceAdminService; import org.onosproject.net.newresource.ResourcePath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.List; import java.util.concurrent.ExecutorService; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import static com.google.common.base.Preconditions.checkNotNull; @@ -31,6 +40,13 @@ import static com.google.common.base.Preconditions.checkNotNull; */ final class ResourceDeviceListener implements DeviceListener { + private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class); + + private static final int TOTAL_ODU2_TRIBUTARY_SLOTS = 8; + private static final int TOTAL_ODU4_TRIBUTARY_SLOTS = 80; + private static final List ENTIRE_ODU2_TRIBUTARY_SLOTS = getEntireOdu2TributarySlots(); + private static final List ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots(); + private final ResourceAdminService adminService; private final ExecutorService executor; @@ -67,20 +83,56 @@ final class ResourceDeviceListener implements DeviceListener { } private void registerDeviceResource(Device device) { - executor.submit(() -> adminService.registerResources(ResourcePath.ROOT, device.id())); + executor.submit(() -> adminService.registerResources(ResourcePath.discrete(device.id()))); } private void unregisterDeviceResource(Device device) { - executor.submit(() -> adminService.unregisterResources(ResourcePath.ROOT, device.id())); + executor.submit(() -> adminService.unregisterResources(ResourcePath.discrete(device.id()))); } private void registerPortResource(Device device, Port port) { - ResourcePath parent = ResourcePath.discrete(device.id()); - executor.submit(() -> adminService.registerResources(parent, port.number())); + ResourcePath portPath = ResourcePath.discrete(device.id(), port.number()); + executor.submit(() -> { + adminService.registerResources(portPath); + + switch (port.type()) { + case OCH: + // register ODU TributarySlots against the OCH port + registerTributarySlotsResources(((OchPort) port).signalType(), portPath); + break; + default: + break; + } + }); + } + + private void registerTributarySlotsResources(OduSignalType oduSignalType, ResourcePath portPath) { + switch (oduSignalType) { + case ODU2: + adminService.registerResources(Lists.transform(ENTIRE_ODU2_TRIBUTARY_SLOTS, portPath::child)); + break; + case ODU4: + adminService.registerResources(Lists.transform(ENTIRE_ODU4_TRIBUTARY_SLOTS, portPath::child)); + break; + default: + break; + } } private void unregisterPortResource(Device device, Port port) { - ResourcePath parent = ResourcePath.discrete(device.id()); - executor.submit(() -> adminService.unregisterResources(parent, port.number())); + ResourcePath resource = ResourcePath.discrete(device.id(), port.number()); + executor.submit(() -> adminService.unregisterResources(resource)); } + + private static List getEntireOdu2TributarySlots() { + return IntStream.rangeClosed(1, TOTAL_ODU2_TRIBUTARY_SLOTS) + .mapToObj(x -> TributarySlot.of(x)) + .collect(Collectors.toList()); + } + private static List getEntireOdu4TributarySlots() { + return IntStream.rangeClosed(1, TOTAL_ODU4_TRIBUTARY_SLOTS) + .mapToObj(x -> TributarySlot.of(x)) + .collect(Collectors.toList()); + } + } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java index 68fd6612..9d2e06f5 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java @@ -15,6 +15,7 @@ */ package org.onosproject.net.newresource.impl; +import com.google.common.collect.Lists; import org.onlab.packet.MplsLabel; import org.onlab.packet.VlanId; import org.onlab.util.ItemNotFoundException; @@ -85,24 +86,24 @@ final class ResourceLinkListener implements LinkListener { executor.submit(() -> { // register the link LinkKey linkKey = LinkKey.linkKey(link); - adminService.registerResources(ResourcePath.ROOT, linkKey); + adminService.registerResources(ResourcePath.discrete(linkKey)); ResourcePath linkPath = ResourcePath.discrete(linkKey); // register VLAN IDs against the link if (isEnabled(link, this::isVlanEnabled)) { - adminService.registerResources(linkPath, ENTIRE_VLAN_IDS); + adminService.registerResources(Lists.transform(ENTIRE_VLAN_IDS, linkPath::child)); } // register MPLS labels against the link if (isEnabled(link, this::isMplsEnabled)) { - adminService.registerResources(linkPath, ENTIRE_MPLS_LABELS); + adminService.registerResources(Lists.transform(ENTIRE_MPLS_LABELS, linkPath::child)); } }); } private void unregisterLinkResource(Link link) { LinkKey linkKey = LinkKey.linkKey(link); - executor.submit(() -> adminService.unregisterResources(ResourcePath.ROOT, linkKey)); + executor.submit(() -> adminService.unregisterResources(ResourcePath.discrete(linkKey))); } private boolean isEnabled(Link link, Predicate predicate) { diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java index 1c6930bb..3014951a 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java @@ -17,7 +17,6 @@ package org.onosproject.net.newresource.impl; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -41,7 +40,6 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; /** @@ -164,23 +162,17 @@ public final class ResourceManager extends AbstractListenerManager boolean registerResources(ResourcePath parent, List children) { - checkNotNull(parent); - checkNotNull(children); - checkArgument(!children.isEmpty()); + public boolean registerResources(List resources) { + checkNotNull(resources); - List resources = Lists.transform(children, parent::child); return store.register(resources); } @Override - public boolean unregisterResources(ResourcePath parent, List children) { - checkNotNull(parent); - checkNotNull(children); - checkArgument(!children.isEmpty()); + public boolean unregisterResources(List resources) { + checkNotNull(resources); - List resources = Lists.transform(children, parent::child); - return store.unregister(resources); + return store.register(resources); } private class InternalStoreDelegate implements ResourceStoreDelegate { -- cgit 1.2.3-korg