Search in sources :

Example 21 with IntentService

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());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) Constraint(org.onosproject.net.intent.Constraint) ProtectedConstraint(org.onosproject.net.intent.constraint.ProtectedConstraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Intent(org.onosproject.net.intent.Intent) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 22 with IntentService

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());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) Constraint(org.onosproject.net.intent.Constraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Constraint(org.onosproject.net.intent.Constraint) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 23 with IntentService

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;
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentState(org.onosproject.net.intent.IntentState) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Link(org.onosproject.net.Link)

Example 24 with IntentService

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);
}
Also used : IntentService(org.onosproject.net.intent.IntentService) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) TransportEndpointDescription(org.onosproject.net.behaviour.protection.TransportEndpointDescription) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent)

Example 25 with IntentService

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);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) LinkAdminService(org.onosproject.net.link.LinkAdminService) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) IntentEvent(org.onosproject.net.intent.IntentEvent) UiExtensionService(org.onosproject.ui.UiExtensionService) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Link(org.onosproject.net.Link) Command(org.apache.karaf.shell.api.action.Command) PacketRequest(org.onosproject.net.packet.PacketRequest) FlowRuleService(org.onosproject.net.flow.FlowRuleService) IntentService(org.onosproject.net.intent.IntentService) MeterService(org.onosproject.net.meter.MeterService) UiTopoLayoutService(org.onosproject.ui.UiTopoLayoutService) Intent(org.onosproject.net.intent.Intent) Device(org.onosproject.net.Device) GroupService(org.onosproject.net.group.GroupService) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) HostAdminService(org.onosproject.net.host.HostAdminService) PacketService(org.onosproject.net.packet.PacketService) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) Key(org.onosproject.net.intent.Key) WITHDRAWN(org.onosproject.net.intent.IntentState.WITHDRAWN) IntentListener(org.onosproject.net.intent.IntentListener) Service(org.apache.karaf.shell.api.action.lifecycle.Service) RegionAdminService(org.onosproject.net.region.RegionAdminService) IntentService(org.onosproject.net.intent.IntentService) Intent(org.onosproject.net.intent.Intent) CompletableFuture(java.util.concurrent.CompletableFuture) IntentListener(org.onosproject.net.intent.IntentListener) ExecutionException(java.util.concurrent.ExecutionException) Key(org.onosproject.net.intent.Key) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

IntentService (org.onosproject.net.intent.IntentService)36 Intent (org.onosproject.net.intent.Intent)19 ApplicationId (org.onosproject.core.ApplicationId)8 ConnectPoint (org.onosproject.net.ConnectPoint)8 CoreService (org.onosproject.core.CoreService)7 Key (org.onosproject.net.intent.Key)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)5 Link (org.onosproject.net.Link)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 Constraint (org.onosproject.net.intent.Constraint)5 OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Consumes (javax.ws.rs.Consumes)3