Search in sources :

Example 51 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class ExternalRoutersListener method getTunnelInterfaceName.

protected String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId) {
    Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
    RpcResult<GetTunnelInterfaceNameOutput> rpcResult;
    try {
        Future<RpcResult<GetTunnelInterfaceNameOutput>> result = itmManager.getTunnelInterfaceName(new GetTunnelInterfaceNameInputBuilder().setSourceDpid(srcDpId).setDestinationDpid(dstDpId).setTunnelType(tunType).build());
        rpcResult = result.get();
        if (!rpcResult.isSuccessful()) {
            tunType = TunnelTypeGre.class;
            result = itmManager.getTunnelInterfaceName(new GetTunnelInterfaceNameInputBuilder().setSourceDpid(srcDpId).setDestinationDpid(dstDpId).setTunnelType(tunType).build());
            rpcResult = result.get();
            if (!rpcResult.isSuccessful()) {
                LOG.warn("getTunnelInterfaceName : RPC Call to getTunnelInterfaceId returned with Errors {}", rpcResult.getErrors());
            } else {
                return rpcResult.getResult().getInterfaceName();
            }
            LOG.warn("getTunnelInterfaceName : RPC Call to getTunnelInterfaceId returned with Errors {}", rpcResult.getErrors());
        } else {
            return rpcResult.getResult().getInterfaceName();
        }
    } catch (InterruptedException | ExecutionException | NullPointerException e) {
        LOG.error("getTunnelInterfaceName : Exception when getting tunnel interface Id for tunnel " + "between {} and {}", srcDpId, dstDpId, e);
    }
    return null;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetTunnelInterfaceNameOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameOutput) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) ExecutionException(java.util.concurrent.ExecutionException) GetTunnelInterfaceNameInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameInputBuilder)

Example 52 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class ExternalRoutersListener method update.

