Search in sources :

Example 1 with OFController

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

the class OFAgentCodec method decode.

public OFAgent decode(ObjectNode json, CodecContext context) {
    JsonNode networkId = json.get("networkId");
    checkNotNull(networkId);
    JsonNode tenantId = json.get("tenantId");
    checkNotNull(tenantId);
    checkNotNull(json.get("controllers"));
    checkState(json.get("controllers").isArray());
    Set<OFController> controllers = Sets.newHashSet();
    json.get("controllers").forEach(jsonController -> controllers.add((new OFControllerCodec()).decode((ObjectNode) jsonController, context)));
    return DefaultOFAgent.builder().networkId(NetworkId.networkId(networkId.asLong())).tenantId(TenantId.tenantId(tenantId.asText())).controllers(controllers).state(OFAgent.State.STOPPED).build();
}
Also used : OFController(org.onosproject.ofagent.api.OFController) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with OFController

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

the class OFAgentCreateCommand method doExecute.

@Override
protected void doExecute() {
    Set<OFController> ctrls = Sets.newHashSet();
    for (String strCtrl : strCtrls) {
        if (!isValidController(strCtrl)) {
            print("Invalid controller %s, ignores it.", strCtrl);
            continue;
        }
        String[] temp = strCtrl.split(":");
        ctrls.add(DefaultOFController.of(IpAddress.valueOf(temp[0]), TpPort.tpPort(Integer.valueOf(temp[1]))));
    }
    VirtualNetworkService virtualNetworkService = get(VirtualNetworkService.class);
    TenantId tenantId = virtualNetworkService.getTenantId(NetworkId.networkId(networkId));
    checkNotNull(tenantId, "Virtual network %s does not have tenant.", networkId);
    OFAgentAdminService adminService = get(OFAgentAdminService.class);
    OFAgent ofAgent = DefaultOFAgent.builder().networkId(NetworkId.networkId(networkId)).tenantId(tenantId).controllers(ctrls).state(OFAgent.State.STOPPED).build();
    adminService.createAgent(ofAgent);
    print("Successfully created OFAgent for network %s, tenant %s", networkId, tenantId);
}
Also used : TenantId(org.onosproject.net.TenantId) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) DefaultOFController(org.onosproject.ofagent.impl.DefaultOFController) OFController(org.onosproject.ofagent.api.OFController) DefaultOFAgent(org.onosproject.ofagent.impl.DefaultOFAgent) OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService)

Aggregations

OFController (org.onosproject.ofagent.api.OFController)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)1 TenantId (org.onosproject.net.TenantId)1 OFAgent (org.onosproject.ofagent.api.OFAgent)1 OFAgentAdminService (org.onosproject.ofagent.api.OFAgentAdminService)1 DefaultOFAgent (org.onosproject.ofagent.impl.DefaultOFAgent)1 DefaultOFController (org.onosproject.ofagent.impl.DefaultOFController)1