Search in sources :

Example 1 with RouterPorts

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts in project netvirt by opendaylight.

the class ExternalNetworksChangeListener method disassociateExternalNetworkFromVPN.

private void disassociateExternalNetworkFromVPN(Networks network, String vpnName) {
    List<Uuid> routerIds = network.getRouterIds();
    for (Uuid routerId : routerIds) {
        InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
        Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
        if (!optRouterPorts.isPresent()) {
            LOG.debug("disassociateExternalNetworkFromVPN : Could not read Router Ports data object with id: {} " + "to handle disassociate ext nw {}", routerId, network.getId());
            continue;
        }
        RouterPorts routerPorts = optRouterPorts.get();
        List<Ports> interfaces = routerPorts.getPorts();
        WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
        for (Ports port : interfaces) {
            String portName = port.getPortName();
            BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
            if (dpnId.equals(BigInteger.ZERO)) {
                LOG.debug("disassociateExternalNetworkFromVPN : DPN not found for {}," + "skip handling of ext nw {} disassociation", portName, network.getId());
                continue;
            }
            List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
            for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
                floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(), intExtPortMap, removeFlowInvTx);
            }
        }
        NatUtil.waitForTransactionToComplete(removeFlowInvTx);
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) 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) BigInteger(java.math.BigInteger) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)

Example 2 with RouterPorts

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts in project netvirt by opendaylight.

the class ExternalNetworksChangeListener method associateExternalNetworkWithVPN.

private void associateExternalNetworkWithVPN(Networks network, WriteTransaction writeFlowInvTx) {
    List<Uuid> routerIds = network.getRouterIds();
    for (Uuid routerId : routerIds) {
        // long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
        InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
        Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
        if (!optRouterPorts.isPresent()) {
            LOG.debug("associateExternalNetworkWithVPN : Could not read Router Ports data object with id: {} " + "to handle associate ext nw {}", routerId, network.getId());
            continue;
        }
        RouterPorts routerPorts = optRouterPorts.get();
        List<Ports> interfaces = routerPorts.getPorts();
        for (Ports port : interfaces) {
            String portName = port.getPortName();
            BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
            if (dpnId.equals(BigInteger.ZERO)) {
                LOG.debug("associateExternalNetworkWithVPN : DPN not found for {}, " + "skip handling of ext nw {} association", portName, network.getId());
                continue;
            }
            List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
            for (InternalToExternalPortMap ipMap : intExtPortMapList) {
                // remove all VPN related entries
                floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(), ipMap, writeFlowInvTx);
            }
        }
    }
    // SNAT
    for (Uuid routerId : routerIds) {
        LOG.debug("associateExternalNetworkWithVPN() : for routerId {}", routerId);
        Uuid networkId = network.getId();
        if (networkId == null) {
            LOG.error("associateExternalNetworkWithVPN : networkId is null for the router ID {}", routerId);
            return;
        }
        final String vpnName = network.getVpnid().getValue();
        if (vpnName == null) {
            LOG.error("associateExternalNetworkWithVPN : No VPN associated with ext nw {} for router {}", networkId, routerId);
            return;
        }
        BigInteger dpnId = new BigInteger("0");
        InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitch = NatUtil.buildNaptSwitchRouterIdentifier(routerId.getValue());
        Optional<RouterToNaptSwitch> rtrToNapt = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerToNaptSwitch);
        if (rtrToNapt.isPresent()) {
            dpnId = rtrToNapt.get().getPrimarySwitchId();
        }
        LOG.debug("associateExternalNetworkWithVPN : got primarySwitch as dpnId{} ", dpnId);
        if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
            LOG.warn("associateExternalNetworkWithVPN : primary napt Switch not found for router {} on dpn: {}", routerId, dpnId);
            return;
        }
        Long routerIdentifier = NatUtil.getVpnId(dataBroker, routerId.getValue());
        InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey(routerIdentifier));
        InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> id = idBuilder.build();
        Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
        if (ipMapping.isPresent()) {
            List<IpMap> ipMaps = ipMapping.get().getIpMap();
            for (IpMap ipMap : ipMaps) {
                String externalIp = ipMap.getExternalIp();
                LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows for dpnId {}," + "vpnName {} and externalIp {}", dpnId, vpnName, externalIp);
                if (natMode == NatMode.Controller) {
                    externalRouterListener.advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerIdentifier, routerId.getValue(), externalIp, network.getId(), null, /* external-router */
                    writeFlowInvTx);
                }
            }
        } else {
            LOG.warn("associateExternalNetworkWithVPN : No ipMapping present fot the routerId {}", routerId);
        }
        long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
        // Install 47 entry to point to 21
        if (natMode == NatMode.Controller) {
            externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), dpnId, writeFlowInvTx);
            if (vpnId != -1) {
                LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener installNaptPfibEntry " + "for dpnId {} and vpnId {}", dpnId, vpnId);
                externalRouterListener.installNaptPfibEntry(dpnId, vpnId, writeFlowInvTx);
            }
        }
    }
}
Also used : RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) 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) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger)

