Search in sources :

Example 11 with IntentService

use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.

the class IntentDetailsCommand method detailIntents.

/**
 * Print detailed data for intents, given a list of IDs.
 *
 * @param intentsIds List of intent IDs
 */
public void detailIntents(List<String> intentsIds) {
    if (intentsIds != null) {
        ids = intentsIds.stream().map(IntentId::valueOf).collect(Collectors.toSet());
    }
    IntentService service = get(IntentService.class);
    Tools.stream(service.getIntentData()).filter(this::filter).forEach(this::printIntentData);
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentId(org.onosproject.net.intent.IntentId)

Example 12 with IntentService

use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.

the class AddOpticalIntentCommand method doExecute.

@Override
protected void doExecute() {
    IntentService service = get(IntentService.class);
    DeviceService deviceService = get(DeviceService.class);
    ConnectPoint ingress = createConnectPoint(ingressString);
    ConnectPoint egress = createConnectPoint(egressString);
    Intent intent = createOpticalIntent(ingress, egress, deviceService, key(), appId(), bidirectional, createOchSignal(), null);
    service.submit(intent);
    print("Optical intent submitted:\n%s", intent.toString());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) DeviceService(org.onosproject.net.device.DeviceService) OpticalIntentUtility.createOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createOpticalIntent) Intent(org.onosproject.net.intent.Intent) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 13 with IntentService

use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.

the class IntentsWebResource method createIntent.

/**
 * Submits a new intent.
 * Creates and submits intent from the JSON request.
 *
 * @param stream input JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel IntentHost
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createIntent(InputStream stream) {
    try {
        IntentService service = get(IntentService.class);
        ObjectNode root = readTreeFromStream(mapper(), stream);
        Intent intent = codec(Intent.class).decode(root, this);
        service.submit(intent);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("intents").path(intent.appId().name()).path(Long.toString(intent.id().fingerprint()));
        return Response.created(locationBuilder.build()).build();
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Intent(org.onosproject.net.intent.Intent) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 14 with IntentService

use of org.onosproject.net.intent.IntentService in project onos by opennetworkinglab.

the class ProtectedIntentMonitor method protectedIntentMultiLayer.

/**
 * Returns the packet to optical mapping given a head and tail of a protection path.
 *
 * @param head head of path
 * @param tail tail of path
 */
private Set<Link> protectedIntentMultiLayer(ConnectPoint head, ConnectPoint tail) {
    List<Link> links = new LinkedList<>();
    LinkService linkService = services.link();
    IntentService intentService = services.intent();
    // Ingress cross connect link
    links.addAll(linkService.getEgressLinks(head).stream().filter(l -> l.type() == Link.Type.OPTICAL).collect(Collectors.toList()));
    // Egress cross connect link
    links.addAll(linkService.getIngressLinks(tail).stream().filter(l -> l.type() == Link.Type.OPTICAL).collect(Collectors.toList()));
    // The protected intent does not rely on a multi-layer mapping
    if (links.size() != 2) {
        return Collections.emptySet();
    }
    // Expected head and tail of optical circuit (not connectivity!) intent
    ConnectPoint ocHead = links.get(0).dst();
    ConnectPoint ocTail = links.get(1).src();
    // Optical connectivity
    // FIXME: assumes that transponder (OTN device) is a one-to-one mapping
    // We need to track the multi-layer aspects better
    intentService.getIntents().forEach(intent -> {
        if (intent instanceof OpticalConnectivityIntent) {
            OpticalConnectivityIntent ocIntent = (OpticalConnectivityIntent) intent;
            if (ocHead.deviceId().equals(ocIntent.getSrc().deviceId()) && ocTail.deviceId().equals(ocIntent.getDst().deviceId())) {
                intentService.getInstallableIntents(ocIntent.key()).forEach(i -> {
                    if (i instanceof FlowRuleIntent) {
                        FlowRuleIntent fr = (FlowRuleIntent) i;
                        links.addAll(linkResources(fr));
                    }
                });
            }
        }
    });
    return new LinkedHashSet<>(links);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IntentService(org.onosproject.net.intent.IntentService) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) LinkService(org.onosproject.net.link.LinkService) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) LinkedList(java.util.LinkedList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 15 with IntentService

use of org.onosproject.net.intent.IntentService 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!");
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) CoreService(org.onosproject.core.CoreService) BigInteger(java.math.BigInteger) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key)

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