Search in sources :

Example 36 with MultiPointToSinglePointIntent

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

the class MultiPointToSinglePointIntentCompilerTest method testTwoIngressCompilation.

/**
 * Tests a simple topology where two ingress points share some path segments
 * and some path segments are not shared.
 */
@Test
public void testTwoIngressCompilation() {
    Set<FilteredConnectPoint> ingress = Sets.newHashSet(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)), new FilteredConnectPoint(new ConnectPoint(DID_2, PORT_1)));
    FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_1));
    MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
    assertThat(intent, is(notNullValue()));
    final String[] hops = { S3 };
    MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
    assertThat(compiler, is(notNullValue()));
    List<Intent> result = compiler.compile(intent, null);
    assertThat(result, is(notNullValue()));
    assertThat(result, hasSize(1));
    Intent resultIntent = result.get(0);
    assertThat(resultIntent instanceof LinkCollectionIntent, is(true));
    if (resultIntent instanceof LinkCollectionIntent) {
        LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
        assertThat(linkIntent.links(), hasSize(3));
        assertThat(linkIntent.links(), linksHasPath(S1, S3));
        assertThat(linkIntent.links(), linksHasPath(S2, S3));
        assertThat(linkIntent.links(), linksHasPath(S3, S4));
    }
    assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
Also used : MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 37 with MultiPointToSinglePointIntent

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

the class MultiPointToSinglePointIntentCodec method decode.

