Search in sources :

Example 61 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class NatVpnMapsChangeListener method update.

@Override
public void update(InstanceIdentifier<VpnMap> identifier, VpnMap original, VpnMap updated) {
    Uuid vpnUuid = updated.getVpnId();
    String vpnName = vpnUuid.getValue();
    List<RouterIds> updatedRouterIdList = new ArrayList<RouterIds>(updated.nonnullRouterIds().values());
    List<RouterIds> originalRouterIdList = new ArrayList<RouterIds>(original.nonnullRouterIds().values());
    List<RouterIds> routersAddedList = null;
    List<RouterIds> routersRemovedList = null;
    if (originalRouterIdList == null && updatedRouterIdList != null) {
        routersAddedList = updatedRouterIdList;
    } else if (originalRouterIdList != null && updatedRouterIdList != null) {
        routersAddedList = updatedRouterIdList.stream().filter(routerId -> (!originalRouterIdList.contains(routerId))).collect(Collectors.toList());
    }
    if (originalRouterIdList != null && updatedRouterIdList == null) {
        routersRemovedList = originalRouterIdList;
    } else if (originalRouterIdList != null && updatedRouterIdList != null) {
        routersRemovedList = originalRouterIdList.stream().filter(routerId -> (!updatedRouterIdList.contains(routerId))).collect(Collectors.toList());
    }
    if (routersAddedList != null) {
        routersAddedList.stream().filter(router -> !(Objects.equals(router.getRouterId(), updated.getVpnId()))).forEach(router -> {
            String routerName = router.getRouterId().getValue();
            onRouterAssociatedToVpn(vpnName, routerName);
        });
    }
    if (routersRemovedList != null) {
        routersRemovedList.stream().filter(router -> !(Objects.equals(router.getRouterId(), original.getVpnId()))).forEach(router -> {
            String routerName = router.getRouterId().getValue();
            onRouterDisassociatedFromVpn(vpnName, routerName);
        });
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) LoggerFactory(org.slf4j.LoggerFactory) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Singleton(javax.inject.Singleton) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) PreDestroy(javax.annotation.PreDestroy) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) Uint32(org.opendaylight.yangtools.yang.common.Uint32) VpnMaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps) Logger(org.slf4j.Logger) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) Collectors(java.util.stream.Collectors) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Optional(java.util.Optional) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList)

Example 62 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class RouterPortsListener method add.

