use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder in project netvirt by opendaylight.
the class NexthopManager method removeLocalNextHop.
public void removeLocalNextHop(BigInteger dpnId, Long vpnId, String ipNextHopAddress, String ipPrefixAddress) {
String ipPrefixStr = vpnId + ipPrefixAddress;
VpnNexthop prefixNh = null;
synchronized (ipPrefixStr.intern()) {
prefixNh = getVpnNexthop(vpnId, ipPrefixAddress);
}
String ipAddress = prefixNh != null ? ipPrefixAddress : ipNextHopAddress;
String nextHopLockStr = vpnId + ipAddress;
synchronized (nextHopLockStr.intern()) {
VpnNexthop nh = getVpnNexthop(vpnId, ipAddress);
if (nh != null) {
int newFlowrefCnt = nh.getFlowrefCount() - 1;
if (newFlowrefCnt == 0) {
// remove the group only if there are no more flows using this group
GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, nh.getEgressPointer(), ipAddress, GroupTypes.GroupAll, Collections.EMPTY_LIST);
// remove Group ...
mdsalApiManager.removeGroup(groupEntity);
// update MD-SAL DS
removeVpnNexthopFromDS(vpnId, ipAddress);
// release groupId
removeNextHopPointer(getNextHopKey(vpnId, ipAddress));
LOG.debug("Local Next hop {} for {} {} on dpn {} successfully deleted", nh.getEgressPointer(), vpnId, ipAddress, dpnId);
} else {
// just update the flowrefCount of the vpnNexthop
VpnNexthop currNh = new VpnNexthopBuilder().setKey(new VpnNexthopKey(ipAddress)).setFlowrefCount(newFlowrefCnt).build();
LOG.trace("Updating vpnnextHop {} for refCount {} to Operational DS", currNh, newFlowrefCnt);
MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, getVpnNextHopIdentifier(vpnId, ipAddress), currNh);
}
} else {
// throw error
LOG.error("Local Next hop for Prefix {} VpnId {} on dpn {} not deleted", ipAddress, vpnId, dpnId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder in project netvirt by opendaylight.
the class NexthopManager method addVpnNexthopToDS.
protected void addVpnNexthopToDS(BigInteger dpnId, long vpnId, String ipPrefix, long egressPointer) {
InstanceIdentifierBuilder<VpnNexthops> idBuilder = InstanceIdentifier.builder(L3nexthop.class).child(VpnNexthops.class, new VpnNexthopsKey(vpnId));
// Add nexthop to vpn node
VpnNexthop nh = new VpnNexthopBuilder().setKey(new VpnNexthopKey(ipPrefix)).setDpnId(dpnId).setIpAddress(ipPrefix).setFlowrefCount(1).setEgressPointer(egressPointer).build();
InstanceIdentifier<VpnNexthop> id1 = idBuilder.child(VpnNexthop.class, new VpnNexthopKey(ipPrefix)).build();
LOG.trace("Adding vpnnextHop {} to Operational DS", nh);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, id1, nh);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder in project netvirt by opendaylight.
the class NexthopManager method createLocalNextHop.
public long createLocalNextHop(long vpnId, BigInteger dpnId, String ifName, String ipNextHopAddress, String ipPrefixAddress, String gwMacAddress, String jobKey) {
String vpnName = fibUtil.getVpnNameFromId(vpnId);
if (vpnName == null) {
return 0;
}
String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipPrefixAddress);
String ipAddress = macAddress != null ? ipPrefixAddress : ipNextHopAddress;
long groupId = createNextHopPointer(getNextHopKey(vpnId, ipAddress));
if (groupId == 0) {
LOG.error("Unable to allocate groupId for vpnId {} , prefix {} IntfName {}, nextHopAddr {}", vpnId, ipAddress, ifName, ipNextHopAddress);
return groupId;
}
String nextHopLockStr = vpnId + ipAddress;
jobCoordinator.enqueueJob(jobKey, () -> {
synchronized (nextHopLockStr.intern()) {
VpnNexthop nexthop = getVpnNexthop(vpnId, ipAddress);
LOG.trace("nexthop: {} retrieved for vpnId {}, prefix {}, ifName {} on dpn {}", nexthop, vpnId, ipAddress, ifName, dpnId);
if (nexthop == null) {
String encMacAddress = macAddress == null ? fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipAddress) : macAddress;
List<BucketInfo> listBucketInfo = new ArrayList<>();
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 {
// FIXME: Log message here.
LOG.debug("mac address for new local nexthop is null");
}
listActionInfo.addAll(getEgressActionsForInterface(ifName, actionKey));
BucketInfo bucket = new BucketInfo(listActionInfo);
listBucketInfo.add(bucket);
GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, ipAddress, GroupTypes.GroupAll, listBucketInfo);
LOG.trace("Install LNH Group: id {}, mac address {}, interface {} for prefix {}", groupId, encMacAddress, ifName, ipAddress);
// 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, ipAddress, listBucketInfo, getNextHopKey(vpnId, ipAddress), GroupTypes.GroupAll);
// install Group
mdsalApiManager.syncInstallGroup(groupEntity);
// update MD-SAL DS
addVpnNexthopToDS(dpnId, vpnId, ipAddress, groupId);
} else {
// nexthop exists already; a new flow is going to point to
// it, increment the flowrefCount by 1
int flowrefCnt = nexthop.getFlowrefCount() + 1;
VpnNexthop nh = new VpnNexthopBuilder().setKey(new VpnNexthopKey(ipAddress)).setFlowrefCount(flowrefCnt).build();
LOG.trace("Updating vpnnextHop {} for refCount {} to Operational DS", nh, flowrefCnt);
MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, getVpnNextHopIdentifier(vpnId, ipAddress), nh);
}
}
return Collections.emptyList();
});
return groupId;
}
Aggregations