@Override
public MultiPointToSinglePointIntent decode(ObjectNode json, CodecContext context) {
    MultiPointToSinglePointIntent.Builder builder = MultiPointToSinglePointIntent.builder();
    IntentCodec.intentAttributes(json, context, builder);
    ConnectivityIntentCodec.intentAttributes(json, context, builder);
    ArrayNode ingressJson = nullIsIllegal((ArrayNode) json.get(INGRESS_POINT), INGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
    if (ingressJson != null) {
        final JsonCodec<ConnectPoint> connectPointCodec = context.codec(ConnectPoint.class);
        JsonNode connectPointsJson = json.get(INGRESS_POINT);
        Set<FilteredConnectPoint> ingressCp = new HashSet<>();
        if (connectPointsJson != null) {
            for (int i = 0; i < connectPointsJson.size(); i++) {
                ingressCp.add(new FilteredConnectPoint(connectPointCodec.decode(get(connectPointsJson, i), context)));
            }
            builder.filteredIngressPoints(ingressCp);
        }
    }
    ObjectNode egressJson = nullIsIllegal(get(json, EGRESS_POINT), EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
    ConnectPoint egress = context.codec(ConnectPoint.class).decode(egressJson, context);
    builder.filteredEgressPoint(new FilteredConnectPoint(egress));
    return builder.build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 38 with MultiPointToSinglePointIntent

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

the class MultiPointToSinglePointIntentCodecTest method decodeMultiPointToSinglePointIntent.

/**
 * Tests the multi point to single point intent decoding with JSON codec.
 *
 * @throws IOException if JSON processing fails
 */
@Test
public void decodeMultiPointToSinglePointIntent() throws IOException {
    final JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    ObjectNode json = nodeFactory.objectNode();
    json.put("type", "MultiPointToSinglePointIntent");
    json.put("id", "0x0");
    json.put("appId", "foo");
    json.put("priority", 100);
    ArrayNode ingress = nodeFactory.arrayNode();
    ObjectNode ingressPoint = nodeFactory.objectNode();
    ingressPoint.put("port", "3");
    ingressPoint.put("device", "333");
    ingress.add(ingressPoint);
    ObjectNode ingressPoint2 = nodeFactory.objectNode();
    ingressPoint2.put("port", "1");
    ingressPoint2.put("device", "111");
    ingress.add(ingressPoint2);
    json.set("ingressPoint", ingress);
    ObjectNode egressPoint = nodeFactory.objectNode();
    egressPoint.put("port", "2");
    egressPoint.put("device", "222");
    json.set("egressPoint", egressPoint);
    assertThat(json, notNullValue());
    JsonCodec<MultiPointToSinglePointIntent> intentCodec = context.codec(MultiPointToSinglePointIntent.class);
    assertThat(intentCodec, notNullValue());
    final MultiPointToSinglePointIntent intent = intentCodec.decode(json, context);
    assertThat(intent.toString(), notNullValue());
    assertThat(intent, instanceOf(MultiPointToSinglePointIntent.class));
    assertThat(intent.priority(), is(100));
    assertThat(intent.ingressPoints().toString(), is("[333/3, 111/1]"));
    assertThat(intent.egressPoint().toString(), is("222/2"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 39 with MultiPointToSinglePointIntent

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

the class MultiPointToSinglePointIntentCodecTest method encodeMultiPointToSinglePointIntent.

/**
 * Tests the encoding of a multi point to single point intent using Intent Codec.
 */
@Test
public void encodeMultiPointToSinglePointIntent() {
    final MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(APPID).selector(MATCH).treatment(NOP).filteredIngressPoints(FPS1).filteredEgressPoint(FP2).build();
    assertThat(intent, notNullValue());
    assertThat(intent, instanceOf(MultiPointToSinglePointIntent.class));
    final JsonCodec<MultiPointToSinglePointIntent> intentCodec = context.codec(MultiPointToSinglePointIntent.class);
    assertThat(intentCodec, notNullValue());
    final ObjectNode result = intentCodec.encode(intent, context);
    assertThat(result.get("type").textValue(), is("MultiPointToSinglePointIntent"));
    assertThat(result.get("id").textValue(), is("0x0"));
    assertThat(result.get("appId").textValue(), is("foo"));
    assertThat(result.get("priority").asInt(), is(100));
    boolean found1 = false;
    boolean found3 = false;
    for (int i = 0; i < FPS1.size(); i++) {
        String portString = result.get("ingressPoint").get(i).get("port").textValue();
        if (portString.equals("1")) {
            found1 = true;
        } else if (portString.equals("3")) {
            found3 = true;
        }
    }
    assertThat("Port 1 was not found", found1, is(true));
    assertThat("Port 3 was not found", found3, is(true));
    assertThat(result.get("egressPoint").get("port").textValue(), is("2"));
    assertThat(result.get("egressPoint").get("device").textValue(), is("222"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 40 with MultiPointToSinglePointIntent

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

the class ReactiveRoutingFib method updateExistingMp2pIntent.

@Override
public void updateExistingMp2pIntent(IpPrefix ipPrefix, ConnectPoint ingressConnectPoint) {
    checkNotNull(ipPrefix);
    checkNotNull(ingressConnectPoint);
    MultiPointToSinglePointIntent existingIntent = getExistingMp2pIntent(ipPrefix);
    if (existingIntent != null) {
        Set<FilteredConnectPoint> ingressPoints = existingIntent.filteredIngressPoints();
        // Add host connect point into ingressPoints of the existing intent
        if (ingressPoints.add(new FilteredConnectPoint(ingressConnectPoint))) {
            MultiPointToSinglePointIntent updatedMp2pIntent = MultiPointToSinglePointIntent.builder().appId(appId).key(existingIntent.key()).selector(existingIntent.selector()).treatment(existingIntent.treatment()).filteredIngressPoints(ingressPoints).filteredEgressPoint(existingIntent.filteredEgressPoint()).priority(existingIntent.priority()).constraints(CONSTRAINTS).build();
            log.trace("Update an existing MultiPointToSinglePointIntent " + "to new intent = {} ", updatedMp2pIntent);
            submitReactiveIntent(ipPrefix, updatedMp2pIntent);
        }
    // If adding ingressConnectPoint to ingressPoints failed, it
    // because between the time interval from checking existing intent
    // to generating new intent, onos updated this intent due to other
    // packet-in and the new intent also includes the
    // ingressConnectPoint. This will not affect reactive routing.
    }
}
Also used : MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

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