@Override
public void add(final InstanceIdentifier<RouterPorts> identifier, final RouterPorts routerPorts) {
    LOG.trace("add : key:{}  value:{}", routerPorts.key(), routerPorts);
    Optional<RouterPorts> optRouterPorts = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
    if (optRouterPorts.isPresent()) {
        RouterPorts ports = optRouterPorts.get();
        String routerName = ports.getRouterId();
        MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().withKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
    } else {
        String routerName = routerPorts.getRouterId();
        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().withKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
    }
    // Check if the router is associated with any BGP VPN and update the association
    String routerName = routerPorts.getRouterId();
    Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
    if (vpnName != null) {
        InstanceIdentifier<Routermapping> routerMappingId = NatUtil.getRouterVpnMappingId(routerName);
        Optional<Routermapping> optRouterMapping = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId);
        if (!optRouterMapping.isPresent()) {
            Uint32 vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
            LOG.debug("add : Updating router {} to VPN {} association with Id {}", routerName, vpnName, vpnId);
            Routermapping routerMapping = new RoutermappingBuilder().withKey(new RoutermappingKey(routerName)).setRouterName(routerName).setVpnName(vpnName.getValue()).setVpnId(vpnId).build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId, routerMapping);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutermappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.RoutermappingBuilder) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Routermapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.Routermapping) RouterPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder) RoutermappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.RoutermappingKey) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 63 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class NaptSwitchHA method isNaptSwitchDown.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public boolean isNaptSwitchDown(Routers extRouter, Uint32 routerId, Uint64 dpnId, Uint64 naptSwitch, Uint32 routerVpnId, Collection<String> externalIpCache, boolean isClearBgpRts, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
    externalIpsCache = externalIpCache;
    String routerName = extRouter.getRouterName();
    if (!naptSwitch.equals(dpnId)) {
        LOG.debug("isNaptSwitchDown : DpnId {} is not a naptSwitch {} for Router {}", dpnId, naptSwitch, routerName);
        return false;
    }
    LOG.debug("NaptSwitch {} is down for Router {}", naptSwitch, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("isNaptSwitchDown : Invalid routerId returned for routerName {}", routerName);
        return true;
    }
    Uuid networkId = extRouter.getNetworkId();
    String vpnName = getExtNetworkVpnName(routerName, networkId);
    // elect a new NaptSwitch
    naptSwitch = naptSwitchSelector.selectNewNAPTSwitch(routerName, Arrays.asList(naptSwitch));
    if (natMode == NatMode.Conntrack) {
        Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
        natServiceManager.notify(confTx, extRouters, null, dpnId, dpnId, SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_DISBL);
        if (extRouters.isEnableSnat()) {
            natServiceManager.notify(confTx, extRouters, null, dpnId, dpnId, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
        }
        natServiceManager.notify(confTx, extRouters, null, naptSwitch, naptSwitch, SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_ENBL);
        if (extRouters.isEnableSnat()) {
            natServiceManager.notify(confTx, extRouters, null, naptSwitch, naptSwitch, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
        }
    } else {
        if (naptSwitch.equals(Uint64.ZERO)) {
            LOG.warn("isNaptSwitchDown : No napt switch is elected since all the switches for router {}" + " are down. SNAT IS NOT SUPPORTED FOR ROUTER {}", routerName, routerName);
            boolean naptUpdatedStatus = updateNaptSwitch(routerName, naptSwitch);
            if (!naptUpdatedStatus) {
                LOG.debug("isNaptSwitchDown : Failed to update naptSwitch {} for router {} in ds", naptSwitch, routerName);
            }
            // clearBgpRoutes
            if (externalIpsCache != null) {
                if (vpnName != null) {
                    // if (externalIps != null) {
                    if (isClearBgpRts) {
                        LOG.debug("isNaptSwitchDown : Clearing both FIB entries and the BGP routes");
                        for (String externalIp : externalIpsCache) {
                            externalRouterListener.clearBgpRoutes(externalIp, vpnName);
                        }
                    } else {
                        LOG.debug("isNaptSwitchDown : Clearing the FIB entries but not the BGP routes");
                        String rd = NatUtil.getVpnRd(dataBroker, vpnName);
                        for (String externalIp : externalIpsCache) {
                            LOG.debug("isNaptSwitchDown : Removing Fib entry rd {} prefix {}", rd, externalIp);
                            fibManager.removeFibEntry(rd, externalIp, null, null);
                        }
                    }
                } else {
                    LOG.debug("isNaptSwitchDown : vpn is not associated to extn/w for router {}", routerName);
                }
            } else {
                LOG.debug("isNaptSwitchDown : No ExternalIps found for subnets under router {}, " + "no bgp routes need to be cleared", routerName);
            }
            return true;
        }
        // checking elected switch health status
        if (!NatUtil.getSwitchStatus(dataBroker, naptSwitch)) {
            LOG.error("isNaptSwitchDown : Newly elected Napt switch {} for router {} is down", naptSwitch, routerName);
            return true;
        }
        LOG.debug("isNaptSwitchDown : New NaptSwitch {} is up for Router {} and can proceed for flow installation", naptSwitch, routerName);
        // update napt model for new napt switch
        boolean naptUpdated = updateNaptSwitch(routerName, naptSwitch);
        if (naptUpdated) {
            // update group of ordinary switch point to naptSwitch tunnel port
            updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
        } else {
            LOG.error("isNaptSwitchDown : Failed to update naptSwitch model for newNaptSwitch {} for router {}", naptSwitch, routerName);
        }
        // update table26 forward packets to table46(outbound napt table)
        FlowEntity flowEntity = buildSnatFlowEntityForNaptSwitch(naptSwitch, routerName, routerVpnId, NatConstants.ADD_FLOW);
        if (flowEntity == null) {
            LOG.error("isNaptSwitchDown : Failed to populate flowentity for router {} in naptSwitch {}", routerName, naptSwitch);
        } else {
            LOG.debug("isNaptSwitchDown : Successfully installed flow in naptSwitch {} for router {}", naptSwitch, routerName);
            mdsalManager.addFlow(confTx, flowEntity);
        }
        installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, networkId, vpnName, confTx);
        boolean flowInstalledStatus = handleNatFlowsInNewNaptSwitch(routerName, routerId, dpnId, naptSwitch, routerVpnId, networkId);
        if (flowInstalledStatus) {
            LOG.debug("isNaptSwitchDown :Installed all active session flows in newNaptSwitch {} for routerName {}", naptSwitch, routerName);
        } else {
            LOG.error("isNaptSwitchDown : Failed to install flows in newNaptSwitch {} for routerId {}", naptSwitch, routerId);
        }
        // remove group in new naptswitch, coz this switch acted previously as ordinary switch
        Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
        if (groupId != NatConstants.INVALID_ID) {
            try {
                LOG.info("isNaptSwitchDown : Removing NAPT Group in new naptSwitch {}", naptSwitch);
                mdsalManager.removeGroup(confTx, naptSwitch, groupId.longValue());
            } catch (Exception ex) {
                LOG.error("isNaptSwitchDown : Failed to remove group in new naptSwitch {}", naptSwitch, ex);
            }
        } else {
            LOG.error("NAT Service : Unable to obtain groupId for router:{}", routerName);
        }
    }
    return true;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) Uint32(org.opendaylight.yangtools.yang.common.Uint32) ExecutionException(java.util.concurrent.ExecutionException) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 64 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class SnatExternalRoutersListener method update.

@Override
public void update(InstanceIdentifier<Routers> identifier, Routers original, Routers update) {
    if (natMode != NatMode.Conntrack) {
        return;
    }
    String routerName = original.getRouterName();
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("update : external router event - Invalid routerId for routerName {}", routerName);
        return;
    }
    LOG.info("update :called for router {} with originalSNATStatus {} and updatedSNATStatus {}", routerName, original.isEnableSnat(), update.isEnableSnat());
    if (!upgradeState.isUpgradeInProgress()) {
        centralizedSwitchScheduler.updateCentralizedSwitch(original, update);
    }
    if (!Objects.equals(original.getSubnetIds(), update.getSubnetIds()) || !Objects.equals(original.getExternalIps(), update.getExternalIps())) {
        LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> natServiceManager.notify(confTx, update, original, null, null, SnatServiceManager.Action.SNAT_ROUTER_UPDATE)), LOG, "error handling external router update");
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) NatserviceConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig) LoggerFactory(org.slf4j.LoggerFactory) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Singleton(javax.inject.Singleton) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) 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) UpgradeState(org.opendaylight.serviceutils.upgrade.UpgradeState) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) Objects(java.util.Objects) CentralizedSwitchScheduler(org.opendaylight.netvirt.natservice.api.CentralizedSwitchScheduler) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) SnatServiceManager(org.opendaylight.netvirt.natservice.api.SnatServiceManager) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 65 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class BgpConfigurationManager method addNeighbor.

