Search in sources :

Example 1 with L2TunnelDescription

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

the class SegmentRoutingManager method addPseudowiresBulk.

@Override
@Deprecated
public L2TunnelHandler.Result addPseudowiresBulk(List<DefaultL2TunnelDescription> bulkPseudowires) {
    // get both added and pending pseudowires
    List<L2TunnelDescription> pseudowires = new ArrayList<>();
    pseudowires.addAll(l2TunnelHandler.getL2Descriptions(false));
    pseudowires.addAll(l2TunnelHandler.getL2Descriptions(true));
    pseudowires.addAll(bulkPseudowires);
    Set<L2TunnelDescription> newPseudowires = new HashSet(bulkPseudowires);
    L2TunnelHandler.Result retRes = L2TunnelHandler.Result.SUCCESS;
    L2TunnelHandler.Result res;
    for (DefaultL2TunnelDescription pw : bulkPseudowires) {
        res = addPseudowire(pw);
        if (res != L2TunnelHandler.Result.SUCCESS) {
            log.error("Pseudowire with id {} can not be instantiated !", res);
            retRes = res;
        }
    }
    return retRes;
}
Also used : DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) DefaultL2TunnelHandler(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelHandler) L2TunnelHandler(org.onosproject.segmentrouting.pwaas.L2TunnelHandler) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) L2TunnelDescription(org.onosproject.segmentrouting.pwaas.L2TunnelDescription) HashSet(java.util.HashSet)

Example 2 with L2TunnelDescription

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

the class PseudowireAddCommand method doExecute.

@Override
protected void doExecute() {
    SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class);
    L2Tunnel tun;
    L2TunnelPolicy policy;
    try {
        tun = new DefaultL2Tunnel(parseMode(mode), parseVlan(sDTag), parsePwId(pwId), parsePWLabel(pwLabel));
    } catch (IllegalArgumentException e) {
        log.error("Exception while parsing L2Tunnel : \n\t %s", e.getMessage());
        print("Exception while parsing L2Tunnel : \n\t %s", e.getMessage());
        return;
    }
    try {
        policy = new DefaultL2TunnelPolicy(parsePwId(pwId), ConnectPoint.deviceConnectPoint(cP1), parseVlan(cP1InnerVlan), parseVlan(cP1OuterVlan), ConnectPoint.deviceConnectPoint(cP2), parseVlan(cP2InnerVlan), parseVlan(cP2OuterVlan));
    } catch (IllegalArgumentException e) {
        log.error("Exception while parsing L2TunnelPolicy : \n\t %s", e.getMessage());
        print("Exception while parsing L2TunnelPolicy : \n\t %s", e.getMessage());
        return;
    }
    L2TunnelDescription pw = new DefaultL2TunnelDescription(tun, policy);
    L2TunnelHandler.Result res = srService.addPseudowire(pw);
    log.info("Deploying pseudowire {} via the command line.", pw);
    switch(res) {
        case WRONG_PARAMETERS:
            print("Pseudowire could not be added , error in the parameters : \n\t%s", res.getSpecificError());
            break;
        case CONFIGURATION_ERROR:
            print("Pseudowire could not be added, configuration error : \n\t%s", res.getSpecificError());
            break;
        case PATH_NOT_FOUND:
            print("Pseudowire path not found : \n\t%s", res.getSpecificError());
            break;
        case INTERNAL_ERROR:
            print("Pseudowire could not be added, internal error : \n\t%s", res.getSpecificError());
            break;
        case SUCCESS:
            break;
        default:
            break;
    }
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) DefaultL2Tunnel(org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel) L2Tunnel(org.onosproject.segmentrouting.pwaas.L2Tunnel) DefaultL2Tunnel(org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel) DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) L2TunnelHandler(org.onosproject.segmentrouting.pwaas.L2TunnelHandler) DefaultL2TunnelPolicy(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy) L2TunnelPolicy(org.onosproject.segmentrouting.pwaas.L2TunnelPolicy) DefaultL2TunnelPolicy(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy) DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) L2TunnelDescription(org.onosproject.segmentrouting.pwaas.L2TunnelDescription)

Example 3 with L2TunnelDescription

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

the class PseudowireWebResource method createPseudowiresBulk.

