Search in sources :

Example 11 with Key

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

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

the class ReactiveRoutingFib method setUpConnectivityInternetToHost.

@Override
public void setUpConnectivityInternetToHost(IpAddress hostIpAddress) {
    checkNotNull(hostIpAddress);
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (hostIpAddress.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
    }
    // Match the destination IP prefix at the first hop
    IpPrefix ipPrefix = hostIpAddress.toIpPrefix();
    selector.matchIPDst(ipPrefix);
    // Rewrite the destination MAC address
    MacAddress hostMac = null;
    FilteredConnectPoint egressPoint = null;
    for (Host host : hostService.getHostsByIp(hostIpAddress)) {
        if (host.mac() != null) {
            hostMac = host.mac();
            egressPoint = new FilteredConnectPoint(host.location());
            break;
        }
    }
    if (hostMac == null) {
        hostService.startMonitoringIp(hostIpAddress);
        return;
    }
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(hostMac);
    Key key = Key.of(ipPrefix.toString(), appId);
    int priority = ipPrefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
    Set<ConnectPoint> interfaceConnectPoints = interfaceService.getInterfaces().stream().map(intf -> intf.connectPoint()).collect(Collectors.toSet());
    if (interfaceConnectPoints.isEmpty()) {
        log.error("The interface connect points are empty!");
        return;
    }
    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    for (ConnectPoint connectPoint : interfaceConnectPoints) {
        if (!connectPoint.equals(egressPoint.connectPoint())) {
            ingressPoints.add(new FilteredConnectPoint(connectPoint));
        }
    }
    MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(ingressPoints).filteredEgressPoint(egressPoint).priority(priority).constraints(CONSTRAINTS).build();
    log.trace("Generates ConnectivityInternetToHost intent {}", intent);
    submitReactiveIntent(ipPrefix, intent);
}
Also used : Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) IntentSynchronizationService(org.onosproject.intentsync.IntentSynchronizationService) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Constraint(org.onosproject.net.intent.Constraint) Key(org.onosproject.net.intent.Key) MacAddress(org.onlab.packet.MacAddress) Collections(java.util.Collections) IpPrefix(org.onlab.packet.IpPrefix) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) 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) IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 13 with Key

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

the class ReactiveRoutingFib method hostToHostIntentGenerator.

/**
 * Generates MultiPointToSinglePointIntent for both source host and
 * destination host located in local SDN network.
 *
 * @param dstIpAddress the destination IP address
 * @param dstConnectPoint the destination host connect point
 * @param dstMacAddress the MAC address of destination host
 * @param srcConnectPoint the connect point where packet-in from
 * @return the generated MultiPointToSinglePointIntent
 */
