Search in sources :

Example 26 with VplsData

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

the class VplsCommand method addIface.

/**
 * Adds an inteterface to a VPLS.
 *
 * @param vplsName the name of the VLPS
 * @param ifaceName the name of the interface to add
 */
protected void addIface(String vplsName, String ifaceName) {
    if (vplsName == null) {
        print(INSERT_VPLS_NAME);
        return;
    }
    if (ifaceName == null) {
        print(INSERT_INTERFACE);
        return;
    }
    Interface iface = getInterface(ifaceName);
    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;
    }
    if (iface == null) {
        print(IFACE_NOT_FOUND, ifaceName);
        return;
    }
    if (isIfaceAssociated(iface)) {
        print(IFACE_ALREADY_ASSOCIATED, ifaceName, getVplsByInterface(iface).name());
        return;
    }
    vpls.addInterface(vplsData, iface);
}
Also used : VplsData(org.onosproject.vpls.api.VplsData) Interface(org.onosproject.net.intf.Interface)

Example 27 with VplsData

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

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

the class VplsManager method removeInterfaces.

@Override
public Collection<Interface> removeInterfaces(VplsData vplsData, Collection<Interface> interfaces) {
    requireNonNull(vplsData);
    requireNonNull(interfaces);
    VplsData newData = VplsData.of(vplsData);
    newData.removeInterfaces(interfaces);
    updateVplsStatus(newData, VplsData.VplsState.UPDATING);
    return interfaces;
}
Also used : VplsData(org.onosproject.vpls.api.VplsData)

Example 29 with VplsData

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

the class VplsManager method setEncapsulationType.

@Override
public void setEncapsulationType(VplsData vplsData, EncapsulationType encapsulationType) {
    requireNonNull(vplsData);
    requireNonNull(encapsulationType);
    VplsData newData = VplsData.of(vplsData);
    if (newData.encapsulationType().equals(encapsulationType)) {
        // Encap type not changed.
        return;
    }
    newData.encapsulationType(encapsulationType);
    updateVplsStatus(newData, VplsData.VplsState.UPDATING);
}
Also used : VplsData(org.onosproject.vpls.api.VplsData)

Example 30 with VplsData

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

the class VplsNeighbourHandler method findVpls.

/**
 * Finds the VPLS with given neighbour message context.
 *
 * @param context the neighbour message context
 * @return the VPLS for specific neighbour message context
 */
private VplsData findVpls(NeighbourMessageContext context) {
    Collection<VplsData> vplses = vplsStore.getAllVpls();
    for (VplsData vplsData : vplses) {
        Set<Interface> interfaces = vplsData.interfaces();
        ConnectPoint port = context.inPort();
        VlanId vlanId = context.vlan();
        boolean match = interfaces.stream().anyMatch(iface -> iface.connectPoint().equals(port) && iface.vlan().equals(vlanId));
        if (match) {
            return vplsData;
        }
    }
    return null;
}
Also used : VplsData(org.onosproject.vpls.api.VplsData) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) VlanId(org.onlab.packet.VlanId)

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