use of org.onosproject.ofagent.api.OFAgentService in project onos by opennetworkinglab.
the class OFAgentAddControllerCommand method doExecute.
@Override
protected void doExecute() {
if (!isValidController(strCtrl)) {
error("Invalid controller string %s, must be IP:PORT", strCtrl);
return;
}
OFAgentService service = get(OFAgentService.class);
OFAgentAdminService adminService = get(OFAgentAdminService.class);
OFAgent existing = service.agent(NetworkId.networkId(networkId));
if (existing == null) {
error("OFAgent for network %s does not exist", networkId);
return;
}
String[] temp = strCtrl.split(":");
OFAgent updated = DefaultOFAgent.builder().from(existing).addController(DefaultOFController.of(IpAddress.valueOf(temp[0]), TpPort.tpPort(Integer.valueOf(temp[1])))).build();
adminService.updateAgent(updated);
}
use of org.onosproject.ofagent.api.OFAgentService in project onos by opennetworkinglab.
the class OFAgentDeleteControllerCommand method doExecute.
@Override
protected void doExecute() {
if (!isValidController(strCtrl)) {
error("Invalid controller string %s, must be IP:PORT", strCtrl);
return;
}
OFAgentService service = get(OFAgentService.class);
OFAgentAdminService adminService = get(OFAgentAdminService.class);
OFAgent existing = service.agent(NetworkId.networkId(networkId));
if (existing == null) {
error("OFAgent for network %s does not exist", networkId);
return;
}
String[] temp = strCtrl.split(":");
OFAgent updated = DefaultOFAgent.builder().from(existing).deleteController(DefaultOFController.of(IpAddress.valueOf(temp[0]), TpPort.tpPort(Integer.valueOf(temp[1])))).build();
adminService.updateAgent(updated);
}
use of org.onosproject.ofagent.api.OFAgentService in project onos by opennetworkinglab.
the class OFAgentListCommand method doExecute.
@Override
protected void doExecute() {
OFAgentService service = get(OFAgentService.class);
print(FORMAT, "Network", "Status", "Controllers");
service.agents().forEach(agent -> {
Set<String> ctrls = agent.controllers().stream().map(ctrl -> String.format(CTRL, ctrl.ip(), ctrl.port())).collect(Collectors.toSet());
print(FORMAT, agent.networkId(), agent.state().name(), ctrls);
});
}
use of org.onosproject.ofagent.api.OFAgentService in project onos by opennetworkinglab.
the class OFAgentWebResource method listOFAgent.
/**
* Lists OpenFlow agent.
* Shows OpenFlow agent for given network.
*
* @param networkId OFAgent networkId
* @return 200 OK if OFAgent exists, 404 NOT FOUND otherwise
*/
@GET
@Path("ofagent/{networkId}")
public Response listOFAgent(@PathParam("networkId") long networkId) {
OFAgentService service = get(OFAgentService.class);
OFAgent ofAgent = service.agent(NetworkId.networkId(networkId));
if (ofAgent == null) {
return Response.status(NOT_FOUND).entity(OFAGENT_NOT_FOUND).build();
} else {
return Response.ok((new OFAgentCodec()).encode(ofAgent, this), MediaType.APPLICATION_JSON_TYPE).build();
}
}
use of org.onosproject.ofagent.api.OFAgentService in project onos by opennetworkinglab.
the class OFAgentWebResource method listOFAgents.
/**
* Lists OpenFlow agents.
* Shows OpenFlow agents for all virtual networks.
*
* @return 200 OK if set exists, 500 INTERNAL SERVER ERROR otherwise
*/
@GET
@Path("ofagents")
public Response listOFAgents() {
OFAgentService service = get(OFAgentService.class);
ObjectMapper mapper = new ObjectMapper();
ObjectNode root = mapper.createObjectNode();
ArrayNode ofAgentsArray = mapper.createArrayNode();
if (service.agents() == null) {
return Response.status(INTERNAL_SERVER_ERROR).entity(OFAGENTS_NOT_FOUND).build();
} else {
service.agents().forEach(ofAgent -> ofAgentsArray.add((new OFAgentCodec()).encode(ofAgent, this)));
root.set("ofAgents", ofAgentsArray);
return Response.ok(root, MediaType.APPLICATION_JSON_TYPE).build();
}
}
Aggregations