Search in sources :

Example 16 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds in project netvirt by opendaylight.

the class VpnInterfaceManager method processExternalVpnInterface.

private void processExternalVpnInterface(String interfaceName, String vpnName, long vpnId, BigInteger dpId, int lportTag, WriteTransaction writeInvTxn, int addOrRemove) {
    Uuid extNetworkId;
    try {
        // vpn instance of ext-net interface is the network-id
        extNetworkId = new Uuid(vpnName);
    } catch (IllegalArgumentException e) {
        LOG.error("processExternalVpnInterface: VPN instance {} is not Uuid. Processing external vpn interface {}" + " on dpn {} failed", vpnName, interfaceName, dpId);
        return;
    }
    List<Uuid> routerIds = VpnUtil.getExternalNetworkRouterIds(dataBroker, extNetworkId);
    if (routerIds == null || routerIds.isEmpty()) {
        LOG.info("processExternalVpnInterface: No router is associated with {}." + " Bailing out of processing external vpn interface {} on dpn {} for vpn {}", extNetworkId.getValue(), interfaceName, dpId, vpnName);
        return;
    }
    LOG.info("processExternalVpnInterface: Router-ids {} associated with exernal vpn-interface {} on dpn {}" + " for vpn {}", routerIds, interfaceName, dpId, vpnName);
    for (Uuid routerId : routerIds) {
        String routerName = routerId.getValue();
        BigInteger primarySwitch = VpnUtil.getPrimarySwitchForRouter(dataBroker, routerName);
        if (Objects.equals(primarySwitch, dpId)) {
            Routers router = VpnUtil.getExternalRouter(dataBroker, routerName);
            if (router != null) {
                if (addOrRemove == NwConstants.ADD_FLOW) {
                    vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), router.getExtGwMacAddress(), dpId, interfaceName, lportTag, writeInvTxn);
                } else {
                    vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), dpId, interfaceName, lportTag);
                }
            } else {
                LOG.error("processExternalVpnInterface: No external-router found for router-id {}. Bailing out of" + " processing external vpn-interface {} on dpn {} for vpn {}", routerName, interfaceName, dpId, vpnName);
            }
        }
    }
}
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)

Example 17 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds in project netvirt by opendaylight.

the class ArpNotificationHandler method getSubnetId.

private String getSubnetId(String vpnName, String ip) {
    // Check if this IP belongs to a router_interface
    VpnPortipToPort vpnPortipToPort = VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnName, ip);
    if (vpnPortipToPort != null && vpnPortipToPort.isSubnetIp()) {
        List<Adjacency> adjacecnyList = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, vpnPortipToPort.getPortName());
        for (Adjacency adjacency : adjacecnyList) {
            if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                return adjacency.getSubnetId().getValue();
            }
        }
    }
    // Check if this IP belongs to a router_gateway
    List<Uuid> routerIds = VpnUtil.getExternalNetworkRouterIds(dataBroker, new Uuid(vpnName));
    for (Uuid routerId : routerIds) {
        Uuid subnetId = VpnUtil.getSubnetFromExternalRouterByIp(dataBroker, routerId, ip);
        if (subnetId != null) {
            return subnetId.getValue();
        }
    }
    return null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)

Example 18 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds in project netvirt by opendaylight.

the class NatUtil method createRouterIdsConfigDS.

static void createRouterIdsConfigDS(DataBroker dataBroker, long routerId, String routerName) {
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("createRouterIdsConfigDS : invalid routerId for routerName {}", routerName);
        return;
    }
    RouterIds rtrs = new RouterIdsBuilder().setKey(new RouterIdsKey(routerId)).setRouterId(routerId).setRouterName(routerName).build();
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, buildRouterIdentifier(routerId), rtrs);
}
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 19 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds in project netvirt by opendaylight.

the class VpnInterfaceManager method processExternalVpnInterface.

