Search in sources :

Example 1 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds 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 RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds 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 RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds 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 4 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds in project netvirt by opendaylight.

the class ExternalRoutersListener method changeLocalVpnIdToBgpVpnId.

/**
 * router association to vpn.
 *
 * @param routerName - Name of router
 * @param routerId - router id
 * @param bgpVpnName BGP VPN name
 */
public void changeLocalVpnIdToBgpVpnId(String routerName, long routerId, String bgpVpnName, WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
    LOG.debug("changeLocalVpnIdToBgpVpnId : Router associated to BGP VPN");
    if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
        long bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
        LOG.debug("changeLocalVpnIdToBgpVpnId : BGP VPN ID value {} ", bgpVpnId);
        if (bgpVpnId != NatConstants.INVALID_ID) {
            LOG.debug("changeLocalVpnIdToBgpVpnId : 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);
            // Get the allocated Primary NAPT Switch for this router
            LOG.debug("changeLocalVpnIdToBgpVpnId : Router ID value {} ", routerId);
            LOG.debug("changeLocalVpnIdToBgpVpnId : Update the Router ID {} to the BGP VPN ID {} ", routerId, bgpVpnId);
            addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, true, writeFlowInvTx);
            // Get the group ID
            BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
            createGroupId(getGroupIdKey(routerName));
            installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, true, writeFlowInvTx, extNwProvType);
        }
    }
}
Also used : RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RouterIdsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsKey) BigInteger(java.math.BigInteger) RouterIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsBuilder)

Example 5 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds in project netvirt by opendaylight.

the class NeutronvpnNatManager method removeRouterFromExternalSubnets.

private void removeRouterFromExternalSubnets(Uuid routerId, Uuid externalNetworkId, List<ExternalFixedIps> externalFixedIps) {
    LOG.debug("Removing routerID {} from external subnets of external network{}", routerId, externalNetworkId);
    List<Subnets> fixedIpsSubnets = getSubnets(getExternalSubnetsUuidsSetForFixedIps(externalFixedIps));
    for (Subnets subnets : fixedIpsSubnets) {
        Uuid subnetId = subnets.getId();
        List<Uuid> routerIds = subnets.getRouterIds();
        if (routerIds != null) {
            if (subnets.getExternalNetworkId() != null && subnets.getExternalNetworkId().equals(externalNetworkId) && routerIds.contains(routerId)) {
                routerIds.remove(routerId);
                LOG.debug("Will remove routerIDs {} from external subnet {} router ID {}", routerIds, subnetId, routerId);
                addExternalSubnet(externalNetworkId, subnetId, routerIds);
            }
        }
    }
}
Also used : ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) 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)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)10 BigInteger (java.math.BigInteger)4 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)4 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3 SubnetsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey)3 RouterIds (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds)3 RouterIdsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsBuilder)3 RouterIdsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsKey)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)2 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)2 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)2 Optional (com.google.common.base.Optional)1 Strings (com.google.common.base.Strings)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1