Search in sources :

Example 16 with SegmentRoutingService

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

the class TunnelWebResource method createTunnel.

/**
 * Create a new segment routing tunnel.
 *
 * @param input JSON stream for tunnel to create
 * @return status of the request - OK if the tunnel is created,
 * @throws IOException if the JSON is invalid
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response createTunnel(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.createTunnel(tunnelInfo);
    return Response.ok().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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 17 with SegmentRoutingService

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

the class McastTreeListCommand method doExecute.

@Override
protected void doExecute() {
    // Get SR service and the handled mcast groups
    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);
        if (!mcastTree.isEmpty()) {
            // Build a json object for each group
            if (outputJson()) {
                root.putPOJO(group.toString(), json(mcastTree));
            } else {
                // Banner and then the trees
                printMcastGroup(group);
                mcastTree.forEach(this::printMcastSink);
            }
        }
    });
    // Print the json object at the end
    if (outputJson()) {
        print("%s", 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 18 with SegmentRoutingService

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

the class NextDstCommand method doExecute.

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

Example 19 with SegmentRoutingService

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

the class NextPortCommand method doExecute.

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

Example 20 with SegmentRoutingService

use of org.onosproject.segmentrouting.SegmentRoutingService 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)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