Search in sources :

Example 1 with OFAgentService

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);
}
Also used : DefaultOFAgent(org.onosproject.ofagent.impl.DefaultOFAgent) OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentService(org.onosproject.ofagent.api.OFAgentService) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService)

Example 2 with OFAgentService

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);
}
Also used : DefaultOFAgent(org.onosproject.ofagent.impl.DefaultOFAgent) OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentService(org.onosproject.ofagent.api.OFAgentService) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService)

Example 3 with OFAgentService

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);
    });
}
Also used : AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OFAgentService(org.onosproject.ofagent.api.OFAgentService) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Set(java.util.Set) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) OFAgentService(org.onosproject.ofagent.api.OFAgentService)

Example 4 with OFAgentService

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();
    }
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentService(org.onosproject.ofagent.api.OFAgentService) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with OFAgentService

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();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) OFAgentService(org.onosproject.ofagent.api.OFAgentService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

OFAgentService (org.onosproject.ofagent.api.OFAgentService)5 OFAgent (org.onosproject.ofagent.api.OFAgent)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 OFAgentAdminService (org.onosproject.ofagent.api.OFAgentAdminService)2 DefaultOFAgent (org.onosproject.ofagent.impl.DefaultOFAgent)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Command (org.apache.karaf.shell.api.action.Command)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1