Search in sources :

Example 1 with L2Tunnel

use of org.onosproject.segmentrouting.pwaas.L2Tunnel 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 2 with L2Tunnel

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

the class PseudowireWebResource method getPseudowire.

/**
 * Get all pseudowires.
 * Returns an array of pseudowires.
 *
 * @return status of OK
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getPseudowire() {
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    log.debug("Fetching pseudowires form rest api!");
    List<L2TunnelPolicy> policies = srService.getL2Policies();
    List<L2Tunnel> tunnels = srService.getL2Tunnels();
    List<DefaultL2TunnelDescription> pseudowires = tunnels.stream().map(l2Tunnel -> {
        L2TunnelPolicy policy = null;
        for (L2TunnelPolicy l2Policy : policies) {
            if (l2Policy.tunnelId() == l2Tunnel.tunnelId()) {
                policy = l2Policy;
                break;
            }
        }
        // return a copy
        return new DefaultL2TunnelDescription(l2Tunnel, policy);
    }).collect(Collectors.toList());
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("pseudowires", new PseudowireCodec().encode(pseudowires, this));
    return ok(result.toString()).build();
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) L2Tunnel(org.onosproject.segmentrouting.pwaas.L2Tunnel) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) L2TunnelDescription(org.onosproject.segmentrouting.pwaas.L2TunnelDescription) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) L2TunnelHandler(org.onosproject.segmentrouting.pwaas.L2TunnelHandler) MediaType(javax.ws.rs.core.MediaType) Pair(org.apache.commons.lang3.tuple.Pair) Consumes(javax.ws.rs.Consumes) JsonNode(com.fasterxml.jackson.databind.JsonNode) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) DELETE(javax.ws.rs.DELETE) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) L2TunnelPolicy(org.onosproject.segmentrouting.pwaas.L2TunnelPolicy) List(java.util.List) Response(javax.ws.rs.core.Response) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) InputStream(java.io.InputStream) L2Tunnel(org.onosproject.segmentrouting.pwaas.L2Tunnel) DefaultL2TunnelDescription(org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) L2TunnelPolicy(org.onosproject.segmentrouting.pwaas.L2TunnelPolicy) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with L2Tunnel

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

the class PseudowireIdCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class);
    List<L2Tunnel> tunnels = srService.getL2Tunnels();
    // combine polices and tunnels to pseudowires
    Iterator<String> pseudowires = tunnels.stream().map(l2Tunnel -> Long.toString(l2Tunnel.tunnelId())).collect(Collectors.toList()).iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (pseudowires.hasNext()) {
        strings.add(pseudowires.next());
    }
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) L2Tunnel(org.onosproject.segmentrouting.pwaas.L2Tunnel) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter)

Aggregations

SegmentRoutingService (org.onosproject.segmentrouting.SegmentRoutingService)3 L2Tunnel (org.onosproject.segmentrouting.pwaas.L2Tunnel)3 DefaultL2TunnelDescription (org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription)2 L2TunnelDescription (org.onosproject.segmentrouting.pwaas.L2TunnelDescription)2 L2TunnelHandler (org.onosproject.segmentrouting.pwaas.L2TunnelHandler)2 L2TunnelPolicy (org.onosproject.segmentrouting.pwaas.L2TunnelPolicy)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1