Search in sources :

Example 26 with TransportZone

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.

the class TepCommandHelper method checkTepPerTzPerDpn.

public boolean checkTepPerTzPerDpn(String tzone, BigInteger dpnId) {
    // check in local cache
    if (transportZonesHashMap.containsKey(tzone)) {
        Map<SubnetObject, List<Vteps>> subVtepMapTemp = transportZonesHashMap.get(tzone);
        for (List<Vteps> vtepList : subVtepMapTemp.values()) {
            for (Vteps vtep : vtepList) {
                if (vtep.getDpnId().equals(dpnId)) {
                    return true;
                }
            }
        }
    }
    // check in DS
    InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(tzone)).build();
    Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
    if (transportZoneOptional.isPresent()) {
        TransportZone tz = transportZoneOptional.get();
        if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
            return false;
        }
        for (Subnets sub : tz.getSubnets()) {
            if (sub.getVteps() == null || sub.getVteps().isEmpty()) {
                continue;
            }
            for (Vteps vtep : sub.getVteps()) {
                if (vtep.getDpnId().equals(dpnId)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) List(java.util.List) ArrayList(java.util.ArrayList) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Example 27 with TransportZone

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.

the class TepCommandHelper method buildTeps.

@SuppressWarnings("checkstyle:IllegalCatch")
public void buildTeps() {
    TransportZones transportZonesBuilt = null;
    TransportZone transportZone = null;
    try {
        LOG.debug("no of teps added {}", CHECK);
        if (transportZonesHashMap != null && !transportZonesHashMap.isEmpty()) {
            transportZoneArrayList = new ArrayList<>();
            for (Entry<String, Map<SubnetObject, List<Vteps>>> mapEntry : transportZonesHashMap.entrySet()) {
                String tz = mapEntry.getKey();
                LOG.debug("transportZonesHashMap {}", tz);
                subnetList = new ArrayList<>();
                Map<SubnetObject, List<Vteps>> subVtepMapTemp = mapEntry.getValue();
                for (Entry<SubnetObject, List<Vteps>> entry : subVtepMapTemp.entrySet()) {
                    SubnetObject subOb = entry.getKey();
                    LOG.debug("subnets {}", subOb.get_prefix());
                    List<Vteps> vtepList = entry.getValue();
                    Subnets subnet = new SubnetsBuilder().setGatewayIp(subOb.get_gatewayIp()).setKey(subOb.get_key()).setPrefix(subOb.get_prefix()).setVlanId(subOb.get_vlanId()).setVteps(vtepList).build();
                    subnetList.add(subnet);
                    LOG.debug("vteps {}", vtepList);
                }
                InstanceIdentifier<TransportZone> transportZonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(tz)).build();
                Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, transportZonePath, dataBroker);
                LOG.debug("read container from DS");
                if (transportZoneOptional.isPresent()) {
                    TransportZone tzoneFromDs = transportZoneOptional.get();
                    LOG.debug("read tzone container {}", tzoneFromDs);
                    if (tzoneFromDs.getTunnelType() == null || tzoneFromDs.getTunnelType().equals(TunnelTypeVxlan.class)) {
                        transportZone = new TransportZoneBuilder().setKey(new TransportZoneKey(tz)).setTunnelType(TunnelTypeVxlan.class).setSubnets(subnetList).setZoneName(tz).build();
                    } else if (tzoneFromDs.getTunnelType().equals(TunnelTypeGre.class)) {
                        transportZone = new TransportZoneBuilder().setKey(new TransportZoneKey(tz)).setTunnelType(TunnelTypeGre.class).setSubnets(subnetList).setZoneName(tz).build();
                    }
                } else {
                    transportZone = new TransportZoneBuilder().setKey(new TransportZoneKey(tz)).setTunnelType(TunnelTypeVxlan.class).setSubnets(subnetList).setZoneName(tz).build();
                }
                LOG.debug("tzone object {}", transportZone);
                transportZoneArrayList.add(transportZone);
            }
            transportZonesBuilt = new TransportZonesBuilder().setTransportZone(transportZoneArrayList).build();
            InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
            LOG.debug("InstanceIdentifier {}", path);
            ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, transportZonesBuilt, dataBroker, ItmUtils.DEFAULT_CALLBACK);
            LOG.debug("wrote to Config DS {}", transportZonesBuilt);
            transportZonesHashMap.clear();
            transportZoneArrayList.clear();
            subnetList.clear();
            LOG.debug("Everything cleared");
        } else {
            LOG.debug("NO vteps were configured");
        }
    } catch (RuntimeException e) {
        LOG.error("Error building TEPs", e);
    }
}
Also used : TunnelTypeGre(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre) TransportZonesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZonesBuilder) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets) SubnetsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsBuilder) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) TransportZoneBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) List(java.util.List) ArrayList(java.util.ArrayList) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) Map(java.util.Map) HashMap(java.util.HashMap) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Example 28 with TransportZone

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.

