Search in sources :

Example 16 with Intent

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

the class HostToHostIntentCompiler method createLinkCollectionIntent.

private Intent createLinkCollectionIntent(Path path, Host src, Host dst, HostToHostIntent intent) {
    // Try to allocate bandwidth
    List<ConnectPoint> pathCPs = path.links().stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
    allocateBandwidth(intent, pathCPs);
    Link ingressLink = path.links().get(0);
    Link egressLink = path.links().get(path.links().size() - 1);
    FilteredConnectPoint ingressPoint = getFilteredPointFromLink(ingressLink);
    FilteredConnectPoint egressPoint = getFilteredPointFromLink(egressLink);
    TrafficSelector selector = builder(intent.selector()).matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
    /*
         * The path contains also the edge links, these are not necessary
         * for the LinkCollectionIntent.
         */
    Set<Link> coreLinks = path.links().stream().filter(link -> !link.type().equals(EDGE)).collect(Collectors.toSet());
    return LinkCollectionIntent.builder().key(intent.key()).appId(intent.appId()).selector(selector).treatment(intent.treatment()).links(coreLinks).filteredIngressPoints(ImmutableSet.of(ingressPoint)).filteredEgressPoints(ImmutableSet.of(egressPoint)).applyTreatmentOnEgress(true).constraints(intent.constraints()).priority(intent.priority()).resourceGroup(intent.resourceGroup()).build();
}
Also used : Arrays(java.util.Arrays) Host(org.onosproject.net.Host) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) DefaultLink(org.onosproject.net.DefaultLink) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) DefaultTrafficSelector.builder(org.onosproject.net.flow.DefaultTrafficSelector.builder) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) EDGE(org.onosproject.net.Link.Type.EDGE) Path(org.onosproject.net.Path) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 17 with Intent

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

the class CompilerRegistry method compile.

/**
 * Compiles an intent recursively.
 *
 * @param intent intent
 * @param previousInstallables previous intent installables
 * @return result of compilation
 */
List<Intent> compile(Intent intent, List<Intent> previousInstallables) {
    if (intent.isInstallable()) {
        return ImmutableList.of(intent);
    }
    // FIXME: get previous resources
    List<Intent> installables = new ArrayList<>();
    Queue<Intent> compileQueue = new LinkedList<>();
    compileQueue.add(intent);
    Intent compiling;
    while ((compiling = compileQueue.poll()) != null) {
        registerSubclassCompilerIfNeeded(compiling);
        List<Intent> compiled = getCompiler(compiling).compile(compiling, previousInstallables);
        compiled.forEach(i -> {
            if (i.isInstallable()) {
                installables.add(i);
            } else {
                compileQueue.add(i);
            }
        });
    }
    return installables;
}
Also used : ArrayList(java.util.ArrayList) Intent(org.onosproject.net.intent.Intent) LinkedList(java.util.LinkedList)

Example 18 with Intent

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

the class ConnectivityIntentCodec method encode.

@Override
public ObjectNode encode(ConnectivityIntent intent, CodecContext context) {
    checkNotNull(intent, "Connectivity intent cannot be null");
    final JsonCodec<Intent> intentCodec = context.codec(Intent.class);
    final ObjectNode result = intentCodec.encode(intent, context);
    if (intent.selector() != null) {
        final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
        result.set(SELECTOR, selectorCodec.encode(intent.selector(), context));
    }
    if (intent.treatment() != null) {
        final JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        result.set(TREATMENT, treatmentCodec.encode(intent.treatment(), context));
    }
    result.put(IntentCodec.PRIORITY, intent.priority());
    if (intent.constraints() != null) {
        final ArrayNode jsonConstraints = result.putArray(CONSTRAINTS);
        if (intent.constraints() != null) {
            final JsonCodec<Constraint> constraintCodec = context.codec(Constraint.class);
            for (final Constraint constraint : intent.constraints()) {
                final ObjectNode constraintNode = constraintCodec.encode(constraint, context);
                jsonConstraints.add(constraintNode);
            }
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Constraint(org.onosproject.net.intent.Constraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 19 with Intent

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

the class IntentMonitorAndRerouteManager method startMonitorIntent.

@Override
public synchronized boolean startMonitorIntent(Key intentKey) {
    checkNotNull(intentKey, "Intent Key must not be null");
    log.debug("Start Monitor Intent: {}", intentKey.toString());
    toBeMonitoredIntents.add(intentKey);
    // Check if the requested intent is already present in the intent manager
    Intent installedIntent = intentService.getIntent(intentKey);
    if (!allowedIntent(installedIntent)) {
        return false;
    }
    // Check if the intent that is present in the intent subsystem is already installed
    if (intentService.getIntentState(intentKey) == IntentState.INSTALLED) {
        storeMonitoredIntent((ConnectivityIntent) installedIntent);
    }
    return true;
}
Also used : FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent)

Example 20 with Intent

use of org.onosproject.net.intent.Intent 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)

Aggregations

Intent (org.onosproject.net.intent.Intent)282 Test (org.junit.Test)176 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)133 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)110 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)108 FlowRule (org.onosproject.net.flow.FlowRule)90 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)87 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)84 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)77 List (java.util.List)75 Collectors (java.util.stream.Collectors)71 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)70 PathIntent (org.onosproject.net.intent.PathIntent)70 Collection (java.util.Collection)60 VlanId (org.onlab.packet.VlanId)60 TrafficSelector (org.onosproject.net.flow.TrafficSelector)60 CoreService (org.onosproject.core.CoreService)59 Collections (java.util.Collections)57 ImmutableSet (com.google.common.collect.ImmutableSet)54