Search in sources :

Example 1 with AdjacencyKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey in project netvirt by opendaylight.

the class ArpMonitorStopTask method removeMipAdjacency.

private void removeMipAdjacency(String fixedip, String vpnName, String interfaceName) {
    synchronized (interfaceName.intern()) {
        InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
        InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
        Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
        if (adjacencies.isPresent()) {
            InstanceIdentifier<Adjacency> adid = vpnIfId.augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(ipToPrefix(fixedip)));
            try {
                SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adid);
            } catch (TransactionCommitFailedException e) {
                LOG.error("Failed to delete the learned-ip-adjacency for vpn {} interface {} prefix {}", vpnName, interfaceName, ipToPrefix(fixedip), e);
                return;
            }
            LOG.info("Successfully deleted the learned-ip-adjacency prefix {} on vpn {} for interface {}", ipToPrefix(fixedip), vpnName, interfaceName);
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies)

Example 2 with AdjacencyKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey in project netvirt by opendaylight.

the class ArpNotificationHandler method addMipAdjacency.

private void addMipAdjacency(String vpnName, String vpnInterface, IpAddress srcPrefix, String mipMacAddress, IpAddress dstPrefix) {
    LOG.trace("Adding {} adjacency to VPN Interface {} ", srcPrefix, vpnInterface);
    InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface);
    InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
    synchronized (vpnInterface.intern()) {
        Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
        String nextHopIpAddr = null;
        String nextHopMacAddress = null;
        String ip = srcPrefix.getIpv4Address().getValue();
        if (interfaceManager.isExternalInterface(vpnInterface)) {
            String subnetId = getSubnetId(vpnName, dstPrefix.getIpv4Address().getValue());
            if (subnetId == null) {
                LOG.trace("Can't find corresponding subnet for src IP {}, src MAC {}, dst IP {},  in VPN {}", srcPrefix, mipMacAddress, dstPrefix, vpnName);
                return;
            }
            ip = VpnUtil.getIpPrefix(ip);
            AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip).setKey(new AdjacencyKey(ip)).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setMacAddress(mipMacAddress).setSubnetId(new Uuid(subnetId)).setPhysNetworkFunc(true);
            List<Adjacency> adjacencyList = adjacencies.isPresent() ? adjacencies.get().getAdjacency() : new ArrayList<>();
            adjacencyList.add(newAdjBuilder.build());
            Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
            Optional<VpnInterface> optionalVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
            VpnInterface newVpnIntf;
            if (optionalVpnInterface.isPresent()) {
                newVpnIntf = new VpnInterfaceBuilder(optionalVpnInterface.get()).addAugmentation(Adjacencies.class, aug).build();
                VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
            }
            LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
            return;
        }
        if (adjacencies.isPresent()) {
            List<Adjacency> adjacencyList = adjacencies.get().getAdjacency();
            ip = VpnUtil.getIpPrefix(ip);
            for (Adjacency adjacs : adjacencyList) {
                if (adjacs.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                    if (adjacs.getIpAddress().equals(ip)) {
                        LOG.error("The MIP {} is already present as a primary adjacency for interface {} vpn {}." + "Skipping adjacency addition.", ip, vpnInterface, vpnName);
                        return;
                    }
                    nextHopIpAddr = adjacs.getIpAddress();
                    nextHopMacAddress = adjacs.getMacAddress();
                    break;
                }
            }
            if (nextHopIpAddr != null) {
                String rd = VpnUtil.getVpnRd(dataBroker, vpnName);
                long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(rd != null ? rd : vpnName, ip));
                if (label == 0) {
                    LOG.error("Unable to fetch label from Id Manager. Bailing out of adding MIP adjacency {} " + "to vpn interface {} for vpn {}", ip, vpnInterface, vpnName);
                    return;
                }
                String nextHopIp = nextHopIpAddr.split("/")[0];
                AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip).setKey(new AdjacencyKey(ip)).setNextHopIpList(Collections.singletonList(nextHopIp)).setAdjacencyType(AdjacencyType.LearntIp);
                if (mipMacAddress != null && !mipMacAddress.equalsIgnoreCase(nextHopMacAddress)) {
                    newAdjBuilder.setMacAddress(mipMacAddress);
                }
                adjacencyList.add(newAdjBuilder.build());
                Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
                Optional<VpnInterface> optionalVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
                VpnInterface newVpnIntf;
                if (optionalVpnInterface.isPresent()) {
                    newVpnIntf = new VpnInterfaceBuilder(optionalVpnInterface.get()).addAugmentation(Adjacencies.class, aug).build();
                    VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
                }
                LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
            }
        }
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) 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) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)

Example 3 with AdjacencyKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey in project netvirt by opendaylight.

the class L3vpnOverVxlanPopulator method createOperationalAdjacency.

@Override
public Adjacency createOperationalAdjacency(L3vpnInput input) {
    Adjacency nextHop = input.getNextHop();
    String nextHopIp = input.getNextHopIp();
    String rd = input.getRd();
    String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
    List<String> adjNextHop = nextHop.getNextHopIpList();
    List<String> nextHopList = adjNextHop != null && !adjNextHop.isEmpty() ? adjNextHop : nextHopIp == null ? Collections.emptyList() : Collections.singletonList(nextHopIp);
    return new AdjacencyBuilder(nextHop).setNextHopIpList(nextHopList).setIpAddress(prefix).setVrfId(rd).setKey(new AdjacencyKey(prefix)).setAdjacencyType(nextHop.getAdjacencyType()).setSubnetGatewayMacAddress(nextHop.getSubnetGatewayMacAddress()).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) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)

Example 4 with AdjacencyKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey in project netvirt by opendaylight.

the class CoeUtils method createPortIpAdjacencies.

static Adjacencies createPortIpAdjacencies(Pods pod, String interfaceName, String macAddress, Boolean isRouterInterface) {
    List<Adjacency> adjList = new ArrayList<>();
    LOG.trace("create config adjacencies for Port: {}", interfaceName);
    IpAddress ip = pod.getInterface().get(0).getIpAddress();
    String ipValue = ip.getIpv4Address() != null ? ip.getIpv4Address().getValue() : ip.getIpv6Address().getValue();
    String ipPrefix = ip.getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
    String hostIp = new String(pod.getHostIpAddress().getValue());
    UUID subnetId = UUID.nameUUIDFromBytes(hostIp.getBytes(StandardCharsets.UTF_8));
    String gatewayIP = ipValue.replaceFirst("\\d+$", "1");
    Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(macAddress).setAdjacencyType(Adjacency.AdjacencyType.PrimaryAdjacency).setSubnetId(new Uuid(subnetId.toString())).setSubnetGatewayIp(gatewayIP).build();
    if (!adjList.contains(vmAdj)) {
        adjList.add(vmAdj);
    }
    // }
    return new AdjacenciesBuilder().setAdjacency(adjList).build();
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) 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) 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) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) UUID(java.util.UUID)

Example 5 with AdjacencyKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey 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)

Aggregations

Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)9 AdjacencyKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey)9 AdjacencyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder)8 ArrayList (java.util.ArrayList)4 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)4 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies)4 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)4 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)3 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)3 AdjacenciesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesBuilder)3 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 VpnInterfaceBuilder (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder)2 VpnInterfaceKey (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey)2 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Nonnull (javax.annotation.Nonnull)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1