From f5e3580f8d6cefb9ac47349c12768c0fbcddf12c Mon Sep 17 00:00:00 2001 From: Jonathan Hart Date: Mon, 1 Dec 2014 20:45:18 -0800 Subject: [PATCH] Modified the MultiPointToSinglePointIntentCompiler to prevent duplicate packets Change-Id: Ifb7609be04ed8a0330b7a0b47420ca33af0656c6 --- ...MultiPointToSinglePointIntentCompiler.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java index 9b8b149df1..047ace20f0 100644 --- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java +++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java @@ -15,12 +15,19 @@ */ package org.onlab.onos.net.intent.impl; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + 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.onlab.onos.net.ConnectPoint; +import org.onlab.onos.net.DeviceId; import org.onlab.onos.net.Link; import org.onlab.onos.net.Path; import org.onlab.onos.net.intent.Intent; @@ -32,10 +39,7 @@ import org.onlab.onos.net.intent.PointToPointIntent; import org.onlab.onos.net.resource.LinkResourceAllocations; import org.onlab.onos.net.topology.PathService; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import com.google.common.collect.Sets; /** * An intent compiler for @@ -64,16 +68,25 @@ public class MultiPointToSinglePointIntentCompiler @Override public List compile(MultiPointToSinglePointIntent intent, List installable, Set resources) { - Set links = new HashSet<>(); + Map links = new HashMap<>(); for (ConnectPoint ingressPoint : intent.ingressPoints()) { Path path = getPath(ingressPoint, intent.egressPoint()); - links.addAll(path.links()); + for (Link link : path.links()) { + if (links.containsKey(link.src().deviceId())) { + // We've already reached the existing tree with the first + // part of this path. Don't add the remainder of the path + // in case it differs from the path we already have. + break; + } + + links.put(link.src().deviceId(), link); + } } Intent result = new LinkCollectionIntent(intent.appId(), intent.selector(), intent.treatment(), - links, intent.egressPoint()); + Sets.newHashSet(links.values()), intent.egressPoint()); return Arrays.asList(result); }