Search in sources :

Example 76 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class AbstractSnatService method addCommonEntriesForNaptSwitch.

private void addCommonEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers, Uint64 dpnId) {
    String routerName = routers.getRouterName();
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    addDefaultFibRouteForSNAT(confTx, dpnId, routerId);
    for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
        if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
            // In this class we handle only IPv4 use-cases.
            continue;
        }
        // The logic now handle only one external IP per router, others if present will be ignored.
        Uint32 extSubnetId = NatUtil.getExternalSubnetVpnId(dataBroker, externalIp.getSubnetId());
        addInboundTerminatingServiceTblEntry(confTx, dpnId, routerId, extSubnetId);
        addTerminatingServiceTblEntry(confTx, dpnId, routerId);
        break;
    }
}
Also used : Uint32(org.opendaylight.yangtools.yang.common.Uint32) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 77 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class AbstractSnatService method removeMipAdjacencies.

private void removeMipAdjacencies(Routers routers) {
    LOG.info("removeMipAdjacencies for router {}", routers.getRouterName());
    String externalSubNetId = null;
    for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
        if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
            // In this class we handle only IPv4 use-cases.
            continue;
        }
        externalSubNetId = externalIp.getSubnetId().getValue();
        break;
    }
    if (externalSubNetId == null) {
        LOG.info("removeMipAdjacencies no external Ipv4 address present on router {}", routers.getRouterName());
        return;
    }
    InstanceIdentifier<VpnInterfaces> vpnInterfacesId = InstanceIdentifier.builder(VpnInterfaces.class).build();
    try {
        VpnInterfaces vpnInterfaces = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnInterfacesId);
        List<VpnInterface> updatedVpnInterface = new ArrayList<>();
        for (VpnInterface vpnInterface : vpnInterfaces.nonnullVpnInterface().values()) {
            List<Adjacency> updatedAdjacencies = new ArrayList<>();
            Adjacencies adjacencies = vpnInterface.augmentation(Adjacencies.class);
            if (null != adjacencies) {
                for (Adjacency adjacency : adjacencies.nonnullAdjacency().values()) {
                    if (!adjacency.getSubnetId().getValue().equals(externalSubNetId)) {
                        updatedAdjacencies.add(adjacency);
                    }
                }
            }
            AdjacenciesBuilder adjacenciesBuilder = new AdjacenciesBuilder();
            adjacenciesBuilder.setAdjacency(updatedAdjacencies);
            VpnInterfaceBuilder vpnInterfaceBuilder = new VpnInterfaceBuilder(vpnInterface);
            vpnInterfaceBuilder.addAugmentation(adjacenciesBuilder.build());
            updatedVpnInterface.add(vpnInterfaceBuilder.build());
        }
        VpnInterfacesBuilder vpnInterfacesBuilder = new VpnInterfacesBuilder();
        vpnInterfacesBuilder.setVpnInterface(updatedVpnInterface);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnInterfacesId, vpnInterfacesBuilder.build());
    } catch (ExpectedDataObjectNotFoundException e) {
        LOG.warn("Failed to read removeMipAdjacencies with error {}", e.getMessage());
    } catch (TransactionCommitFailedException e) {
        LOG.warn("Failed to remove removeMipAdjacencies with error {}", e.getMessage());
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceBuilder) ExpectedDataObjectNotFoundException(org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces) ArrayList(java.util.ArrayList) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder) VpnInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfacesBuilder) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency)

Example 78 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class SnatCentralizedSwitchChangeListener method remove.

@Override
public void remove(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch routerToNaptSwitch) {
    LOG.debug("Deleting {}", routerToNaptSwitch);
    if (natMode == NatMode.Controller) {
        LOG.info("Do Not Processing this remove() event for (routerName:designatedDpn) {}:{}" + "configured in Controller Mode", routerToNaptSwitch.getRouterName(), routerToNaptSwitch.getPrimarySwitchId());
        return;
    }
    Uint64 primarySwitchId = routerToNaptSwitch.getPrimarySwitchId();
    Routers router = natDataUtil.getRouter(routerToNaptSwitch.getRouterName());
    if (router != null) {
        LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> snatServiceManger.notify(confTx, router, null, primarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL)), LOG, "error handling SNAT centralized switch removal");
        natDataUtil.removeFromRouterMap(router);
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) NatConstants(org.opendaylight.netvirt.natservice.internal.NatConstants) NatserviceConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig) Uint64(org.opendaylight.yangtools.yang.common.Uint64) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) LoggerFactory(org.slf4j.LoggerFactory) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) Duration(java.time.Duration) NatUtil(org.opendaylight.netvirt.natservice.internal.NatUtil) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) NatMode(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NaptSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.NaptSwitches) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) SnatServiceManager(org.opendaylight.netvirt.natservice.api.SnatServiceManager) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 79 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class WeightedCentralizedSwitchScheduler method updateCentralizedSwitch.

