use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class IntentRemoveCommand method doExecute.
@Override
protected void doExecute() {
IntentService intentService = get(IntentService.class);
removeIntent(intentService.getIntents(), applicationIdString, keyString, purgeAfterRemove, sync);
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class IntentRemoveCommand method removeIntent.
/**
* Removes the intents passed as argument, assuming these
* belong to the application's ID provided (if any) and
* contain a key string.
*
* If an application ID is provided, it will be used to further
* filter the intents to be removed.
*
* @param intents list of intents to remove
* @param applicationIdString application ID to filter intents
* @param keyString string to filter intents
* @param purgeAfterRemove states whether the intents should be also purged
* @param sync states whether the cli should wait for the operation to finish
* before returning
*/
private void removeIntent(Iterable<Intent> intents, String applicationIdString, String keyString, boolean purgeAfterRemove, boolean sync) {
IntentService intentService = get(IntentService.class);
CoreService coreService = get(CoreService.class);
this.applicationIdString = applicationIdString;
this.keyString = keyString;
this.purgeAfterRemove = purgeAfterRemove;
this.sync = sync;
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)) {
removeIntentsByAppId(intentService, intents, appId);
} 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);
}
}
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class ProtectedIntentMonitor method protectedIntentHighlights.
// =======================================================================
// === Generate messages in JSON object node format
private Highlights protectedIntentHighlights() {
Highlights highlights = new Highlights();
TrafficLinkMap linkMap = new TrafficLinkMap();
IntentService intentService = services.intent();
if (selectedIntent != null) {
List<Intent> installables = intentService.getInstallableIntents(selectedIntent.key());
if (installables != null) {
ProtectionEndpointIntent ep1 = installables.stream().filter(ProtectionEndpointIntent.class::isInstance).map(ProtectionEndpointIntent.class::cast).findFirst().orElse(null);
ProtectionEndpointIntent ep2 = installables.stream().filter(ii -> !ii.equals(ep1)).filter(ProtectionEndpointIntent.class::isInstance).map(ProtectionEndpointIntent.class::cast).findFirst().orElse(null);
if (ep1 == null || ep2 == null) {
log.warn("Selected Intent {} didn't have 2 protection endpoints", selectedIntent.key());
stopMonitoring();
return highlights;
}
Set<Link> primary = new LinkedHashSet<>();
Set<Link> backup = new LinkedHashSet<>();
Map<Boolean, List<FlowRuleIntent>> transits = installables.stream().filter(FlowRuleIntent.class::isInstance).map(FlowRuleIntent.class::cast).collect(Collectors.groupingBy(this::isPrimary));
// walk primary
ConnectPoint primHead = ep1.description().paths().get(0).output().connectPoint();
ConnectPoint primTail = ep2.description().paths().get(0).output().connectPoint();
List<FlowRuleIntent> primTransit = transits.getOrDefault(true, ImmutableList.of());
populateLinks(primary, primHead, primTail, primTransit);
// walk backup
ConnectPoint backHead = ep1.description().paths().get(1).output().connectPoint();
ConnectPoint backTail = ep2.description().paths().get(1).output().connectPoint();
List<FlowRuleIntent> backTransit = transits.getOrDefault(false, ImmutableList.of());
populateLinks(backup, backHead, backTail, backTransit);
// Add packet to optical links
if (!usingBackup(primary)) {
primary.addAll(protectedIntentMultiLayer(primHead, primTail));
}
backup.addAll(protectedIntentMultiLayer(backHead, backTail));
boolean isOptical = selectedIntent instanceof OpticalConnectivityIntent;
// Flavor is swapped so green is primary path.
if (usingBackup(primary)) {
// the backup becomes in use so we have a dotted line
processLinks(linkMap, backup, Flavor.PRIMARY_HIGHLIGHT, isOptical, true, PROTECTED_MOD_BACKUP_SET);
} else {
processLinks(linkMap, primary, Flavor.PRIMARY_HIGHLIGHT, isOptical, true, PROTECTED_MOD_PRIMARY_SET);
processLinks(linkMap, backup, Flavor.SECONDARY_HIGHLIGHT, isOptical, false, PROTECTED_MOD_BACKUP_SET);
}
updateHighlights(highlights, primary);
updateHighlights(highlights, backup);
colorLinks(highlights, linkMap);
highlights.subdueAllElse(Highlights.Amount.MINIMALLY);
} else {
log.debug("Selected Intent has no installable intents");
}
} else {
log.debug("Selected Intent is null");
}
return highlights;
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class ApplicationIdWithIntentNameCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
IntentService service = AbstractShellCommand.get(IntentService.class);
SortedSet<String> strings = delegate.getStrings();
service.getIntents().forEach(intent -> strings.add(intent.appId().name()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class AddHostToHostIntentCommand method doExecute.
@Override
protected void doExecute() {
IntentService service = get(IntentService.class);
HostId oneId = HostId.hostId(one);
HostId twoId = HostId.hostId(two);
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints();
HostToHostIntent intent = HostToHostIntent.builder().appId(appId()).key(key()).one(oneId).two(twoId).selector(selector).treatment(treatment).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
service.submit(intent);
print("Host to Host intent submitted:\n%s", intent.toString());
}
Aggregations