Search in sources :

Example 1 with IpAdjacencies

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacencies in project netvirt by opendaylight.

the class NexthopManager method addVpnNexthopToDS.

protected void addVpnNexthopToDS(Uint64 dpnId, Uint32 vpnId, String primaryIpAddr, String currIpAddr, long egressPointer) {
    InstanceIdentifierBuilder<VpnNexthops> idBuilder = InstanceIdentifier.builder(L3nexthop.class).child(VpnNexthops.class, new VpnNexthopsKey(vpnId));
    List<IpAdjacencies> ipPrefixesList = new ArrayList<>();
    IpAdjacencies prefix = new IpAdjacenciesBuilder().setIpAdjacency(currIpAddr).build();
    ipPrefixesList.add(prefix);
    // Add nexthop to vpn node
    VpnNexthop nh = new VpnNexthopBuilder().withKey(new VpnNexthopKey(primaryIpAddr)).setDpnId(dpnId).setIpAdjacencies(ipPrefixesList).setEgressPointer(egressPointer).build();
    InstanceIdentifier<VpnNexthop> id1 = idBuilder.child(VpnNexthop.class, new VpnNexthopKey(primaryIpAddr)).build();
    LOG.trace("Adding vpnnextHop {} to Operational DS", nh);
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, id1, nh);
}
Also used : VpnNexthopsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthopsKey) IpAdjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacencies) IpAdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacenciesBuilder) VpnNexthopKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopKey) VpnNexthops(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthops) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) L3nexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.L3nexthop) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop) VpnNexthopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder)

Example 2 with IpAdjacencies

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacencies in project netvirt by opendaylight.

the class NexthopManager method createLocalNextHop.

public long createLocalNextHop(Uint32 vpnId, Uint64 dpnId, String ifName, String primaryIpAddress, String currDestIpPrefix, String gwMacAddress, Uint32 parentVpnId) {
    // For VPN Imported routes, getting VPN Instance name using parentVpnId
    String vpnName = parentVpnId != null ? fibUtil.getVpnNameFromId(parentVpnId) : fibUtil.getVpnNameFromId(vpnId);
    if (vpnName == null) {
        return 0;
    }
    String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, primaryIpAddress);
    long groupId = createNextHopPointer(getNextHopKey(vpnId, primaryIpAddress));
    if (groupId == 0) {
        LOG.error("Unable to allocate groupId for vpnId {} , IntfName {}, primaryIpAddress {} curIpPrefix {}", vpnId, ifName, primaryIpAddress, currDestIpPrefix);
        return groupId;
    }
    String nextHopLockStr = vpnId + primaryIpAddress;
    String jobKey = FibUtil.getCreateLocalNextHopJobKey(vpnId, dpnId, currDestIpPrefix);
    jobCoordinator.enqueueJob(jobKey, () -> {
        try {
            if (FibUtil.lockCluster(lockManager, nextHopLockStr, WAIT_TIME_TO_ACQUIRE_LOCK)) {
                VpnNexthop nexthop = getVpnNexthop(vpnId, primaryIpAddress);
                LOG.trace("nexthop: {} retrieved for vpnId {}, prefix {}, ifName {} on dpn {}", nexthop, vpnId, primaryIpAddress, ifName, dpnId);
                if (nexthop == null) {
                    String encMacAddress = macAddress == null ? fibUtil.getMacAddressFromPrefix(ifName, vpnName, primaryIpAddress) : macAddress;
                    List<ActionInfo> listActionInfo = new ArrayList<>();
                    int actionKey = 0;
                    // MAC re-write
                    if (encMacAddress != null) {
                        if (gwMacAddress != null) {
                            LOG.trace("The Local NextHop Group Source Mac {} for VpnInterface {} on VPN {}", gwMacAddress, ifName, vpnId);
                            listActionInfo.add(new ActionSetFieldEthernetSource(actionKey++, new MacAddress(gwMacAddress)));
                        }
                        listActionInfo.add(new ActionSetFieldEthernetDestination(actionKey++, new MacAddress(encMacAddress)));
                    // listActionInfo.add(0, new ActionPopMpls());
                    } else {
                        LOG.error("mac address for new local nexthop group {} is null for vpnId {}, prefix {}, " + "ifName {} on dpn {}", groupId, vpnId, primaryIpAddress, ifName, dpnId);
                    }
                    List<ActionInfo> nhActionInfoList = getEgressActionsForInterface(ifName, actionKey, false, vpnId, currDestIpPrefix);
                    if (nhActionInfoList.isEmpty()) {
                        LOG.error("createLocalNextHop: Skipping, Empty list of egress actions received for " + "interface {} on dpn {} for vpn {} prefix {}", ifName, dpnId, vpnId, currDestIpPrefix);
                    }
                    listActionInfo.addAll(nhActionInfoList);
                    BucketInfo bucket = new BucketInfo(listActionInfo);
                    List<BucketInfo> listBucketInfo = new ArrayList<>();
                    listBucketInfo.add(bucket);
                    GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, primaryIpAddress, GroupTypes.GroupAll, listBucketInfo);
                    LOG.trace("Install LNH Group: id {}, mac address {}, interface {} for prefix {}", groupId, encMacAddress, ifName, primaryIpAddress);
                    // Try to install group directly on the DPN bypassing the FRM, in order to avoid waiting for the
                    // group to get installed before programming the flows
                    installGroupOnDpn(groupId, dpnId, primaryIpAddress, listBucketInfo, getNextHopKey(vpnId, primaryIpAddress), GroupTypes.GroupAll);
                    // install Group
                    mdsalApiManager.syncInstallGroup(groupEntity);
                    // update MD-SAL DS
                    addVpnNexthopToDS(dpnId, vpnId, primaryIpAddress, currDestIpPrefix, groupId);
                } else {
                    // Ignore adding new prefix , if it already exists
                    Map<IpAdjacenciesKey, IpAdjacencies> keyIpAdjacenciesMap = nexthop.getIpAdjacencies();
                    IpAdjacencies prefix = new IpAdjacenciesBuilder().setIpAdjacency(currDestIpPrefix).build();
                    if (keyIpAdjacenciesMap != null && keyIpAdjacenciesMap.values().contains(prefix)) {
                        LOG.trace("Prefix {} is already present in l3nextHop {} ", currDestIpPrefix, nexthop);
                    } else {
                        IpAdjacenciesBuilder ipPrefixesBuilder = new IpAdjacenciesBuilder().withKey(new IpAdjacenciesKey(currDestIpPrefix));
                        LOG.trace("Updating prefix {} to vpnNextHop {} Operational DS", currDestIpPrefix, nexthop);
                        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getVpnNextHopIpPrefixIdentifier(vpnId, primaryIpAddress, currDestIpPrefix), ipPrefixesBuilder.build());
                    }
                }
            }
        } finally {
            FibUtil.unlockCluster(lockManager, nextHopLockStr);
        }
        return Collections.emptyList();
    });
    return groupId;
}
Also used : IpAdjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacencies) IpAdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacenciesBuilder) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) IpAdjacenciesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacenciesKey) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo)