@Override
public boolean updateCentralizedSwitch(Routers oldRouter, Routers newRouter) {
    LOG.info("updateCentralizedSwitch for router {}", newRouter.getRouterName());
    String routerName = newRouter.getRouterName();
    List<Uuid> addedSubnetIds = getUpdatedSubnetIds(newRouter.getSubnetIds(), oldRouter.getSubnetIds());
    List<Uuid> deletedSubnetIds = getUpdatedSubnetIds(oldRouter.getSubnetIds(), newRouter.getSubnetIds());
    Uint64 primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, newRouter.getRouterName());
    addToDpnMaps(routerName, addedSubnetIds, primarySwitchId);
    deleteFromDpnMaps(routerName, deletedSubnetIds, primarySwitchId);
    try {
        InstanceIdentifier<RouterToNaptSwitch> id = NatUtil.buildNaptSwitchIdentifier(routerName);
        RouterToNaptSwitch routerToNaptSwitch = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
        boolean isSnatEnabled = newRouter.isEnableSnat();
        Map<ExternalIpsKey, ExternalIps> updateExternalIpsMap = newRouter.getExternalIps();
        if (updateExternalIpsMap == null || updateExternalIpsMap.isEmpty()) {
            isSnatEnabled = false;
        }
        if (isSnatEnabled != routerToNaptSwitch.isEnableSnat()) {
            RouterToNaptSwitchBuilder routerToNaptSwitchBuilder = new RouterToNaptSwitchBuilder(routerToNaptSwitch);
            routerToNaptSwitchBuilder.setEnableSnat(isSnatEnabled);
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier(routerName), routerToNaptSwitchBuilder.build());
        }
    } catch (ExpectedDataObjectNotFoundException e) {
        LOG.error("updateCentralizedSwitch ReadFailedException for {}", routerName);
    } catch (TransactionCommitFailedException e) {
        LOG.error("updateCentralizedSwitch TransactionCommitFailedException for {}", routerName);
    }
    return true;
}
Also used : RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) ExpectedDataObjectNotFoundException(org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ExternalIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RouterToNaptSwitchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 80 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class ExternalRoutersListener method handleSnatReverseTraffic.

public void handleSnatReverseTraffic(TypedWriteTransaction<Configuration> confTx, Uint64 dpnId, Routers router, Uint32 routerId, String routerName, String externalIp) {
    LOG.debug("handleSnatReverseTraffic : entry for DPN ID {}, routerId {}, externalIp: {}", dpnId, routerId, externalIp);
    Uuid networkId = router.getNetworkId();
    if (networkId == null) {
        LOG.error("handleSnatReverseTraffic : networkId is null for the router ID {}", routerId);
        return;
    }
    Collection<Uuid> externalSubnetList = NatUtil.getExternalSubnetIdsFromExternalIps(new ArrayList<ExternalIps>(router.nonnullExternalIps().values()));
    // FLAT/VLAN case having external-subnet as VPN
    String externalSubnetVpn = null;
    if (externalSubnetList != null && !externalSubnetList.isEmpty()) {
        Boolean isExternalIpsAdvertized = Boolean.FALSE;
        for (Uuid externalSubnetId : externalSubnetList) {
            Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
            // externalSubnet data model will exist for FLAT/VLAN external netowrk UCs.
            if (externalSubnet.isPresent()) {
                externalSubnetVpn = externalSubnetId.getValue();
                advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, externalSubnetVpn, routerId, routerName, externalIp, networkId, router, confTx);
                isExternalIpsAdvertized = Boolean.TRUE;
            }
        }
        if (isExternalIpsAdvertized) {
            LOG.trace("External Ips {} advertized for Router {}", router.getExternalIps(), routerName);
            return;
        }
    }
    // VXVLAN/GRE case having Internet-VPN
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
    if (vpnName == null) {
        LOG.error("handleSnatReverseTraffic : No VPN associated with ext nw {} to handle add external ip " + "configuration {} in router {}", networkId, externalIp, routerId);
        return;
    }
    advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName, externalIp, networkId, router, confTx);
    LOG.debug("handleSnatReverseTraffic : exit for DPN ID {}, routerId {}, externalIp : {}", dpnId, routerId, externalIp);
}
Also used : Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)158 ArrayList (java.util.ArrayList)96 ExecutionException (java.util.concurrent.ExecutionException)88 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)77 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)71 BigInteger (java.math.BigInteger)47 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)47 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)45 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)37 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)37 Inject (javax.inject.Inject)33 Singleton (javax.inject.Singleton)33 Logger (org.slf4j.Logger)33 LoggerFactory (org.slf4j.LoggerFactory)33 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)31 List (java.util.List)29 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)28 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)27 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)26 UnknownHostException (java.net.UnknownHostException)25