use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class AddPointToPointIntentCommand method doExecute.
@Override
protected void doExecute() {
IntentService service = get(IntentService.class);
ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints();
if (backup) {
constraints.add(protection());
}
if (useProtected) {
constraints.add(ProtectedConstraint.useProtectedLink());
}
Intent intent = PointToPointIntent.builder().appId(appId()).key(key()).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
service.submit(intent);
print("Point to point intent submitted:\n%s", intent.toString());
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class AddSinglePointToMultiPointIntentCommand method doExecute.
@Override
protected void doExecute() {
IntentService service = get(IntentService.class);
if (deviceStrings.length < 2) {
return;
}
String ingressDeviceString = deviceStrings[0];
ConnectPoint ingressPoint = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Set<FilteredConnectPoint> egressPoints = new HashSet<>();
for (int index = 1; index < deviceStrings.length; index++) {
String egressDeviceString = deviceStrings[index];
ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
egressPoints.add(new FilteredConnectPoint(egress));
}
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints();
SinglePointToMultiPointIntent intent = SinglePointToMultiPointIntent.builder().appId(appId()).key(key()).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingressPoint)).filteredEgressPoints(egressPoints).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
service.submit(intent);
print("Single point to multipoint intent submitted:\n%s", intent.toString());
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class IntentCodec method encode.
@Override
public ObjectNode encode(Intent intent, CodecContext context) {
checkNotNull(intent, "Intent cannot be null");
final ObjectNode result = context.mapper().createObjectNode().put(TYPE, intent.getClass().getSimpleName()).put(ID, intent.id().toString()).put(KEY, intent.key().toString()).put(APP_ID, UrlEscapers.urlPathSegmentEscaper().escape(intent.appId().name()));
if (intent.resourceGroup() != null) {
result.put(RESOURCE_GROUP, intent.resourceGroup().toString());
}
final ArrayNode jsonResources = result.putArray(RESOURCES);
intent.resources().forEach(resource -> {
if (resource instanceof Link) {
jsonResources.add(context.codec(Link.class).encode((Link) resource, context));
} else {
jsonResources.add(resource.toString());
}
});
IntentService service = context.getService(IntentService.class);
IntentState state = service.getIntentState(intent.key());
if (state != null) {
result.put(STATE, state.toString());
}
return result;
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class TestProtectionEndpointIntentCommand method doExecute.
@Override
protected void doExecute() {
fingerprint = Optional.ofNullable(fingerprint).orElse(DEFAULT_FINGERPRINT);
intentService = get(IntentService.class);
deviceService = get(DeviceService.class);
DeviceId did = DeviceId.deviceId(deviceIdStr);
DeviceId peer = DeviceId.deviceId(peerStr);
ProtectedTransportEndpointDescription description;
List<TransportEndpointDescription> paths = new ArrayList<>();
paths.add(TransportEndpointDescription.builder().withOutput(output(did, portNumber1Str, vlan1Str)).build());
paths.add(TransportEndpointDescription.builder().withOutput(output(did, portNumber2Str, vlan2Str)).build());
description = ProtectedTransportEndpointDescription.of(paths, peer, fingerprint);
ProtectionEndpointIntent intent;
intent = ProtectionEndpointIntent.builder().key(Key.of(fingerprint, appId())).appId(appId()).deviceId(did).description(description).build();
print("Submitting: %s", intent);
intentService.submit(intent);
}
use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.
the class WipeOutCommand method wipeOutIntents.
private void wipeOutIntents() {
print("Wiping intents");
IntentService intentService = get(IntentService.class);
Set<Key> keysToWithdrawn = Sets.newConcurrentHashSet();
Set<Intent> intentsToWithdrawn = Tools.stream(intentService.getIntents()).filter(intent -> intentService.getIntentState(intent.key()) != WITHDRAWN).collect(Collectors.toSet());
intentsToWithdrawn.stream().map(Intent::key).forEach(keysToWithdrawn::add);
CompletableFuture<Void> completableFuture = new CompletableFuture<>();
IntentListener listener = e -> {
if (e.type() == IntentEvent.Type.WITHDRAWN) {
keysToWithdrawn.remove(e.subject().key());
}
if (keysToWithdrawn.isEmpty()) {
completableFuture.complete(null);
}
};
intentService.addListener(listener);
intentsToWithdrawn.forEach(intentService::withdraw);
try {
if (!intentsToWithdrawn.isEmpty()) {
// Wait 1.5 seconds for each Intent
completableFuture.get(intentsToWithdrawn.size() * 1500L, TimeUnit.MILLISECONDS);
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
print("Encountered exception while withdrawing intents: " + e.toString());
} finally {
intentService.removeListener(listener);
}
intentsToWithdrawn.forEach(intentService::purge);
}
Aggregations