Search in sources :

Example 1 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method handlePacketToExternalNetwork.

private void handlePacketToExternalNetwork(Uuid vpnInstanceNameUuid, String routerId, byte[] dstIp, long elanTag) throws UnknownHostException {
    Routers externalRouter = VpnUtil.getExternalRouter(dataBroker, routerId);
    if (externalRouter == null) {
        VpnManagerCounters.subnet_route_packet_failed.inc();
        LOG.debug("{} handlePacketToExternalNetwork: Can't find external router with id {}", LOGGING_PREFIX, routerId);
        return;
    }
    List<ExternalIps> externalIps = externalRouter.getExternalIps();
    if (externalIps == null || externalIps.isEmpty()) {
        VpnManagerCounters.subnet_route_packet_failed.inc();
        LOG.debug("{} handlePacketToExternalNetwork: Router {} doesn't have any external ips.", LOGGING_PREFIX, externalRouter.getRouterName());
        return;
    }
    java.util.Optional<ExternalIps> externalIp = externalRouter.getExternalIps().stream().filter(eip -> vpnInstanceNameUuid.equals(eip.getSubnetId())).findFirst();
    if (!externalIp.isPresent()) {
        VpnManagerCounters.subnet_route_packet_failed.inc();
        LOG.debug("{} handlePacketToExternalNetwork: Router {} doesn't have an external ip for subnet id {}.", LOGGING_PREFIX, externalRouter.getRouterName(), vpnInstanceNameUuid);
        return;
    }
    BigInteger dpnId = centralizedSwitchProvider.getPrimarySwitchForRouter(externalRouter.getRouterName());
    if (BigInteger.ZERO.equals(dpnId)) {
        VpnManagerCounters.subnet_route_packet_failed.inc();
        LOG.debug("{} handlePacketToExternalNetwork: Could not find primary switch for router {}.", LOGGING_PREFIX, externalRouter.getRouterName());
        return;
    }
    transmitArpPacket(dpnId, externalIp.get().getIpAddress(), externalRouter.getExtGwMacAddress(), dstIp, elanTag);
    return;
}
Also used : NWUtil(org.opendaylight.genius.mdsalutil.NWUtil) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) PacketProcessingListener(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) NetUtils(org.opendaylight.openflowplugin.libraries.liblldp.NetUtils) IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap) InetAddress(java.net.InetAddress) Inject(javax.inject.Inject) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) PacketProcessingService(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService) Optional(com.google.common.base.Optional) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) BigInteger(java.math.BigInteger) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) ICentralizedSwitchProvider(org.opendaylight.netvirt.vpnmanager.api.ICentralizedSwitchProvider) JdkFutures(org.opendaylight.infrautils.utils.concurrent.JdkFutures) VpnIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance.VpnIds) Logger(org.slf4j.Logger) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) VpnManagerCounters(org.opendaylight.netvirt.vpnmanager.utilities.VpnManagerCounters) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) Ints(com.google.common.primitives.Ints) UnknownHostException(java.net.UnknownHostException) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) VpnHelper(org.opendaylight.netvirt.vpnmanager.api.VpnHelper) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) ExecutionException(java.util.concurrent.ExecutionException) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) List(java.util.List) ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) HexEncode(org.opendaylight.openflowplugin.libraries.liblldp.HexEncode) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 2 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class CentralizedSwitchChangeListener method setupRouterGwFlows.

private void setupRouterGwFlows(RouterToNaptSwitch routerToNaptSwitch, WriteTransaction writeTx, int addOrRemove) {
    Routers router = VpnUtil.getExternalRouter(dataBroker, routerToNaptSwitch.getRouterName());
    if (router == null) {
        LOG.warn("No router data found for router id {}", routerToNaptSwitch.getRouterName());
        return;
    }
    BigInteger primarySwitchId = routerToNaptSwitch.getPrimarySwitchId();
    Uuid extNetworkId = router.getNetworkId();
    String extGwMacAddress = router.getExtGwMacAddress();
    String routerName = router.getRouterName();
    List<ExternalIps> externalIps = router.getExternalIps();
    if (externalIps.isEmpty()) {
        LOG.error("CentralizedSwitchChangeListener: setupRouterGwFlows no externalIP present");
        return;
    }
    Uuid subnetVpnName = externalIps.get(0).getSubnetId();
    if (addOrRemove == NwConstants.ADD_FLOW) {
        vpnManager.addRouterGwMacFlow(routerName, extGwMacAddress, primarySwitchId, extNetworkId, subnetVpnName.getValue(), writeTx);
        vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), extGwMacAddress, primarySwitchId, extNetworkId, writeTx);
    } else {
        vpnManager.removeRouterGwMacFlow(routerName, extGwMacAddress, primarySwitchId, extNetworkId, subnetVpnName.getValue(), writeTx);
        vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), extGwMacAddress, primarySwitchId, extNetworkId);
    }
}
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) BigInteger(java.math.BigInteger) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 3 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class ExternalNetworksChangeListener method removeSnatEntries.

