use of org.onosproject.net.intf.InterfaceAdminService in project onos by opennetworkinglab.
the class VplsWebResource method addInterfaces.
/**
* Add new interfaces. Add new interfaces to a Vpls.<br>
*
* @param stream interfaces JSON
* @param vplsName Vpls name
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel InterfacesPost
*/
@POST
@Path("interfaces/{vplsName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addInterfaces(@PathParam("vplsName") String vplsName, InputStream stream) {
Vpls service = get(Vpls.class);
DeviceService deviceService = get(DeviceService.class);
InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
final VplsData vplsData = nullIsNotFound(service.getVpls(vplsName), VPLS_NOT_FOUND + vplsName);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(INTERFACES), INTERFACES_KEY_ERROR);
Collection<Interface> interfaceList = new ArrayList<>();
routesArray.forEach(interfJson -> {
Interface inter = codec(Interface.class).decode((ObjectNode) interfJson, this);
nullIsNotFound(deviceService.getDevice(inter.connectPoint().deviceId()), DEVICE_NOT_FOUND + inter.connectPoint().deviceId());
nullIsNotFound(deviceService.getPort(inter.connectPoint()), PORT_NOT_FOUND + inter.connectPoint().port());
interfaceList.add(inter);
interfaceService.add(inter);
});
service.addInterfaces(vplsData, interfaceList);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(INTERFACES).path(vplsName);
return Response.created(locationBuilder.build()).build();
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
use of org.onosproject.net.intf.InterfaceAdminService in project onos by opennetworkinglab.
the class VplsWebResource method createVpls.
/**
* Creates new vpls. Creates and installs a new Vplps.<br>
*
* @param stream Vpls JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel VplsPost
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createVpls(InputStream stream) {
Vpls service = get(Vpls.class);
DeviceService deviceService = get(DeviceService.class);
InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
VplsData vplsData = codec(VplsData.class).decode(jsonTree, this);
vplsData.interfaces().forEach(interf -> {
nullIsNotFound(deviceService.getDevice(interf.connectPoint().deviceId()), DEVICE_NOT_FOUND + interf.connectPoint().deviceId());
nullIsNotFound(deviceService.getPort(interf.connectPoint()), PORT_NOT_FOUND + interf.connectPoint().port());
interfaceService.add(interf);
});
service.addInterfaces(vplsData, vplsData.interfaces());
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(VPLS);
return Response.created(locationBuilder.build()).build();
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
use of org.onosproject.net.intf.InterfaceAdminService in project onos by opennetworkinglab.
the class VplsWebResource method deleteInterface.
/**
* Removes a specified interface.
*
* @param vplsName Vpls name
* @param interfaceName interface name
* @return 204 NO CONTENT
*/
@DELETE
@Path("interface/{vplsName}/{interfaceName}")
public Response deleteInterface(@PathParam("vplsName") String vplsName, @PathParam("interfaceName") String interfaceName) {
Vpls service = get(Vpls.class);
InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
final VplsData vplsData = nullIsNotFound(service.getVpls(vplsName), VPLS_NOT_FOUND + vplsName);
vplsData.interfaces().forEach(anInterface -> {
if (anInterface.name().equals(interfaceName)) {
interfaceService.remove(anInterface.connectPoint(), anInterface.name());
service.removeInterface(vplsData, anInterface);
}
});
return Response.noContent().build();
}
use of org.onosproject.net.intf.InterfaceAdminService in project onos by opennetworkinglab.
the class InterfaceAddCommand method doExecute.
@Override
protected void doExecute() {
InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
List<InterfaceIpAddress> ipAddresses = Lists.newArrayList();
if (ips != null) {
for (String strIp : ips) {
ipAddresses.add(InterfaceIpAddress.valueOf(strIp));
}
}
MacAddress macAddr = mac == null ? null : MacAddress.valueOf(mac);
VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan));
Interface intf = new Interface(name, ConnectPoint.deviceConnectPoint(connectPoint), ipAddresses, macAddr, vlanId);
interfaceService.add(intf);
print("Interface added");
}
use of org.onosproject.net.intf.InterfaceAdminService in project onos by opennetworkinglab.
the class InterfaceRemoveCommand method doExecute.
@Override
protected void doExecute() {
InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
boolean success = interfaceService.remove(ConnectPoint.deviceConnectPoint(connectPoint), name);
if (success) {
print("Interface removed");
} else {
print("Unable to remove interface");
}
}
Aggregations