Search in sources :

Example 1 with OFAgent

use of org.onosproject.ofagent.api.OFAgent 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 OFAgent

use of org.onosproject.ofagent.api.OFAgent 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 OFAgent

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

the class OFAgentRemoveCommand method doExecute.

@Override
protected void doExecute() {
    OFAgentAdminService adminService = get(OFAgentAdminService.class);
    OFAgent removed = adminService.removeAgent(NetworkId.networkId(networkId));
    if (removed != null) {
        print("Successfully removed OFAgent for network %s", networkId);
    } else {
        print("Failed to remove OFAgent for network %s", networkId);
    }
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService)

Example 4 with OFAgent

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

the class OFAgentManager method stopAgent.

@Override
public void stopAgent(NetworkId networkId) {
    checkNotNull(networkId, ERR_NULL_NETID);
    synchronized (this) {
        OFAgent existing = ofAgentStore.ofAgent(networkId);
        if (existing == null) {
            final String error = String.format(MSG_OFAGENT, networkId, ERR_NOT_EXIST);
            throw new IllegalStateException(error);
        }
        if (existing.state() == STOPPED) {
            final String error = String.format(MSG_OFAGENT, networkId, MSG_IN_STOPPED);
            throw new IllegalStateException(error);
        }
        OFAgent updated = DefaultOFAgent.builder().from(existing).state(STOPPED).build();
        ofAgentStore.updateOfAgent(updated);
        log.info(String.format(MSG_OFAGENT, networkId, MSG_STOPPED));
    }
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent)

Example 5 with OFAgent

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

the class OFAgentManager method startAgent.

@Override
public void startAgent(NetworkId networkId) {
    checkNotNull(networkId, ERR_NULL_NETID);
    synchronized (this) {
        OFAgent existing = ofAgentStore.ofAgent(networkId);
        if (existing == null) {
            final String error = String.format(MSG_OFAGENT, networkId, ERR_NOT_EXIST);
            throw new IllegalStateException(error);
        }
        if (existing.state() == STARTED) {
            final String error = String.format(MSG_OFAGENT, networkId, MSG_IN_STARTED);
            throw new IllegalStateException(error);
        }
        OFAgent updated = DefaultOFAgent.builder().from(existing).state(STARTED).build();
        ofAgentStore.updateOfAgent(updated);
        log.info(String.format(MSG_OFAGENT, networkId, MSG_STARTED));
    }
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent)

Aggregations

OFAgent (org.onosproject.ofagent.api.OFAgent)15 OFAgentAdminService (org.onosproject.ofagent.api.OFAgentAdminService)7 Path (javax.ws.rs.Path)4 OFAgentService (org.onosproject.ofagent.api.OFAgentService)4 Test (org.junit.Test)3 DefaultOFAgent (org.onosproject.ofagent.impl.DefaultOFAgent)3 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)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 OFSwitch (org.onosproject.ofagent.api.OFSwitch)1 DefaultOFController (org.onosproject.ofagent.impl.DefaultOFController)1