Search in sources :

Example 6 with OFAgentAdminService

use of org.onosproject.ofagent.api.OFAgentAdminService in project onos by opennetworkinglab.

the class OFAgentWebResource method updateOFAgent.

/**
 * Updates OpenFlow agent.
 * Updates existing OpenFlow agent for the given network.
 *
 * @param stream JSON stream
 * @return 200 OK if OFAgent was updated, 404 NOT FOUND when OF agent does not exist, 400 BAD REQUEST otherwise
 * @throws IOException if request cannot be parsed
 */
@PUT
@Path("ofagent-update")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateOFAgent(InputStream stream) throws IOException {
    OFAgentAdminService adminService = get(OFAgentAdminService.class);
    OFAgent ofAgent = (new OFAgentCodec()).decode(readTreeFromStream(mapper(), stream), this);
    if (ofAgent == null) {
        return Response.status(NOT_FOUND).entity(OFAGENT_NOT_UPDATED).build();
    } else if (get(OFAgentService.class).agent(ofAgent.networkId()) == null) {
        return Response.status(NOT_FOUND).entity(OFAGENT_NOT_UPDATED).build();
    }
    adminService.updateAgent(ofAgent);
    return Response.status(OK).entity(OFAGENT_UPDATED).build();
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentService(org.onosproject.ofagent.api.OFAgentService) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 7 with OFAgentAdminService

use of org.onosproject.ofagent.api.OFAgentAdminService in project onos by opennetworkinglab.

the class OFAgentWebResource method createOFAgent.

/**
 * Adds a new OpenFlow agent.
 * Creates a new OpenFlow agent and adds it to OpenFlow agent store.
 *
 * @param stream JSON stream
 * @return 201 CREATED , 400 BAD REQUEST if stream cannot be decoded to OFAgent
 * @throws IOException if request cannot be parsed
 */
@POST
@Path("ofagent-create")
@Consumes(MediaType.APPLICATION_JSON)
public Response createOFAgent(InputStream stream) throws IOException {
    OFAgentAdminService adminService = get(OFAgentAdminService.class);
    OFAgent ofAgent = (new OFAgentCodec()).decode(readTreeFromStream(mapper(), stream), this);
    if (ofAgent == null) {
        return Response.status(BAD_REQUEST).entity(OFAGENT_NOT_CREATED).build();
    } else {
        adminService.createAgent(ofAgent);
        return Response.status(CREATED).entity(OFAGENT_CREATED).build();
    }
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 8 with OFAgentAdminService

use of org.onosproject.ofagent.api.OFAgentAdminService in project onos by opennetworkinglab.

the class OFAgentWebResource method stopOFAgent.

/**
 * Stops OFAgent.
 * Stops OFAgent for the given virtual network.
 *
 * @param stream JSON stream
 * @return 204 NO CONTENT if OpenFlow agent was stopped, 404 NOT FOUND otherwise
 * @throws IOException if request cannot be parsed
 */
@POST
@Path("ofagent-stop")
@Consumes(MediaType.APPLICATION_JSON)
public Response stopOFAgent(InputStream stream) throws IOException {
    OFAgentAdminService adminService = get(OFAgentAdminService.class);
    ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
    JsonNode networkId = jsonTree.get("networkId");
    if (get(OFAgentService.class).agent(NetworkId.networkId(networkId.asLong())) == null) {
        return Response.status(NOT_FOUND).entity(OFAGENT_NOT_FOUND).build();
    }
    adminService.stopAgent(NetworkId.networkId(networkId.asLong()));
    return Response.noContent().build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 9 with OFAgentAdminService

use of org.onosproject.ofagent.api.OFAgentAdminService in project onos by opennetworkinglab.

the class OFAgentWebResource method removeOFAgent.

/**
 * Deletes OFAgent.
 * Removes OFAgent for the given virtual network from repository.
 *
 * @param networkId OFAgent networkId
 * @return 200 OK if OFAgent was removed, 404 NOT FOUND when OF agent does not exist, 400 BAD REQUEST otherwise
 */
@DELETE
@Path("ofagent-remove/{networkId}")
public Response removeOFAgent(@PathParam("networkId") long networkId) {
    if (get(OFAgentService.class).agent(NetworkId.networkId(networkId)) == null) {
        return Response.status(BAD_REQUEST).entity(OFAGENT_NOT_FOUND).build();
    }
    OFAgentAdminService adminService = get(OFAgentAdminService.class);
    OFAgent removed = adminService.removeAgent(NetworkId.networkId(networkId));
    if (removed != null) {
        return Response.ok((new OFAgentCodec()).encode(removed, this), MediaType.APPLICATION_JSON_TYPE).build();
    } else {
        return Response.status(NOT_FOUND).entity(OFAGENT_NOT_FOUND).build();
    }
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 10 with OFAgentAdminService

use of org.onosproject.ofagent.api.OFAgentAdminService in project onos by opennetworkinglab.

the class OFAgentWebResource method startOFAgent.

/**
 * Starts OpenFlow agent.
 * Starts OpenFlow agent for the given network.
 *
 * @param stream JSON stream
 * @return 200 OK if OFAgent was started, 404 NOT FOUND when OF agent does not exist, 400 BAD REQUEST otherwise
 * @throws IOException if request cannot be parsed
 */
@POST
@Path("ofagent-start")
@Consumes(MediaType.APPLICATION_JSON)
public Response startOFAgent(InputStream stream) throws IOException {
    OFAgentAdminService adminService = get(OFAgentAdminService.class);
    ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
    JsonNode networkId = jsonTree.get("networkId");
    if (networkId == null) {
        return Response.status(BAD_REQUEST).entity(OFAGENT_NOT_STARTED).build();
    } else if (get(OFAgentService.class).agent(NetworkId.networkId(networkId.asLong())) == null) {
        return Response.status(NOT_FOUND).entity(OFAGENT_NOT_STARTED).build();
    } else {
        adminService.startAgent(NetworkId.networkId(networkId.asLong()));
        return Response.status(OK).entity(OFAGENT_STARTED).build();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) OFAgentService(org.onosproject.ofagent.api.OFAgentService) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

OFAgentAdminService (org.onosproject.ofagent.api.OFAgentAdminService)11 OFAgent (org.onosproject.ofagent.api.OFAgent)7 Path (javax.ws.rs.Path)5 Consumes (javax.ws.rs.Consumes)4 OFAgentService (org.onosproject.ofagent.api.OFAgentService)4 POST (javax.ws.rs.POST)3 DefaultOFAgent (org.onosproject.ofagent.impl.DefaultOFAgent)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DELETE (javax.ws.rs.DELETE)1 PUT (javax.ws.rs.PUT)1 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)1 TenantId (org.onosproject.net.TenantId)1 OFController (org.onosproject.ofagent.api.OFController)1 DefaultOFController (org.onosproject.ofagent.impl.DefaultOFController)1