Search in sources :

Example 1 with TepException

use of org.opendaylight.genius.itm.cli.TepException in project genius by opendaylight.

the class VtepConfigSchemaListener method addVteps.

/**
 * Adds the vteps.
 *
 * @param schema
 *            the schema
 * @param vtepIpPool
 *            the vtep ip pool
 */
private void addVteps(VtepConfigSchema schema, VtepIpPool vtepIpPool) {
    if (schema.getDpnIds() == null || schema.getDpnIds().isEmpty()) {
        LOG.debug("DPN list is empty, skipping addVteps for schema: {}", schema);
        return;
    }
    String subnetCidr = ItmUtils.getSubnetCidrAsString(schema.getSubnet());
    if (vtepIpPool == null) {
        LOG.error("VTEP config pool not found for subnetCidr {}. Failed to add VTEPs for schema {}", subnetCidr, schema);
        return;
    }
    TepCommandHelper tepCommandHelper = new TepCommandHelper(this.dataBroker, itmConfig);
    // Check this later
    String tunType;
    Class<? extends TunnelTypeBase> tunnelType = schema.getTunnelType();
    if (tunnelType.equals(TunnelTypeVxlan.class)) {
        tunType = ITMConstants.TUNNEL_TYPE_VXLAN;
    } else {
        tunType = ITMConstants.TUNNEL_TYPE_GRE;
    }
    tepCommandHelper.configureTunnelType(schema.getTransportZoneName(), StringUtils.upperCase(tunType));
    List<IpAddress> availableIps = vtepIpPool.getAvailableIpaddress();
    List<IpAddress> newlyAllocatedIps = new ArrayList<>();
    List<BigInteger> skippedDpnIds = new ArrayList<>();
    String gatewayIp = handleGatewayIp(schema.getGatewayIp());
    for (BigInteger dpnId : ItmUtils.getDpnIdList(schema.getDpnIds())) {
        IpAddress ipAddress = getAnAvailableIP(availableIps);
        if (ipAddress == null) {
            skippedDpnIds.add(dpnId);
            continue;
        }
        try {
            tepCommandHelper.createLocalCache(dpnId, schema.getPortName(), schema.getVlanId(), String.valueOf(ipAddress.getValue()), subnetCidr, gatewayIp, schema.getTransportZoneName(), null);
        } catch (TepException e) {
            LOG.error("create local cache Failed", e);
        }
        newlyAllocatedIps.add(ipAddress);
    }
    if (!skippedDpnIds.isEmpty()) {
        LOG.error("No available IP addresses in the VTEP config pool {}, skipping VTEP configurations for DPN's {}", subnetCidr, skippedDpnIds);
    }
    if (!newlyAllocatedIps.isEmpty()) {
        LOG.debug("Delete OnCommit and buildTeps in NewlyAddedDpns");
        tepCommandHelper.deleteOnCommit();
        tepCommandHelper.buildTeps();
        allocateIpAddresses(newlyAllocatedIps, vtepIpPool, subnetCidr);
    }
}
Also used : TepCommandHelper(org.opendaylight.genius.itm.cli.TepCommandHelper) ArrayList(java.util.ArrayList) TepException(org.opendaylight.genius.itm.cli.TepException) BigInteger(java.math.BigInteger) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 2 with TepException

use of org.opendaylight.genius.itm.cli.TepException in project genius by opendaylight.

the class VtepConfigSchemaListener method deleteVteps.

/**
 * Delete vteps.
 *
 * @param schema
 *            the schema
 * @param lstDpnIdsToBeDeleted
 *            the dpn ids list to be deleted
 */
private void deleteVteps(VtepConfigSchema schema, List<BigInteger> lstDpnIdsToBeDeleted) {
    TepCommandHelper tepCommandHelper = new TepCommandHelper(this.dataBroker, itmConfig);
    List<IpAddress> freeIps = new ArrayList<>();
    String subnetCidr = ItmUtils.getSubnetCidrAsString(schema.getSubnet());
    String gatewayIp = handleGatewayIp(schema.getGatewayIp());
    for (BigInteger dpnId : lstDpnIdsToBeDeleted) {
        VtepsKey vtepkey = new VtepsKey(dpnId, schema.getPortName());
        InstanceIdentifier<Vteps> vpath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(schema.getTransportZoneName())).child(Subnets.class, new SubnetsKey(schema.getSubnet())).child(Vteps.class, vtepkey).build();
        Vteps vtep;
        Optional<Vteps> vtepOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, vpath, dataBroker);
        if (vtepOptional.isPresent()) {
            vtep = vtepOptional.get();
        } else {
            LOG.warn("VTEP doesn't exist for DPN [{}] and port [{}].", dpnId, schema.getPortName());
            continue;
        }
        IpAddress ipAddress = vtep.getIpAddress();
        try {
            tepCommandHelper.deleteVtep(dpnId, vtep.getPortname(), schema.getVlanId(), String.valueOf(ipAddress.getValue()), subnetCidr, gatewayIp, schema.getTransportZoneName(), null);
        } catch (TepException e) {
            LOG.error("delete Vtep Failed", e);
        }
        freeIps.add(ipAddress);
    }
    LOG.debug("Delete OnCommit in NewlyAddedDpns");
    tepCommandHelper.deleteOnCommit();
    deAllocateIpAddresses(freeIps, subnetCidr);
}
Also used : SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey) VtepsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey) ArrayList(java.util.ArrayList) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) TepCommandHelper(org.opendaylight.genius.itm.cli.TepCommandHelper) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) TepException(org.opendaylight.genius.itm.cli.TepException) BigInteger(java.math.BigInteger) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Aggregations

BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 TepCommandHelper (org.opendaylight.genius.itm.cli.TepCommandHelper)2 TepException (org.opendaylight.genius.itm.cli.TepException)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)1 TransportZoneKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)1 SubnetsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey)1 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)1 VtepsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey)1