private MultiPointToSinglePointIntent hostToHostIntentGenerator(IpAddress dstIpAddress, ConnectPoint dstConnectPoint, MacAddress dstMacAddress, ConnectPoint srcConnectPoint) {
    checkNotNull(dstIpAddress);
    checkNotNull(dstConnectPoint);
    checkNotNull(dstMacAddress);
    checkNotNull(srcConnectPoint);
    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    ingressPoints.add(new FilteredConnectPoint(srcConnectPoint));
    IpPrefix dstIpPrefix = dstIpAddress.toIpPrefix();
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (dstIpAddress.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
        selector.matchIPDst(dstIpPrefix);
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
        selector.matchIPv6Dst(dstIpPrefix);
    }
    // Rewrite the destination MAC address
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(dstMacAddress);
    Key key = Key.of(dstIpPrefix.toString(), appId);
    int priority = dstIpPrefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
    MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(ingressPoints).filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)).priority(priority).constraints(CONSTRAINTS).build();
    log.trace("Generates ConnectivityHostToHost = {} ", intent);
    return intent;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Key(org.onosproject.net.intent.Key) ConnectPoint(org.onosproject.net.ConnectPoint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 14 with Key

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

the class IntentRemoveCommand method removeIntent.

/**
 * Removes the intent passed as argument.
 *
 * @param intentService IntentService object
 * @param intent intent to remove
 */
private void removeIntent(IntentService intentService, Intent intent) {
    IntentListener listener = null;
    Key key = intent.key();
    final CountDownLatch withdrawLatch, purgeLatch;
    if (purgeAfterRemove || sync) {
        // set up latch and listener to track uninstall progress
        withdrawLatch = new CountDownLatch(1);
        purgeLatch = purgeAfterRemove ? new CountDownLatch(1) : null;
        listener = (IntentEvent event) -> {
            if (Objects.equals(event.subject().key(), key)) {
                if (event.type() == IntentEvent.Type.WITHDRAWN || event.type() == IntentEvent.Type.FAILED) {
                    withdrawLatch.countDown();
                } else if (purgeLatch != null && purgeAfterRemove && event.type() == IntentEvent.Type.PURGED) {
                    purgeLatch.countDown();
                }
            }
        };
        intentService.addListener(listener);
    } else {
        purgeLatch = null;
        withdrawLatch = null;
    }
    // request the withdraw
    intentService.withdraw(intent);
    if (withdrawLatch != null && (purgeAfterRemove || sync)) {
        try {
            // wait for withdraw event
            withdrawLatch.await(5, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            print("Timed out waiting for intent {} withdraw", key);
        }
        if (purgeLatch != null && purgeAfterRemove && CAN_PURGE.contains(intentService.getIntentState(key))) {
            intentService.purge(intent);
            if (sync) {
                /* TODO
                       Technically, the event comes before map.remove() is called.
                       If we depend on sync and purge working together, we will
                       need to address this.
                    */
                try {
                    purgeLatch.await(5, TimeUnit.SECONDS);
                } catch (InterruptedException e) {
                    print("Timed out waiting for intent {} purge", key);
                }
            }
        }
    }
    if (listener != null) {
        // clean up the listener
        intentService.removeListener(listener);
    }
}
Also used : IntentListener(org.onosproject.net.intent.IntentListener) CountDownLatch(java.util.concurrent.CountDownLatch) Key(org.onosproject.net.intent.Key) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 15 with Key

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

the class IntentsListCommand method fullFormat.

/*
     * Prints information about the intent state, given an intent.
     */
private StringBuilder fullFormat(Intent intent, IntentState state) {
    StringBuilder builder = new StringBuilder();
    NodeId nodeId = workPartitionService.getLeader(intent.key(), Key::hash);
    builder.append(format(ID, intent.id()));
    if (state != null) {
        builder.append('\n').append(format(STATE, state));
    }
    builder.append('\n').append(format(KEY, intent.key()));
    builder.append('\n').append(format(TYPE, intent.getClass().getSimpleName()));
    builder.append('\n').append(format(APP_ID, intent.appId().name()));
    builder.append('\n').append(nodeId == null ? NONE : format(LEADER_ID, nodeId.id()));
    return builder;
}
Also used : NodeId(org.onosproject.cluster.NodeId) Key(org.onosproject.net.intent.Key)

Aggregations

Key (org.onosproject.net.intent.Key)65 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)25 Intent (org.onosproject.net.intent.Intent)22 ConnectPoint (org.onosproject.net.ConnectPoint)20 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 MultiPointToSinglePointIntent (org.onosproject.net.intent.MultiPointToSinglePointIntent)19 Test (org.junit.Test)15 Constraint (org.onosproject.net.intent.Constraint)15 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)14 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 SinglePointToMultiPointIntent (org.onosproject.net.intent.SinglePointToMultiPointIntent)12 ApplicationId (org.onosproject.core.ApplicationId)11 IntentService (org.onosproject.net.intent.IntentService)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 Interface (org.onosproject.net.intf.Interface)9 Set (java.util.Set)8 MacAddress (org.onlab.packet.MacAddress)8