Search in sources :

Example 21 with PointToPointIntent

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

the class ConnectivityManager method buildIntents.

/**
 * Builds the required intents between the two pairs of connect points and
 * IP addresses.
 *
 * @param portOne the first connect point
 * @param ipOne the first IP address
 * @param portTwo the second connect point
 * @param ipTwo the second IP address
 * @return the intents to install
 */
private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, IpAddress ipOne, ConnectPoint portTwo, IpAddress ipTwo) {
    List<PointToPointIntent> intents = new ArrayList<>();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    TrafficSelector selector;
    Key key;
    byte tcpProtocol;
    byte icmpProtocol;
    if (ipOne.isIp4()) {
        tcpProtocol = IPv4.PROTOCOL_TCP;
        icmpProtocol = IPv4.PROTOCOL_ICMP;
    } else {
        tcpProtocol = IPv6.PROTOCOL_TCP;
        icmpProtocol = IPv6.PROTOCOL_ICMP6;
    }
    // Path from BGP speaker to BGP peer matching source TCP port 179
    selector = buildSelector(tcpProtocol, ipOne, ipTwo, BGP_PORT, null);
    key = buildKey(ipOne, ipTwo, SUFFIX_SRC);
    intents.add(PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(portOne)).filteredEgressPoint(new FilteredConnectPoint(portTwo)).priority(PRIORITY_OFFSET).build());
    // Path from BGP peer to BGP speaker matching destination TCP port 179
    selector = buildSelector(tcpProtocol, ipTwo, ipOne, null, BGP_PORT);
    key = buildKey(ipTwo, ipOne, SUFFIX_DST);
    intents.add(PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(portTwo)).filteredEgressPoint(new FilteredConnectPoint(portOne)).priority(PRIORITY_OFFSET).build());
    // ICMP path from BGP speaker to BGP peer
    selector = buildSelector(icmpProtocol, ipOne, ipTwo, null, null);
    key = buildKey(ipOne, ipTwo, SUFFIX_ICMP);
    intents.add(PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(portOne)).filteredEgressPoint(new FilteredConnectPoint(portTwo)).priority(PRIORITY_OFFSET).build());
    // ICMP path from BGP peer to BGP speaker
    selector = buildSelector(icmpProtocol, ipTwo, ipOne, null, null);
    key = buildKey(ipTwo, ipOne, SUFFIX_ICMP);
    intents.add(PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(portTwo)).filteredEgressPoint(new FilteredConnectPoint(portOne)).priority(PRIORITY_OFFSET).build());
    return intents;
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 22 with PointToPointIntent

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

the class IntentCodecTest method intentWithTreatmentSelectorAndConstraints.

/**
 * Tests the encoding of an intent with treatment, selector and constraints
 * specified.
 */
@Test
public void intentWithTreatmentSelectorAndConstraints() {
    ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
    ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
    DeviceId did1 = did("device1");
    DeviceId did2 = did("device2");
    DeviceId did3 = did("device3");
    Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
    final TrafficSelector selector = DefaultTrafficSelector.builder().matchIPProtocol((byte) 3).matchMplsLabel(MplsLabel.mplsLabel(4)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).matchEthDst(MacAddress.BROADCAST).matchIPDst(IpPrefix.valueOf("1.2.3.4/24")).build();
    final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(44)).setOutput(PortNumber.CONTROLLER).setEthDst(MacAddress.BROADCAST).build();
    final List<Constraint> constraints = ImmutableList.of(new BandwidthConstraint(Bandwidth.bps(1.0)), new AnnotationConstraint("key", 33.0), new AsymmetricPathConstraint(), new LatencyConstraint(Duration.ofSeconds(2)), new ObstacleConstraint(did1, did2), new WaypointConstraint(did3));
    final PointToPointIntent intent = PointToPointIntent.builder().appId(appId).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).constraints(constraints).build();
    final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
    assertThat(intentCodec, notNullValue());
    final ObjectNode intentJson = intentCodec.encode(intent, context);
    assertThat(intentJson, matchesIntent(intent));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) DeviceId(org.onosproject.net.DeviceId) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Lambda(org.onosproject.net.Lambda) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 23 with PointToPointIntent

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

the class IntentCodecTest method pointToPointIntent.

/**
 * Tests the encoding of a point to point intent.
 */
@Test
public void pointToPointIntent() {
    ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
    ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
    final PointToPointIntent intent = PointToPointIntent.builder().appId(appId).selector(emptySelector).treatment(emptyTreatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).build();
    final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
    assertThat(intentCodec, notNullValue());
    final ObjectNode intentJson = intentCodec.encode(intent, context);
    assertThat(intentJson, matchesIntent(intent));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 24 with PointToPointIntent

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

the class IntentJsonMatcher method matchPointToPointIntent.

/**
 * Matches the JSON representation of a point to point 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 matchPointToPointIntent(JsonNode jsonIntent, Description description) {
    final PointToPointIntent pointToPointIntent = (PointToPointIntent) intent;
    // check ingress connection
    final ConnectPoint ingress = pointToPointIntent.filteredIngressPoint().connectPoint();
    final ConnectPointJsonMatcher ingressMatcher = ConnectPointJsonMatcher.matchesConnectPoint(ingress);
    final JsonNode jsonIngress = jsonIntent.get("ingressPoint");
    final boolean ingressMatches = ingressMatcher.matchesSafely(jsonIngress, description);
    if (!ingressMatches) {
        description.appendText("ingress was " + jsonIngress);
        return false;
    }
    // check egress connection
    final ConnectPoint egress = pointToPointIntent.filteredEgressPoint().connectPoint();
    final ConnectPointJsonMatcher egressMatcher = ConnectPointJsonMatcher.matchesConnectPoint(egress);
    final JsonNode jsonEgress = jsonIntent.get("egressPoint");
    final boolean egressMatches = egressMatcher.matchesSafely(jsonEgress, description);
    if (!egressMatches) {
        description.appendText("egress was " + jsonEgress);
        return false;
    }
    return true;
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 25 with PointToPointIntent

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

Aggregations

PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)48 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)28 ConnectPoint (org.onosproject.net.ConnectPoint)24 Intent (org.onosproject.net.intent.Intent)19 Test (org.junit.Test)18 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)16 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)13 Key (org.onosproject.net.intent.Key)13 ArrayList (java.util.ArrayList)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 Link (org.onosproject.net.Link)11 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)11 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)11 Constraint (org.onosproject.net.intent.Constraint)11 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)10 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)10 PathIntent (org.onosproject.net.intent.PathIntent)8 MockResourceService (org.onosproject.net.resource.MockResourceService)8 ResourceService (org.onosproject.net.resource.ResourceService)8