Search in sources :

Example 6 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId 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 7 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId 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 8 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.

the class ExternalRoutersListener method checkExternalIpLabel.

protected Long checkExternalIpLabel(long routerId, String externalIp) {
    List<IpMap> ipMaps = naptManager.getIpMapList(dataBroker, routerId);
    for (IpMap ipMap : ipMaps) {
        if (ipMap.getExternalIp().equals(externalIp)) {
            if (ipMap.getLabel() != null) {
                return ipMap.getLabel();
            }
        }
    }
    LOG.error("checkExternalIpLabel : no ipMaps found for routerID:{} and externalIP:{}", routerId, externalIp);
    return null;
}
Also used : IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap)

Example 9 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.

the class ExternalRoutersListener method addOrDelDefFibRouteToSNAT.

private void addOrDelDefFibRouteToSNAT(String routerName, long routerId, long bgpVpnId, Uuid bgpVpnUuid, boolean create, WriteTransaction writeFlowInvTx) {
    // Check if BGP VPN exists. If exists then invoke the new method.
    if (bgpVpnId != NatConstants.INVALID_ID) {
        if (bgpVpnUuid != null) {
            String bgpVpnName = bgpVpnUuid.getValue();
            LOG.debug("Populate the router-id-name container with the mapping BGP VPN-ID {} -> BGP VPN-NAME {}", bgpVpnId, bgpVpnName);
            RouterIds rtrs = new RouterIdsBuilder().setKey(new RouterIdsKey(bgpVpnId)).setRouterId(bgpVpnId).setRouterName(bgpVpnName).build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getRoutersIdentifier(bgpVpnId), rtrs);
        }
        addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, create, writeFlowInvTx);
        return;
    }
    // Router ID is used as the internal VPN's name, hence the vrf-id in VpnInstance Op DataStore
    addOrDelDefaultFibRouteForSNAT(routerName, routerId, create, writeFlowInvTx);
}
Also used : RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds) RouterIdsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsKey) RouterIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsBuilder)

Example 10 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId 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)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)86 BigInteger (java.math.BigInteger)35 ArrayList (java.util.ArrayList)34 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)23 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)22 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)20 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)20 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)19 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)19 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)17 ExecutionException (java.util.concurrent.ExecutionException)16 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)14 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)12 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)12 IpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)12 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)11 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)11 HashSet (java.util.HashSet)10 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)10 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)10