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