the class TepCommandHelper method validateForDuplicates.

/**
 * Validate for duplicates.
 *
 * @param inputVtep
 *            the input vtep
 * @param transportZone
 *            the transport zone
 */
public void validateForDuplicates(Vteps inputVtep, String transportZone) {
    Map<String, TransportZone> allTransportZonesAsMap = getAllTransportZonesAsMap();
    boolean isConfiguredTepGreType = isGreTunnelType(transportZone, allTransportZonesAsMap);
    // Checking for duplicates in local cache
    for (Entry<String, Map<SubnetObject, List<Vteps>>> entry : transportZonesHashMap.entrySet()) {
        String tz = entry.getKey();
        boolean isGreType = isGreTunnelType(tz, allTransportZonesAsMap);
        Map<SubnetObject, List<Vteps>> subVtepMapTemp = entry.getValue();
        for (List<Vteps> vtepList : subVtepMapTemp.values()) {
            validateForDuplicateAndSingleGreTep(inputVtep, isConfiguredTepGreType, isGreType, vtepList);
        }
    }
    // Checking for duplicates in config DS
    for (TransportZone tz : allTransportZonesAsMap.values()) {
        boolean isGreType = false;
        if (tz.getTunnelType().equals(TunnelTypeGre.class)) {
            isGreType = true;
        }
        for (Subnets sub : ItmUtils.emptyIfNull(tz.getSubnets())) {
            List<Vteps> vtepList = sub.getVteps();
            validateForDuplicateAndSingleGreTep(inputVtep, isConfiguredTepGreType, isGreType, vtepList);
        }
    }
}
Also used : Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)

Example 29 with TransportZone

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project netvirt by opendaylight.

the class TransportZoneNotificationUtil method updateTransportZone.

@SuppressWarnings("checkstyle:IllegalCatch")
private void updateTransportZone(String zoneName, BigInteger dpnId, @Nullable String localIp, @Nonnull ReadWriteTransaction tx) throws ReadFailedException {
    InstanceIdentifier<TransportZone> inst = InstanceIdentifier.create(TransportZones.class).child(TransportZone.class, new TransportZoneKey(zoneName));
    // FIXME: Read this through a cache
    TransportZone zone = tx.read(LogicalDatastoreType.CONFIGURATION, inst).checkedGet().orNull();
    if (zone == null) {
        zone = createZone(ALL_SUBNETS, zoneName);
    }
    try {
        if (addVtep(zone, ALL_SUBNETS, dpnId, localIp)) {
            updateTransportZone(zone, dpnId, tx);
        }
    } catch (Exception e) {
        LOG.error("Failed to add tunnels for dpn {} in zone {}", dpnId, zoneName, e);
    }
}
Also used : TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Example 30 with TransportZone

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project netvirt by opendaylight.

the class TransportZoneNotificationUtil method deleteTransportZone.

@SuppressWarnings("checkstyle:IllegalCatch")
private void deleteTransportZone(String zoneName, BigInteger dpnId, @Nonnull ReadWriteTransaction tx) throws ReadFailedException {
    InstanceIdentifier<TransportZone> inst = InstanceIdentifier.create(TransportZones.class).child(TransportZone.class, new TransportZoneKey(zoneName));
    // FIXME: Read this through a cache
    TransportZone zone = tx.read(LogicalDatastoreType.CONFIGURATION, inst).checkedGet().orNull();
    if (zone != null) {
        try {
            deleteTransportZone(zone, dpnId, tx);
        } catch (Exception e) {
            LOG.error("Failed to remove tunnels for dpn {} in zone {}", dpnId, zoneName, e);
        }
    }
}
Also used : TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Aggregations

TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)42 TransportZoneKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)27 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)26 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets)21 TransportZones (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones)19 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)18 ArrayList (java.util.ArrayList)17 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)16 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)16 SubnetsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey)14 DeviceVteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps)13 TransportZoneBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder)12 Test (org.junit.Test)10 DeviceVtepsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsKey)9 List (java.util.List)8 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)8 TransportZonesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZonesBuilder)8 SubnetsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsBuilder)8 VtepsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsBuilder)8 HwVtep (org.opendaylight.genius.itm.confighelpers.HwVtep)7