private void removeSnatEntries(Networks original, Uuid networkUuid, WriteTransaction writeFlowInvTx) {
    List<Uuid> routerUuids = original.getRouterIds();
    for (Uuid routerUuid : routerUuids) {
        Long routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
        if (routerId == NatConstants.INVALID_ID) {
            LOG.error("removeSnatEntries : Invalid routerId returned for routerName {}", routerUuid.getValue());
            return;
        }
        Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
        if (natMode == NatMode.Controller) {
            externalRouterListener.handleDisableSnatInternetVpn(routerUuid.getValue(), routerId, networkUuid, externalIps, original.getVpnid().getValue(), writeFlowInvTx);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 4 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class ExternalRoutersListener method handleDisableSnatInternetVpn.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleDisableSnatInternetVpn(String routerName, long routerId, Uuid networkUuid, @Nonnull Collection<String> externalIps, String vpnId, WriteTransaction writeFlowInvTx) {
    LOG.debug("handleDisableSnatInternetVpn: Started to process handle disable snat for router {} " + "with internet vpn {}", routerName, vpnId);
    try {
        BigInteger naptSwitchDpnId = null;
        InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitch = NatUtil.buildNaptSwitchRouterIdentifier(routerName);
        Optional<RouterToNaptSwitch> rtrToNapt = read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerToNaptSwitch);
        if (rtrToNapt.isPresent()) {
            naptSwitchDpnId = rtrToNapt.get().getPrimarySwitchId();
        }
        LOG.debug("handleDisableSnatInternetVpn : got primarySwitch as dpnId{} ", naptSwitchDpnId);
        removeNaptFlowsFromActiveSwitchInternetVpn(routerId, routerName, naptSwitchDpnId, networkUuid, vpnId, writeFlowInvTx);
        try {
            String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
            if (extGwMacAddress != null) {
                LOG.debug("handleDisableSnatInternetVpn : External Gateway MAC address {} found for " + "External Router ID {}", extGwMacAddress, routerId);
            } else {
                LOG.error("handleDisableSnatInternetVpn : No External Gateway MAC address found for " + "External Router ID {}", routerId);
                return;
            }
            clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, vpnId, extGwMacAddress, writeFlowInvTx);
        } catch (Exception ex) {
            LOG.error("handleDisableSnatInternetVpn : Failed to remove fib entries for routerId {} " + "in naptSwitchDpnId {}", routerId, naptSwitchDpnId, ex);
        }
        NatOverVxlanUtil.releaseVNI(vpnId, idManager);
    } catch (Exception ex) {
        LOG.error("handleDisableSnatInternetVpn: Exception while handling disableSNATInternetVpn for router {} " + "with internet vpn {}", routerName, vpnId, ex);
    }
    LOG.debug("handleDisableSnatInternetVpn: Processed handle disable snat for router {} with internet vpn {}", routerName, vpnId);
}
Also used : RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) BigInteger(java.math.BigInteger) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class ExternalRoutersListener method handleDisableSnat.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleDisableSnat(Routers router, Uuid networkUuid, @Nonnull Collection<String> externalIps, boolean routerFlag, String vpnName, BigInteger naptSwitchDpnId, long routerId, WriteTransaction removeFlowInvTx) {
    LOG.info("handleDisableSnat : Entry");
    String routerName = router.getRouterName();
    try {
        if (routerFlag) {
            removeNaptSwitch(routerName);
        } else {
            updateNaptSwitch(routerName, BigInteger.ZERO);
        }
        LOG.debug("handleDisableSnat : Remove the ExternalCounter model for the router ID {}", routerId);
        naptManager.removeExternalCounter(routerId);
        LOG.debug("handleDisableSnat : got primarySwitch as dpnId {}", naptSwitchDpnId);
        if (naptSwitchDpnId == null || naptSwitchDpnId.equals(BigInteger.ZERO)) {
            LOG.error("handleDisableSnat : Unable to retrieve the primary NAPT switch for the " + "router ID {} from RouterNaptSwitch model", routerId);
            return;
        }
        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, networkUuid);
        if (extNwProvType == null) {
            LOG.error("handleDisableSnat : External Network Provider Type missing");
            return;
        }
        Collection<Uuid> externalSubnetList = NatUtil.getExternalSubnetIdsFromExternalIps(router.getExternalIps());
        removeNaptFlowsFromActiveSwitch(routerId, routerName, naptSwitchDpnId, networkUuid, vpnName, externalIps, externalSubnetList, removeFlowInvTx, extNwProvType);
        removeFlowsFromNonActiveSwitches(routerId, routerName, naptSwitchDpnId, removeFlowInvTx);
        try {
            String externalSubnetVpn = null;
            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();
                    clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, externalSubnetVpn, router.getExtGwMacAddress(), removeFlowInvTx);
                }
            }
            if (externalSubnetVpn == null) {
                clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, vpnName, router.getExtGwMacAddress(), removeFlowInvTx);
            }
        } catch (Exception ex) {
            LOG.error("handleDisableSnat : Failed to remove fib entries for routerId {} in naptSwitchDpnId {}", routerId, naptSwitchDpnId, ex);
        }
        // Use the NaptMananager removeMapping API to remove the entire list of IP addresses maintained
        // for the router ID.
        LOG.debug("handleDisableSnat : Remove the Internal to external IP address maintained for the " + "router ID {} in the DS", routerId);
        naptManager.removeMapping(routerId);
    } catch (Exception ex) {
        LOG.error("handleDisableSnat : Exception while handling disableSNAT for router :{}", routerName, ex);
    }
    LOG.info("handleDisableSnat : Exit");
}
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) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)23 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)15 BigInteger (java.math.BigInteger)10 ArrayList (java.util.ArrayList)8 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)8 ExecutionException (java.util.concurrent.ExecutionException)6 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)6 UnknownHostException (java.net.UnknownHostException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 IpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)4 IpPortExternal (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.ip.port.map.IpPortExternal)4 HashSet (java.util.HashSet)3 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)3 IntextIpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap)3 IpPortMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping)3 IntextIpProtocolType (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 InetAddress (java.net.InetAddress)2 List (java.util.List)2