Search in sources :

Example 96 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 NatVpnMapsChangeListener method onRouterAssociatedToVpn.

public void onRouterAssociatedToVpn(String vpnName, String routerName) {
    // check router is associated to external network
    String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
    if (extNetwork != null) {
        try {
            LOG.debug("onRouterAssociatedToVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
            handleDNATConfigurationForRouterAssociation(routerName, vpnName, extNetwork);
            Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
            if (extNetworkUuid == null) {
                LOG.error("onRouterAssociatedToVpn : Unable to retrieve external network Uuid for router {}", routerName);
                return;
            }
            ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkUuid);
            if (extNwProvType == null) {
                LOG.error("onRouterAssociatedToVpn : External Network Provider Type missing");
                return;
            }
            Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
            txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> externalRoutersListener.changeLocalVpnIdToBgpVpnId(routerName, routerId, extNetwork, vpnName, tx, extNwProvType)).get();
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("Error changling local VPN identifier to BGP VPN identifier", e);
        }
    } else {
        LOG.debug("onRouterAssociatedToVpn : Ignoring the Router {} association with VPN {} " + "since it is not external router", routerName, vpnName);
    }
}
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) 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) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 97 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 NatVpnMapsChangeListener method remove.

@Override
public void remove(InstanceIdentifier<VpnMap> identifier, VpnMap vpnMap) {
    Uuid vpnUuid = vpnMap.getVpnId();
    String vpnName = vpnUuid.getValue();
    if (vpnMap.getRouterIds() != null) {
        vpnMap.nonnullRouterIds().values().stream().filter(router -> !(Objects.equals(router.getRouterId(), vpnUuid))).forEach(router -> {
            String routerName = router.getRouterId().getValue();
            LOG.info("REMOVE: Router {} is disassociated from Vpn {}", routerName, vpnName);
            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) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 98 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 NatVpnMapsChangeListener method handleDNATConfigurationForRouterAssociation.

void handleDNATConfigurationForRouterAssociation(String routerName, String vpnName, String externalNetwork) throws ExecutionException, InterruptedException {
    InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
    Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
    if (!optRouterPorts.isPresent()) {
        LOG.debug("handleDNATConfigurationForRouterAssociation : Could not read Router Ports data " + "object with id: {} to handle associate vpn {}", routerName, vpnName);
        return;
    }
    Uuid networkId = Uuid.getDefaultInstance(externalNetwork);
    for (Ports port : optRouterPorts.get().nonnullPorts().values()) {
        String portName = port.getPortName();
        Uint64 dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
        if (dpnId.equals(Uint64.ZERO)) {
            LOG.warn("handleDNATConfigurationForRouterAssociation : DPN not found for {}, " + "skip handling of router {} association with vpn {}", portName, routerName, vpnName);
            continue;
        }
        for (InternalToExternalPortMap intExtPortMap : port.nonnullInternalToExternalPortMap().values()) {
            // remove all NAT related entries with routerName
            // floatingIpListener.removeNATOnlyFlowEntries(dpnId, portName, routerName, null,
            // intExtPortMap.getInternalIp(), externalIp);
            // Create NAT entries with VPN Id
            LOG.debug("handleDNATConfigurationForRouterAssociation : Updating DNAT flows with VPN metadata {} ", vpnName);
            floatingIpListener.createNATOnlyFlowEntries(dpnId, routerName, vpnName, networkId, intExtPortMap);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 99 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 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 100 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 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)

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