Search in sources :

Example 6 with FpmInfoService

use of org.onosproject.routing.fpm.FpmInfoService in project onos by opennetworkinglab.

the class FpmWebResource method getFpmPeerRouteInfoJsonOutput.

private ObjectNode getFpmPeerRouteInfoJsonOutput() {
    FpmInfoService fpmService = get(FpmInfoService.class);
    ObjectNode node = mapper().createObjectNode();
    ArrayNode connectionArray = mapper().createArrayNode();
    Map<FpmPeer, FpmPeerInfo> fpmPeers = fpmService.peers();
    fpmPeers.entrySet().stream().sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address()).thenComparing(e -> e.getKey().port())).map(Map.Entry::getValue).forEach(fpmPeerInfo -> {
        fpmPeerInfo.connections().forEach(connection -> {
            ObjectNode fpmNode = mapper().createObjectNode();
            fpmNode.put(PEER_ADDRESS, connection.peer().address().toString());
            fpmNode.put(PEER_PORT, connection.peer().port());
            fpmNode.put(ACCEPT_ROUTES, connection.isAcceptRoutes());
            connectionArray.add(fpmNode);
        });
    });
    node.put("fpm-peer-info", connectionArray);
    return node;
}
Also used : FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) FpmPeerInfo(org.onosproject.routing.fpm.FpmPeerInfo) PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) IpAddress(org.onlab.packet.IpAddress) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FpmPeer(org.onosproject.routing.fpm.FpmPeer) List(java.util.List) Response(javax.ws.rs.core.Response) FpmPeerInfo(org.onosproject.routing.fpm.FpmPeerInfo) FpmPeerAcceptRoutes(org.onosproject.routing.fpm.FpmPeerAcceptRoutes) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) Comparator(java.util.Comparator) InputStream(java.io.InputStream) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FpmPeer(org.onosproject.routing.fpm.FpmPeer) Map(java.util.Map)

Example 7 with FpmInfoService

use of org.onosproject.routing.fpm.FpmInfoService in project onos by opennetworkinglab.

the class FpmWebResource method getFpmPeerAcceptFlagInfoJsonOutput.

private ObjectNode getFpmPeerAcceptFlagInfoJsonOutput(String address) {
    FpmInfoService fpmService = get(FpmInfoService.class);
    ObjectNode fpmNode = mapper().createObjectNode();
    Map<FpmPeer, FpmPeerInfo> fpmPeers = fpmService.peers();
    IpAddress peerAddress = IpAddress.valueOf(address);
    fpmPeers.entrySet().stream().filter(peer -> peer.getKey().address().equals(peerAddress)).map(Map.Entry::getValue).forEach(fpmPeerInfo -> {
        fpmPeerInfo.connections().forEach(connection -> {
            fpmNode.put(ACCEPT_ROUTES, connection.isAcceptRoutes());
        });
    });
    return fpmNode;
}
Also used : FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) FpmPeerInfo(org.onosproject.routing.fpm.FpmPeerInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IpAddress(org.onlab.packet.IpAddress) FpmPeer(org.onosproject.routing.fpm.FpmPeer) Map(java.util.Map)

Example 8 with FpmInfoService

use of org.onosproject.routing.fpm.FpmInfoService in project onos by opennetworkinglab.

the class FpmWebResource method updateAcceptRouteFlagForConnection.

/**
 * Performs disabling of FPM Peer.
 *
 * @param stream array of peer address and accept route flag
 * @return 200 OK disable peer.
 * @onos.rsModel FpmPeerSetAcceptRouteFlag
 */
@POST
@Path("acceptRoutes")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateAcceptRouteFlagForConnection(InputStream stream) {
    FpmInfoService fpmService = get(FpmInfoService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        ArrayNode peersArray = nullIsIllegal((ArrayNode) jsonTree.get(PEERS), PEERS_KEY_ERROR);
        List<FpmPeerAcceptRoutes> fpmPeerRouteInfo = (new FpmAcceptRoutesCodec()).decode(peersArray, this);
        fpmService.updateAcceptRouteFlag(fpmPeerRouteInfo);
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.ok().build();
}
Also used : FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) FpmPeerAcceptRoutes(org.onosproject.routing.fpm.FpmPeerAcceptRoutes) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

FpmInfoService (org.onosproject.routing.fpm.FpmInfoService)8 IpAddress (org.onlab.packet.IpAddress)6 FpmPeer (org.onosproject.routing.fpm.FpmPeer)6 Map (java.util.Map)5 FpmPeerInfo (org.onosproject.routing.fpm.FpmPeerInfo)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Comparator (java.util.Comparator)4 FpmPeerAcceptRoutes (org.onosproject.routing.fpm.FpmPeerAcceptRoutes)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 IOException (java.io.IOException)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 InputStream (java.io.InputStream)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 PathParam (javax.ws.rs.PathParam)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2