Search in sources :

Example 36 with Key

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

the class VbngManager method dstMatchIntentGenerator.

/**
 * PointToPointIntent Generator.
 * <p>
 * The intent will match the destination IP address in packet, rewrite the
 * destination IP address, and rewrite the destination MAC address.
 * </p>
 *
 * @param dstIpAddress the destination IP address in packet to match
 * @param newDstIpAddress the new destination IP address to set
 * @param dstMacAddress the destination MAC address to set
 * @param dstConnectPoint the egress point
 * @param srcConnectPoint the ingress point
 * @return a PointToPointIntent
 */
private PointToPointIntent dstMatchIntentGenerator(IpAddress dstIpAddress, IpAddress newDstIpAddress, MacAddress dstMacAddress, ConnectPoint dstConnectPoint, ConnectPoint srcConnectPoint) {
    checkNotNull(dstIpAddress);
    checkNotNull(newDstIpAddress);
    checkNotNull(dstMacAddress);
    checkNotNull(dstConnectPoint);
    checkNotNull(srcConnectPoint);
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4);
    selector.matchIPDst(IpPrefix.valueOf(dstIpAddress, IpPrefix.MAX_INET_MASK_LENGTH));
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.setEthDst(dstMacAddress);
    treatment.setIpDst(newDstIpAddress);
    Key key = Key.of(newDstIpAddress.toString() + "MatchDst", appId);
    PointToPointIntent intent = PointToPointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)).filteredIngressPoint(new FilteredConnectPoint(srcConnectPoint)).build();
    log.info("Generated a PointToPointIntent for traffic to local host " + ": {}", intent);
    return intent;
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) 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 37 with Key

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

the class WorkPartitionManagerTest method testIsMine.

/**
 * Tests that the isMine method returns the correct result based on the
 * underlying leadership service data.
 */
@Test
public void testIsMine() {
    // We'll own only the first partition
    setUpLeadershipService(1);
    replay(leadershipService);
    Key myKey = new ControllableHashKey(0);
    Key notMyKey = new ControllableHashKey(1);
    assertTrue(partitionManager.isMine(myKey, Key::hash));
    assertFalse(partitionManager.isMine(notMyKey, Key::hash));
    // Make us the owner of 4 partitions now
    reset(leadershipService);
    setUpLeadershipService(4);
    replay(leadershipService);
    assertTrue(partitionManager.isMine(myKey, Key::hash));
    // notMyKey is now my key because because we're in control of that
    // partition now
    assertTrue(partitionManager.isMine(notMyKey, Key::hash));
    assertFalse(partitionManager.isMine(new ControllableHashKey(4), Key::hash));
}
Also used : Key(org.onosproject.net.intent.Key) Test(org.junit.Test)

Example 38 with Key

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

the class IntentPerfInstaller method createIntents.

/**
 * Creates a specified number of intents for testing purposes.
 *
 * @param numberOfKeys number of intents
 * @param pathLength   path depth
 * @param firstKey     first key to attempt
 * @return set of intents
 */
private Set<Intent> createIntents(int numberOfKeys, int pathLength, int firstKey) {
    List<NodeId> neighbors = getNeighbors();
    Multimap<NodeId, Device> devices = ArrayListMultimap.create();
    deviceService.getAvailableDevices().forEach(device -> devices.put(mastershipService.getMasterFor(device.id()), device));
    // ensure that we have at least one device per neighbor
    neighbors.forEach(node -> checkState(!devices.get(node).isEmpty(), "There are no devices for {}", node));
    // TODO pull this outside so that createIntent can use it
    // prefix based on node id for keys generated on this instance
    long keyPrefix = ((long) clusterService.getLocalNode().ip().getIp4Address().toInt()) << 32;
    int maxKeysPerNode = (int) Math.ceil((double) numberOfKeys / neighbors.size());
    Multimap<NodeId, Intent> intents = ArrayListMultimap.create();
    for (int count = 0, k = firstKey; count < numberOfKeys; k++) {
        Key key = Key.of(keyPrefix + k, appId);
        NodeId leader = partitionService.getLeader(key, Key::hash);
        if (!neighbors.contains(leader) || intents.get(leader).size() >= maxKeysPerNode) {
            // Bail if we are not sending to this node or we have enough for this node
            continue;
        }
        intents.put(leader, createIntent(key, keyPrefix + k, leader, devices));
        // Bump up the counter and remember this as the last key used.
        count++;
        lastKey = k;
        if (count % 1000 == 0) {
            log.info("Building intents... {} (attempt: {})", count, lastKey);
        }
    }
    checkState(intents.values().size() == numberOfKeys, "Generated wrong number of intents");
    log.info("Created {} intents", numberOfKeys);
    intents.keySet().forEach(node -> log.info("\t{}\t{}", node, intents.get(node).size()));
    return Sets.newHashSet(intents.values());
}
Also used : Device(org.onosproject.net.Device) NodeId(org.onosproject.cluster.NodeId) Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Key(org.onosproject.net.intent.Key)