Example 3 with IpAdjacencies

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacencies in project netvirt by opendaylight.

the class NexthopManager method removeLocalNextHop.

public void removeLocalNextHop(Uint64 dpnId, Uint32 vpnId, String primaryIpAddress, String currDestIpPrefix) {
    String nextHopLockStr = vpnId + primaryIpAddress;
    try {
        if (FibUtil.lockCluster(lockManager, nextHopLockStr, WAIT_TIME_TO_ACQUIRE_LOCK)) {
            VpnNexthop nh = getVpnNexthop(vpnId, primaryIpAddress);
            if (nh != null) {
                List<IpAdjacencies> prefixesList = new ArrayList<IpAdjacencies>(nh.nonnullIpAdjacencies().values());
                IpAdjacencies prefix = new IpAdjacenciesBuilder().setIpAdjacency(currDestIpPrefix).build();
                prefixesList.remove(prefix);
                if (prefixesList.isEmpty()) {
                    // remove the group only if there are no more flows using this group
                    GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, nh.getEgressPointer().toJava(), primaryIpAddress, GroupTypes.GroupAll, Collections.emptyList());
                    // remove Group ...
                    mdsalApiManager.removeGroup(groupEntity);
                    // update MD-SAL DS
                    removeVpnNexthopFromDS(vpnId, primaryIpAddress);
                    // release groupId
                    removeNextHopPointer(getNextHopKey(vpnId, primaryIpAddress));
                    LOG.debug("Local Next hop {} for {} {} on dpn {} successfully deleted", nh.getEgressPointer(), vpnId, primaryIpAddress, dpnId);
                } else {
                    // remove the currIpPrefx from IpPrefixList of the vpnNexthop
                    LOG.trace("Removing the prefix {} from vpnNextHop {} Operational DS", currDestIpPrefix, nh);
                    MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, getVpnNextHopIpPrefixIdentifier(vpnId, primaryIpAddress, currDestIpPrefix));
                }
            } else {
                // throw error
                LOG.error("Local NextHop for VpnId {} curIpPrefix {} on dpn {} primaryIpAddress {} not deleted", vpnId, currDestIpPrefix, dpnId, primaryIpAddress);
            }
        }
    } finally {
        FibUtil.unlockCluster(lockManager, nextHopLockStr);
    }
}
Also used : IpAdjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacencies) IpAdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacenciesBuilder) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop)

Aggregations

ArrayList (java.util.ArrayList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 VpnNexthop (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop)3 IpAdjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacencies)3 IpAdjacenciesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacenciesBuilder)3 GroupEntity (org.opendaylight.genius.mdsalutil.GroupEntity)2 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)1 BucketInfo (org.opendaylight.genius.mdsalutil.BucketInfo)1 ActionSetFieldEthernetDestination (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination)1 ActionSetFieldEthernetSource (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource)1 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)1 L3nexthop (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.L3nexthop)1 VpnNexthops (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthops)1 VpnNexthopsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthopsKey)1 VpnNexthopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder)1 VpnNexthopKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopKey)1 IpAdjacenciesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.vpnnexthop.IpAdjacenciesKey)1