Search in sources :

Example 21 with SegmentRoutingService

use of org.onosproject.segmentrouting.SegmentRoutingService in project trellis-control by opennetworkinglab.

the class PseudowireNextListCommand method doExecute.

@Override
protected void doExecute() {
    SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class);
    print(srService.getPwInitNext());
    print(srService.getPwTermNext());
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService)

Example 22 with SegmentRoutingService

use of org.onosproject.segmentrouting.SegmentRoutingService in project trellis-control by opennetworkinglab.

the class RerouteNetworkCommand method doExecute.

@Override
protected void doExecute() {
    SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class);
    srService.rerouteNetwork();
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService)

Example 23 with SegmentRoutingService

use of org.onosproject.segmentrouting.SegmentRoutingService in project trellis-control by opennetworkinglab.

the class McastWebResource method encodeMcastTrees.

private ObjectNode encodeMcastTrees(String gAddr, String source) {
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    Set<IpAddress> mcastGroups = ImmutableSet.copyOf(srService.getMcastLeaders(null).keySet());
    if (!isNullOrEmpty(gAddr)) {
        mcastGroups = mcastGroups.stream().filter(mcastIp -> mcastIp.equals(IpAddress.valueOf(gAddr))).collect(Collectors.toSet());
    }
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode root = mapper.createObjectNode();
    // Print the trees for each group or build json objects
    mcastGroups.forEach(group -> {
        // We want to use source cp only for a specific group
        ConnectPoint sourcecp = null;
        if (!isNullOrEmpty(source) && !isNullOrEmpty(gAddr)) {
            sourcecp = ConnectPoint.deviceConnectPoint(source);
        }
        Multimap<ConnectPoint, List<ConnectPoint>> mcastTree = srService.getMcastTrees(group, sourcecp);
        // Build a json object for each group
        root.putPOJO(group.toString(), json(mcastTree));
    });
    return root;
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IpAddress(org.onlab.packet.IpAddress) List(java.util.List) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 24 with SegmentRoutingService

use of org.onosproject.segmentrouting.SegmentRoutingService in project trellis-control by opennetworkinglab.

the class PseudowireWebResource method removePseudowiresBulk.

/**
 * Delete a bulk of pseudowires.
 *
 * @param input JSON stream for pseudowires to delete
 * @return Response with appropriate status
 * @throws IOException Throws IO exception.
 * @onos.rsModel PseudowireDeleteBulk
 */
@DELETE
@Path("/bulk")
@Consumes(MediaType.APPLICATION_JSON)
public Response removePseudowiresBulk(InputStream input) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode pseudowireJson = readTreeFromStream(mapper, input);
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    List<Integer> ids = new ArrayList<>();
    // throw an exception and stop process
    try {
        for (JsonNode node : pseudowireJson.withArray(PWS)) {
            Integer idToDelete = PseudowireCodec.decodeId((ObjectNode) node);
            if (idToDelete == null) {
                log.error("Error when parsing pseudowire for deletion in REST API.");
                throw new IllegalArgumentException("Id of pseudowire should be an integer!");
            }
            ids.add(idToDelete);
        }
    } catch (IllegalArgumentException e) {
        log.error("Pseudowire ID should be an integer.");
        return Response.serverError().status(Response.Status.BAD_REQUEST).build();
    } catch (UnsupportedOperationException e) {
        log.error("Pseudowires for deletion should be an array of pseudowire ids.");
        return Response.serverError().status(Response.Status.BAD_REQUEST).build();
    }
    for (Integer pseudowireId : ids) {
        L2TunnelHandler.Result res = srService.removePseudowire(pseudowireId);
        switch(res) {
            case WRONG_PARAMETERS:
            case INTERNAL_ERROR:
                log.error("Pseudowire {} could not be removed, internal error : {}", pseudowireId, res.getSpecificError());
                break;
            case SUCCESS:
                log.debug("Pseudowire {} was removed succesfully!", pseudowireId);
                break;
            default:
        }
    }
    return Response.noContent().build();
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) L2TunnelHandler(org.onosproject.segmentrouting.pwaas.L2TunnelHandler) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 25 with SegmentRoutingService

use of org.onosproject.segmentrouting.SegmentRoutingService in project trellis-control by opennetworkinglab.

the class TunnelWebResource method removeTunnel.

/**
 * Delete a segment routing tunnel.
 *
 * @param input JSON stream for tunnel to delete
 * @return 204 NO CONTENT, if the tunnel is removed
 * @throws IOException if JSON is invalid
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
public Response removeTunnel(InputStream input) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode tunnelJson = readTreeFromStream(mapper, input);
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    Tunnel tunnelInfo = TUNNEL_CODEC.decode(tunnelJson, this);
    srService.removeTunnel(tunnelInfo);
    return Response.noContent().build();
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) Tunnel(org.onosproject.segmentrouting.Tunnel) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Aggregations

SegmentRoutingService (org.onosproject.segmentrouting.SegmentRoutingService)31 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 Consumes (javax.ws.rs.Consumes)7 L2TunnelHandler (org.onosproject.segmentrouting.pwaas.L2TunnelHandler)7 List (java.util.List)5 IpAddress (org.onlab.packet.IpAddress)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ArrayList (java.util.ArrayList)4 DELETE (javax.ws.rs.DELETE)4 POST (javax.ws.rs.POST)4 Pair (org.apache.commons.lang3.tuple.Pair)4 DeviceId (org.onosproject.net.DeviceId)4 DefaultL2TunnelDescription (org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription)4 Collectors (java.util.stream.Collectors)3 Path (javax.ws.rs.Path)3 Tunnel (org.onosproject.segmentrouting.Tunnel)3 L2Tunnel (org.onosproject.segmentrouting.pwaas.L2Tunnel)3 L2TunnelDescription (org.onosproject.segmentrouting.pwaas.L2TunnelDescription)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2