Search in sources :

Example 1 with HostToHostIntent

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

the class IntentJsonMatcher method matchConnectivityIntent.

/**
 * Matches the JSON representation of a connectivity intent. Calls the
 * matcher for the connectivity intent subtype.
 *
 * @param jsonIntent JSON representation of the intent
 * @param description Description object used for recording errors
 * @return true if the JSON matches the intent, false otherwise
 */
private boolean matchConnectivityIntent(JsonNode jsonIntent, Description description) {
    final ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent;
    // check selector
    final JsonNode jsonSelector = jsonIntent.get("selector");
    final TrafficSelector selector = connectivityIntent.selector();
    final Set<Criterion> criteria = selector.criteria();
    final JsonNode jsonCriteria = jsonSelector.get("criteria");
    if (jsonCriteria.size() != criteria.size()) {
        description.appendText("size of criteria array is " + Integer.toString(jsonCriteria.size()));
        return false;
    }
    for (Criterion criterion : criteria) {
        boolean criterionFound = false;
        for (int criterionIndex = 0; criterionIndex < jsonCriteria.size(); criterionIndex++) {
            final CriterionJsonMatcher criterionMatcher = CriterionJsonMatcher.matchesCriterion(criterion);
            if (criterionMatcher.matches(jsonCriteria.get(criterionIndex))) {
                criterionFound = true;
                break;
            }
        }
        if (!criterionFound) {
            description.appendText("criterion not found " + criterion.toString());
            return false;
        }
    }
    // check treatment
    final JsonNode jsonTreatment = jsonIntent.get("treatment");
    final TrafficTreatment treatment = connectivityIntent.treatment();
    final List<Instruction> instructions = treatment.immediate();
    final JsonNode jsonInstructions = jsonTreatment.get("instructions");
    if (jsonInstructions.size() != instructions.size()) {
        description.appendText("size of instructions array is " + Integer.toString(jsonInstructions.size()));
        return false;
    }
    for (Instruction instruction : instructions) {
        boolean instructionFound = false;
        for (int instructionIndex = 0; instructionIndex < jsonInstructions.size(); instructionIndex++) {
            final InstructionJsonMatcher instructionMatcher = InstructionJsonMatcher.matchesInstruction(instruction);
            if (instructionMatcher.matches(jsonInstructions.get(instructionIndex))) {
                instructionFound = true;
                break;
            }
        }
        if (!instructionFound) {
            description.appendText("instruction not found " + instruction.toString());
            return false;
        }
    }
    // Check constraints
    final JsonNode jsonConstraints = jsonIntent.get("constraints");
    if (connectivityIntent.constraints() != null) {
        if (connectivityIntent.constraints().size() != jsonConstraints.size()) {
            description.appendText("constraints array size was " + Integer.toString(jsonConstraints.size()));
            return false;
        }
        for (final Constraint constraint : connectivityIntent.constraints()) {
            boolean constraintFound = false;
            for (int constraintIndex = 0; constraintIndex < jsonConstraints.size(); constraintIndex++) {
                final JsonNode value = jsonConstraints.get(constraintIndex);
                if (matchConstraint(constraint, value)) {
                    constraintFound = true;
                }
            }
            if (!constraintFound) {
                final String constraintString = constraint.toString();
                description.appendText("constraint missing " + constraintString);
                return false;
            }
        }
    } else if (jsonConstraints.size() != 0) {
        description.appendText("constraint array not empty");
        return false;
    }
    if (connectivityIntent instanceof HostToHostIntent) {
        return matchHostToHostIntent(jsonIntent, description);
    } else if (connectivityIntent instanceof PointToPointIntent) {
        return matchPointToPointIntent(jsonIntent, description);
    } else {
        description.appendText("class of connectivity intent is unknown");
        return false;
    }
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) ConnectPoint(org.onosproject.net.ConnectPoint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector)

Example 2 with HostToHostIntent

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

the class IntentJsonMatcher method matchHostToHostIntent.

/**
 * Matches the JSON representation of a host to host intent.
 *
 * @param jsonIntent JSON representation of the intent
 * @param description Description object used for recording errors
 * @return true if the JSON matches the intent, false otherwise
 */
private boolean matchHostToHostIntent(JsonNode jsonIntent, Description description) {
    final HostToHostIntent hostToHostIntent = (HostToHostIntent) intent;
    // check host one
    final String host1 = hostToHostIntent.one().toString();
    final String jsonHost1 = jsonIntent.get("one").asText();
    if (!host1.equals(jsonHost1)) {
        description.appendText("host one was " + jsonHost1);
        return false;
    }
    // check host 2
    final String host2 = hostToHostIntent.two().toString();
    final String jsonHost2 = jsonIntent.get("two").asText();
    if (!host2.equals(jsonHost2)) {
        description.appendText("host two was " + jsonHost2);
        return false;
    }
    return true;
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent)

Example 3 with HostToHostIntent

use of org.onosproject.net.intent.HostToHostIntent 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 4 with HostToHostIntent

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

the class HostToHostIntentCompilerTest method testSingleLongPathCompilation.

/**
 * Tests a pair of hosts with 8 hops between them.
 */