@Override
protected void update(InstanceIdentifier<Routers> identifier, Routers original, Routers update) {
    String routerName = original.getRouterName();
    Long routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("update : external router event - Invalid routerId for routerName {}", routerName);
        return;
    }
    // Check if its update on SNAT flag
    boolean originalSNATEnabled = original.isEnableSnat();
    boolean updatedSNATEnabled = update.isEnableSnat();
    LOG.debug("update :called with originalFlag and updatedFlag for SNAT enabled " + "as {} and {}", originalSNATEnabled, updatedSNATEnabled);
    if (natMode == NatMode.Conntrack && !upgradeState.isUpgradeInProgress()) {
        if (originalSNATEnabled != updatedSNATEnabled) {
            BigInteger primarySwitchId;
            if (originalSNATEnabled) {
                // SNAT disabled for the router
                centralizedSwitchScheduler.releaseCentralizedSwitch(update);
            } else {
                centralizedSwitchScheduler.scheduleCentralizedSwitch(update);
            }
        } else if (updatedSNATEnabled) {
            centralizedSwitchScheduler.updateCentralizedSwitch(original, update);
        }
        List<ExternalIps> originalExternalIps = original.getExternalIps();
        List<ExternalIps> updateExternalIps = update.getExternalIps();
        if (!Objects.equals(originalExternalIps, updateExternalIps)) {
            if (originalExternalIps == null || originalExternalIps.isEmpty()) {
                centralizedSwitchScheduler.scheduleCentralizedSwitch(update);
            }
        }
    } else {
        /* Get Primary Napt Switch for existing router from "router-to-napt-switch" DS.
             * if dpnId value is null or zero then go for electing new Napt switch for existing router.
             */
        long bgpVpnId = NatConstants.INVALID_ID;
        Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
        if (bgpVpnUuid != null) {
            bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
        }
        BigInteger dpnId = getPrimaryNaptSwitch(routerName);
        if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
            // Router has no interface attached
            return;
        }
        final long finalBgpVpnId = bgpVpnId;
        coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.getKey(), () -> {
            WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
            WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
            Uuid networkId = original.getNetworkId();
            if (originalSNATEnabled != updatedSNATEnabled) {
                if (originalSNATEnabled) {
                    // SNAT disabled for the router
                    Uuid networkUuid = original.getNetworkId();
                    LOG.info("update : SNAT disabled for Router {}", routerName);
                    Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
                    handleDisableSnat(original, networkUuid, externalIps, false, null, dpnId, routerId, removeFlowInvTx);
                } else {
                    LOG.info("update : SNAT enabled for Router {}", original.getRouterName());
                    handleEnableSnat(original, routerId, dpnId, finalBgpVpnId, removeFlowInvTx);
                }
            }
            if (!Objects.equals(original.getExtGwMacAddress(), update.getExtGwMacAddress())) {
                NatUtil.installRouterGwFlows(dataBroker, vpnManager, original, dpnId, NwConstants.DEL_FLOW);
                NatUtil.installRouterGwFlows(dataBroker, vpnManager, update, dpnId, NwConstants.ADD_FLOW);
            }
            // Check if the Update is on External IPs
            LOG.debug("update : Checking if this is update on External IPs");
            List<String> originalExternalIps = NatUtil.getIpsListFromExternalIps(original.getExternalIps());
            List<String> updatedExternalIps = NatUtil.getIpsListFromExternalIps(update.getExternalIps());
            // Check if the External IPs are added during the update.
            Set<String> addedExternalIps = new HashSet<>(updatedExternalIps);
            addedExternalIps.removeAll(originalExternalIps);
            if (addedExternalIps.size() != 0) {
                LOG.debug("update : Start processing of the External IPs addition during the update operation");
                vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, addedExternalIps, update.getExtGwMacAddress(), dpnId, update.getNetworkId(), null);
                for (String addedExternalIp : addedExternalIps) {
                    /*
                        1) Do nothing in the IntExtIp model.
                        2) Initialise the count of the added external IP to 0 in the ExternalCounter model.
                     */
                    String[] externalIpParts = NatUtil.getExternalIpAndPrefix(addedExternalIp);
                    String externalIp = externalIpParts[0];
                    String externalIpPrefix = externalIpParts[1];
                    String externalpStr = externalIp + "/" + externalIpPrefix;
                    LOG.debug("update : Initialise the count mapping of the external IP {} for the " + "router ID {} in the ExternalIpsCounter model.", externalpStr, routerId);
                    naptManager.initialiseNewExternalIpCounter(routerId, externalpStr);
                }
                LOG.debug("update : End processing of the External IPs addition during the update operation");
            }
            // Check if the External IPs are removed during the update.
            Set<String> removedExternalIps = new HashSet<>(originalExternalIps);
            removedExternalIps.removeAll(updatedExternalIps);
            if (removedExternalIps.size() > 0) {
                LOG.debug("update : Start processing of the External IPs removal during the update operation");
                vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, removedExternalIps, original.getExtGwMacAddress(), dpnId, networkId);
                for (String removedExternalIp : removedExternalIps) {
                    /*
                        1) Remove the mappings in the IntExt IP model which has external IP.
                        2) Remove the external IP in the ExternalCounter model.
                        3) For the corresponding subnet IDs whose external IP mapping was removed, allocate one of the
                           least loaded external IP.
                           Store the subnet IP and the reallocated external IP mapping in the IntExtIp model.
                        4) Increase the count of the allocated external IP by one.
                        5) Advertise to the BGP if external IP is allocated for the first time for the router
                         i.e. the route for the external IP is absent.
                        6) Remove the NAPT translation entries from Inbound and Outbound NAPT tables for
                         the removed external IPs and also from the model.
                        7) Advertise to the BGP for removing the route for the removed external IPs.
                     */
                    String[] externalIpParts = NatUtil.getExternalIpAndPrefix(removedExternalIp);
                    String externalIp = externalIpParts[0];
                    String externalIpPrefix = externalIpParts[1];
                    String externalIpAddrStr = externalIp + "/" + externalIpPrefix;
                    LOG.debug("update : Clear the routes from the BGP and remove the FIB and TS " + "entries for removed external IP {}", externalIpAddrStr);
                    Uuid vpnUuId = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
                    String vpnName = "";
                    if (vpnUuId != null) {
                        vpnName = vpnUuId.getValue();
                    }
                    clrRtsFromBgpAndDelFibTs(dpnId, routerId, externalIpAddrStr, vpnName, networkId, update.getExtGwMacAddress(), removeFlowInvTx);
                    LOG.debug("update : Remove the mappings in the IntExtIP model which has external IP.");
                    // Get the internal IPs which are associated to the removed external IPs
                    List<IpMap> ipMaps = naptManager.getIpMapList(dataBroker, routerId);
                    List<String> removedInternalIps = new ArrayList<>();
                    for (IpMap ipMap : ipMaps) {
                        if (ipMap.getExternalIp().equals(externalIpAddrStr)) {
                            removedInternalIps.add(ipMap.getInternalIp());
                        }
                    }
                    LOG.debug("update : Remove the mappings of the internal IPs from the IntExtIP model.");
                    for (String removedInternalIp : removedInternalIps) {
                        LOG.debug("update : Remove the IP mapping of the internal IP {} for the " + "router ID {} from the IntExtIP model", removedInternalIp, routerId);
                        naptManager.removeFromIpMapDS(routerId, removedInternalIp);
                    }
                    LOG.debug("update : Remove the count mapping of the external IP {} for the " + "router ID {} from the ExternalIpsCounter model.", externalIpAddrStr, routerId);
                    naptManager.removeExternalIpCounter(routerId, externalIpAddrStr);
                    LOG.debug("update : Allocate the least loaded external IPs to the subnets " + "whose external IPs were removed.");
                    for (String removedInternalIp : removedInternalIps) {
                        allocateExternalIp(dpnId, update, routerId, routerName, networkId, removedInternalIp, writeFlowInvTx);
                    }
                    LOG.debug("update : Remove the NAPT translation entries from " + "Inbound and Outbound NAPT tables for the removed external IPs.");
                    // Get the internalIP and internal Port which were associated to the removed external IP.
                    List<Integer> externalPorts = new ArrayList<>();
                    Map<ProtocolTypes, List<String>> protoTypesIntIpPortsMap = new HashMap<>();
                    InstanceIdentifier<IpPortMapping> ipPortMappingId = InstanceIdentifier.builder(IntextIpPortMap.class).child(IpPortMapping.class, new IpPortMappingKey(routerId)).build();
                    Optional<IpPortMapping> ipPortMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, ipPortMappingId);
                    if (ipPortMapping.isPresent()) {
                        List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.get().getIntextIpProtocolType();
                        for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
                            ProtocolTypes protoType = intextIpProtocolType.getProtocol();
                            List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
                            for (IpPortMap ipPortMap : ipPortMaps) {
                                IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
                                if (ipPortExternal.getIpAddress().equals(externalIp)) {
                                    externalPorts.add(ipPortExternal.getPortNum());
                                    List<String> removedInternalIpPorts = protoTypesIntIpPortsMap.get(protoType);
                                    if (removedInternalIpPorts != null) {
                                        removedInternalIpPorts.add(ipPortMap.getIpPortInternal());
                                        protoTypesIntIpPortsMap.put(protoType, removedInternalIpPorts);
                                    } else {
                                        removedInternalIpPorts = new ArrayList<>();
                                        removedInternalIpPorts.add(ipPortMap.getIpPortInternal());
                                        protoTypesIntIpPortsMap.put(protoType, removedInternalIpPorts);
                                    }
                                }
                            }
                        }
                    }
                    // Remove the IP port map from the intext-ip-port-map model, which were containing
                    // the removed external IP.
                    Set<Map.Entry<ProtocolTypes, List<String>>> protoTypesIntIpPorts = protoTypesIntIpPortsMap.entrySet();
                    Map<String, List<String>> internalIpPortMap = new HashMap<>();
                    for (Map.Entry protoTypesIntIpPort : protoTypesIntIpPorts) {
                        ProtocolTypes protocolType = (ProtocolTypes) protoTypesIntIpPort.getKey();
                        List<String> removedInternalIpPorts = (List<String>) protoTypesIntIpPort.getValue();
                        for (String removedInternalIpPort : removedInternalIpPorts) {
                            // Remove the IP port map from the intext-ip-port-map model,
                            // which were containing the removed external IP
                            naptManager.removeFromIpPortMapDS(routerId, removedInternalIpPort, protocolType);
                            // Remove the IP port incomint packer map.
                            naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIpPort);
                            String[] removedInternalIpPortParts = removedInternalIpPort.split(NatConstants.COLON_SEPARATOR);
                            if (removedInternalIpPortParts.length == 2) {
                                String removedInternalIp = removedInternalIpPortParts[0];
                                String removedInternalPort = removedInternalIpPortParts[1];
                                List<String> removedInternalPortsList = internalIpPortMap.get(removedInternalPort);
                                if (removedInternalPortsList != null) {
                                    removedInternalPortsList.add(removedInternalPort);
                                    internalIpPortMap.put(removedInternalIp, removedInternalPortsList);
                                } else {
                                    removedInternalPortsList = new ArrayList<>();
                                    removedInternalPortsList.add(removedInternalPort);
                                    internalIpPortMap.put(removedInternalIp, removedInternalPortsList);
                                }
                            }
                        }
                    }
                    // Delete the entry from SnatIntIpPortMap DS
                    Set<String> internalIps = internalIpPortMap.keySet();
                    for (String internalIp : internalIps) {
                        LOG.debug("update : Removing IpPort having the internal IP {} from the " + "model SnatIntIpPortMap", internalIp);
                        naptManager.removeFromSnatIpPortDS(routerId, internalIp);
                    }
                    naptManager.removeNaptPortPool(externalIp);
                    LOG.debug("update : Remove the NAPT translation entries from Inbound NAPT tables for the " + "removed external IP {}", externalIp);
                    for (Integer externalPort : externalPorts) {
                        // Remove the NAPT translation entries from Inbound NAPT table
                        naptEventHandler.removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, externalIp, externalPort);
                    }
                    Set<Map.Entry<String, List<String>>> internalIpPorts = internalIpPortMap.entrySet();
                    for (Map.Entry<String, List<String>> internalIpPort : internalIpPorts) {
                        String internalIp = internalIpPort.getKey();
                        LOG.debug("update : Remove the NAPT translation entries from Outbound NAPT tables for " + "the removed internal IP {}", internalIp);
                        List<String> internalPorts = internalIpPort.getValue();
                        for (String internalPort : internalPorts) {
                            // Remove the NAPT translation entries from Outbound NAPT table
                            naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + internalIp + NatConstants.COLON_SEPARATOR + internalPort);
                            naptEventHandler.removeNatFlows(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, Integer.parseInt(internalPort));
                        }
                    }
                }
                LOG.debug("update : End processing of the External IPs removal during the update operation");
            }
            // Check if its Update on subnets
            LOG.debug("update : Checking if this is update on subnets");
            List<Uuid> originalSubnetIds = original.getSubnetIds();
            List<Uuid> updatedSubnetIds = update.getSubnetIds();
            Set<Uuid> addedSubnetIds = new HashSet<>(updatedSubnetIds);
            addedSubnetIds.removeAll(originalSubnetIds);
            // Check if the Subnet IDs are added during the update.
            if (addedSubnetIds.size() != 0) {
                LOG.debug("update : Start processing of the Subnet IDs addition during the update operation");
                for (Uuid addedSubnetId : addedSubnetIds) {
                    /*
                        1) Select the least loaded external IP for the subnet and store the mapping of the
                        subnet IP and the external IP in the IntExtIp model.
                        2) Increase the count of the selected external IP by one.
                        3) Advertise to the BGP if external IP is allocated for the first time for the
                        router i.e. the route for the external IP is absent.
                     */
                    String subnetIp = NatUtil.getSubnetIp(dataBroker, addedSubnetId);
                    if (subnetIp != null) {
                        allocateExternalIp(dpnId, update, routerId, routerName, networkId, subnetIp, writeFlowInvTx);
                    }
                }
                LOG.debug("update : End processing of the Subnet IDs addition during the update operation");
            }
            // Check if the Subnet IDs are removed during the update.
            Set<Uuid> removedSubnetIds = new HashSet<>(originalSubnetIds);
            removedSubnetIds.removeAll(updatedSubnetIds);
            List<ListenableFuture<Void>> futures = new ArrayList<>();
            if (removedSubnetIds.size() != 0) {
                LOG.debug("update : Start processing of the Subnet IDs removal during the update operation");
                for (Uuid removedSubnetId : removedSubnetIds) {
                    String[] subnetAddr = NatUtil.getSubnetIpAndPrefix(dataBroker, removedSubnetId);
                    if (subnetAddr != null) {
                        /*
                            1) Remove the subnet IP and the external IP in the IntExtIp map
                            2) Decrease the count of the coresponding external IP by one.
                            3) Advertise to the BGP for removing the routes of the corresponding external
                            IP if its not allocated to any other internal IP.
                        */
                        String externalIp = naptManager.getExternalIpAllocatedForSubnet(routerId, subnetAddr[0] + "/" + subnetAddr[1]);
                        if (externalIp == null) {
                            LOG.error("update : No mapping found for router ID {} and internal IP {}", routerId, subnetAddr[0]);
                            futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
                            futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
                            return futures;
                        }
                        naptManager.updateCounter(routerId, externalIp, false);
                        // used by any other internal ip in any router
                        if (!isExternalIpAllocated(externalIp)) {
                            LOG.debug("update : external ip is not allocated to any other " + "internal IP so proceeding to remove routes");
                            clrRtsFromBgpAndDelFibTs(dpnId, routerId, networkId, Collections.singleton(externalIp), null, update.getExtGwMacAddress(), removeFlowInvTx);
                            LOG.debug("update : Successfully removed fib entries in switch {} for " + "router {} with networkId {} and externalIp {}", dpnId, routerId, networkId, externalIp);
                        }
                        LOG.debug("update : Remove the IP mapping for the router ID {} and " + "internal IP {} external IP {}", routerId, subnetAddr[0], externalIp);
                        naptManager.removeIntExtIpMapDS(routerId, subnetAddr[0] + "/" + subnetAddr[1]);
                    }
                }
                LOG.debug("update : End processing of the Subnet IDs removal during the update operation");
            }
            futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
            futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
            return futures;
        }, NatConstants.NAT_DJC_MAX_RETRIES);
    }
