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();
}
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();
}
}
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();
}
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();
}
}
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();
}
}
Aggregations