Search in sources :

Example 21 with VplsData

use of org.onosproject.vpls.api.VplsData 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 22 with VplsData

use of org.onosproject.vpls.api.VplsData in project onos by opennetworkinglab.

the class VplsCommand method delete.

/**
 * Deletes a VPLS.
 *
 * @param vplsName the name of the VLPS
 */
protected void delete(String vplsName) {
    if (vplsName == null) {
        print(INSERT_VPLS_NAME);
        return;
    }
    VplsData vplsData = vpls.getVpls(vplsName);
    if (vplsData == null) {
        print(VPLS_NOT_FOUND, vplsName);
        return;
    }
    if (CHANGING_STATE.contains(vplsData.state())) {
        // when a VPLS is updating, we shouldn't try modify it.
        print("VPLS %s still updating, please wait it finished", vplsData.name());
        return;
    }
    vpls.removeVpls(vplsData);
}
Also used : VplsData(org.onosproject.vpls.api.VplsData)

Example 23 with VplsData

use of org.onosproject.vpls.api.VplsData in project onos by opennetworkinglab.

the class VplsCommand method show.

/**
 * Shows the details of one or more VPLSs.
 *
 * @param vplsName the name of the VPLS
 */
protected void show(String vplsName) {
    if (!isNullOrEmpty(vplsName)) {
        // A VPLS name is provided. Check first if the VPLS exists
        VplsData vplsData = vpls.getVpls(vplsName);
        if (vplsData != null) {
            Set<String> ifaceNames = vplsData.interfaces().stream().map(Interface::name).collect(Collectors.toSet());
            print(VPLS_DISPLAY, vplsName, ifaceNames, vplsData.encapsulationType().toString(), vplsData.state());
        } else {
            print(VPLS_NOT_FOUND, vplsName);
        }
    } else {
        Collection<VplsData> vplses = vpls.getAllVpls();
        // No VPLS names are provided. Display all VPLSs configured
        print(SEPARATOR);
        vplses.forEach(vplsData -> {
            Set<String> ifaceNames = vplsData.interfaces().stream().map(Interface::name).collect(Collectors.toSet());
            print(VPLS_DISPLAY, vplsData.name(), ifaceNames, vplsData.encapsulationType().toString(), vplsData.state());
            print(SEPARATOR);
        });
    }
}
Also used : VplsData(org.onosproject.vpls.api.VplsData)

Example 24 with VplsData

use of org.onosproject.vpls.api.VplsData in project onos by opennetworkinglab.

the class VplsCommand method create.

/**
 * Creates a new VPLS.
 *
 * @param vplsName the name of the VLPS
 */
protected void create(String vplsName) {
    if (vplsName == null || vplsName.isEmpty()) {
        print(INSERT_VPLS_NAME);
        return;
    }
    VplsData vplsData = vpls.getVpls(vplsName);
    if (vplsData != null) {
        print(VPLS_ALREADY_EXISTS, vplsName);
        return;
    }
    vpls.createVpls(vplsName, EncapsulationType.NONE);
}
Also used : VplsData(org.onosproject.vpls.api.VplsData)

Example 25 with VplsData

use of org.onosproject.vpls.api.VplsData in project onos by opennetworkinglab.

the class VplsCommand method setEncap.

/**
 * Sets the encapsulation type for a VPLS.
 *
 * @param vplsName the name of the VPLS
 * @param encap the encapsulation type
 */
protected void setEncap(String vplsName, String encap) {
    if (vplsName == null) {
        print(INSERT_VPLS_NAME);
        return;
    }
    if (encap == null) {
        print(INSERT_ENCAP_TYPE);
        return;
    }
    VplsData vplsData = vpls.getVpls(vplsName);
    if (vplsData == null) {
        print(VPLS_NOT_FOUND, vplsName);
        return;
    }
    EncapsulationType encapType = EncapsulationType.enumFromString(encap);
    if (encapType.equals(EncapsulationType.NONE) && !encapType.toString().equals(encap)) {
        print(ENCAP_NOT_FOUND, encap);
        return;
    }
    vpls.setEncapsulationType(vplsData, encapType);
}
Also used : EncapsulationType(org.onosproject.net.EncapsulationType) VplsData(org.onosproject.vpls.api.VplsData)

Aggregations

VplsData (org.onosproject.vpls.api.VplsData)73 Test (org.junit.Test)44 VplsOperation (org.onosproject.vpls.api.VplsOperation)18 VplsTest (org.onosproject.vpls.VplsTest)11 ArrayDeque (java.util.ArrayDeque)10 Interface (org.onosproject.net.intf.Interface)10 Vpls (org.onosproject.vpls.api.Vpls)7 NetworkConfigEvent (org.onosproject.net.config.NetworkConfigEvent)6 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Host (org.onosproject.net.Host)4 HostEvent (org.onosproject.net.host.HostEvent)4 Intent (org.onosproject.net.intent.Intent)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Objects (java.util.Objects)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 MacAddress (org.onlab.packet.MacAddress)3