Example 3 with RouterPorts

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts in project netvirt by opendaylight.

the class RouterPortsListener method remove.

@Override
protected void remove(InstanceIdentifier<RouterPorts> identifier, RouterPorts routerPorts) {
    LOG.trace("remove : key:{}  value:{}", routerPorts.getKey(), routerPorts);
    // MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
    // Remove the router to vpn association mapping entry if at all present
    String routerName = routerPorts.getRouterId();
    Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
    if (vpnName != null) {
        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, NatUtil.getRouterVpnMappingId(routerName));
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 4 with RouterPorts

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts in project netvirt by opendaylight.

the class RouterPortsListener method add.

@Override
protected void add(final InstanceIdentifier<RouterPorts> identifier, final RouterPorts routerPorts) {
    LOG.trace("add : key:{}  value:{}", routerPorts.getKey(), 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().setKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
    } else {
        String routerName = routerPorts.getRouterId();
        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().setKey(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()) {
            Long vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
            LOG.debug("add : Updating router {} to VPN {} association with Id {}", routerName, vpnName, vpnId);
            Routermapping routerMapping = new RoutermappingBuilder().setKey(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)

Example 5 with RouterPorts

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts in project netvirt by opendaylight.

the class FloatingIPListener method removeNATFlowEntries.

void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, InstanceIdentifier<RouterPorts> portIid, final String routerName, BigInteger dpnId, WriteTransaction removeFlowInvTx) {
    String internalIp = mapping.getInternalIp();
    String externalIp = mapping.getExternalIp();
    // Get the DPN on which this interface resides
    if (dpnId == null) {
        dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
        if (dpnId.equals(BigInteger.ZERO)) {
            LOG.warn("removeNATFlowEntries: Abort processing Floating ip configuration. No DPN for port: {}", interfaceName);
            return;
        }
    }
    long routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("removeNATFlowEntries : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
        return;
    }
    // Delete the DNAT and SNAT table entries
    removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
    Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.OPERATIONAL);
    if (extNwId == null) {
        LOG.error("removeNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
        return;
    }
    long vpnId = getVpnId(extNwId, mapping.getExternalId());
    if (vpnId < 0) {
        LOG.error("removeNATFlowEntries : No VPN associated with ext nw {}. Unable to delete SNAT table " + "entry for fixed ip {}", extNwId, internalIp);
        return;
    }
    removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, removeFlowInvTx);
    // Remove the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
    boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
    if (!isSnatEnabled) {
        addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, removeFlowInvTx, false);
    }
    ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNwId);
    if (provType == null) {
        LOG.error("removeNATFlowEntries : External Network Provider Type missing");
        return;
    }
    if (provType == ProviderTypes.VXLAN) {
        floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, NatConstants.DEFAULT_L3VNI_VALUE, removeFlowInvTx);
        removeOperationalDS(routerName, interfaceName, internalIp);
        return;
    }
    long label = getOperationalIpMapping(routerName, interfaceName, internalIp);
    if (label < 0) {
        LOG.error("removeNATFlowEntries : Could not retrieve label for prefix {} in router {}", internalIp, routerId);
        return;
    }
    floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, (int) label, removeFlowInvTx);
    removeOperationalDS(routerName, interfaceName, internalIp);
}
Also used : 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)

Aggregations

RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)17 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)12 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)10 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)10 BigInteger (java.math.BigInteger)7 RouterPortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey)6 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 PortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey)5 ArrayList (java.util.ArrayList)4 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)4 FloatingIpInfo (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.FloatingIpInfo)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 RouterPortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder)2 InternalToExternalPortMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)1 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)1 CreateFibEntryInput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput)1