Example 39 with Key

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

the class GossipIntentStore method write.

@Override
public void write(IntentData newData) {
    checkNotNull(newData);
    IntentData currentData = currentMap.get(newData.key());
    if (IntentData.isUpdateAcceptable(currentData, newData)) {
        // this always succeeds
        if (newData.state() == PURGE_REQ) {
            if (currentData != null) {
                if (log.isTraceEnabled()) {
                    log.trace("Purging {} in currentMap. {}@{}", newData.key(), newData.state(), newData.version(), new Backtrace());
                }
                currentMap.remove(newData.key(), currentData);
            } else {
                log.info("Gratuitous purge request for intent: {}", newData.key());
            }
        } else {
            if (log.isTraceEnabled()) {
                log.trace("Putting {} in currentMap. {}@{}", newData.key(), newData.state(), newData.version(), new Backtrace());
            }
            currentMap.put(newData.key(), IntentData.copy(newData));
        }
    } else {
        log.debug("Update for {} not acceptable from:\n{}\nto:\n{}", newData.key(), currentData, newData);
    }
    // Remove the intent data from the pending map if the newData is more
    // recent or equal to the existing entry. No matter if it is an acceptable
    // update or not
    Key key = newData.key();
    IntentData existingValue = pendingMap.get(key);
    if (existingValue == null) {
        return;
    }
    if (!existingValue.version().isNewerThan(newData.version())) {
        pendingMap.remove(key, existingValue);
    } else {
        log.debug("{} in pending map was newer, leaving it there", key);
    }
}
Also used : Backtrace(org.onlab.util.Backtrace) IntentData(org.onosproject.net.intent.IntentData) Key(org.onosproject.net.intent.Key)

Example 40 with Key

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

the class VplsIntentUtility method buildUniIntents.

/**
 * Builds unicast Intents for a VPLS.
 *
 * @param vplsData the VPLS
 * @param hosts the hosts of the VPLS
 * @param appId application ID for Intents
 * @return unicast Intents for the VPLS
 */
public static Set<Intent> buildUniIntents(VplsData vplsData, Set<Host> hosts, ApplicationId appId) {
    Set<Interface> interfaces = vplsData.interfaces();
    if (interfaces.size() < 2) {
        return ImmutableSet.of();
    }
    Set<Intent> uniIntents = Sets.newHashSet();
    ResourceGroup resourceGroup = ResourceGroup.of(vplsData.name());
    hosts.forEach(host -> {
        FilteredConnectPoint hostFcp = buildFilteredConnectedPoint(host);
        Set<FilteredConnectPoint> srcFcps = interfaces.stream().map(VplsIntentUtility::buildFilteredConnectedPoint).filter(fcp -> !fcp.equals(hostFcp)).collect(Collectors.toSet());
        Key key = buildKey(PREFIX_UNICAST, hostFcp.connectPoint(), vplsData.name(), host.mac(), appId);
        Intent uniIntent = buildUniIntent(key, appId, srcFcps, hostFcp, host, vplsData.encapsulationType(), resourceGroup);
        uniIntents.add(uniIntent);
    });
    return uniIntents;
}
Also used : Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) VplsData(org.onosproject.vpls.api.VplsData) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) ApplicationId(org.onosproject.core.ApplicationId) Intent(org.onosproject.net.intent.Intent) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ResourceGroup(org.onosproject.net.ResourceGroup) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Constraint(org.onosproject.net.intent.Constraint) Objects(java.util.Objects) Key(org.onosproject.net.intent.Key) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) MacAddress(org.onlab.packet.MacAddress) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Interface(org.onosproject.net.intf.Interface) ResourceGroup(org.onosproject.net.ResourceGroup) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

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