Search in sources :

Example 6 with FilteredConnectPoint

use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.

the class ReactiveRoutingFib method setUpConnectivityHostToInternet.

@Override
public void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix, IpAddress nextHopIpAddress) {
    // Find the attachment point (egress interface) of the next hop
    Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress);
    if (egressInterface == null) {
        log.warn("No outgoing interface found for {}", nextHopIpAddress);
        return;
    }
    Set<Host> hosts = hostService.getHostsByIp(nextHopIpAddress);
    if (hosts.isEmpty()) {
        log.warn("No host found for next hop IP address");
        return;
    }
    MacAddress nextHopMacAddress = null;
    for (Host host : hosts) {
        nextHopMacAddress = host.mac();
        break;
    }
    hosts = hostService.getHostsByIp(hostIp);
    if (hosts.isEmpty()) {
        log.warn("No host found for host IP address");
        return;
    }
    Host host = hosts.stream().findFirst().get();
    ConnectPoint ingressPoint = host.location();
    // Generate the intent itself
    ConnectPoint egressPort = egressInterface.connectPoint();
    log.debug("Generating intent for prefix {}, next hop mac {}", prefix, nextHopMacAddress);
    // Match the destination IP prefix at the first hop
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (prefix.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
        selector.matchIPDst(prefix);
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
        selector.matchIPv6Dst(prefix);
    }
    // Rewrite the destination MAC address
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(nextHopMacAddress);
    if (!egressInterface.vlan().equals(VlanId.NONE)) {
        treatment.setVlanId(egressInterface.vlan());
        // If we set VLAN ID, we have to make sure a VLAN tag exists.
        // TODO support no VLAN -> VLAN routing
        selector.matchVlanId(VlanId.ANY);
    }
    int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
    Key key = Key.of(prefix.toString() + "-reactive", appId);
    MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(Collections.singleton(new FilteredConnectPoint(ingressPoint))).filteredEgressPoint(new FilteredConnectPoint(egressPort)).priority(priority).constraints(CONSTRAINTS).build();
    submitReactiveIntent(prefix, intent);
}
Also used : Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Interface(org.onosproject.net.intf.Interface) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 7 with FilteredConnectPoint

use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.

the class IntentCycleCommand method generateIntents.

private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
    TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    List<Intent> intents = Lists.newArrayList();
    for (long i = 0; i < count; i++) {
        TrafficSelector selector = selectorBldr.matchEthSrc(MacAddress.valueOf(i + keyOffset)).build();
        intents.add(PointToPointIntent.builder().appId(appId()).key(Key.of(i + keyOffset, appId())).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).build());
    }
    return intents;
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 8 with FilteredConnectPoint

use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.

the class SinglePointToMultiPointIntentCodec method decode.

