mirror of
				https://github.com/opennetworkinglab/onos.git
				synced 2025-11-04 10:11:16 +01:00 
			
		
		
		
	Simplify MP2S compiler, fix ingress/egress on same switch bug in SP2M compiler
Change-Id: Ib47bba01aac0f358f2caa5525c18e0e90a0b13ff
This commit is contained in:
		
							parent
							
								
									a7f81e5e03
								
							
						
					
					
						commit
						066244c31c
					
				@ -27,7 +27,6 @@ import org.onosproject.core.CoreService;
 | 
			
		||||
import org.onosproject.core.DefaultGroupId;
 | 
			
		||||
import org.onosproject.net.ConnectPoint;
 | 
			
		||||
import org.onosproject.net.DeviceId;
 | 
			
		||||
import org.onosproject.net.EdgeLink;
 | 
			
		||||
import org.onosproject.net.Link;
 | 
			
		||||
import org.onosproject.net.PortNumber;
 | 
			
		||||
import org.onosproject.net.flow.DefaultFlowRule;
 | 
			
		||||
@ -78,18 +77,8 @@ public class LinkCollectionIntentCompiler implements IntentCompiler<LinkCollecti
 | 
			
		||||
        SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
 | 
			
		||||
 | 
			
		||||
        for (Link link : intent.links()) {
 | 
			
		||||
            DeviceId srcDeviceId;
 | 
			
		||||
            DeviceId dstDeviceId;
 | 
			
		||||
 | 
			
		||||
            if (link instanceof EdgeLink) {
 | 
			
		||||
                EdgeLink edgeLink = (EdgeLink) link;
 | 
			
		||||
                dstDeviceId = edgeLink.hostLocation().deviceId();
 | 
			
		||||
                srcDeviceId = dstDeviceId;
 | 
			
		||||
            } else {
 | 
			
		||||
            inputPorts.put(link.dst().deviceId(), link.dst().port());
 | 
			
		||||
                srcDeviceId = link.src().deviceId();
 | 
			
		||||
            }
 | 
			
		||||
            outputPorts.put(srcDeviceId, link.src().port());
 | 
			
		||||
            outputPorts.put(link.src().deviceId(), link.src().port());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (ConnectPoint ingressPoint : intent.ingressPoints()) {
 | 
			
		||||
 | 
			
		||||
@ -15,12 +15,8 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.onosproject.net.intent.impl.compiler;
 | 
			
		||||
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableSet;
 | 
			
		||||
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;
 | 
			
		||||
@ -40,10 +36,11 @@ import org.onosproject.net.intent.impl.PathNotFoundException;
 | 
			
		||||
import org.onosproject.net.resource.link.LinkResourceAllocations;
 | 
			
		||||
import org.onosproject.net.topology.PathService;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableSet;
 | 
			
		||||
import com.google.common.collect.Sets;
 | 
			
		||||
 | 
			
		||||
import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An intent compiler for
 | 
			
		||||
@ -73,14 +70,12 @@ public class MultiPointToSinglePointIntentCompiler
 | 
			
		||||
    public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable,
 | 
			
		||||
                                Set<LinkResourceAllocations> resources) {
 | 
			
		||||
        Map<DeviceId, Link> links = new HashMap<>();
 | 
			
		||||
        Map<DeviceId, Link> edgeLinks = new HashMap<>();
 | 
			
		||||
        ConnectPoint egressPoint = intent.egressPoint();
 | 
			
		||||
 | 
			
		||||
        for (ConnectPoint ingressPoint : intent.ingressPoints()) {
 | 
			
		||||
            if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
 | 
			
		||||
                edgeLinks.put(ingressPoint.deviceId(), createEdgeLink(ingressPoint, true));
 | 
			
		||||
                edgeLinks.put(egressPoint.deviceId(), createEdgeLink(egressPoint, false));
 | 
			
		||||
            } else {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            Path path = getPath(ingressPoint, intent.egressPoint());
 | 
			
		||||
            for (Link link : path.links()) {
 | 
			
		||||
                if (links.containsKey(link.src().deviceId())) {
 | 
			
		||||
@ -95,15 +90,12 @@ public class MultiPointToSinglePointIntentCompiler
 | 
			
		||||
                links.put(link.src().deviceId(), link);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Set<Link> allLinks = Sets.newHashSet(links.values());
 | 
			
		||||
        allLinks.addAll(edgeLinks.values());
 | 
			
		||||
        Intent result = LinkCollectionIntent.builder()
 | 
			
		||||
                .appId(intent.appId())
 | 
			
		||||
                .selector(intent.selector())
 | 
			
		||||
                .treatment(intent.treatment())
 | 
			
		||||
                .links(Sets.newHashSet(allLinks))
 | 
			
		||||
                .links(Sets.newHashSet(links.values()))
 | 
			
		||||
                .ingressPoints(intent.ingressPoints())
 | 
			
		||||
                .egressPoints(ImmutableSet.of(intent.egressPoint()))
 | 
			
		||||
                .priority(intent.priority())
 | 
			
		||||
 | 
			
		||||
@ -15,11 +15,7 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.onosproject.net.intent.impl.compiler;
 | 
			
		||||
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableSet;
 | 
			
		||||
import org.apache.felix.scr.annotations.Activate;
 | 
			
		||||
import org.apache.felix.scr.annotations.Component;
 | 
			
		||||
import org.apache.felix.scr.annotations.Deactivate;
 | 
			
		||||
@ -32,7 +28,10 @@ import org.onosproject.net.intent.SinglePointToMultiPointIntent;
 | 
			
		||||
import org.onosproject.net.provider.ProviderId;
 | 
			
		||||
import org.onosproject.net.resource.link.LinkResourceAllocations;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableSet;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
@Component(immediate = true)
 | 
			
		||||
public class SinglePointToMultiPointIntentCompiler
 | 
			
		||||
@ -59,8 +58,12 @@ public class SinglePointToMultiPointIntentCompiler
 | 
			
		||||
                                List<Intent> installable,
 | 
			
		||||
                                Set<LinkResourceAllocations> resources) {
 | 
			
		||||
        Set<Link> links = new HashSet<>();
 | 
			
		||||
        //FIXME: need to handle the case where ingress/egress points are on same switch
 | 
			
		||||
 | 
			
		||||
        for (ConnectPoint egressPoint : intent.egressPoints()) {
 | 
			
		||||
            if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
 | 
			
		||||
            links.addAll(path.links());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -15,10 +15,6 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.onosproject.net.intent.impl.compiler;
 | 
			
		||||
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import org.hamcrest.Matchers;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.onosproject.TestApplicationId;
 | 
			
		||||
@ -36,6 +32,10 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent;
 | 
			
		||||
import org.onosproject.net.topology.LinkWeight;
 | 
			
		||||
import org.onosproject.net.topology.PathService;
 | 
			
		||||
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import static org.hamcrest.CoreMatchers.instanceOf;
 | 
			
		||||
import static org.hamcrest.CoreMatchers.notNullValue;
 | 
			
		||||
import static org.hamcrest.MatcherAssert.assertThat;
 | 
			
		||||
@ -255,11 +255,9 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
 | 
			
		||||
 | 
			
		||||
        if (resultIntent instanceof LinkCollectionIntent) {
 | 
			
		||||
            LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
 | 
			
		||||
            assertThat(linkIntent.links(), hasSize(ingress.length + 1));
 | 
			
		||||
            assertThat(linkIntent.links(), hasSize(ingress.length));
 | 
			
		||||
 | 
			
		||||
            assertThat(linkIntent.links(), linksHasPath("i2", "i1"));
 | 
			
		||||
 | 
			
		||||
            assertThat(linkIntent.links(), linksHasPath("i1", "i1"));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user