Search in sources :

Example 1 with MultiPointToSinglePointIntent

use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.

the class IntentSynchronizerTest method intentBuilder.

/**
 * MultiPointToSinglePointIntent builder.
 *
 * @param ipPrefix the ipPrefix to match
 * @param nextHopMacAddress to which the destination MAC address in packet
 * should be rewritten
 * @param egressPoint to which packets should be sent
 * @return the constructed MultiPointToSinglePointIntent
 */
private MultiPointToSinglePointIntent intentBuilder(IpPrefix ipPrefix, String nextHopMacAddress, ConnectPoint egressPoint) {
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    if (ipPrefix.isIp4()) {
        selectorBuilder.matchEthType(Ethernet.TYPE_IPV4);
        selectorBuilder.matchIPDst(ipPrefix);
    } else {
        selectorBuilder.matchEthType(Ethernet.TYPE_IPV6);
        selectorBuilder.matchIPv6Dst(ipPrefix);
    }
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress));
    Set<ConnectPoint> ingressPoints = new HashSet<>(connectPoints);
    ingressPoints.remove(egressPoint);
    MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(APPID).key(Key.of(ipPrefix.toString(), APPID)).selector(selectorBuilder.build()).treatment(treatmentBuilder.build()).ingressPoints(ingressPoints).egressPoint(egressPoint).build();
    return intent;
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) HashSet(java.util.HashSet)

Example 2 with MultiPointToSinglePointIntent

use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.

the class IntentSynchronizerTest method testIntentSync.

/**
 * Tests the synchronization behavior of intent synchronizer. We set up
 * a discrepancy between the intent service state and the intent
 * synchronizer's state and ensure that this is reconciled correctly.
 */
