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;
}
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));
}
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());
}
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);
}
}
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;
}
Aggregations