/**
 * Create a bulk of pseudowires.
 *
 * @param input JSON stream for pseudowires to create
 * @return Response with appropriate status
 * @throws IOException Throws IO exception.
 * @onos.rsModel PseudowireCreateBulk
 */
@POST
@Path("/bulk")
@Consumes(MediaType.APPLICATION_JSON)
public Response createPseudowiresBulk(InputStream input) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode pseudowireJson = readTreeFromStream(mapper, input);
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    Pair<List<Pair<JsonNode, String>>, List<L2TunnelDescription>> pseudowires;
    try {
        ArrayNode pseudowiresArray = nullIsIllegal((ArrayNode) pseudowireJson.get(PWS), PWS_KEY_ERROR);
        // get two lists, first one contains pseudowires that we were unable to decode
        // that have faulty arguments, second one contains pseudowires that we decoded
        // succesfully
        pseudowires = PSEUDOWIRE_CODEC.decodePws(pseudowiresArray, this);
    } catch (ItemNotFoundException e) {
        return Response.serverError().status(Response.Status.BAD_REQUEST).build();
    }
    log.debug("Creating pseudowires {} from rest api!", pseudowires);
    List<Pair<DefaultL2TunnelDescription, String>> failed = new ArrayList<>();
    for (L2TunnelDescription pw : pseudowires.getRight()) {
        L2TunnelHandler.Result res = srService.addPseudowire(pw);
        if (res != L2TunnelHandler.Result.SUCCESS) {
            log.error("Could not create pseudowire {} : {}", pw.l2Tunnel().tunnelId(), res.getSpecificError());
            failed.add(Pair.of((DefaultL2TunnelDescription) pw, res.getSpecificError()));
        }
    }
    List<Pair<JsonNode, String>> undecodedPws = pseudowires.getLeft();
    if ((failed.size() == 0) && (undecodedPws.size() == 0)) {
        // all pseudowires were decoded and instantiated succesfully
        return Response.ok().build();
    } else {
        PseudowireCodec pwCodec = new PseudowireCodec();
        // some failed, need to report them to user
        ObjectNode result = pwCodec.encodeFailedPseudowires(failed, undecodedPws, this);
        return Response.serverError().entity(result).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) DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Pair(org.apache.commons.lang3.tuple.Pair) DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) L2TunnelDescription(org.onosproject.segmentrouting.pwaas.L2TunnelDescription) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 4 with L2TunnelDescription

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

the class PseudowireCodec method decodePws.

/**
 * @param json The json containing the pseudowires.
 * @param context The context
 * @return A pair of lists.
 *         First list contains pseudowires that we were not able to decode
 *         along with the reason we could not decode them.
 *         Second list contains successfully decoded pseudowires which we are
 *         going to instantiate.
 */
public Pair<List<Pair<JsonNode, String>>, List<L2TunnelDescription>> decodePws(ArrayNode json, CodecContext context) {
    List<L2TunnelDescription> decodedPws = new ArrayList<>();
    List<Pair<JsonNode, String>> notDecodedPws = new ArrayList<>();
    for (JsonNode node : json) {
        DefaultL2TunnelDescription l2Description;
        try {
            l2Description = decode((ObjectNode) node, context);
            decodedPws.add(l2Description);
        } catch (IllegalArgumentException e) {
            // the reason why we could not decode this pseudowire is encoded in the
            // exception, we need to store it now
            notDecodedPws.add(Pair.of(node, e.getMessage()));
        }
    }
    return Pair.of(notDecodedPws, decodedPws);
}
Also used : DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) L2TunnelDescription(org.onosproject.segmentrouting.pwaas.L2TunnelDescription) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

DefaultL2TunnelDescription (org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription)4 L2TunnelDescription (org.onosproject.segmentrouting.pwaas.L2TunnelDescription)4 ArrayList (java.util.ArrayList)3 L2TunnelHandler (org.onosproject.segmentrouting.pwaas.L2TunnelHandler)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Pair (org.apache.commons.lang3.tuple.Pair)2 SegmentRoutingService (org.onosproject.segmentrouting.SegmentRoutingService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 ItemNotFoundException (org.onlab.util.ItemNotFoundException)1 DefaultL2Tunnel (org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel)1 DefaultL2TunnelHandler (org.onosproject.segmentrouting.pwaas.DefaultL2TunnelHandler)1 DefaultL2TunnelPolicy (org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy)1