Search in sources :

Example 1 with ItmConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig 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 ItmConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig 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 3 with ItmConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig in project genius by opendaylight.

the class ItmTepAutoConfigTest method defTzEnabledTrueConfigTest.

@Test
public void defTzEnabledTrueConfigTest() throws Exception {
    InstanceIdentifier<ItmConfig> iid = InstanceIdentifier.create(ItmConfig.class);
    // set def-tz-enabled flag to true
    ItmConfig itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(true).build();
    // write into config DS
    CheckedFuture<Void, TransactionCommitFailedException> futures = ItmTepAutoConfigTestUtil.writeItmConfig(iid, itmConfigObj, dataBroker);
    futures.get();
    // read from config DS
    boolean defTzEnabled = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, iid).get().isDefTzEnabled();
    Assert.assertEquals(defTzEnabled, true);
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ItmConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig) ItmConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfigBuilder) Test(org.junit.Test)

Example 4 with ItmConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig in project genius by opendaylight.

the class ItmUtils method buildTunnelOptions.

public static List<TunnelOptions> buildTunnelOptions(TunnelEndPoints tep, ItmConfig itmConfig) {
    List<TunnelOptions> tunOptions = new ArrayList<>();
    String tos = tep.getOptionTunnelTos();
    if (tos == null) {
        tos = itmConfig.getDefaultTunnelTos();
    }
    /* populate tos option only if its not default value of 0 */
    if (tos != null && !tos.equals("0")) {
        TunnelOptionsBuilder optionsBuilder = new TunnelOptionsBuilder();
        optionsBuilder.setKey(new TunnelOptionsKey("tos"));
        optionsBuilder.setTunnelOption("tos");
        optionsBuilder.setValue(tos);
        tunOptions.add(optionsBuilder.build());
    }
    if (tep.getTunnelType() == TunnelTypeVxlan.class && itmConfig.isGpeExtensionEnabled()) {
        TunnelOptionsBuilder optionsBuilder = new TunnelOptionsBuilder();
        optionsBuilder.setKey(new TunnelOptionsKey("exts"));
        optionsBuilder.setTunnelOption("exts");
        optionsBuilder.setValue("gpe");
        tunOptions.add(optionsBuilder.build());
    }
    return tunOptions.isEmpty() ? null : tunOptions;
}
Also used : TunnelOptionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.tunnel.optional.params.TunnelOptionsBuilder) TunnelOptionsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.tunnel.optional.params.TunnelOptionsKey) ArrayList(java.util.ArrayList) TunnelOptions(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.tunnel.optional.params.TunnelOptions) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan)

Example 5 with ItmConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig in project genius by opendaylight.

the class ItmTestModule method configureBindings.

@Override
protected void configureBindings() {
    // Bindings for services from this project
    bind(ItmRpcService.class).to(ItmManagerRpcService.class);
    bind(ItmProvider.class);
    ItmConfig itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(true).setDefTzTunnelType(ITMConstants.TUNNEL_TYPE_VXLAN).setGpeExtensionEnabled(false).build();
    bind(ItmConfig.class).toInstance(itmConfigObj);
    IfmConfig interfaceConfig = new IfmConfigBuilder().setItmDirectTunnels(false).build();
    bind(IfmConfig.class).toInstance(interfaceConfig);
    bind(TunnelMonitorIntervalListener.class);
    bind(TransportZoneListener.class);
    bind(OvsdbNodeListener.class);
    bind(InterfaceStateListener.class);
    bind(VtepConfigSchemaListener.class);
    bind(TunnelMonitorChangeListener.class);
    bind(ItmTunnelEventListener.class);
    // Bindings for external services to "real" implementations
    bind(EntityOwnershipService.class).toInstance(mock(EntityOwnershipService.class));
    bind(IdManagerService.class).to(IdManager.class);
    bind(LockManagerService.class).to(LockManagerServiceImpl.class);
    DataBroker dataBroker = DataBrokerTestModule.dataBroker();
    bind(DataBroker.class).toInstance(dataBroker);
    bind(DataBroker.class).annotatedWith(OsgiService.class).toInstance(dataBroker);
    bind(InterfaceManagerService.class).to(InterfaceManagerServiceImpl.class);
    bind(IInterfaceManager.class).to(InterfacemgrProvider.class);
    bind(ServiceRecoveryRegistry.class).toInstance(mock(ServiceRecoveryRegistry.class));
    // Bindings to test infra (fakes & mocks)
    TestIMdsalApiManager mdsalManager = TestIMdsalApiManager.newInstance();
    bind(IMdsalApiManager.class).toInstance(mdsalManager);
    bind(TestIMdsalApiManager.class).toInstance(mdsalManager);
    bind(DataImportBootReady.class).annotatedWith(OsgiService.class).toInstance(new DataImportBootReady() {
    });
    bind(DiagStatusService.class).toInstance(mock(DiagStatusService.class));
}
Also used : InterfaceManagerService(org.opendaylight.genius.interfacemanager.interfaces.InterfaceManagerService) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) ItmConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfigBuilder) TestIMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.testutils.TestIMdsalApiManager) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LockManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService) TestIMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.testutils.TestIMdsalApiManager) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) ItmConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig) IfmConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.config.rev160406.IfmConfig) EntityOwnershipService(org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) IfmConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.config.rev160406.IfmConfigBuilder) ServiceRecoveryRegistry(org.opendaylight.genius.srm.ServiceRecoveryRegistry) DataImportBootReady(org.opendaylight.daexim.DataImportBootReady) DiagStatusService(org.opendaylight.infrautils.diagstatus.DiagStatusService) OsgiService(org.ops4j.pax.cdi.api.OsgiService)

Aggregations

ItmConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig)6 ItmConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfigBuilder)6 ArrayList (java.util.ArrayList)5 TepCommandHelper (org.opendaylight.genius.itm.cli.TepCommandHelper)5 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)5 Test (org.junit.Test)4 DPNTEPsInfo (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo)4 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)3 ItmTepAddWorker (org.opendaylight.genius.itm.confighelpers.ItmTepAddWorker)3 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)3 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)3 BigInteger (java.math.BigInteger)2 TepException (org.opendaylight.genius.itm.cli.TepException)2 HwVtep (org.opendaylight.genius.itm.confighelpers.HwVtep)2 ItmTepRemoveWorker (org.opendaylight.genius.itm.confighelpers.ItmTepRemoveWorker)2 TunnelOptions (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.tunnel.optional.params.TunnelOptions)2 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)2 SubnetUtils (org.apache.commons.net.util.SubnetUtils)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1