use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class VplsIntentTest method generateVplsUni.
/**
* Generates a list of expected mp2sp intents for a given VPLS.
*
* @param fcPoints the filtered connect point
* @param hosts the hosts
* @param name the name of the VPLS
* @param encap the encapsulation type
* @return the list of expected mp2sp intents for the given VPLS
*/
private List<MultiPointToSinglePointIntent> generateVplsUni(Set<FilteredConnectPoint> fcPoints, Set<Host> hosts, String name, EncapsulationType encap) {
List<MultiPointToSinglePointIntent> intents = Lists.newArrayList();
hosts.forEach(host -> {
FilteredConnectPoint hostPoint = getHostPoint(host, fcPoints);
Set<FilteredConnectPoint> otherPoints = fcPoints.stream().filter(fcp -> !fcp.equals(hostPoint)).collect(Collectors.toSet());
Key uniKey = buildKey(VplsIntentUtility.PREFIX_UNICAST, host.location(), name, host.mac());
intents.add(buildUniIntent(uniKey, otherPoints, hostPoint, host, encap));
});
return intents;
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class TopologyViewMessageHandler method findIntentByPayload.
private Intent findIntentByPayload(ObjectNode payload) {
Intent intent;
Key key;
int appId = Integer.parseInt(string(payload, APP_ID));
String appName = string(payload, APP_NAME);
ApplicationId applicId = new DefaultApplicationId(appId, appName);
String stringKey = string(payload, KEY);
try {
// FIXME: If apps use different string key, but they contains
// same numeric value (e.g. "020", "0x10", "16", "#10")
// and one intent using long key (e.g. 16L)
// this function might return wrong intent.
long longKey = Long.decode(stringKey);
key = Key.of(longKey, applicId);
intent = services.intent().getIntent(key);
if (intent == null) {
// Intent might using string key, not long key
key = Key.of(stringKey, applicId);
intent = services.intent().getIntent(key);
}
} catch (NumberFormatException ex) {
// string key
key = Key.of(stringKey, applicId);
intent = services.intent().getIntent(key);
}
log.debug("Attempting to select intent by key={}", key);
return intent;
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class VirtualNetworkIntentRemoveCommand method removeIntent.
/**
* Removes the intent using the specified intentService.
*
* @param intentService intent service
* @param intent intent
*/
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 ((purgeAfterRemove || sync) && purgeLatch != null) {
try {
// wait for withdraw event
withdrawLatch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
print("Timed out waiting for intent {} withdraw", key);
}
if (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);
}
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class VirtualNetworkIntentRemoveCommand method doExecute.
@Override
protected void doExecute() {
VirtualNetworkService service = get(VirtualNetworkService.class);
IntentService intentService = service.get(NetworkId.networkId(networkId), IntentService.class);
CoreService coreService = get(CoreService.class);
if (purgeAfterRemove || sync) {
print("Using \"sync\" to remove/purge intents - this may take a while...");
print("Check \"summary\" to see remove/purge progress.");
}
ApplicationId appId = appId();
if (!isNullOrEmpty(applicationIdString)) {
appId = coreService.getAppId(applicationIdString);
if (appId == null) {
print("Cannot find application Id %s", applicationIdString);
return;
}
}
if (isNullOrEmpty(keyString)) {
for (Intent intent : intentService.getIntents()) {
if (intent.appId().equals(appId)) {
removeIntent(intentService, intent);
}
}
} else {
final Key key;
if (keyString.startsWith("0x")) {
// The intent uses a LongKey
keyString = keyString.replaceFirst("0x", "");
key = Key.of(new BigInteger(keyString, 16).longValue(), appId);
} else {
// The intent uses a StringKey
key = Key.of(keyString, appId);
}
Intent intent = intentService.getIntent(key);
if (intent != null) {
removeIntent(intentService, intent);
} else {
print("Intent not found!");
}
}
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class VbngManager method srcMatchIntentGenerator.
/**
* PointToPointIntent Generator.
* <p>
* The intent will match the source IP address in packet, rewrite the
* source IP address, and rewrite the destination MAC address.
* </p>
*
* @param srcIpAddress the source IP address in packet to match
* @param newSrcIpAddress the new source 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 srcMatchIntentGenerator(IpAddress srcIpAddress, IpAddress newSrcIpAddress, MacAddress dstMacAddress, ConnectPoint dstConnectPoint, ConnectPoint srcConnectPoint) {
checkNotNull(srcIpAddress);
checkNotNull(newSrcIpAddress);
checkNotNull(dstMacAddress);
checkNotNull(dstConnectPoint);
checkNotNull(srcConnectPoint);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPSrc(IpPrefix.valueOf(srcIpAddress, IpPrefix.MAX_INET_MASK_LENGTH));
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.setEthDst(dstMacAddress);
treatment.setIpSrc(newSrcIpAddress);
Key key = Key.of(srcIpAddress.toString() + "MatchSrc", 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 from local host " + ": {}", intent);
return intent;
}
Aggregations