private void processExternalVpnInterface(String interfaceName, String vpnName, Uint64 dpId, int lportTag, int addOrRemove) {
    Uuid extNetworkId;
    try {
        // vpn instance of ext-net interface is the network-id
        extNetworkId = new Uuid(vpnName);
    } catch (IllegalArgumentException e) {
        LOG.error("processExternalVpnInterface: VPN instance {} is not Uuid. Processing external vpn interface {}" + " on dpn {} failed", vpnName, interfaceName, dpId);
        return;
    }
    List<Uuid> routerIds = vpnUtil.getExternalNetworkRouterIds(extNetworkId);
    if (routerIds == null || routerIds.isEmpty()) {
        LOG.info("processExternalVpnInterface: No router is associated with {}." + " Bailing out of processing external vpn interface {} on dpn {} for vpn {}", extNetworkId.getValue(), interfaceName, dpId, vpnName);
        return;
    }
    LOG.info("processExternalVpnInterface: Router-ids {} associated with exernal vpn-interface {} on dpn {}" + " for vpn {}", routerIds, interfaceName, dpId, vpnName);
    for (Uuid routerId : routerIds) {
        String routerName = routerId.getValue();
        Uint64 primarySwitch = vpnUtil.getPrimarySwitchForRouter(routerName);
        if (Objects.equals(primarySwitch, dpId)) {
            Routers router = vpnUtil.getExternalRouter(routerName);
            if (router != null) {
                if (addOrRemove == NwConstants.ADD_FLOW) {
                    vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(new ArrayList<>(router.nonnullExternalIps().values())), router.getExtGwMacAddress(), dpId, interfaceName, lportTag);
                } else {
                    vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(new ArrayList<>(router.nonnullExternalIps().values())), dpId, interfaceName, lportTag);
                }
            } else {
                LOG.error("processExternalVpnInterface: No external-router found for router-id {}. Bailing out of" + " processing external vpn-interface {} on dpn {} for vpn {}", routerName, interfaceName, dpId, vpnName);
            }
        }
    }
}
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) ArrayList(java.util.ArrayList) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 20 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortDeleted.

private void handleNeutronPortDeleted(final Port port) {
    final String portName = port.getUuid().getValue();
    final Uuid portId = port.getUuid();
    final Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.nonnullFixedIps();
    if (!NeutronUtils.isPortVnicTypeNormal(port) && !isPortTypeSwitchdev(port)) {
        for (FixedIps ip : keyFixedIpsMap.values()) {
            // remove direct port from subnetMaps config DS
            // TODO: for direct port as well, operations should be carried out per subnet based on port IP
            nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
        }
        LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "Skipping OF Port interfaces removal", portName);
        return;
    }
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
            Uuid vpnId = null;
            Set<Uuid> routerIds = new HashSet<>();
            Uuid internetVpnId = null;
            for (FixedIps ip : keyFixedIpsMap.values()) {
                Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
                if (subnetMap == null) {
                    continue;
                }
                if (subnetMap.getVpnId() != null) {
                    // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
                    // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
                    vpnId = subnetMap.getVpnId();
                }
                if (subnetMap.getRouterId() != null) {
                    routerIds.add(subnetMap.getRouterId());
                }
                internetVpnId = subnetMap.getInternetVpnId();
                if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(port.getDeviceOwner()) || NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(port.getDeviceOwner())) {
                    String ipAddress = ip.getIpAddress().stringValue();
                    if (vpnId != null) {
                        neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipAddress, confTx);
                    }
                    if (internetVpnId != null) {
                        neutronvpnUtils.removeVpnPortFixedIpToPort(internetVpnId.getValue(), ipAddress, confTx);
                    }
                }
            }
            if (vpnId != null || internetVpnId != null) {
                // remove vpn-interface for this neutron port
                LOG.debug("removing VPN Interface for port {}", portName);
                if (!routerIds.isEmpty()) {
                    for (Uuid routerId : routerIds) {
                        nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portName);
                    }
                }
                nvpnManager.deleteVpnInterface(portName, null, /* vpn-id */
                confTx);
            }
            // Remove of-port interface for this neutron port
            // ELAN interface is also implicitly deleted as part of this operation
            LOG.debug("Of-port-interface removal for port {}", portName);
            deleteOfPortInterface(port, confTx);
            // dissociate fixedIP from floatingIP if associated
            nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
        });
        LoggingFutures.addErrorLogging(future, LOG, "handleNeutronPortDeleted: Failed to update interface {} with networkId", portName, port.getNetworkId().getValue());
        return Collections.singletonList(future);
    });
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) FixedIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) HashSet(java.util.HashSet)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)23 ArrayList (java.util.ArrayList)9 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)9 ExecutionException (java.util.concurrent.ExecutionException)8 RouterIds (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds)8 RouterIds (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds)6 RouterIdsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsBuilder)6 RouterIdsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsKey)6 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)5 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)5 SubnetsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey)4 VpnMaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps)4 VpnMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)4 RouterIdsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsKey)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)4 BigInteger (java.math.BigInteger)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets)3 Router (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router)3