Java Code Examples for org.onosproject.net.intent.IntentService#submit()

The following examples show how to use org.onosproject.net.intent.IntentService#submit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntentsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: AddHostToHostIntentCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: OpticalIntentsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Submits a new optical intent.
 * Creates and submits optical intents 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 CreateIntent
 */
@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 = decode(root);
        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);
    }
}
 
Example 4
Source File: AddSinglePointToMultiPointIntentCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 5
Source File: AddMultiPointToSinglePointIntentCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    IntentService service = get(IntentService.class);

    if (deviceStrings.length < 2) {
        return;
    }

    String egressDeviceString = deviceStrings[deviceStrings.length - 1];
    FilteredConnectPoint egress = new FilteredConnectPoint(ConnectPoint.deviceConnectPoint(egressDeviceString));

    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    for (int index = 0; index < deviceStrings.length - 1; index++) {
        String ingressDeviceString = deviceStrings[index];
        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
        ingressPoints.add(new FilteredConnectPoint(ingress));
    }

    TrafficSelector selector = buildTrafficSelector();
    TrafficTreatment treatment = buildTrafficTreatment();
    List<Constraint> constraints = buildConstraints();

    Intent intent = MultiPointToSinglePointIntent.builder()
            .appId(appId())
            .key(key())
            .selector(selector)
            .treatment(treatment)
            .filteredIngressPoints(ingressPoints)
            .filteredEgressPoint(egress)
            .constraints(constraints)
            .priority(priority())
            .resourceGroup(resourceGroup())
            .build();
    service.submit(intent);
    print("Multipoint to single point intent submitted:\n%s", intent.toString());
}
 
Example 6
Source File: AddPointToPointIntentCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 7
Source File: AddOpticalIntentCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 8
Source File: VirtualNetworkIntentCreateCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    IntentService virtualNetworkIntentService = service.get(NetworkId.networkId(networkId), IntentService.class);

    ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
    ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);

    TrafficSelector selector = buildTrafficSelector();
    TrafficTreatment treatment = buildTrafficTreatment();

    List<Constraint> constraints = buildConstraints();

    Intent intent = VirtualNetworkIntent.builder()
            .networkId(NetworkId.networkId(networkId))
            .appId(appId())
            .key(key())
            .selector(selector)
            .treatment(treatment)
            .ingressPoint(ingress)
            .egressPoint(egress)
            .constraints(constraints)
            .priority(priority())
            .build();
    virtualNetworkIntentService.submit(intent);
    print("Virtual intent submitted:\n%s", intent.toString());
}