Search in sources :

Example 16 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6 in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalNetworkToRouter.

private void addExternalNetworkToRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    List<ExternalFixedIps> externalFixedIps = update.getExternalGatewayInfo().getExternalFixedIps();
    try {
        Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
        ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
        if (providerNwType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
            return;
        }
        // Add this router to the ExtRouters list
        addExternalRouter(update);
        // Update External Subnets for this router
        updateExternalSubnetsForRouter(routerId, extNetId, externalFixedIps);
        // Create and add Networks object for this External Network to the ExternalNetworks list
        InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        if (!optionalNets.isPresent()) {
            LOG.error("External Network {} not present in the NVPN datamodel", extNetId.getValue());
            return;
        }
        NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
        List<Uuid> rtrList = builder.getRouterIds();
        if (rtrList == null) {
            rtrList = new ArrayList<>();
        }
        rtrList.add(routerId);
        builder.setRouterIds(rtrList);
        if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
            builder.setVpnid(extNetId);
        }
        Networks networkss = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("Updating externalnetworks {}", networkss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
        LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
        // get vpn external form this network external to setup vpnInternet for ipv6
        Uuid vpnExternal = neutronvpnUtils.getVpnForNetwork(extNetId);
        if (vpnExternal == null) {
            LOG.debug("addExternalNetworkToRouter : no vpnExternal for Network {}", extNetId);
        }
        LOG.debug("addExternalNetworkToRouter : the vpnExternal {}", vpnExternal);
        // get subnetmap associate to the router, any subnetmap "external" could be existing
        List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
        LOG.debug("addExternalNetworkToRouter : the vpnExternal {} subnetmap to be set with vpnInternet {}", vpnExternal, snList);
        for (Subnetmap sn : snList) {
            if (sn.getInternetVpnId() == null) {
                continue;
            }
            IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
            if (ipVers == IpVersionChoice.IPV6) {
                LOG.debug("addExternalNetworkToRouter : setup vpnInternet IPv6 for vpnExternal {} subnetmap {}", vpnExternal, sn);
                nvpnManager.updateVpnInternetForSubnet(sn, vpnExternal, true);
            }
        }
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 17 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6 in project netvirt by opendaylight.

the class NeutronvpnUtils method getIpVersionChoicesFromRouterUuid.

/**
 * Method to get an ipVersionChosen as IPV4 and/or IPV6 or undefined from the subnetmaps of the router.
 * @param routerUuid the Uuid for which find out the IP version associated
 * @return an IpVersionChoice used by the router from its attached subnetmaps. IpVersionChoice.UNDEFINED if any
 */
public IpVersionChoice getIpVersionChoicesFromRouterUuid(Uuid routerUuid) {
    IpVersionChoice rep = IpVersionChoice.UNDEFINED;
    if (routerUuid == null) {
        return rep;
    }
    List<Subnetmap> subnetmapList = getNeutronRouterSubnetMaps(routerUuid);
    if (subnetmapList.isEmpty()) {
        return rep;
    }
    for (Subnetmap sn : subnetmapList) {
        if (sn.getSubnetIp() != null) {
            IpVersionChoice ipVers = getIpVersionFromString(sn.getSubnetIp());
            if (rep.choice != ipVers.choice) {
                rep = rep.addVersion(ipVers);
            }
            if (rep.choice == IpVersionChoice.IPV4AND6.choice) {
                return rep;
            }
        }
    }
    return rep;
}
Also used : Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 18 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6 in project netvirt by opendaylight.

the class NeutronvpnManager method associateExtNetworkToVpn.

private boolean associateExtNetworkToVpn(@Nonnull Uuid vpnId, @Nonnull Network extNet) {
    VpnInstanceOpDataEntry vpnOpDataEntry = neutronvpnUtils.getVpnInstanceOpDataEntryFromVpnId(vpnId.getValue());
    if (vpnOpDataEntry == null) {
        LOG.error("associateExtNetworkToVpn: can not find VpnOpDataEntry for VPN {}", vpnId.getValue());
        return false;
    }
    if (!addExternalNetworkToVpn(extNet, vpnId)) {
        return false;
    }
    if (!vpnOpDataEntry.getBgpvpnType().equals(BgpvpnType.BGPVPNInternet)) {
        LOG.info("associateExtNetworkToVpn: set type {} for VPN {}", BgpvpnType.BGPVPNInternet, vpnId.getValue());
        neutronvpnUtils.updateVpnInstanceOpWithType(BgpvpnType.BGPVPNInternet, vpnId);
    }
    for (Uuid snId : neutronvpnUtils.getPrivateSubnetsToExport(extNet)) {
        Subnetmap sm = neutronvpnUtils.getSubnetmap(snId);
        if (sm == null) {
            LOG.error("associateExtNetworkToVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
            continue;
        }
        updateVpnInternetForSubnet(sm, vpnId, true);
        if (!(vpnOpDataEntry.isIpv6Configured()) && (NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()) == IpVersionChoice.IPV6)) {
            LOG.info("associateExtNetworkToVpn: add IPv6 Internet default route in VPN {}", vpnId.getValue());
            neutronvpnUtils.updateVpnInstanceWithFallback(vpnId.getValue(), true);
        }
    }
    return true;
}
Also used : VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)

Example 19 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6 in project netvirt by opendaylight.

the class NeutronvpnManager method createPortIpAdjacencies.

protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface, WriteTransaction wrtConfigTxn, Subnetmap sn, VpnInterface vpnIface) {
    List<Adjacency> adjList = new ArrayList<>();
    if (vpnIface != null) {
        adjList = vpnIface.getAugmentation(Adjacencies.class).getAdjacency();
    }
    String infName = port.getUuid().getValue();
    LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
    for (FixedIps ip : port.getFixedIps()) {
        String ipValue = String.valueOf(ip.getIpAddress().getValue());
        String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
        if (sn != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, sn.getSubnetIp(), false)) {
            continue;
        }
        Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(port.getMacAddress().getValue()).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setSubnetId(ip.getSubnetId()).build();
        if (!adjList.contains(vmAdj)) {
            adjList.add(vmAdj);
        }
        Subnetmap snTemp = sn != null ? sn : neutronvpnUtils.getSubnetmap(ip.getSubnetId());
        Uuid routerId = snTemp != null ? snTemp.getRouterId() : null;
        Uuid vpnId = snTemp != null ? snTemp.getVpnId() : null;
        if (vpnId != null) {
            neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
        }
        if (snTemp != null && snTemp.getInternetVpnId() != null) {
            neutronvpnUtils.createVpnPortFixedIpToPort(sn.getInternetVpnId().getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
        }
        if (routerId != null) {
            Router rtr = neutronvpnUtils.getNeutronRouter(routerId);
            if (rtr != null && rtr.getRoutes() != null) {
                List<Routes> routeList = rtr.getRoutes();
                // create extraroute Adjacence for each ipValue,
                // because router can have IPv4 and IPv6 subnet ports, or can have
                // more that one IPv4 subnet port or more than one IPv6 subnet port
                List<Adjacency> erAdjList = getAdjacencyforExtraRoute(routeList, ipValue);
                if (!erAdjList.isEmpty()) {
                    adjList.addAll(erAdjList);
                }
            }
        }
    }
    return new AdjacenciesBuilder().setAdjacency(adjList).build();
}
Also used : AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesBuilder) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)

Example 20 with Ipv6

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6 in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleRouterInterfaceRemoved.

private void handleRouterInterfaceRemoved(Port routerPort) {
    if (routerPort.getDeviceId() != null) {
        Uuid routerId = new Uuid(routerPort.getDeviceId());
        Uuid infNetworkId = routerPort.getNetworkId();
        elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
        Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
        if (vpnId == null) {
            vpnId = routerId;
        }
        List<FixedIps> portIps = routerPort.getFixedIps();
        boolean vpnInstanceInternetIpVersionRemoved = false;
        Uuid vpnInstanceInternetUuid = null;
        for (FixedIps portIP : portIps) {
            // Internet VPN : flush InternetVPN first
            Uuid subnetId = portIP.getSubnetId();
            Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
            if (sn != null && sn.getInternetVpnId() != null) {
                if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, sn.getInternetVpnId())) {
                    vpnInstanceInternetIpVersionRemoved = true;
                    vpnInstanceInternetUuid = sn.getInternetVpnId();
                }
                nvpnManager.updateVpnInternetForSubnet(sn, sn.getInternetVpnId(), false);
            }
        }
        /* Remove ping responder for router interfaces
             *  A router interface reference in a VPN will have to be removed before the host interface references
             * for that subnet in the VPN are removed. This is to ensure that the FIB Entry of the router interface
             *  is not the last entry to be removed for that subnet in the VPN.
             *  If router interface FIB entry is the last to be removed for a subnet in a VPN , then all the host
             *  interface references in the vpn will already have been cleared, which will cause failures in
             *  cleanup of router interface flows*/
        nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(), null, /* vpn-id */
        null);
        // update RouterInterfaces map
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        boolean vpnInstanceIpVersionRemoved = false;
        IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
        for (FixedIps portIP : portIps) {
            Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
            // router Port have either IPv4 or IPv6, never both
            if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
                vpnInstanceIpVersionRemoved = true;
                vpnInstanceIpVersionToRemove = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
            }
            String ipValue = String.valueOf(portIP.getIpAddress().getValue());
            neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, wrtConfigTxn);
            // NOTE:  Please donot change the order of calls to removeSubnetFromVpn and
            // and updateSubnetNodeWithFixedIP
            nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(), sn != null ? sn.getInternetVpnId() : null);
            nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null, null, null, null);
        }
        nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
        deleteElanInterface(routerPort.getUuid().getValue(), wrtConfigTxn);
        deleteOfPortInterface(routerPort, wrtConfigTxn);
        wrtConfigTxn.submit();
        nvpnNatManager.handleSubnetsForExternalRouter(routerId);
        if (vpnInstanceIpVersionRemoved) {
            neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove, false);
        }
        if (vpnInstanceInternetIpVersionRemoved) {
            neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(), IpVersionChoice.IPV6, false);
            neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
        }
    }
}
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) 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) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Aggregations

Test (org.junit.Test)64 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)36 ArrayList (java.util.ArrayList)30 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)21 ByteBuf (io.netty.buffer.ByteBuf)20 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)16 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)16 BigInteger (java.math.BigInteger)15 InetAddress (java.net.InetAddress)13 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)13 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)13 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)13 List (java.util.List)10 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)10 Inet6Address (java.net.Inet6Address)9 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)9 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)9 Ipv6 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6)9 Ipv6SrcCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCaseBuilder)9 Ipv6SrcBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6SrcBuilder)9