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());
}
}
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();
}
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);
}
}
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);
}
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);
}
Aggregations