Jonathan Hart

Modified the MultiPointToSinglePointIntentCompiler to prevent duplicate packets

Change-Id: Ifb7609be04ed8a0330b7a0b47420ca33af0656c6
...@@ -15,12 +15,19 @@ ...@@ -15,12 +15,19 @@
15 */ 15 */
16 package org.onlab.onos.net.intent.impl; 16 package org.onlab.onos.net.intent.impl;
17 17
18 +import java.util.Arrays;
19 +import java.util.HashMap;
20 +import java.util.List;
21 +import java.util.Map;
22 +import java.util.Set;
23 +
18 import org.apache.felix.scr.annotations.Activate; 24 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 25 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 26 import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference; 27 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 28 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.onlab.onos.net.ConnectPoint; 29 import org.onlab.onos.net.ConnectPoint;
30 +import org.onlab.onos.net.DeviceId;
24 import org.onlab.onos.net.Link; 31 import org.onlab.onos.net.Link;
25 import org.onlab.onos.net.Path; 32 import org.onlab.onos.net.Path;
26 import org.onlab.onos.net.intent.Intent; 33 import org.onlab.onos.net.intent.Intent;
...@@ -32,10 +39,7 @@ import org.onlab.onos.net.intent.PointToPointIntent; ...@@ -32,10 +39,7 @@ import org.onlab.onos.net.intent.PointToPointIntent;
32 import org.onlab.onos.net.resource.LinkResourceAllocations; 39 import org.onlab.onos.net.resource.LinkResourceAllocations;
33 import org.onlab.onos.net.topology.PathService; 40 import org.onlab.onos.net.topology.PathService;
34 41
35 -import java.util.Arrays; 42 +import com.google.common.collect.Sets;
36 -import java.util.HashSet;
37 -import java.util.List;
38 -import java.util.Set;
39 43
40 /** 44 /**
41 * An intent compiler for 45 * An intent compiler for
...@@ -64,16 +68,25 @@ public class MultiPointToSinglePointIntentCompiler ...@@ -64,16 +68,25 @@ public class MultiPointToSinglePointIntentCompiler
64 @Override 68 @Override
65 public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable, 69 public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable,
66 Set<LinkResourceAllocations> resources) { 70 Set<LinkResourceAllocations> resources) {
67 - Set<Link> links = new HashSet<>(); 71 + Map<DeviceId, Link> links = new HashMap<>();
68 72
69 for (ConnectPoint ingressPoint : intent.ingressPoints()) { 73 for (ConnectPoint ingressPoint : intent.ingressPoints()) {
70 Path path = getPath(ingressPoint, intent.egressPoint()); 74 Path path = getPath(ingressPoint, intent.egressPoint());
71 - links.addAll(path.links()); 75 + for (Link link : path.links()) {
76 + if (links.containsKey(link.src().deviceId())) {
77 + // We've already reached the existing tree with the first
78 + // part of this path. Don't add the remainder of the path
79 + // in case it differs from the path we already have.
80 + break;
81 + }
82 +
83 + links.put(link.src().deviceId(), link);
84 + }
72 } 85 }
73 86
74 Intent result = new LinkCollectionIntent(intent.appId(), 87 Intent result = new LinkCollectionIntent(intent.appId(),
75 intent.selector(), intent.treatment(), 88 intent.selector(), intent.treatment(),
76 - links, intent.egressPoint()); 89 + Sets.newHashSet(links.values()), intent.egressPoint());
77 return Arrays.asList(result); 90 return Arrays.asList(result);
78 } 91 }
79 92
......