@Test
public void testIntentSync() {
    // Construct routes and intents.
    // This test simulates the following cases during the master change
    // time interval:
    // 1. intent1 did not change and the intent also did not change.
    // 2. intent2 was deleted, but the intent was not deleted.
    // 3. intent3 was newly added, and the intent was also submitted.
    // 4. intent4 was updated to RouteEntry4Update, and the intent was
    // also updated to a new one.
    // 5. intent5 did not change, but its intent id changed.
    // 6. intent6 was newly added, but the intent was not submitted.
    MultiPointToSinglePointIntent intent1 = intentBuilder(Ip4Prefix.valueOf("1.1.1.0/24"), "00:00:00:00:00:01", SW1_ETH1);
    MultiPointToSinglePointIntent intent2 = intentBuilder(Ip4Prefix.valueOf("2.2.2.0/24"), "00:00:00:00:00:02", SW2_ETH1);
    MultiPointToSinglePointIntent intent3 = intentBuilder(Ip4Prefix.valueOf("3.3.3.0/24"), "00:00:00:00:00:03", SW3_ETH1);
    MultiPointToSinglePointIntent intent4 = intentBuilder(Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:03", SW3_ETH1);
    MultiPointToSinglePointIntent intent4Update = intentBuilder(Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:02", SW2_ETH1);
    MultiPointToSinglePointIntent intent5 = intentBuilder(Ip4Prefix.valueOf("5.5.5.0/24"), "00:00:00:00:00:01", SW1_ETH1);
    MultiPointToSinglePointIntent intent7 = intentBuilder(Ip4Prefix.valueOf("7.7.7.0/24"), "00:00:00:00:00:01", SW1_ETH1);
    MultiPointToSinglePointIntent intent6 = intentBuilder(Ip4Prefix.valueOf("6.6.6.0/24"), "00:00:00:00:00:01", SW1_ETH1);
    // Set up expectation
    Set<Intent> intents = new HashSet<>();
    intents.add(intent1);
    EasyMock.expect(intentService.getIntentState(intent1.key())).andReturn(IntentState.INSTALLED).anyTimes();
    intents.add(intent2);
    EasyMock.expect(intentService.getIntentState(intent2.key())).andReturn(IntentState.INSTALLED).anyTimes();
    intents.add(intent4);
    EasyMock.expect(intentService.getIntentState(intent4.key())).andReturn(IntentState.INSTALLED).anyTimes();
    intents.add(intent5);
    EasyMock.expect(intentService.getIntentState(intent5.key())).andReturn(IntentState.INSTALLED).anyTimes();
    intents.add(intent7);
    EasyMock.expect(intentService.getIntentState(intent7.key())).andReturn(IntentState.WITHDRAWING).anyTimes();
    EasyMock.expect(intentService.getIntents()).andReturn(intents).anyTimes();
    // These are the operations that should be done to the intentService
    // during synchronization
    intentService.withdraw(intent2);
    intentService.submit(intent3);
    intentService.submit(intent4Update);
    intentService.submit(intent6);
    intentService.submit(intent7);
    EasyMock.replay(intentService);
    // Start the test
    // Simulate some input from the clients. The intent synchronizer has not
    // gained the global leadership yet, but it will remember this input for
    // when it does.
    intentSynchronizer.submit(intent1);
    intentSynchronizer.submit(intent2);
    intentSynchronizer.withdraw(intent2);
    intentSynchronizer.submit(intent3);
    intentSynchronizer.submit(intent4);
    intentSynchronizer.submit(intent4Update);
    intentSynchronizer.submit(intent5);
    intentSynchronizer.submit(intent6);
    intentSynchronizer.submit(intent7);
    // Give the leadership to the intent synchronizer. It will now attempt
    // to synchronize the intents in the store with the intents it has
    // recorded based on the earlier user input.
    intentSynchronizer.modifyPrimary(true);
    EasyMock.verify(intentService);
}
Also used : MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 3 with MultiPointToSinglePointIntent

use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.

the class SdnIpFib method update.

private void update(ResolvedRoute route) {
    synchronized (this) {
        IpPrefix prefix = route.prefix();
        EncapsulationType encap = encap();
        MultiPointToSinglePointIntent intent = generateRouteIntent(prefix, route.nextHop(), route.nextHopMac(), encap);
        if (intent == null) {
            log.debug("No interface found for route {}", route);
            return;
        }
        routeIntents.put(prefix, intent);
        intentSynchronizer.submit(intent);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) EncapsulationType(org.onosproject.net.EncapsulationType) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent)

Example 4 with MultiPointToSinglePointIntent

use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.

the class SdnIpFib method removeInterface.

/*
     * Handles the case in which an existing interface gets removed.
     */
private void removeInterface(Interface intf) {
    synchronized (this) {
        for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) {
            // Retrieve the IP prefix and intent possibly affected
            IpPrefix prefix = entry.getKey();
            MultiPointToSinglePointIntent intent = entry.getValue();
            // The interface removed might be an ingress interface, so the
            // selector needs to match on the interface tagging params and
            // on the prefix
            TrafficSelector.Builder ingressSelector = buildIngressTrafficSelector(intf, prefix);
            FilteredConnectPoint removedIngressFilteredCP = new FilteredConnectPoint(intf.connectPoint(), ingressSelector.build());
            // The interface removed might be an egress interface, so the
            // selector needs to match only on the interface tagging params
            TrafficSelector.Builder selector = buildTrafficSelector(intf);
            FilteredConnectPoint removedEgressFilteredCP = new FilteredConnectPoint(intf.connectPoint(), selector.build());
            if (intent.filteredEgressPoint().equals(removedEgressFilteredCP)) {
                // The interface is an egress interface for the intent.
                // This intent just lost its head. Remove it and let higher
                // layer routing reroute
                intentSynchronizer.withdraw(routeIntents.remove(entry.getKey()));
            } else {
                if (intent.filteredIngressPoints().contains(removedIngressFilteredCP)) {
                    // The FilteredConnectPoint is an ingress
                    // FilteredConnectPoint for the intent
                    Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(intent.filteredIngressPoints());
                    // Remove FilteredConnectPoint from the existing set
                    ingressFilteredCPs.remove(removedIngressFilteredCP);
                    if (!ingressFilteredCPs.isEmpty()) {
                        // There are still ingress points. Create a new
                        // intent and resubmit
                        MultiPointToSinglePointIntent newIntent = MultiPointToSinglePointIntent.builder(intent).filteredIngressPoints(ingressFilteredCPs).build();
                        routeIntents.put(entry.getKey(), newIntent);
                        intentSynchronizer.submit(newIntent);
                    } else {
                        // No more ingress FilteredConnectPoint. Withdraw
                        // the intent
                        intentSynchronizer.withdraw(routeIntents.remove(entry.getKey()));
                    }
                }
            }
        }
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 5 with MultiPointToSinglePointIntent

use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.

the class SdnIpFib method encapUpdate.

/*
     * Triggered when the network configuration configuration is modified.
     * It checks if the encapsulation type has changed from last time, and in
     * case modifies all intents.
     */
private void encapUpdate() {
    synchronized (this) {
        // Get the encapsulation type just set from the configuration
        EncapsulationType encap = encap();
        for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) {
            // Get each intent currently registered by SDN-IP
            MultiPointToSinglePointIntent intent = entry.getValue();
            // Make sure the same constraint is not already part of the
            // intent constraints
            List<Constraint> constraints = intent.constraints();
            if (!constraints.stream().filter(c -> c instanceof EncapsulationConstraint && new EncapsulationConstraint(encap).equals(c)).findAny().isPresent()) {
                MultiPointToSinglePointIntent.Builder intentBuilder = MultiPointToSinglePointIntent.builder(intent);
                // Set the new encapsulation constraint
                setEncap(intentBuilder, constraints, encap);
                // Build and submit the new intent
                MultiPointToSinglePointIntent newIntent = intentBuilder.build();
                routeIntents.put(entry.getKey(), newIntent);
                intentSynchronizer.submit(newIntent);
            }
        }
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) NONE(org.onosproject.net.EncapsulationType.NONE) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) LoggerFactory(org.slf4j.LoggerFactory) RouteEvent(org.onosproject.routeservice.RouteEvent) InterfaceService(org.onosproject.net.intf.InterfaceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) Ethernet(org.onlab.packet.Ethernet) InterfaceListener(org.onosproject.net.intf.InterfaceListener) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Activate(org.osgi.service.component.annotations.Activate) IntentSynchronizationService(org.onosproject.intentsync.IntentSynchronizationService) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) RouteService(org.onosproject.routeservice.RouteService) SdnIpConfig(org.onosproject.sdnip.config.SdnIpConfig) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) VlanId(org.onlab.packet.VlanId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) InterfaceEvent(org.onosproject.net.intf.InterfaceEvent) Sets(com.google.common.collect.Sets) Constraint(org.onosproject.net.intent.Constraint) RouteListener(org.onosproject.routeservice.RouteListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Key(org.onosproject.net.intent.Key) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) IpPrefix(org.onlab.packet.IpPrefix) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) EncapsulationType(org.onosproject.net.EncapsulationType) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent)

Aggregations

MultiPointToSinglePointIntent (org.onosproject.net.intent.MultiPointToSinglePointIntent)52 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)31 ConnectPoint (org.onosproject.net.ConnectPoint)25 Test (org.junit.Test)21 TrafficSelector (org.onosproject.net.flow.TrafficSelector)21 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)20 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)20 Intent (org.onosproject.net.intent.Intent)16 Key (org.onosproject.net.intent.Key)14 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)11 HashSet (java.util.HashSet)10 Constraint (org.onosproject.net.intent.Constraint)9 PartialFailureConstraint (org.onosproject.net.intent.constraint.PartialFailureConstraint)9 Interface (org.onosproject.net.intf.Interface)9 Map (java.util.Map)8 IpPrefix (org.onlab.packet.IpPrefix)8 MacAddress (org.onlab.packet.MacAddress)8 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)6