public void addNeighbor(String nbrIp, long remoteAs, @Nullable final TcpMd5SignaturePasswordType md5Secret) {
    Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
    InstanceIdentifier.InstanceIdentifierBuilder<Neighbors> iib = InstanceIdentifier.builder(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class, new NeighborsKey(nbrAddr));
    InstanceIdentifier<Neighbors> iid = iib.build();
    TcpSecurityOption tcpSecOption = null;
    if (md5Secret != null) {
        tcpSecOption = new TcpMd5SignatureOptionBuilder().setTcpMd5SignaturePassword(md5Secret).build();
    }
    // else let tcpSecOption be null
    Neighbors dto = new NeighborsBuilder().setAddress(nbrAddr).setRemoteAs(remoteAs).setTcpSecurityOption(tcpSecOption).build();
    update(iid, dto);
}
Also used : TcpSecurityOption(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.tcp.security.option.grouping.TcpSecurityOption) TcpMd5SignatureOptionBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.tcp.security.option.grouping.tcp.security.option.TcpMd5SignatureOptionBuilder) NeighborsBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.NeighborsBuilder) NeighborsContainer(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NeighborsContainer) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.Neighbors) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NeighborsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.NeighborsKey) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Aggregations

ArrayList (java.util.ArrayList)120 Test (org.junit.Test)85 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)71 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)64 ExecutionException (java.util.concurrent.ExecutionException)56 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)47 List (java.util.List)46 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)38 Logger (org.slf4j.Logger)38 LoggerFactory (org.slf4j.LoggerFactory)38 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)37 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)35 Collections (java.util.Collections)35 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)35 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)34 Map (java.util.Map)33 Inject (javax.inject.Inject)32 Singleton (javax.inject.Singleton)32 BigInteger (java.math.BigInteger)31 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)29