@Override
public SinglePointToMultiPointIntent decode(ObjectNode json, CodecContext context) {
    SinglePointToMultiPointIntent.Builder builder = SinglePointToMultiPointIntent.builder();
    IntentCodec.intentAttributes(json, context, builder);
    ConnectivityIntentCodec.intentAttributes(json, context, builder);
    ObjectNode ingressJson = nullIsIllegal(get(json, INGRESS_POINT), INGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
    ConnectPoint ingress = context.codec(ConnectPoint.class).decode(ingressJson, context);
    builder.filteredIngressPoint(new FilteredConnectPoint(ingress));
    ArrayNode egressJson = nullIsIllegal((ArrayNode) json.get(EGRESS_POINT), EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
    final JsonCodec<ConnectPoint> connectPointCodec = context.codec(ConnectPoint.class);
    Set<FilteredConnectPoint> egressCp = new HashSet<>();
    for (int i = 0; i < egressJson.size(); i++) {
        ConnectPoint cp = connectPointCodec.decode(get(egressJson, i), context);
        egressCp.add(new FilteredConnectPoint(cp));
    }
    builder.filteredEgressPoints(egressCp);
    return builder.build();
}
Also used : SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) 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 9 with FilteredConnectPoint

use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.

the class IntentsResourceTest method testIntentsForApplicationWithDetail.

/**
 * Tests the result of the rest api GET when intents are defined and the detail flag is true.
 */
@Test
public void testIntentsForApplicationWithDetail() {
    final Intent intent1 = PointToPointIntent.builder().key(Key.of(0, APP_ID)).appId(APP_ID).selector(selector1).treatment(treatment1).filteredIngressPoint(new FilteredConnectPoint(connectPoint1)).filteredEgressPoint(new FilteredConnectPoint(connectPoint2)).build();
    final HostToHostIntent intent2 = HostToHostIntent.builder().key(Key.of(1, APP_ID_2)).appId(APP_ID_2).selector(selector2).treatment(treatment2).one(hostId1).two(hostId2).build();
    intents.add(intent1);
    List<Intent> appIntents1 = new ArrayList<>();
    appIntents1.add(intent1);
    intents.add(intent2);
    List<Intent> appIntents2 = new ArrayList<>();
    appIntents2.add(intent2);
    expect(mockIntentService.getIntentsByAppId(APP_ID)).andReturn(appIntents1).anyTimes();
    expect(mockIntentService.getIntentsByAppId(APP_ID_2)).andReturn(appIntents2).anyTimes();
    replay(mockIntentService);
    expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
    expect(mockCoreService.getAppId(APP_ID_2.name())).andReturn(APP_ID_2).anyTimes();
    replay(mockCoreService);
    final WebTarget wt = target();
    // Verify intents for app_id
    final String response1 = wt.path("intents/application/" + APP_ID.name()).queryParam("detail", true).request().get(String.class);
    assertThat(response1, containsString("{\"intents\":["));
    final JsonObject result1 = Json.parse(response1).asObject();
    assertThat(result1, notNullValue());
    assertThat(result1.names(), hasSize(1));
    assertThat(result1.names().get(0), is("intents"));
    final JsonArray jsonIntents1 = result1.get("intents").asArray();
    assertThat(jsonIntents1, notNullValue());
    assertThat(jsonIntents1.size(), is(1));
    assertThat(jsonIntents1, hasIntent(intent1, true));
    assertThat(jsonIntents1, is(not(hasIntent(intent2, true))));
    // Verify intents for app_id_2
    final String response2 = wt.path("intents/application/" + APP_ID_2.name()).queryParam("detail", true).request().get(String.class);
    assertThat(response2, containsString("{\"intents\":["));
    final JsonObject result2 = Json.parse(response2).asObject();
    assertThat(result2, notNullValue());
    assertThat(result2.names(), hasSize(1));
    assertThat(result2.names().get(0), is("intents"));
    final JsonArray jsonIntents2 = result2.get("intents").asArray();
    assertThat(jsonIntents2, notNullValue());
    assertThat(jsonIntents2.size(), is(1));
    assertThat(jsonIntents2, hasIntent(intent2, true));
    assertThat(jsonIntents2, is(not(hasIntent(intent1, true))));
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test)

Example 10 with FilteredConnectPoint

use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.

the class TransportEndpointDescriptionTest method testConstruction.

@Test
public void testConstruction() {
    FilteredConnectPoint output = new FilteredConnectPoint(NetTestTools.connectPoint("xxx", 1));
    TransportEndpointDescription ted = TransportEndpointDescription.builder().withEnabled(true).withOutput(output).build();
    assertThat(ted, notNullValue());
    assertThat(ted.isEnabled(), is(true));
    assertThat(ted.output(), is(output));
}
Also used : FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test)

Aggregations

FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)161 Test (org.junit.Test)101 Intent (org.onosproject.net.intent.Intent)101 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)92 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)87 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)80 TrafficSelector (org.onosproject.net.flow.TrafficSelector)65 ConnectPoint (org.onosproject.net.ConnectPoint)64 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)53 List (java.util.List)52 Collectors (java.util.stream.Collectors)52 VlanId (org.onlab.packet.VlanId)52 DeviceId (org.onosproject.net.DeviceId)50 FlowRule (org.onosproject.net.flow.FlowRule)50 DomainService (org.onosproject.net.domain.DomainService)48 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)48 ImmutableSet (com.google.common.collect.ImmutableSet)47 LOCAL (org.onosproject.net.domain.DomainId.LOCAL)47 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)47 Before (org.junit.Before)46