Search in sources :

Example 6 with OFAgent

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

the class OFSwitchManager method addOFSwitch.

private void addOFSwitch(NetworkId networkId, DeviceId deviceId) {
    OFSwitch ofSwitch = DefaultOFSwitch.of(dpidWithDeviceId(deviceId), DEFAULT_CAPABILITIES, networkId, deviceId, virtualNetService.getServiceDirectory());
    ofSwitchMap.put(deviceId, ofSwitch);
    log.info("Added virtual OF switch for {}", deviceId);
    OFAgent ofAgent = ofAgentService.agent(networkId);
    if (ofAgent == null) {
        log.error("OFAgent for network {} does not exist", networkId);
        return;
    }
    if (ofAgent.state() == STARTED) {
        connectController(ofSwitch, ofAgent.controllers());
    }
}
Also used : OFSwitch(org.onosproject.ofagent.api.OFSwitch) OFAgent(org.onosproject.ofagent.api.OFAgent)

Example 7 with OFAgent

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

the class OFAgentWebResource method updateOFAgent.

/**
 * Updates OpenFlow agent.
 * Updates existing OpenFlow agent for the given network.
 *
 * @param stream JSON stream
 * @return 200 OK if OFAgent was updated, 404 NOT FOUND when OF agent does not exist, 400 BAD REQUEST otherwise
 * @throws IOException if request cannot be parsed
 */
@PUT
@Path("ofagent-update")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateOFAgent(InputStream stream) throws IOException {
    OFAgentAdminService adminService = get(OFAgentAdminService.class);
    OFAgent ofAgent = (new OFAgentCodec()).decode(readTreeFromStream(mapper(), stream), this);
    if (ofAgent == null) {
        return Response.status(NOT_FOUND).entity(OFAGENT_NOT_UPDATED).build();
    } else if (get(OFAgentService.class).agent(ofAgent.networkId()) == null) {
        return Response.status(NOT_FOUND).entity(OFAGENT_NOT_UPDATED).build();
    }
    adminService.updateAgent(ofAgent);
    return Response.status(OK).entity(OFAGENT_UPDATED).build();
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentService(org.onosproject.ofagent.api.OFAgentService) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 8 with OFAgent

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

the class OFAgentManager method removeAgent.

@Override
public OFAgent removeAgent(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, ERR_IN_USE);
            throw new IllegalStateException(error);
        }
        log.info(String.format(MSG_OFAGENT, networkId, MSG_REMOVED));
        return ofAgentStore.removeOfAgent(networkId);
    }
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent)

Example 9 with OFAgent

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

the class OFAgentManagerTest method testStartAndStopAgent.

@Test
public void testStartAndStopAgent() {
    target.createAgent(OFAGENT_1);
    target.startAgent(NETWORK_1);
    OFAgent ofAgent = target.agent(NETWORK_1);
    assertEquals("OFAgent state did not match", STARTED, ofAgent.state());
    target.stopAgent(NETWORK_1);
    ofAgent = target.agent(NETWORK_1);
    assertEquals("OFAgent state did not match", STOPPED, ofAgent.state());
    validateEvents(OFAGENT_CREATED, OFAGENT_STARTED, OFAGENT_STOPPED);
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) Test(org.junit.Test)

Example 10 with OFAgent

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

the class OFAgentManagerTest method testAddController.

@Test
public void testAddController() {
    target.createAgent(OFAGENT_1);
    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_CTRL_2);
    ofAgent = target.agent(NETWORK_1);
    assertEquals("OFAgent controller did not match", CONTROLLER_2, ofAgent.controllers());
    validateEvents(OFAGENT_CREATED, OFAGENT_CONTROLLER_ADDED, OFAGENT_CONTROLLER_ADDED);
}
Also used : OFAgent(org.onosproject.ofagent.api.OFAgent) Test(org.junit.Test)

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