@Test
public void testSingleLongPathCompilation() {
    HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO);
    assertThat(intent, is(notNullValue()));
    String[] hops = { HOST_ONE, S1, S2, S3, S4, S5, S6, S7, S8, HOST_TWO };
    HostToHostIntentCompiler compiler = makeCompiler(hops);
    assertThat(compiler, is(notNullValue()));
    List<Intent> result = compiler.compile(intent, null);
    assertThat(result, is(Matchers.notNullValue()));
    assertThat(result, hasSize(2));
    Intent forwardIntent = result.get(0);
    assertThat(forwardIntent instanceof LinkCollectionIntent, is(true));
    Intent reverseIntent = result.get(1);
    assertThat(reverseIntent instanceof LinkCollectionIntent, is(true));
    LinkCollectionIntent forwardLCIntent = (LinkCollectionIntent) forwardIntent;
    Set<Link> links = forwardLCIntent.links();
    assertThat(links, hasSize(7));
    Set<FilteredConnectPoint> ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
    assertThat(forwardLCIntent.filteredIngressPoints(), is(ingressPoints));
    assertThat(links, linksHasPath(S1, S2));
    assertThat(links, linksHasPath(S2, S3));
    assertThat(links, linksHasPath(S3, S4));
    assertThat(links, linksHasPath(S4, S5));
    assertThat(links, linksHasPath(S5, S6));
    assertThat(links, linksHasPath(S6, S7));
    assertThat(links, linksHasPath(S7, S8));
    Set<FilteredConnectPoint> egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
    assertThat(forwardLCIntent.filteredEgressPoints(), is(egressPoints));
    LinkCollectionIntent reverseLCIntent = (LinkCollectionIntent) reverseIntent;
    links = reverseLCIntent.links();
    assertThat(reverseLCIntent.links(), hasSize(7));
    ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
    assertThat(reverseLCIntent.filteredIngressPoints(), is(ingressPoints));
    assertThat(links, linksHasPath(S2, S1));
    assertThat(links, linksHasPath(S3, S2));
    assertThat(links, linksHasPath(S4, S3));
    assertThat(links, linksHasPath(S5, S4));
    assertThat(links, linksHasPath(S6, S5));
    assertThat(links, linksHasPath(S7, S6));
    assertThat(links, linksHasPath(S8, S7));
    egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
    assertThat(reverseLCIntent.filteredEgressPoints(), is(egressPoints));
    assertThat("key is inherited", result.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Intent(org.onosproject.net.intent.Intent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Link(org.onosproject.net.Link) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 5 with HostToHostIntent

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

the class HostToHostIntentCompilerTest method testBandwidthConstrainedIntentAllocation.

/**
 * Tests if bandwidth resources get allocated correctly.
 */
@Test
public void testBandwidthConstrainedIntentAllocation() {
    final double bpsTotal = 1000.0;
    final double bpsToReserve = 100.0;
    ContinuousResource resourceSw1P1 = Resources.continuous(DID_S1, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw1P2 = Resources.continuous(DID_S1, PORT_2, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw2P1 = Resources.continuous(DID_S2, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw2P2 = Resources.continuous(DID_S2, PORT_2, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw3P1 = Resources.continuous(DID_S3, PORT_1, Bandwidth.class).resource(bpsToReserve);
    ContinuousResource resourceSw3P2 = Resources.continuous(DID_S3, PORT_2, Bandwidth.class).resource(bpsToReserve);
    String[] hops = { HOST_ONE, S1, S2, S3, HOST_TWO };
    final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
    final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
    final HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO, constraints);
    HostToHostIntentCompiler compiler = makeCompiler(hops, resourceService);
    compiler.compile(intent, null);
    Key intentKey = intent.key();
    ResourceAllocation rAOne = new ResourceAllocation(resourceSw1P1, intentKey);
    ResourceAllocation rATwo = new ResourceAllocation(resourceSw1P2, intentKey);
    ResourceAllocation rAThree = new ResourceAllocation(resourceSw2P1, intentKey);
    ResourceAllocation rAFour = new ResourceAllocation(resourceSw2P2, intentKey);
    ResourceAllocation rAFive = new ResourceAllocation(resourceSw3P1, intentKey);
    ResourceAllocation rASix = new ResourceAllocation(resourceSw3P2, intentKey);
    Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
    Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey));
    assertThat(resourceAllocations, hasSize(6));
    assertEquals(expectedresourceAllocations, resourceAllocations);
}
Also used : Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ResourceService(org.onosproject.net.resource.ResourceService) MockResourceService(org.onosproject.net.resource.MockResourceService) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) Bandwidth(org.onlab.util.Bandwidth) Key(org.onosproject.net.intent.Key) ContinuousResource(org.onosproject.net.resource.ContinuousResource) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

HostToHostIntent (org.onosproject.net.intent.HostToHostIntent)15 Test (org.junit.Test)8 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)8 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)7 Intent (org.onosproject.net.intent.Intent)7 ArrayList (java.util.ArrayList)5 JsonArray (com.eclipsesource.json.JsonArray)4 JsonObject (com.eclipsesource.json.JsonObject)4 WebTarget (javax.ws.rs.client.WebTarget)4 ConnectPoint (org.onosproject.net.ConnectPoint)4 TrafficSelector (org.onosproject.net.flow.TrafficSelector)4 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)4 ConnectivityIntent (org.onosproject.net.intent.ConnectivityIntent)4 PathIntent (org.onosproject.net.intent.PathIntent)4 HashSet (java.util.HashSet)3 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 List (java.util.List)2 Set (java.util.Set)2