diff options
author | CNlucius <lukai1@huawei.com> | 2016-09-13 11:40:12 +0800 |
---|---|---|
committer | CNlucius <lukai1@huawei.com> | 2016-09-13 11:41:53 +0800 |
commit | b731e2f1dd0972409b136aebc7b463dd72c9cfad (patch) | |
tree | 5107d7d80c19ad8076c2c97c2b5ef8d1cf3ab903 /framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link | |
parent | ee93993458266114c29271a481ef9ce7ce621b2a (diff) |
ONOSFW-171
O/S-SFC-ONOS scenario documentation
Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365
Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link')
10 files changed, 0 insertions, 1748 deletions
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java deleted file mode 100644 index 243caf80..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java +++ /dev/null @@ -1,405 +0,0 @@ -/* - * 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.store.link.impl; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onosproject.net.DefaultAnnotations.merge; -import static org.onosproject.net.DefaultAnnotations.union; -import static org.onosproject.net.Link.State.ACTIVE; -import static org.onosproject.net.Link.State.INACTIVE; -import static org.onosproject.net.Link.Type.DIRECT; -import static org.onosproject.net.Link.Type.INDIRECT; -import static org.onosproject.net.LinkKey.linkKey; -import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED; -import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED; -import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED; -import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; -import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; -import static org.slf4j.LoggerFactory.getLogger; - -import java.util.Collection; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -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.util.KryoNamespace; -import org.onlab.util.SharedExecutors; -import org.onosproject.cluster.ClusterService; -import org.onosproject.cluster.NodeId; -import org.onosproject.mastership.MastershipService; -import org.onosproject.net.AnnotationKeys; -import org.onosproject.net.AnnotationsUtil; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.LinkKey; -import org.onosproject.net.Link.Type; -import org.onosproject.net.device.DeviceClockService; -import org.onosproject.net.link.DefaultLinkDescription; -import org.onosproject.net.link.LinkDescription; -import org.onosproject.net.link.LinkEvent; -import org.onosproject.net.link.LinkStore; -import org.onosproject.net.link.LinkStoreDelegate; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.store.AbstractStore; -import org.onosproject.store.cluster.messaging.ClusterCommunicationService; -import org.onosproject.store.cluster.messaging.MessageSubject; -import org.onosproject.store.impl.MastershipBasedTimestamp; -import org.onosproject.store.serializers.KryoNamespaces; -import org.onosproject.store.serializers.KryoSerializer; -import org.onosproject.store.serializers.custom.DistributedStoreSerializers; -import org.onosproject.store.service.EventuallyConsistentMap; -import org.onosproject.store.service.EventuallyConsistentMapEvent; -import org.onosproject.store.service.EventuallyConsistentMapListener; -import org.onosproject.store.service.StorageService; -import org.slf4j.Logger; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import com.google.common.util.concurrent.Futures; - -/** - * Manages the inventory of links using a {@code EventuallyConsistentMap}. - */ -@Component(immediate = true, enabled = true) -@Service -public class ECLinkStore - extends AbstractStore<LinkEvent, LinkStoreDelegate> - implements LinkStore { - - private final Logger log = getLogger(getClass()); - - private final Map<LinkKey, Link> links = Maps.newConcurrentMap(); - private EventuallyConsistentMap<Provided<LinkKey>, LinkDescription> linkDescriptions; - - private static final MessageSubject LINK_INJECT_MESSAGE = new MessageSubject("inject-link-request"); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected StorageService storageService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected MastershipService mastershipService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceClockService deviceClockService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ClusterCommunicationService clusterCommunicator; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ClusterService clusterService; - - private EventuallyConsistentMapListener<Provided<LinkKey>, LinkDescription> linkTracker = - new InternalLinkTracker(); - - protected static final KryoSerializer SERIALIZER = new KryoSerializer() { - @Override - protected void setupKryoPool() { - serializerPool = KryoNamespace.newBuilder() - .register(DistributedStoreSerializers.STORE_COMMON) - .nextId(DistributedStoreSerializers.STORE_CUSTOM_BEGIN) - .register(Provided.class) - .build(); - } - }; - - @Activate - public void activate() { - KryoNamespace.Builder serializer = KryoNamespace.newBuilder() - .register(KryoNamespaces.API) - .register(MastershipBasedTimestamp.class) - .register(Provided.class); - - linkDescriptions = storageService.<Provided<LinkKey>, LinkDescription>eventuallyConsistentMapBuilder() - .withName("onos-link-descriptions") - .withSerializer(serializer) - .withTimestampProvider((k, v) -> { - try { - return v == null ? null : deviceClockService.getTimestamp(v.dst().deviceId()); - } catch (IllegalStateException e) { - return null; - } - }).build(); - - clusterCommunicator.addSubscriber(LINK_INJECT_MESSAGE, - SERIALIZER::decode, - this::injectLink, - SERIALIZER::encode, - SharedExecutors.getPoolThreadExecutor()); - - linkDescriptions.addListener(linkTracker); - - log.info("Started"); - } - - @Deactivate - public void deactivate() { - linkDescriptions.removeListener(linkTracker); - linkDescriptions.destroy(); - links.clear(); - clusterCommunicator.removeSubscriber(LINK_INJECT_MESSAGE); - - log.info("Stopped"); - } - - @Override - public int getLinkCount() { - return links.size(); - } - - @Override - public Iterable<Link> getLinks() { - return links.values(); - } - - @Override - public Set<Link> getDeviceEgressLinks(DeviceId deviceId) { - return filter(links.values(), link -> deviceId.equals(link.src().deviceId())); - } - - @Override - public Set<Link> getDeviceIngressLinks(DeviceId deviceId) { - return filter(links.values(), link -> deviceId.equals(link.dst().deviceId())); - } - - @Override - public Link getLink(ConnectPoint src, ConnectPoint dst) { - return links.get(linkKey(src, dst)); - } - - @Override - public Set<Link> getEgressLinks(ConnectPoint src) { - return filter(links.values(), link -> src.equals(link.src())); - } - - @Override - public Set<Link> getIngressLinks(ConnectPoint dst) { - return filter(links.values(), link -> dst.equals(link.dst())); - } - - @Override - public LinkEvent createOrUpdateLink(ProviderId providerId, - LinkDescription linkDescription) { - final DeviceId dstDeviceId = linkDescription.dst().deviceId(); - final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId); - - // Process link update only if we're the master of the destination node, - // otherwise signal the actual master. - if (clusterService.getLocalNode().id().equals(dstNodeId)) { - LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst()); - Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId); - if (internalLinkKey == null) { - return null; - } - linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v , linkDescription)); - return refreshLinkCache(linkKey); - } else { - if (dstNodeId == null) { - return null; - } - return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), - LINK_INJECT_MESSAGE, - SERIALIZER::encode, - SERIALIZER::decode, - dstNodeId)); - } - } - - private Provided<LinkKey> getProvided(LinkKey linkKey, ProviderId provId) { - ProviderId bpid = getBaseProviderId(linkKey); - if (provId == null) { - // The LinkService didn't know who this LinkKey belongs to. - // A fix is to either modify the getProvider() in LinkService classes - // or expose the contents of linkDescriptions to the LinkService. - return (bpid == null) ? null : new Provided<>(linkKey, bpid); - } else { - return new Provided<>(linkKey, provId); - } - } - - private LinkDescription createOrUpdateLinkInternal(LinkDescription current, LinkDescription updated) { - if (current != null) { - // we only allow transition from INDIRECT -> DIRECT - return new DefaultLinkDescription( - current.src(), - current.dst(), - current.type() == DIRECT ? DIRECT : updated.type(), - union(current.annotations(), updated.annotations())); - } - return updated; - } - - private LinkEvent refreshLinkCache(LinkKey linkKey) { - AtomicReference<LinkEvent.Type> eventType = new AtomicReference<>(); - Link link = links.compute(linkKey, (key, existingLink) -> { - Link newLink = composeLink(linkKey); - if (existingLink == null) { - eventType.set(LINK_ADDED); - return newLink; - } else if (existingLink.state() != newLink.state() || - (existingLink.type() == INDIRECT && newLink.type() == DIRECT) || - !AnnotationsUtil.isEqual(existingLink.annotations(), newLink.annotations())) { - eventType.set(LINK_UPDATED); - return newLink; - } else { - return existingLink; - } - }); - return eventType.get() != null ? new LinkEvent(eventType.get(), link) : null; - } - - private Set<ProviderId> getAllProviders(LinkKey linkKey) { - return linkDescriptions.keySet() - .stream() - .filter(key -> key.key().equals(linkKey)) - .map(key -> key.providerId()) - .collect(Collectors.toSet()); - } - - private ProviderId getBaseProviderId(LinkKey linkKey) { - Set<ProviderId> allProviders = getAllProviders(linkKey); - if (allProviders.size() > 0) { - return allProviders.stream() - .filter(p -> !p.isAncillary()) - .findFirst() - .orElse(Iterables.getFirst(allProviders, null)); - } - return null; - } - - private Link composeLink(LinkKey linkKey) { - - ProviderId baseProviderId = checkNotNull(getBaseProviderId(linkKey)); - LinkDescription base = linkDescriptions.get(new Provided<>(linkKey, baseProviderId)); - - ConnectPoint src = base.src(); - ConnectPoint dst = base.dst(); - Type type = base.type(); - AtomicReference<DefaultAnnotations> annotations = new AtomicReference<>(DefaultAnnotations.builder().build()); - annotations.set(merge(annotations.get(), base.annotations())); - - getAllProviders(linkKey).stream() - .map(p -> new Provided<>(linkKey, p)) - .forEach(key -> { - annotations.set(merge(annotations.get(), - linkDescriptions.get(key).annotations())); - }); - - boolean isDurable = Objects.equals(annotations.get().value(AnnotationKeys.DURABLE), "true"); - return new DefaultLink(baseProviderId, src, dst, type, ACTIVE, isDurable, annotations.get()); - } - - // Updates, if necessary the specified link and returns the appropriate event. - // Guarded by linkDescs value (=locking each Link) - private LinkEvent updateLink(LinkKey key, Link oldLink, Link newLink) { - // Note: INDIRECT -> DIRECT transition only - // so that BDDP discovered Link will not overwrite LDDP Link - if (oldLink.state() != newLink.state() || - (oldLink.type() == INDIRECT && newLink.type() == DIRECT) || - !AnnotationsUtil.isEqual(oldLink.annotations(), newLink.annotations())) { - - links.put(key, newLink); - return new LinkEvent(LINK_UPDATED, newLink); - } - return null; - } - - @Override - public LinkEvent removeOrDownLink(ConnectPoint src, ConnectPoint dst) { - Link link = getLink(src, dst); - if (link == null) { - return null; - } - - if (link.isDurable()) { - // FIXME: this will not sync link state!!! - return link.state() == INACTIVE ? null : - updateLink(linkKey(link.src(), link.dst()), link, - new DefaultLink(link.providerId(), - link.src(), link.dst(), - link.type(), INACTIVE, - link.isDurable(), - link.annotations())); - } - return removeLink(src, dst); - } - - @Override - public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { - final LinkKey linkKey = LinkKey.linkKey(src, dst); - ProviderId primaryProviderId = getBaseProviderId(linkKey); - // Stop if there is no base provider. - if (primaryProviderId == null) { - return null; - } - LinkDescription removedLinkDescription = - linkDescriptions.remove(new Provided<>(linkKey, primaryProviderId)); - if (removedLinkDescription != null) { - return purgeLinkCache(linkKey); - } - return null; - } - - private LinkEvent purgeLinkCache(LinkKey linkKey) { - Link removedLink = links.remove(linkKey); - if (removedLink != null) { - getAllProviders(linkKey).forEach(p -> linkDescriptions.remove(new Provided<>(linkKey, p))); - return new LinkEvent(LINK_REMOVED, removedLink); - } - return null; - } - - private Set<Link> filter(Collection<Link> links, Predicate<Link> predicate) { - return links.stream().filter(predicate).collect(Collectors.toSet()); - } - - private LinkEvent injectLink(Provided<LinkDescription> linkInjectRequest) { - log.trace("Received request to inject link {}", linkInjectRequest); - - ProviderId providerId = linkInjectRequest.providerId(); - LinkDescription linkDescription = linkInjectRequest.key(); - - final DeviceId deviceId = linkDescription.dst().deviceId(); - if (!deviceClockService.isTimestampAvailable(deviceId)) { - // workaround for ONOS-1208 - log.warn("Not ready to accept update. Dropping {}", linkInjectRequest); - return null; - } - return createOrUpdateLink(providerId, linkDescription); - } - - private class InternalLinkTracker implements EventuallyConsistentMapListener<Provided<LinkKey>, LinkDescription> { - @Override - public void event(EventuallyConsistentMapEvent<Provided<LinkKey>, LinkDescription> event) { - if (event.type() == PUT) { - notifyDelegate(refreshLinkCache(event.key().key())); - } else if (event.type() == REMOVE) { - notifyDelegate(purgeLinkCache(event.key().key())); - } - } - } -}
\ No newline at end of file diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java deleted file mode 100644 index 47aa85c5..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java +++ /dev/null @@ -1,902 +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.store.link.impl; - -import com.google.common.base.Function; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Multimaps; -import com.google.common.collect.SetMultimap; -import com.google.common.collect.Sets; -import org.apache.commons.lang3.RandomUtils; -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.util.KryoNamespace; -import org.onosproject.cluster.ClusterService; -import org.onosproject.cluster.ControllerNode; -import org.onosproject.cluster.NodeId; -import org.onosproject.mastership.MastershipService; -import org.onosproject.net.AnnotationKeys; -import org.onosproject.net.AnnotationsUtil; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.Link.Type; -import org.onosproject.net.LinkKey; -import org.onosproject.net.SparseAnnotations; -import org.onosproject.net.device.DeviceClockService; -import org.onosproject.net.link.DefaultLinkDescription; -import org.onosproject.net.link.LinkDescription; -import org.onosproject.net.link.LinkEvent; -import org.onosproject.net.link.LinkStore; -import org.onosproject.net.link.LinkStoreDelegate; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.store.AbstractStore; -import org.onosproject.store.Timestamp; -import org.onosproject.store.cluster.messaging.ClusterCommunicationService; -import org.onosproject.store.cluster.messaging.ClusterMessage; -import org.onosproject.store.cluster.messaging.ClusterMessageHandler; -import org.onosproject.store.cluster.messaging.MessageSubject; -import org.onosproject.store.impl.Timestamped; -import org.onosproject.store.serializers.KryoSerializer; -import org.onosproject.store.serializers.custom.DistributedStoreSerializers; -import org.slf4j.Logger; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Multimaps.synchronizedSetMultimap; -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; -import static org.onlab.util.Tools.groupedThreads; -import static org.onlab.util.Tools.minPriority; -import static org.onosproject.cluster.ControllerNodeToNodeId.toNodeId; -import static org.onosproject.net.DefaultAnnotations.merge; -import static org.onosproject.net.DefaultAnnotations.union; -import static org.onosproject.net.Link.State.ACTIVE; -import static org.onosproject.net.Link.State.INACTIVE; -import static org.onosproject.net.Link.Type.DIRECT; -import static org.onosproject.net.Link.Type.INDIRECT; -import static org.onosproject.net.LinkKey.linkKey; -import static org.onosproject.net.link.LinkEvent.Type.*; -import static org.onosproject.store.link.impl.GossipLinkStoreMessageSubjects.LINK_ANTI_ENTROPY_ADVERTISEMENT; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Manages inventory of infrastructure links in distributed data store - * that uses optimistic replication and gossip based techniques. - */ -@Component(immediate = true, enabled = false) -@Service -public class GossipLinkStore - extends AbstractStore<LinkEvent, LinkStoreDelegate> - implements LinkStore { - - // Timeout in milliseconds to process links on remote master node - private static final int REMOTE_MASTER_TIMEOUT = 1000; - - private final Logger log = getLogger(getClass()); - - // Link inventory - private final ConcurrentMap<LinkKey, Map<ProviderId, Timestamped<LinkDescription>>> linkDescs = - new ConcurrentHashMap<>(); - - // Link instance cache - private final ConcurrentMap<LinkKey, Link> links = new ConcurrentHashMap<>(); - - // Egress and ingress link sets - private final SetMultimap<DeviceId, LinkKey> srcLinks = createSynchronizedHashMultiMap(); - private final SetMultimap<DeviceId, LinkKey> dstLinks = createSynchronizedHashMultiMap(); - - // Remove links - private final Map<LinkKey, Timestamp> removedLinks = new ConcurrentHashMap<>(); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceClockService deviceClockService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ClusterCommunicationService clusterCommunicator; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ClusterService clusterService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected MastershipService mastershipService; - - protected static final KryoSerializer SERIALIZER = new KryoSerializer() { - @Override - protected void setupKryoPool() { - serializerPool = KryoNamespace.newBuilder() - .register(DistributedStoreSerializers.STORE_COMMON) - .nextId(DistributedStoreSerializers.STORE_CUSTOM_BEGIN) - .register(InternalLinkEvent.class) - .register(InternalLinkRemovedEvent.class) - .register(LinkAntiEntropyAdvertisement.class) - .register(LinkFragmentId.class) - .register(LinkInjectedEvent.class) - .build(); - } - }; - - private ExecutorService executor; - - private ScheduledExecutorService backgroundExecutors; - - @Activate - public void activate() { - - executor = Executors.newCachedThreadPool(groupedThreads("onos/link", "fg-%d")); - - backgroundExecutors = - newSingleThreadScheduledExecutor(minPriority(groupedThreads("onos/link", "bg-%d"))); - - clusterCommunicator.addSubscriber( - GossipLinkStoreMessageSubjects.LINK_UPDATE, - new InternalLinkEventListener(), executor); - clusterCommunicator.addSubscriber( - GossipLinkStoreMessageSubjects.LINK_REMOVED, - new InternalLinkRemovedEventListener(), executor); - clusterCommunicator.addSubscriber( - GossipLinkStoreMessageSubjects.LINK_ANTI_ENTROPY_ADVERTISEMENT, - new InternalLinkAntiEntropyAdvertisementListener(), backgroundExecutors); - clusterCommunicator.addSubscriber( - GossipLinkStoreMessageSubjects.LINK_INJECTED, - new LinkInjectedEventListener(), executor); - - long initialDelaySec = 5; - long periodSec = 5; - // start anti-entropy thread - backgroundExecutors.scheduleAtFixedRate(new SendAdvertisementTask(), - initialDelaySec, periodSec, TimeUnit.SECONDS); - - log.info("Started"); - } - - @Deactivate - public void deactivate() { - - executor.shutdownNow(); - - backgroundExecutors.shutdownNow(); - try { - if (!backgroundExecutors.awaitTermination(5, TimeUnit.SECONDS)) { - log.error("Timeout during executor shutdown"); - } - } catch (InterruptedException e) { - log.error("Error during executor shutdown", e); - } - - linkDescs.clear(); - links.clear(); - srcLinks.clear(); - dstLinks.clear(); - log.info("Stopped"); - } - - @Override - public int getLinkCount() { - return links.size(); - } - - @Override - public Iterable<Link> getLinks() { - return Collections.unmodifiableCollection(links.values()); - } - - @Override - public Set<Link> getDeviceEgressLinks(DeviceId deviceId) { - // lock for iteration - synchronized (srcLinks) { - return FluentIterable.from(srcLinks.get(deviceId)) - .transform(lookupLink()) - .filter(notNull()) - .toSet(); - } - } - - @Override - public Set<Link> getDeviceIngressLinks(DeviceId deviceId) { - // lock for iteration - synchronized (dstLinks) { - return FluentIterable.from(dstLinks.get(deviceId)) - .transform(lookupLink()) - .filter(notNull()) - .toSet(); - } - } - - @Override - public Link getLink(ConnectPoint src, ConnectPoint dst) { - return links.get(linkKey(src, dst)); - } - - @Override - public Set<Link> getEgressLinks(ConnectPoint src) { - Set<Link> egress = new HashSet<>(); - // - // Change `srcLinks` to ConcurrentMap<DeviceId, (Concurrent)Set> - // to remove this synchronized block, if we hit performance issue. - // SetMultiMap#get returns wrapped collection to provide modifiable-view. - // And the wrapped collection is not concurrent access safe. - // - // Our use case here does not require returned collection to be modifiable, - // so the wrapped collection forces us to lock the whole multiset, - // for benefit we don't need. - // - // Same applies to `dstLinks` - synchronized (srcLinks) { - for (LinkKey linkKey : srcLinks.get(src.deviceId())) { - if (linkKey.src().equals(src)) { - Link link = links.get(linkKey); - if (link != null) { - egress.add(link); - } else { - log.debug("Egress link for {} was null, skipped", linkKey); - } - } - } - } - return egress; - } - - @Override - public Set<Link> getIngressLinks(ConnectPoint dst) { - Set<Link> ingress = new HashSet<>(); - synchronized (dstLinks) { - for (LinkKey linkKey : dstLinks.get(dst.deviceId())) { - if (linkKey.dst().equals(dst)) { - Link link = links.get(linkKey); - if (link != null) { - ingress.add(link); - } else { - log.debug("Ingress link for {} was null, skipped", linkKey); - } - } - } - } - return ingress; - } - - @Override - public LinkEvent createOrUpdateLink(ProviderId providerId, - LinkDescription linkDescription) { - - final DeviceId dstDeviceId = linkDescription.dst().deviceId(); - final NodeId localNode = clusterService.getLocalNode().id(); - final NodeId dstNode = mastershipService.getMasterFor(dstDeviceId); - - // Process link update only if we're the master of the destination node, - // otherwise signal the actual master. - LinkEvent linkEvent = null; - if (localNode.equals(dstNode)) { - - Timestamp newTimestamp = deviceClockService.getTimestamp(dstDeviceId); - - final Timestamped<LinkDescription> deltaDesc = new Timestamped<>(linkDescription, newTimestamp); - - LinkKey key = linkKey(linkDescription.src(), linkDescription.dst()); - final Timestamped<LinkDescription> mergedDesc; - Map<ProviderId, Timestamped<LinkDescription>> map = getOrCreateLinkDescriptions(key); - - synchronized (map) { - linkEvent = createOrUpdateLinkInternal(providerId, deltaDesc); - mergedDesc = map.get(providerId); - } - - if (linkEvent != null) { - log.debug("Notifying peers of a link update topology event from providerId: " - + "{} between src: {} and dst: {}", - providerId, linkDescription.src(), linkDescription.dst()); - notifyPeers(new InternalLinkEvent(providerId, mergedDesc)); - } - - } else { - // FIXME Temporary hack for NPE (ONOS-1171). - // Proper fix is to implement forwarding to master on ConfigProvider - // redo ONOS-490 - if (dstNode == null) { - // silently ignore - return null; - } - - - LinkInjectedEvent linkInjectedEvent = new LinkInjectedEvent(providerId, linkDescription); - - // TODO check unicast return value - clusterCommunicator.unicast(linkInjectedEvent, - GossipLinkStoreMessageSubjects.LINK_INJECTED, - SERIALIZER::encode, - dstNode); - } - - return linkEvent; - } - - @Override - public LinkEvent removeOrDownLink(ConnectPoint src, ConnectPoint dst) { - Link link = getLink(src, dst); - if (link == null) { - return null; - } - - if (link.isDurable()) { - // FIXME: this is not the right thing to call for the gossip store; will not sync link state!!! - return link.state() == INACTIVE ? null : - updateLink(linkKey(link.src(), link.dst()), link, - new DefaultLink(link.providerId(), - link.src(), link.dst(), - link.type(), INACTIVE, - link.isDurable(), - link.annotations())); - } - return removeLink(src, dst); - } - - private LinkEvent createOrUpdateLinkInternal( - ProviderId providerId, - Timestamped<LinkDescription> linkDescription) { - - final LinkKey key = linkKey(linkDescription.value().src(), - linkDescription.value().dst()); - Map<ProviderId, Timestamped<LinkDescription>> descs = getOrCreateLinkDescriptions(key); - - synchronized (descs) { - // if the link was previously removed, we should proceed if and - // only if this request is more recent. - Timestamp linkRemovedTimestamp = removedLinks.get(key); - if (linkRemovedTimestamp != null) { - if (linkDescription.isNewerThan(linkRemovedTimestamp)) { - removedLinks.remove(key); - } else { - log.trace("Link {} was already removed ignoring.", key); - return null; - } - } - - final Link oldLink = links.get(key); - // update description - createOrUpdateLinkDescription(descs, providerId, linkDescription); - final Link newLink = composeLink(descs); - if (oldLink == null) { - return createLink(key, newLink); - } - return updateLink(key, oldLink, newLink); - } - } - - // Guarded by linkDescs value (=locking each Link) - private Timestamped<LinkDescription> createOrUpdateLinkDescription( - Map<ProviderId, Timestamped<LinkDescription>> descs, - ProviderId providerId, - Timestamped<LinkDescription> linkDescription) { - - // merge existing annotations - Timestamped<LinkDescription> existingLinkDescription = descs.get(providerId); - if (existingLinkDescription != null && existingLinkDescription.isNewer(linkDescription)) { - log.trace("local info is more up-to-date, ignoring {}.", linkDescription); - return null; - } - Timestamped<LinkDescription> newLinkDescription = linkDescription; - if (existingLinkDescription != null) { - // we only allow transition from INDIRECT -> DIRECT - final Type newType; - if (existingLinkDescription.value().type() == DIRECT) { - newType = DIRECT; - } else { - newType = linkDescription.value().type(); - } - SparseAnnotations merged = union(existingLinkDescription.value().annotations(), - linkDescription.value().annotations()); - newLinkDescription = new Timestamped<>( - new DefaultLinkDescription( - linkDescription.value().src(), - linkDescription.value().dst(), - newType, merged), - linkDescription.timestamp()); - } - return descs.put(providerId, newLinkDescription); - } - - // Creates and stores the link and returns the appropriate event. - // Guarded by linkDescs value (=locking each Link) - private LinkEvent createLink(LinkKey key, Link newLink) { - links.put(key, newLink); - srcLinks.put(newLink.src().deviceId(), key); - dstLinks.put(newLink.dst().deviceId(), key); - return new LinkEvent(LINK_ADDED, newLink); - } - - // Updates, if necessary the specified link and returns the appropriate event. - // Guarded by linkDescs value (=locking each Link) - private LinkEvent updateLink(LinkKey key, Link oldLink, Link newLink) { - // Note: INDIRECT -> DIRECT transition only - // so that BDDP discovered Link will not overwrite LDDP Link - if (oldLink.state() != newLink.state() || - (oldLink.type() == INDIRECT && newLink.type() == DIRECT) || - !AnnotationsUtil.isEqual(oldLink.annotations(), newLink.annotations())) { - - links.put(key, newLink); - // strictly speaking following can be omitted - srcLinks.put(oldLink.src().deviceId(), key); - dstLinks.put(oldLink.dst().deviceId(), key); - return new LinkEvent(LINK_UPDATED, newLink); - } - return null; - } - - @Override - public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { - final LinkKey key = linkKey(src, dst); - - DeviceId dstDeviceId = dst.deviceId(); - Timestamp timestamp = null; - try { - timestamp = deviceClockService.getTimestamp(dstDeviceId); - } catch (IllegalStateException e) { - log.debug("Failed to remove link {}, was not the master", key); - // there are times when this is called before mastership - // handoff correctly completes. - return null; - } - - LinkEvent event = removeLinkInternal(key, timestamp); - - if (event != null) { - log.debug("Notifying peers of a link removed topology event for a link " - + "between src: {} and dst: {}", src, dst); - notifyPeers(new InternalLinkRemovedEvent(key, timestamp)); - } - return event; - } - - private static Timestamped<LinkDescription> getPrimaryDescription( - Map<ProviderId, Timestamped<LinkDescription>> linkDescriptions) { - - synchronized (linkDescriptions) { - for (Entry<ProviderId, Timestamped<LinkDescription>> - e : linkDescriptions.entrySet()) { - - if (!e.getKey().isAncillary()) { - return e.getValue(); - } - } - } - return null; - } - - - // TODO: consider slicing out as Timestamp utils - /** - * Checks is timestamp is more recent than timestamped object. - * - * @param timestamp to check if this is more recent then other - * @param timestamped object to be tested against - * @return true if {@code timestamp} is more recent than {@code timestamped} - * or {@code timestamped is null} - */ - private static boolean isMoreRecent(Timestamp timestamp, Timestamped<?> timestamped) { - checkNotNull(timestamp); - if (timestamped == null) { - return true; - } - return timestamp.compareTo(timestamped.timestamp()) > 0; - } - - private LinkEvent removeLinkInternal(LinkKey key, Timestamp timestamp) { - Map<ProviderId, Timestamped<LinkDescription>> linkDescriptions - = getOrCreateLinkDescriptions(key); - - synchronized (linkDescriptions) { - if (linkDescriptions.isEmpty()) { - // never seen such link before. keeping timestamp for record - removedLinks.put(key, timestamp); - return null; - } - // accept removal request if given timestamp is newer than - // the latest Timestamp from Primary provider - Timestamped<LinkDescription> prim = getPrimaryDescription(linkDescriptions); - if (!isMoreRecent(timestamp, prim)) { - // outdated remove request, ignore - return null; - } - removedLinks.put(key, timestamp); - Link link = links.remove(key); - linkDescriptions.clear(); - if (link != null) { - srcLinks.remove(link.src().deviceId(), key); - dstLinks.remove(link.dst().deviceId(), key); - return new LinkEvent(LINK_REMOVED, link); - } - return null; - } - } - - /** - * Creates concurrent readable, synchronized HashMultimap. - * - * @return SetMultimap - */ - private static <K, V> SetMultimap<K, V> createSynchronizedHashMultiMap() { - return synchronizedSetMultimap( - Multimaps.newSetMultimap(new ConcurrentHashMap<>(), - () -> Sets.newConcurrentHashSet())); - } - - /** - * @return primary ProviderID, or randomly chosen one if none exists - */ - private static ProviderId pickBaseProviderId( - Map<ProviderId, Timestamped<LinkDescription>> linkDescriptions) { - - ProviderId fallBackPrimary = null; - for (Entry<ProviderId, Timestamped<LinkDescription>> e : linkDescriptions.entrySet()) { - if (!e.getKey().isAncillary()) { - // found primary - return e.getKey(); - } else if (fallBackPrimary == null) { - // pick randomly as a fallback in case there is no primary - fallBackPrimary = e.getKey(); - } - } - return fallBackPrimary; - } - - // Guarded by linkDescs value (=locking each Link) - private Link composeLink(Map<ProviderId, Timestamped<LinkDescription>> descs) { - ProviderId baseProviderId = pickBaseProviderId(descs); - Timestamped<LinkDescription> base = descs.get(baseProviderId); - - ConnectPoint src = base.value().src(); - ConnectPoint dst = base.value().dst(); - Type type = base.value().type(); - DefaultAnnotations annotations = DefaultAnnotations.builder().build(); - annotations = merge(annotations, base.value().annotations()); - - for (Entry<ProviderId, Timestamped<LinkDescription>> e : descs.entrySet()) { - if (baseProviderId.equals(e.getKey())) { - continue; - } - - // Note: In the long run we should keep track of Description timestamp - // and only merge conflicting keys when timestamp is newer - // Currently assuming there will never be a key conflict between - // providers - - // annotation merging. not so efficient, should revisit later - annotations = merge(annotations, e.getValue().value().annotations()); - } - - boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true"); - return new DefaultLink(baseProviderId, src, dst, type, ACTIVE, isDurable, annotations); - } - - private Map<ProviderId, Timestamped<LinkDescription>> getOrCreateLinkDescriptions(LinkKey key) { - Map<ProviderId, Timestamped<LinkDescription>> r; - r = linkDescs.get(key); - if (r != null) { - return r; - } - r = new HashMap<>(); - final Map<ProviderId, Timestamped<LinkDescription>> concurrentlyAdded; - concurrentlyAdded = linkDescs.putIfAbsent(key, r); - if (concurrentlyAdded != null) { - return concurrentlyAdded; - } else { - return r; - } - } - - private final Function<LinkKey, Link> lookupLink = new LookupLink(); - - /** - * Returns a Function to lookup Link instance using LinkKey from cache. - * - * @return lookup link function - */ - private Function<LinkKey, Link> lookupLink() { - return lookupLink; - } - - private final class LookupLink implements Function<LinkKey, Link> { - @Override - public Link apply(LinkKey input) { - if (input == null) { - return null; - } else { - return links.get(input); - } - } - } - - private void notifyDelegateIfNotNull(LinkEvent event) { - if (event != null) { - notifyDelegate(event); - } - } - - private void broadcastMessage(MessageSubject subject, Object event) { - clusterCommunicator.broadcast(event, subject, SERIALIZER::encode); - } - - private void unicastMessage(NodeId recipient, MessageSubject subject, Object event) throws IOException { - clusterCommunicator.unicast(event, subject, SERIALIZER::encode, recipient); - } - - private void notifyPeers(InternalLinkEvent event) { - broadcastMessage(GossipLinkStoreMessageSubjects.LINK_UPDATE, event); - } - - private void notifyPeers(InternalLinkRemovedEvent event) { - broadcastMessage(GossipLinkStoreMessageSubjects.LINK_REMOVED, event); - } - - // notify peer, silently ignoring error - private void notifyPeer(NodeId peer, InternalLinkEvent event) { - try { - unicastMessage(peer, GossipLinkStoreMessageSubjects.LINK_UPDATE, event); - } catch (IOException e) { - log.debug("Failed to notify peer {} with message {}", peer, event); - } - } - - // notify peer, silently ignoring error - private void notifyPeer(NodeId peer, InternalLinkRemovedEvent event) { - try { - unicastMessage(peer, GossipLinkStoreMessageSubjects.LINK_REMOVED, event); - } catch (IOException e) { - log.debug("Failed to notify peer {} with message {}", peer, event); - } - } - - private final class SendAdvertisementTask implements Runnable { - - @Override - public void run() { - if (Thread.currentThread().isInterrupted()) { - log.debug("Interrupted, quitting"); - return; - } - - try { - final NodeId self = clusterService.getLocalNode().id(); - Set<ControllerNode> nodes = clusterService.getNodes(); - - ImmutableList<NodeId> nodeIds = FluentIterable.from(nodes) - .transform(toNodeId()) - .toList(); - - if (nodeIds.size() == 1 && nodeIds.get(0).equals(self)) { - log.trace("No other peers in the cluster."); - return; - } - - NodeId peer; - do { - int idx = RandomUtils.nextInt(0, nodeIds.size()); - peer = nodeIds.get(idx); - } while (peer.equals(self)); - - LinkAntiEntropyAdvertisement ad = createAdvertisement(); - - if (Thread.currentThread().isInterrupted()) { - log.debug("Interrupted, quitting"); - return; - } - - try { - unicastMessage(peer, LINK_ANTI_ENTROPY_ADVERTISEMENT, ad); - } catch (IOException e) { - log.debug("Failed to send anti-entropy advertisement to {}", peer); - return; - } - } catch (Exception e) { - // catch all Exception to avoid Scheduled task being suppressed. - log.error("Exception thrown while sending advertisement", e); - } - } - } - - private LinkAntiEntropyAdvertisement createAdvertisement() { - final NodeId self = clusterService.getLocalNode().id(); - - Map<LinkFragmentId, Timestamp> linkTimestamps = new HashMap<>(linkDescs.size()); - Map<LinkKey, Timestamp> linkTombstones = new HashMap<>(removedLinks.size()); - - linkDescs.forEach((linkKey, linkDesc) -> { - synchronized (linkDesc) { - for (Map.Entry<ProviderId, Timestamped<LinkDescription>> e : linkDesc.entrySet()) { - linkTimestamps.put(new LinkFragmentId(linkKey, e.getKey()), e.getValue().timestamp()); - } - } - }); - - linkTombstones.putAll(removedLinks); - - return new LinkAntiEntropyAdvertisement(self, linkTimestamps, linkTombstones); - } - - private void handleAntiEntropyAdvertisement(LinkAntiEntropyAdvertisement ad) { - - final NodeId sender = ad.sender(); - boolean localOutdated = false; - - for (Entry<LinkKey, Map<ProviderId, Timestamped<LinkDescription>>> - l : linkDescs.entrySet()) { - - final LinkKey key = l.getKey(); - final Map<ProviderId, Timestamped<LinkDescription>> link = l.getValue(); - synchronized (link) { - Timestamp localLatest = removedLinks.get(key); - - for (Entry<ProviderId, Timestamped<LinkDescription>> p : link.entrySet()) { - final ProviderId providerId = p.getKey(); - final Timestamped<LinkDescription> pDesc = p.getValue(); - - final LinkFragmentId fragId = new LinkFragmentId(key, providerId); - // remote - Timestamp remoteTimestamp = ad.linkTimestamps().get(fragId); - if (remoteTimestamp == null) { - remoteTimestamp = ad.linkTombstones().get(key); - } - if (remoteTimestamp == null || - pDesc.isNewerThan(remoteTimestamp)) { - // I have more recent link description. update peer. - notifyPeer(sender, new InternalLinkEvent(providerId, pDesc)); - } else { - final Timestamp remoteLive = ad.linkTimestamps().get(fragId); - if (remoteLive != null && - remoteLive.compareTo(pDesc.timestamp()) > 0) { - // I have something outdated - localOutdated = true; - } - } - - // search local latest along the way - if (localLatest == null || - pDesc.isNewerThan(localLatest)) { - localLatest = pDesc.timestamp(); - } - } - // Tests if remote remove is more recent then local latest. - final Timestamp remoteRemove = ad.linkTombstones().get(key); - if (remoteRemove != null) { - if (localLatest != null && - localLatest.compareTo(remoteRemove) < 0) { - // remote remove is more recent - notifyDelegateIfNotNull(removeLinkInternal(key, remoteRemove)); - } - } - } - } - - // populate remove info if not known locally - for (Entry<LinkKey, Timestamp> remoteRm : ad.linkTombstones().entrySet()) { - final LinkKey key = remoteRm.getKey(); - final Timestamp remoteRemove = remoteRm.getValue(); - // relying on removeLinkInternal to ignore stale info - notifyDelegateIfNotNull(removeLinkInternal(key, remoteRemove)); - } - - if (localOutdated) { - // send back advertisement to speed up convergence - try { - unicastMessage(sender, LINK_ANTI_ENTROPY_ADVERTISEMENT, - createAdvertisement()); - } catch (IOException e) { - log.debug("Failed to send back active advertisement"); - } - } - } - - private final class InternalLinkEventListener - implements ClusterMessageHandler { - @Override - public void handle(ClusterMessage message) { - - log.trace("Received link event from peer: {}", message.sender()); - InternalLinkEvent event = SERIALIZER.decode(message.payload()); - - ProviderId providerId = event.providerId(); - Timestamped<LinkDescription> linkDescription = event.linkDescription(); - - try { - notifyDelegateIfNotNull(createOrUpdateLinkInternal(providerId, linkDescription)); - } catch (Exception e) { - log.warn("Exception thrown handling link event", e); - } - } - } - - private final class InternalLinkRemovedEventListener - implements ClusterMessageHandler { - @Override - public void handle(ClusterMessage message) { - - log.trace("Received link removed event from peer: {}", message.sender()); - InternalLinkRemovedEvent event = SERIALIZER.decode(message.payload()); - - LinkKey linkKey = event.linkKey(); - Timestamp timestamp = event.timestamp(); - - try { - notifyDelegateIfNotNull(removeLinkInternal(linkKey, timestamp)); - } catch (Exception e) { - log.warn("Exception thrown handling link removed", e); - } - } - } - - private final class InternalLinkAntiEntropyAdvertisementListener - implements ClusterMessageHandler { - - @Override - public void handle(ClusterMessage message) { - log.trace("Received Link Anti-Entropy advertisement from peer: {}", message.sender()); - LinkAntiEntropyAdvertisement advertisement = SERIALIZER.decode(message.payload()); - try { - handleAntiEntropyAdvertisement(advertisement); - } catch (Exception e) { - log.warn("Exception thrown while handling Link advertisements", e); - throw e; - } - } - } - - private final class LinkInjectedEventListener - implements ClusterMessageHandler { - @Override - public void handle(ClusterMessage message) { - - log.trace("Received injected link event from peer: {}", message.sender()); - LinkInjectedEvent linkInjectedEvent = SERIALIZER.decode(message.payload()); - - ProviderId providerId = linkInjectedEvent.providerId(); - LinkDescription linkDescription = linkInjectedEvent.linkDescription(); - - final DeviceId deviceId = linkDescription.dst().deviceId(); - if (!deviceClockService.isTimestampAvailable(deviceId)) { - // workaround for ONOS-1208 - log.warn("Not ready to accept update. Dropping {}", linkDescription); - return; - } - - try { - createOrUpdateLink(providerId, linkDescription); - } catch (Exception e) { - log.warn("Exception thrown while handling link injected event", e); - } - } - } -} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStoreMessageSubjects.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStoreMessageSubjects.java deleted file mode 100644 index e0e1dda3..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStoreMessageSubjects.java +++ /dev/null @@ -1,35 +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.store.link.impl; - - import org.onosproject.store.cluster.messaging.MessageSubject; - -/** - * MessageSubjects used by GossipLinkStore peer-peer communication. - */ -public final class GossipLinkStoreMessageSubjects { - - private GossipLinkStoreMessageSubjects() {} - - public static final MessageSubject LINK_UPDATE = - new MessageSubject("peer-link-update"); - public static final MessageSubject LINK_REMOVED = - new MessageSubject("peer-link-removed"); - public static final MessageSubject LINK_ANTI_ENTROPY_ADVERTISEMENT = - new MessageSubject("link-enti-entropy-advertisement"); - public static final MessageSubject LINK_INJECTED = - new MessageSubject("peer-link-injected"); -} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/InternalLinkEvent.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/InternalLinkEvent.java deleted file mode 100644 index 2319f274..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/InternalLinkEvent.java +++ /dev/null @@ -1,61 +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.store.link.impl; - -import com.google.common.base.MoreObjects; - -import org.onosproject.net.link.LinkDescription; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.store.impl.Timestamped; - -/** - * Information published by GossipDeviceStore to notify peers of a device - * change event. - */ -public class InternalLinkEvent { - - private final ProviderId providerId; - private final Timestamped<LinkDescription> linkDescription; - - protected InternalLinkEvent( - ProviderId providerId, - Timestamped<LinkDescription> linkDescription) { - this.providerId = providerId; - this.linkDescription = linkDescription; - } - - public ProviderId providerId() { - return providerId; - } - - public Timestamped<LinkDescription> linkDescription() { - return linkDescription; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("providerId", providerId) - .add("linkDescription", linkDescription) - .toString(); - } - - // for serializer - protected InternalLinkEvent() { - this.providerId = null; - this.linkDescription = null; - } -} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/InternalLinkRemovedEvent.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/InternalLinkRemovedEvent.java deleted file mode 100644 index 9d867203..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/InternalLinkRemovedEvent.java +++ /dev/null @@ -1,64 +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.store.link.impl; - -import org.onosproject.net.LinkKey; -import org.onosproject.store.Timestamp; - -import com.google.common.base.MoreObjects; - -/** - * Information published by GossipLinkStore to notify peers of a link - * being removed. - */ -public class InternalLinkRemovedEvent { - - private final LinkKey linkKey; - private final Timestamp timestamp; - - /** - * Creates a InternalLinkRemovedEvent. - * @param linkKey identifier of the removed link. - * @param timestamp timestamp of when the link was removed. - */ - public InternalLinkRemovedEvent(LinkKey linkKey, Timestamp timestamp) { - this.linkKey = linkKey; - this.timestamp = timestamp; - } - - public LinkKey linkKey() { - return linkKey; - } - - public Timestamp timestamp() { - return timestamp; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("linkKey", linkKey) - .add("timestamp", timestamp) - .toString(); - } - - // for serializer - @SuppressWarnings("unused") - private InternalLinkRemovedEvent() { - linkKey = null; - timestamp = null; - } -} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkAntiEntropyAdvertisement.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkAntiEntropyAdvertisement.java deleted file mode 100644 index 73c1042e..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkAntiEntropyAdvertisement.java +++ /dev/null @@ -1,63 +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.store.link.impl; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import org.onosproject.cluster.NodeId; -import org.onosproject.net.LinkKey; -import org.onosproject.store.Timestamp; - -/** - * Link AE Advertisement message. - */ -public class LinkAntiEntropyAdvertisement { - - private final NodeId sender; - private final Map<LinkFragmentId, Timestamp> linkTimestamps; - private final Map<LinkKey, Timestamp> linkTombstones; - - - public LinkAntiEntropyAdvertisement(NodeId sender, - Map<LinkFragmentId, Timestamp> linkTimestamps, - Map<LinkKey, Timestamp> linkTombstones) { - this.sender = checkNotNull(sender); - this.linkTimestamps = checkNotNull(linkTimestamps); - this.linkTombstones = checkNotNull(linkTombstones); - } - - public NodeId sender() { - return sender; - } - - public Map<LinkFragmentId, Timestamp> linkTimestamps() { - return linkTimestamps; - } - - public Map<LinkKey, Timestamp> linkTombstones() { - return linkTombstones; - } - - // For serializer - @SuppressWarnings("unused") - private LinkAntiEntropyAdvertisement() { - this.sender = null; - this.linkTimestamps = null; - this.linkTombstones = null; - } -} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkFragmentId.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkFragmentId.java deleted file mode 100644 index af7ce4fc..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkFragmentId.java +++ /dev/null @@ -1,77 +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.store.link.impl; - -import java.util.Objects; - -import org.onosproject.net.LinkKey; -import org.onosproject.net.provider.ProviderId; - -import com.google.common.base.MoreObjects; - -/** - * Identifier for LinkDescription from a Provider. - */ -public final class LinkFragmentId { - public final ProviderId providerId; - public final LinkKey linkKey; - - public LinkFragmentId(LinkKey linkKey, ProviderId providerId) { - this.providerId = providerId; - this.linkKey = linkKey; - } - - public LinkKey linkKey() { - return linkKey; - } - - public ProviderId providerId() { - return providerId; - } - - @Override - public int hashCode() { - return Objects.hash(providerId, linkKey); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof LinkFragmentId)) { - return false; - } - LinkFragmentId that = (LinkFragmentId) obj; - return Objects.equals(this.linkKey, that.linkKey) && - Objects.equals(this.providerId, that.providerId); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("providerId", providerId) - .add("linkKey", linkKey) - .toString(); - } - - // for serializer - @SuppressWarnings("unused") - private LinkFragmentId() { - this.providerId = null; - this.linkKey = null; - } -} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkInjectedEvent.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkInjectedEvent.java deleted file mode 100644 index b353208d..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/LinkInjectedEvent.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.store.link.impl; - -import com.google.common.base.MoreObjects; -import org.onosproject.net.link.LinkDescription; -import org.onosproject.net.provider.ProviderId; - -public class LinkInjectedEvent { - - ProviderId providerId; - LinkDescription linkDescription; - - public LinkInjectedEvent(ProviderId providerId, LinkDescription linkDescription) { - this.providerId = providerId; - this.linkDescription = linkDescription; - } - - public ProviderId providerId() { - return providerId; - } - - public LinkDescription linkDescription() { - return linkDescription; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("providerId", providerId) - .add("linkDescription", linkDescription) - .toString(); - } - - // for serializer - protected LinkInjectedEvent() { - this.providerId = null; - this.linkDescription = null; - } -} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/Provided.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/Provided.java deleted file mode 100644 index b5b9e644..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/Provided.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.store.link.impl; - -import java.util.Objects; - -import org.onosproject.net.provider.ProviderId; - -import com.google.common.base.MoreObjects; - -/** - * Encapsulation of a provider supplied key. - * - * @param <K> key - */ -public class Provided<K> { - private final K key; - private final ProviderId providerId; - - public Provided(K key, ProviderId providerId) { - this.key = key; - this.providerId = providerId; - } - - public ProviderId providerId() { - return providerId; - } - - public K key() { - return key; - } - - @Override - public int hashCode() { - return Objects.hash(key, providerId); - } - - @Override - public boolean equals(Object other) { - if (other instanceof Provided) { - Provided<K> that = (Provided) other; - return Objects.equals(key, that.key) && - Objects.equals(providerId, that.providerId); - } - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("key", key) - .add("providerId", providerId) - .toString(); - } -} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/package-info.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/impl/package-info.java deleted file mode 100644 index 97f2ccae..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/link/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. - */ - -/** - * Implementation of distributed link store using p2p synchronization protocol. - */ -package org.onosproject.store.link.impl; |