Search in sources :

Example 1 with InterfaceAdminService

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());
    }
}
Also used : InterfaceAdminService(org.onosproject.net.intf.InterfaceAdminService) VplsData(org.onosproject.vpls.api.VplsData) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) Vpls(org.onosproject.vpls.api.Vpls) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) Interface(org.onosproject.net.intf.Interface) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with InterfaceAdminService

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());
    }
}
Also used : InterfaceAdminService(org.onosproject.net.intf.InterfaceAdminService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VplsData(org.onosproject.vpls.api.VplsData) DeviceService(org.onosproject.net.device.DeviceService) Vpls(org.onosproject.vpls.api.Vpls) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with InterfaceAdminService

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();
}
Also used : InterfaceAdminService(org.onosproject.net.intf.InterfaceAdminService) VplsData(org.onosproject.vpls.api.VplsData) Vpls(org.onosproject.vpls.api.Vpls) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 4 with InterfaceAdminService

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");
}
Also used : InterfaceAdminService(org.onosproject.net.intf.InterfaceAdminService) MacAddress(org.onlab.packet.MacAddress) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Example 5 with InterfaceAdminService

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");
    }
}
Also used : InterfaceAdminService(org.onosproject.net.intf.InterfaceAdminService)

Aggregations

InterfaceAdminService (org.onosproject.net.intf.InterfaceAdminService)5 Vpls (org.onosproject.vpls.api.Vpls)3 VplsData (org.onosproject.vpls.api.VplsData)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 DeviceService (org.onosproject.net.device.DeviceService)2 Interface (org.onosproject.net.intf.Interface)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 MacAddress (org.onlab.packet.MacAddress)1 VlanId (org.onlab.packet.VlanId)1 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)1