diff options
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject/net/link')
2 files changed, 93 insertions, 30 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java index a6b08f62..801092f4 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java @@ -16,12 +16,14 @@ package org.onosproject.net.link.impl; import static org.slf4j.LoggerFactory.getLogger; +import static com.google.common.base.Preconditions.checkNotNull; import java.time.Duration; import org.onosproject.net.AnnotationKeys; import org.onosproject.net.config.ConfigOperator; import org.onosproject.net.config.basics.BasicLinkConfig; +import org.onosproject.net.ConnectPoint; import org.onosproject.net.DefaultAnnotations; import org.onosproject.net.Link; import org.onosproject.net.SparseAnnotations; @@ -81,6 +83,46 @@ public final class BasicLinkOperator implements ConfigOperator { if (cfg.bandwidth() != DEF_BANDWIDTH) { b.set(AnnotationKeys.BANDWIDTH, String.valueOf(cfg.bandwidth())); } + if (cfg.isDurable() != null) { + b.set(AnnotationKeys.DURABLE, String.valueOf(cfg.isDurable())); + } return DefaultAnnotations.union(an, b.build()); } + + /** + * Generates a link description from a link description entity. The endpoints + * must be specified to indicate directionality. + * + * @param src the source ConnectPoint + * @param dst the destination ConnectPoint + * @param link the link config entity + * @return a linkDescription based on the config + */ + public static LinkDescription descriptionOf( + ConnectPoint src, ConnectPoint dst, Link link) { + checkNotNull(src, "Must supply a source endpoint"); + checkNotNull(dst, "Must supply a destination endpoint"); + checkNotNull(link, "Must supply a link"); + return new DefaultLinkDescription( + src, dst, link.type(), (SparseAnnotations) link.annotations()); + } + + /** + * Generates a link description from a link config entity. This is for + * links that cannot be discovered and has to be injected. The endpoints + * must be specified to indicate directionality. + * + * @param src the source ConnectPoint + * @param dst the destination ConnectPoint + * @param link the link config entity + * @return a linkDescription based on the config + */ + public static LinkDescription descriptionOf( + ConnectPoint src, ConnectPoint dst, BasicLinkConfig link) { + checkNotNull(src, "Must supply a source endpoint"); + checkNotNull(dst, "Must supply a destination endpoint"); + checkNotNull(link, "Must supply a link config"); + return new DefaultLinkDescription( + src, dst, link.type(), combine(link, DefaultAnnotations.EMPTY)); + } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java index 157288a4..d6f72fd9 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java @@ -15,9 +15,9 @@ */ package org.onosproject.net.link.impl; -import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; 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; @@ -25,6 +25,7 @@ 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.provider.AbstractListenerProviderRegistry; +import org.onosproject.net.provider.ProviderId; import org.onosproject.net.config.NetworkConfigEvent; import org.onosproject.net.config.NetworkConfigListener; import org.onosproject.net.config.NetworkConfigService; @@ -54,7 +55,6 @@ import org.slf4j.Logger; import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; import static org.onosproject.net.LinkKey.linkKey; import static org.onosproject.security.AppGuard.checkPermission; import static org.slf4j.LoggerFactory.getLogger; @@ -125,13 +125,7 @@ public class LinkManager public Iterable<Link> getActiveLinks() { checkPermission(LINK_READ); return FluentIterable.from(getLinks()) - .filter(new Predicate<Link>() { - - @Override - public boolean apply(Link input) { - return input.state() == State.ACTIVE; - } - }); + .filter(input -> input.state() == State.ACTIVE); } @Override @@ -207,6 +201,10 @@ public class LinkManager post(store.removeLink(src, dst)); } + private boolean isAllowed(BasicLinkConfig cfg) { + return (cfg == null || cfg.isAllowed()); + } + // Auxiliary interceptor for device remove events to prune links that // are associated with the removed device or its port. private class InternalDeviceListener implements DeviceListener { @@ -240,11 +238,12 @@ public class LinkManager checkNotNull(linkDescription, LINK_DESC_NULL); checkValidity(); linkDescription = validateLink(linkDescription); - LinkEvent event = store.createOrUpdateLink(provider().id(), - linkDescription); - if (event != null) { - log.info("Link {} detected", linkDescription); - post(event); + if (linkDescription != null) { + LinkEvent event = store.createOrUpdateLink(provider().id(), linkDescription); + if (event != null) { + log.info("Link {} detected", linkDescription); + post(event); + } } } @@ -258,11 +257,12 @@ public class LinkManager BasicLinkConfig cfgTwo = networkConfigService.getConfig(linkKey(linkDescription.dst(), linkDescription.src()), BasicLinkConfig.class); - - checkState(cfg == null || cfg.isAllowed(), "Link " + linkDescription.toString() + " is not allowed"); - checkState(cfgTwo == null || cfgTwo.isAllowed(), "Link " + linkDescription.toString() + " is not allowed"); - - return BasicLinkOperator.combine(cfg, linkDescription); + if (isAllowed(cfg) && isAllowed(cfgTwo)) { + return BasicLinkOperator.combine(cfg, linkDescription); + } else { + log.trace("Link " + linkDescription.toString() + " is not allowed"); + return null; + } } @Override @@ -324,20 +324,41 @@ public class LinkManager // listens for NetworkConfigEvents of type BasicLinkConfig and removes // links that the config does not allow private class InternalNetworkConfigListener implements NetworkConfigListener { + + @Override + public boolean isRelevant(NetworkConfigEvent event) { + return event.configClass().equals(BasicLinkConfig.class) + && (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED + || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED); + } + @Override public void event(NetworkConfigEvent event) { - if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || - event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && - event.configClass().equals(BasicLinkConfig.class)) { - log.info("Detected Link network config event {}", event.type()); - LinkKey lk = (LinkKey) event.subject(); - BasicLinkConfig cfg = networkConfigService.getConfig(lk, BasicLinkConfig.class); - if (cfg != null && !cfg.isAllowed()) { - log.info("Kicking out links between {} and {}", lk.src(), lk.dst()); - removeLink(lk.src(), lk.dst()); - removeLink(lk.dst(), lk.src()); - } + LinkKey lk = (LinkKey) event.subject(); + BasicLinkConfig cfg = networkConfigService.getConfig(lk, BasicLinkConfig.class); + + if (!isAllowed(cfg)) { + log.info("Kicking out links between {} and {}", lk.src(), lk.dst()); + removeLink(lk.src(), lk.dst()); + removeLink(lk.dst(), lk.src()); + return; } + Link link = getLink(lk.src(), lk.dst()); + LinkDescription fldesc; + LinkDescription rldesc; + if (link == null) { + fldesc = BasicLinkOperator.descriptionOf(lk.src(), lk.dst(), cfg); + rldesc = BasicLinkOperator.descriptionOf(lk.dst(), lk.src(), cfg); + } else { + fldesc = BasicLinkOperator.combine(cfg, + BasicLinkOperator.descriptionOf(lk.src(), lk.dst(), link)); + rldesc = BasicLinkOperator.combine(cfg, + BasicLinkOperator.descriptionOf(lk.dst(), lk.src(), link)); + } + // XXX think of sane way to fetch the LinkProvider + store.createOrUpdateLink(ProviderId.NONE, fldesc); + store.createOrUpdateLink(ProviderId.NONE, rldesc); } + } } |