Search in sources :

Example 1 with Vpls

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

the class VplsConfigManager method reloadConfiguration.

/**
 * Retrieves the VPLS configuration from network configuration.
 * Checks difference between new configuration and old configuration.
 */
private synchronized void reloadConfiguration() {
    VplsAppConfig vplsAppConfig = configService.getConfig(appId, VplsAppConfig.class);
    if (vplsAppConfig == null) {
        log.warn(CONFIG_NULL);
        // If the config is null, removes all VPLS.
        vpls.removeAllVpls();
        return;
    }
    // If there exists a update time in the configuration; it means the
    // configuration was pushed by VPLS store; ignore this configuration.
    long updateTime = vplsAppConfig.updateTime();
    if (updateTime != -1L) {
        return;
    }
    Collection<VplsData> oldVplses = vpls.getAllVpls();
    Collection<VplsData> newVplses;
    // Generates collection of new VPLSs
    newVplses = vplsAppConfig.vplss().stream().map(vplsConfig -> {
        Set<Interface> interfaces = vplsConfig.ifaces().stream().map(this::getInterfaceByName).filter(Objects::nonNull).collect(Collectors.toSet());
        VplsData vplsData = VplsData.of(vplsConfig.name(), vplsConfig.encap());
        vplsData.addInterfaces(interfaces);
        return vplsData;
    }).collect(Collectors.toSet());
    if (newVplses.containsAll(oldVplses) && oldVplses.containsAll(newVplses)) {
        // no update, ignore
        return;
    }
    // To add or update
    newVplses.forEach(newVplsData -> {
        boolean vplsExists = false;
        for (VplsData oldVplsData : oldVplses) {
            if (oldVplsData.name().equals(newVplsData.name())) {
                vplsExists = true;
                // VPLS exists; but need to be updated.
                if (!oldVplsData.equals(newVplsData)) {
                    // Update VPLS
                    Set<Interface> newInterfaces = newVplsData.interfaces();
                    Set<Interface> oldInterfaces = oldVplsData.interfaces();
                    Set<Interface> ifaceToAdd = newInterfaces.stream().filter(iface -> !oldInterfaces.contains(iface)).collect(Collectors.toSet());
                    Set<Interface> ifaceToRem = oldInterfaces.stream().filter(iface -> !newInterfaces.contains(iface)).collect(Collectors.toSet());
                    vpls.addInterfaces(oldVplsData, ifaceToAdd);
                    vpls.removeInterfaces(oldVplsData, ifaceToRem);
                    vpls.setEncapsulationType(oldVplsData, newVplsData.encapsulationType());
                }
            }
        }
        // VPLS not exist; add new VPLS
        if (!vplsExists) {
            vpls.createVpls(newVplsData.name(), newVplsData.encapsulationType());
            vpls.addInterfaces(newVplsData, newVplsData.interfaces());
        }
    });
    // VPLS not exists in old VPLS configuration; remove it.
    Set<VplsData> vplsToRemove = Sets.newHashSet();
    oldVplses.forEach(oldVpls -> {
        Set<String> newVplsNames = newVplses.stream().map(VplsData::name).collect(Collectors.toSet());
        if (!newVplsNames.contains(oldVpls.name())) {
            // To avoid ConcurrentModificationException; do remove after this
            // iteration.
            vplsToRemove.add(oldVpls);
        }
    });
    vplsToRemove.forEach(vpls::removeVpls);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) VplsData(org.onosproject.vpls.api.VplsData) InterfaceService(org.onosproject.net.intf.InterfaceService) Component(org.osgi.service.component.annotations.Component) SubjectFactories(org.onosproject.net.config.basics.SubjectFactories) ApplicationId(org.onosproject.core.ApplicationId) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) Vpls(org.onosproject.vpls.api.Vpls) NodeId(org.onosproject.cluster.NodeId) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) ConfigFactory(org.onosproject.net.config.ConfigFactory) VplsManager(org.onosproject.vpls.VplsManager) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) VplsData(org.onosproject.vpls.api.VplsData) Interface(org.onosproject.net.intf.Interface)

Example 2 with Vpls

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

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

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

the class VplsOptArgCompleter method choices.

@Override
public List<String> choices() {
    if (vpls == null) {
        vpls = get(Vpls.class);
    }
    String[] argList = commandLine.getArguments();
    if (argList == null) {
        return Collections.emptyList();
    }
    String argOne = argList[1];
    VplsCommandEnum vplsCommandEnum = VplsCommandEnum.enumFromString(argOne);
    if (vplsCommandEnum != null) {
        switch(vplsCommandEnum) {
            case ADD_IFACE:
                return availableIfaces();
            case SET_ENCAP:
                return encap();
            case REMOVE_IFACE:
                return vplsIfaces();
            default:
                return Collections.emptyList();
        }
    }
    return Collections.emptyList();
}
Also used : VplsCommandEnum(org.onosproject.vpls.cli.VplsCommandEnum) Vpls(org.onosproject.vpls.api.Vpls)

Example 5 with Vpls

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

the class VplsWebResource method getVplss.

/**
 * Gets all Vplss. Returns array of all Vplss in the system.
 *
 * @return 200 OK with a collection of Vplss
 * @onos.rsModel Vplss
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getVplss() {
    ArrayNode vplssNode = root.putArray(VPLSS);
    Vpls service = get(Vpls.class);
    Collection<VplsData> vplsDatas = service.getAllVpls();
    if (!vplsDatas.isEmpty()) {
        for (VplsData entry : vplsDatas) {
            vplssNode.add(codec(VplsData.class).encode(entry, this));
        }
    }
    return ok(root).build();
}
Also used : VplsData(org.onosproject.vpls.api.VplsData) Vpls(org.onosproject.vpls.api.Vpls) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Vpls (org.onosproject.vpls.api.Vpls)8 VplsData (org.onosproject.vpls.api.VplsData)7 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 InterfaceAdminService (org.onosproject.net.intf.InterfaceAdminService)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 DeviceService (org.onosproject.net.device.DeviceService)2 Interface (org.onosproject.net.intf.Interface)2 Sets (com.google.common.collect.Sets)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 Set (java.util.Set)1