Search in sources :

Example 1 with Schema

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema in project genius by opendaylight.

the class VtepConfigSchemaListener method handleNewlyAddedDpnsToSchema.

/**
 * Handle newly added dpns to schema.
 *
 * @param original
 *            the original
 * @param originalDpnIds
 *            the original dpn ids
 * @param updatedDpnIds
 *            the updated dpn ids
 */
private void handleNewlyAddedDpnsToSchema(VtepConfigSchema original, List<DpnIds> originalDpnIds, List<DpnIds> updatedDpnIds) {
    LOG.trace("Handle Addition of DPNs from VTEP Original Dpn: {}. Updated Dpn: {}", originalDpnIds, updatedDpnIds);
    ArrayList<DpnIds> newlyAddedDpns = new ArrayList<>(updatedDpnIds);
    newlyAddedDpns.removeAll(originalDpnIds);
    LOG.debug("Newly added DPNs {} to VTEP config schema [{}].", newlyAddedDpns, original.getSchemaName());
    if (!newlyAddedDpns.isEmpty()) {
        VtepConfigSchema diffSchema = new VtepConfigSchemaBuilder(original).setDpnIds(newlyAddedDpns).build();
        String subnetCidr = ItmUtils.getSubnetCidrAsString(original.getSubnet());
        VtepIpPool vtepIpPool = getVtepIpPool(subnetCidr);
        LOG.debug("Adding of DPNs in Diff Schema: {}", diffSchema);
        addVteps(diffSchema, vtepIpPool);
    }
}
Also used : DpnIds(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.vtep.config.schema.DpnIds) VtepConfigSchema(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema) VtepConfigSchemaBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchemaBuilder) ArrayList(java.util.ArrayList) VtepIpPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool)

Example 2 with Schema

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema 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 3 with Schema

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema in project genius by opendaylight.

the class VtepConfigSchemaListener method update.

@Override
public void update(@Nonnull VtepConfigSchema original, @Nonnull VtepConfigSchema updated) {
    LOG.error("Received DCN for updating VTEP Original schema: {}. Updated schema: {}", original, updated);
    VtepConfigSchema originalSchema = ItmUtils.validateVtepConfigSchema(original);
    VtepConfigSchema updatedSchema = ItmUtils.validateVtepConfigSchema(updated);
    if (doesDeleteAndAddSchemaRequired(original, updated)) {
        LOG.error("Failed to handle DCN for updating VTEP schema. Original schema: {}. Updated schema: {}", original, updated);
        // TODO: handle updates
        return;
    }
    handleUpdateOfDpnIds(originalSchema, updatedSchema);
}
Also used : VtepConfigSchema(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema)

Example 4 with Schema

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema 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)

Example 5 with Schema

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema in project genius by opendaylight.

the class ItmProvider method updateVtepSchema.

@Override
public void updateVtepSchema(String schemaName, List<BigInteger> lstDpnsForAdd, List<BigInteger> lstDpnsForDelete) {
    LOG.trace("Updating VTEP schema {} by adding DPN's {} and deleting DPN's {}.", schemaName, lstDpnsForAdd, lstDpnsForDelete);
    VtepConfigSchema schema = ItmUtils.validateForUpdateVtepSchema(schemaName, lstDpnsForAdd, lstDpnsForDelete, this);
    VtepConfigSchemaBuilder builder = new VtepConfigSchemaBuilder(schema);
    /* if (ItmUtils.getDpnIdList(schema.getDpnIds()).isEmpty()) {
            builder.setDpnIds(schema.getDpnIds());
        } else {*/
    if (lstDpnsForAdd != null && !lstDpnsForAdd.isEmpty()) {
        List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds());
        originalDpnList.addAll(lstDpnsForAdd);
        builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList));
    }
    if (lstDpnsForDelete != null && !lstDpnsForDelete.isEmpty()) {
        List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds());
        originalDpnList.removeAll(lstDpnsForDelete);
        builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList));
    // schema.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(ItmUtils.getDpnIdList(schema.getDpnIds())
    // .removeAll(lstDpnsForAdd)));
    }
    // }
    schema = builder.build();
    MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION, ItmUtils.getVtepConfigSchemaIdentifier(schemaName), schema);
    LOG.debug("Vtep config schema {} updated to config DS with DPN's {}", schemaName, ItmUtils.getDpnIdList(schema.getDpnIds()));
}
Also used : VtepConfigSchema(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema) VtepConfigSchemaBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchemaBuilder) BigInteger(java.math.BigInteger)

Aggregations

VtepConfigSchema (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema)11 ArrayList (java.util.ArrayList)8 BigInteger (java.math.BigInteger)6 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)4 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)4 Schema (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema)3 VtepConfigSchemaBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchemaBuilder)3 URL (java.net.URL)2 HashMap (java.util.HashMap)2 SubnetUtils (org.apache.commons.net.util.SubnetUtils)2 Test (org.junit.Test)2 TepCommandHelper (org.opendaylight.genius.itm.cli.TepCommandHelper)2 TepException (org.opendaylight.genius.itm.cli.TepException)2 SchemasBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder)2 SchemaKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaKey)2 YangIdentifier (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier)2 VtepIpPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool)2 MalformedURLException (java.net.MalformedURLException)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1