Search in sources :

Example 11 with OFAgent

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

the class OFAgentManagerTest method testRemoveController.

@Test
public void testRemoveController() {
    target.createAgent(OFAGENT_1_CTRL_2);
    target.updateAgent(OFAGENT_1_CTRL_1);
    OFAgent ofAgent = target.agent(NETWORK_1);
    assertEquals("OFAgent controller did not match", CONTROLLER_1, ofAgent.controllers());
    target.updateAgent(OFAGENT_1);
    ofAgent = target.agent(NETWORK_1);
    assertTrue("OFAgent controller did not match", ofAgent.controllers().isEmpty());
    validateEvents(OFAGENT_CREATED, OFAGENT_CONTROLLER_REMOVED, OFAGENT_CONTROLLER_REMOVED);
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) Test(org.junit.Test)

Example 12 with OFAgent

use of org.onosproject.ofagent.api.OFAgent 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();
    }
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 13 with OFAgent

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

Example 14 with OFAgent

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

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

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