// end of controller based SNAT
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) ProtocolTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes) ArrayList(java.util.ArrayList) List(java.util.List) 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) HashSet(java.util.HashSet) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) IpPortMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMappingKey) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) BigInteger(java.math.BigInteger) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IntextIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) IntextIpProtocolType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) Map(java.util.Map) HashMap(java.util.HashMap) IntextIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)

Example 53 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class NatUtil method addToNeutronRouterDpnsMap.

public static void addToNeutronRouterDpnsMap(DataBroker broker, String routerName, String interfaceName, BigInteger dpId, WriteTransaction writeOperTxn) {
    if (dpId.equals(BigInteger.ZERO)) {
        LOG.warn("addToNeutronRouterDpnsMap : Could not retrieve dp id for interface {} " + "to handle router {} association model", interfaceName, routerName);
        return;
    }
    LOG.debug("addToNeutronRouterDpnsMap : Adding the Router {} and DPN {} for the Interface {} in the " + "ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
    InstanceIdentifier<DpnVpninterfacesList> dpnVpnInterfacesListIdentifier = getRouterDpnId(routerName, dpId);
    Optional<DpnVpninterfacesList> optionalDpnVpninterfacesList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnVpnInterfacesListIdentifier);
    org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(interfaceName)).setInterface(interfaceName).build();
    if (optionalDpnVpninterfacesList.isPresent()) {
        LOG.debug("addToNeutronRouterDpnsMap : RouterDpnList already present for the Router {} and DPN {} for the " + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
        writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, dpnVpnInterfacesListIdentifier.child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class, new RouterInterfacesKey(interfaceName)), routerInterface, true);
    } else {
        LOG.debug("addToNeutronRouterDpnsMap : Building new RouterDpnList for the Router {} and DPN {} for the " + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
        RouterDpnListBuilder routerDpnListBuilder = new RouterDpnListBuilder();
        routerDpnListBuilder.setRouterId(routerName);
        DpnVpninterfacesListBuilder dpnVpnList = new DpnVpninterfacesListBuilder().setDpnId(dpId);
        List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces = new ArrayList<>();
        routerInterfaces.add(routerInterface);
        dpnVpnList.setRouterInterfaces(routerInterfaces);
        routerDpnListBuilder.setDpnVpninterfacesList(Collections.singletonList(dpnVpnList.build()));
        writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, getRouterId(routerName), routerDpnListBuilder.build(), true);
    }
}
Also used : ArrayList(java.util.ArrayList) RouterInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesBuilder) RouterDpnListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnListBuilder) DpnVpninterfacesListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesListBuilder) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) RouterInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesKey)

