Search in sources :

Example 6 with AdjacencyBuilder

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

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

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

the class L3vpnOverMplsGrePopulator method createOperationalAdjacency.

@Override
public Adjacency createOperationalAdjacency(L3vpnInput input) {
    Adjacency nextHop = input.getNextHop();
    String nextHopIp = input.getNextHopIp();
    String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
    List<String> adjNextHop = nextHop.getNextHopIpList();
    String rd = input.getRd();
    String primaryRd = input.getPrimaryRd();
    String vpnName = input.getVpnName();
    long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(primaryRd, prefix));
    if (label == VpnConstants.INVALID_LABEL) {
        String error = "Unable to fetch label from Id Manager. Bailing out of creation of operational " + "vpn interface adjacency " + prefix + "for vpn " + vpnName;
        throw new NullPointerException(error);
    }
    List<String> nextHopList = adjNextHop != null && !adjNextHop.isEmpty() ? adjNextHop : nextHopIp == null ? Collections.emptyList() : Collections.singletonList(nextHopIp);
    return new AdjacencyBuilder(nextHop).setLabel(label).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 9 with AdjacencyBuilder

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

the class NeutronvpnManager method removeAdjacencyforExtraRoute.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void removeAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList) {
    for (Routes route : routeList) {
        if (route != null && route.getNexthop() != null && route.getDestination() != null) {
            boolean isLockAcquired = false;
            String nextHop = String.valueOf(route.getNexthop().getValue());
            String destination = String.valueOf(route.getDestination().getValue());
            String infName = neutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(vpnId.getValue(), nextHop);
            if (infName == null) {
                LOG.error("Unable to find VPN NextHop interface to remove extra-route destination {} on VPN {} " + "with nexthop {}", destination, vpnId.getValue(), nextHop);
                // Proceed to remove the next extra-route
                continue;
            }
            LOG.trace("Removing extra route for destination {} on vpn {} with nexthop {} and infName {}", destination, vpnId.getValue(), nextHop, infName);
            InstanceIdentifier<Adjacency> adjacencyIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(destination)).build();
            try {
                // Looking for existing prefix in MDSAL database
                Optional<Adjacency> adjacency = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
                boolean updateNextHops = false;
                List<String> nextHopList = new ArrayList<>();
                if (adjacency.isPresent()) {
                    List<String> nhListRead = adjacency.get().getNextHopIpList();
                    if (nhListRead.size() > 1) {
                        // ECMP case
                        for (String nextHopRead : nhListRead) {
                            if (nextHopRead.equals(nextHop)) {
                                updateNextHops = true;
                            } else {
                                nextHopList.add(nextHopRead);
                            }
                        }
                    }
                }
                isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
                if (updateNextHops) {
                    // An update must be done, not including the current next hop
                    InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
                    Adjacency newAdj = new AdjacencyBuilder(adjacency.get()).setIpAddress(destination).setNextHopIpList(nextHopList).setKey(new AdjacencyKey(destination)).build();
                    Adjacencies erAdjs = new AdjacenciesBuilder().setAdjacency(Collections.singletonList(newAdj)).build();
                    VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName)).addAugmentation(Adjacencies.class, erAdjs).build();
                    SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
                } else {
                    // Remove the whole route
                    SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
                    LOG.trace("extra route {} deleted successfully", route);
                }
            } catch (TransactionCommitFailedException | ReadFailedException e) {
                LOG.error("exception in deleting extra route with destination {} for interface {}", destination, infName, e);
            } finally {
                if (isLockAcquired) {
                    interfaceLock.unlock(infName);
                }
            }
        } else {
            LOG.error("Incorrect input received for extra route: {}", route);
        }
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) VpnInterfaceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) 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)

Example 10 with AdjacencyBuilder

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

the class NeutronvpnManager method updateVpnInterfaceWithExtraRouteAdjacency.

protected void updateVpnInterfaceWithExtraRouteAdjacency(Uuid vpnId, List<Routes> routeList) {
    checkAlarmExtraRoutes(vpnId, routeList);
    for (Routes route : routeList) {
        if (route == null || route.getNexthop() == null || route.getDestination() == null) {
            LOG.error("Incorrect input received for extra route. {}", route);
        } else {
            String nextHop = String.valueOf(route.getNexthop().getValue());
            String destination = String.valueOf(route.getDestination().getValue());
            String infName = neutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(vpnId.getValue(), nextHop);
            if (infName != null) {
                LOG.trace("Updating extra route for destination {} onto vpn {} with nexthop {} and infName {}", destination, vpnId.getValue(), nextHop, infName);
                boolean isLockAcquired = false;
                try {
                    InstanceIdentifier<VpnInterface> identifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
                    InstanceIdentifier<Adjacency> path = identifier.augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(destination));
                    Optional<Adjacency> existingAdjacency = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
                    if (existingAdjacency.isPresent() && existingAdjacency.get().getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                        LOG.error("The route with destination {} nextHop {} is already present as" + " a primary adjacency for interface {}. Skipping adjacency addition.", destination, nextHop, infName);
                        continue;
                    }
                    Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination).setNextHopIpList(Collections.singletonList(nextHop)).setKey(new AdjacencyKey(destination)).setAdjacencyType(AdjacencyType.ExtraRoute).build();
                    isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
                    SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, path, erAdj);
                } catch (TransactionCommitFailedException e) {
                    LOG.error("exception in adding extra route with destination: {}, next hop: {}", destination, nextHop, e);
                } catch (ReadFailedException e) {
                    LOG.error("Exception on reading data-store ", e);
                } finally {
                    if (isLockAcquired) {
                        interfaceLock.unlock(infName);
                    }
                }
            } else {
                LOG.error("Unable to find VPN NextHop interface to apply extra-route destination {} on VPN {} " + "with nexthop {}", destination, vpnId.getValue(), nextHop);
            }
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) VpnInterfaceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey) 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)

Aggregations

Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)11 AdjacencyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder)11 AdjacencyKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey)8 ArrayList (java.util.ArrayList)6 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)4 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)3 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)3 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)3 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies)3 AdjacenciesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesBuilder)3 AdjacenciesOp (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp)3 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)3 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)3 BigInteger (java.math.BigInteger)2 ExecutionException (java.util.concurrent.ExecutionException)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)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 VpnInterfaceOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryBuilder)2