Example 54 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class NatUtil method removeFromNeutronRouterDpnsMap.

public static void removeFromNeutronRouterDpnsMap(DataBroker broker, String routerName, String interfaceName, BigInteger dpId, WriteTransaction writeOperTxn) {
    if (dpId.equals(BigInteger.ZERO)) {
        LOG.error("removeFromNeutronRouterDpnsMap : Could not retrieve dp id for interface {} to handle router {} " + "dissociation model", interfaceName, routerName);
        return;
    }
    InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
    Optional<DpnVpninterfacesList> optionalRouterDpnList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
    if (optionalRouterDpnList.isPresent()) {
        List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces();
        org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(interfaceName)).setInterface(interfaceName).build();
        if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
            if (routerInterfaces.isEmpty()) {
                writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
            } else {
                writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class, new RouterInterfacesKey(interfaceName)));
            }
        }
    }
}
Also used : DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) RouterInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesKey) RouterInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesBuilder)

Example 55 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class NatUtil method removeFromDpnRoutersMap.

static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName, BigInteger curDpnId, OdlInterfaceRpcService ifaceMgrRpcService, WriteTransaction writeOperTxn) {
    /*
            1) Get the DpnRoutersList for the DPN.
            2) Get the RoutersList identifier for the DPN and router.
            3) Get the VPN interfaces for the router (routerList) through which it is connected to the DPN.
            4) If the removed VPN interface is the only interface through which the router is connected to the DPN,
             then remove RouterList.
         */
    LOG.debug("removeFromDpnRoutersMap() : Removing the DPN {} and router {} for the Interface {}" + " in the ODL-L3VPN : DPNRouters map", curDpnId, routerName, vpnInterfaceName);
    // Get the dpn-routers-list instance for the current DPN.
    InstanceIdentifier<DpnRoutersList> dpnRoutersListIdentifier = getDpnRoutersId(curDpnId);
    Optional<DpnRoutersList> dpnRoutersListData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier);
    if (dpnRoutersListData == null || !dpnRoutersListData.isPresent()) {
        LOG.error("removeFromDpnRoutersMap : dpn-routers-list is not present for DPN {} " + "in the ODL-L3VPN:dpn-routers model", curDpnId);
        return;
    }
    // Get the routers-list instance for the router on the current DPN only
    InstanceIdentifier<RoutersList> routersListIdentifier = getRoutersList(curDpnId, routerName);
    Optional<RoutersList> routersListData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
    if (routersListData == null || !routersListData.isPresent()) {
        LOG.error("removeFromDpnRoutersMap : routers-list is not present for the DPN {} " + "in the ODL-L3VPN:dpn-routers model", curDpnId);
        return;
    }
    LOG.debug("removeFromDpnRoutersMap : Get the interfaces for the router {} " + "from the NeutronVPN - router-interfaces-map", routerName);
    InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces> routerInterfacesId = getRoutersInterfacesIdentifier(routerName);
    Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces> routerInterfacesData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
    if (routerInterfacesData == null || !routerInterfacesData.isPresent()) {
        LOG.debug("removeFromDpnRoutersMap : Unable to get the routers list for the DPN {}. Possibly all subnets " + "removed from router {} OR Router {} has been deleted. Hence DPN router model WILL be cleared ", curDpnId, routerName, routerName);
        writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
        return;
    }
    // Get the VM interfaces for the router on the current DPN only.
    List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces> vmInterfaces = routerInterfacesData.get().getInterfaces();
    if (vmInterfaces == null) {
        LOG.debug("removeFromDpnRoutersMap : VM interfaces are not present for the router {} in the " + "NeutronVPN - router-interfaces-map", routerName);
        return;
    }
    // then remove RouterList.
    for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces vmInterface : vmInterfaces) {
        String vmInterfaceName = vmInterface.getInterfaceId();
        BigInteger vmDpnId = getDpnForInterface(ifaceMgrRpcService, vmInterfaceName);
        if (vmDpnId.equals(BigInteger.ZERO) || !vmDpnId.equals(curDpnId)) {
            LOG.debug("removeFromDpnRoutersMap : DPN ID {} for the removed interface {} is not the same as that of " + "the DPN ID {} for the checked interface {}", curDpnId, vpnInterfaceName, vmDpnId, vmInterfaceName);
            continue;
        }
        if (!vmInterfaceName.equalsIgnoreCase(vpnInterfaceName)) {
            LOG.info("removeFromDpnRoutersMap : Router {} is present in the DPN {} through the other interface {} " + "Hence DPN router model WOULD NOT be cleared", routerName, curDpnId, vmInterfaceName);
            return;
        }
    }
    LOG.debug("removeFromDpnRoutersMap : Router {} is present in the DPN {} only through the interface {} " + "Hence DPN router model WILL be cleared. Possibly last VM for the router " + "deleted in the DPN", routerName, curDpnId, vpnInterfaceName);
    writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
}
Also used : RoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.dpn.routers.list.RoutersList) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) BigInteger(java.math.BigInteger)

Aggregations

BigInteger (java.math.BigInteger)131 ArrayList (java.util.ArrayList)117 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface)69 ExecutionException (java.util.concurrent.ExecutionException)64 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)56 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)52 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)47 List (java.util.List)45 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)44 ParentRefs (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs)40 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)39 IfTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel)39 Logger (org.slf4j.Logger)39 LoggerFactory (org.slf4j.LoggerFactory)39 Collections (java.util.Collections)38 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)37 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)34 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)33 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)33 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)32