use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket in project netvirt by opendaylight.
the class FibUtil method buildBuckets.
static Buckets buildBuckets(List<BucketInfo> listBucketInfo) {
long index = 0;
BucketsBuilder bucketsBuilder = new BucketsBuilder();
if (listBucketInfo != null) {
List<Bucket> bucketList = new ArrayList<>();
for (BucketInfo bucketInfo : listBucketInfo) {
BucketBuilder bucketBuilder = new BucketBuilder();
bucketBuilder.setAction(bucketInfo.buildActions());
bucketBuilder.setWeight(bucketInfo.getWeight());
bucketBuilder.setBucketId(new BucketId(index++));
bucketBuilder.setWeight(bucketInfo.getWeight()).setWatchPort(bucketInfo.getWatchPort()).setWatchGroup(bucketInfo.getWatchGroup());
bucketList.add(bucketBuilder.build());
}
bucketsBuilder.setBucket(bucketList);
}
return bucketsBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket in project netvirt by opendaylight.
the class NexthopManager method getBucketsForRemoteNexthop.
private List<BucketInfo> getBucketsForRemoteNexthop(Long vpnId, BigInteger dpnId, VrfEntry vrfEntry, String rd, List<Routes> vpnExtraRoutes) {
List<BucketInfo> listBucketInfo = new ArrayList<>();
Map<String, List<ActionInfo>> egressActionMap = new HashMap<>();
vpnExtraRoutes.forEach(vpnExtraRoute -> vpnExtraRoute.getNexthopIpList().forEach(nextHopIp -> {
String nextHopPrefixIp;
if (isIpv4Address(nextHopIp)) {
nextHopPrefixIp = nextHopIp + NwConstants.IPV4PREFIX;
} else {
nextHopPrefixIp = nextHopIp + NwConstants.IPV6PREFIX;
}
List<String> tepIpAddresses = fibUtil.getNextHopAddresses(rd, nextHopPrefixIp);
if (tepIpAddresses.isEmpty()) {
return;
}
// There would be only one nexthop address for a VM ip which would be the tep Ip
String tepIp = tepIpAddresses.get(0);
AdjacencyResult adjacencyResult = getRemoteNextHopPointer(dpnId, vpnId, vrfEntry.getDestPrefix(), tepIp);
if (adjacencyResult == null) {
return;
}
String egressInterface = adjacencyResult.getInterfaceName();
if (!FibUtil.isTunnelInterface(adjacencyResult)) {
return;
}
Class<? extends TunnelTypeBase> tunnelType = VpnExtraRouteHelper.getTunnelType(interfaceManager, egressInterface);
Interface ifState = fibUtil.getInterfaceStateFromOperDS(egressInterface);
if (ifState == null || ifState.getOperStatus() != OperStatus.Up) {
LOG.trace("Tunnel not up {}", egressInterface);
return;
}
if (!TunnelTypeVxlan.class.equals(tunnelType)) {
return;
}
Long label = FibUtil.getLabelFromRoutePaths(vrfEntry).get();
Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, nextHopPrefixIp);
BigInteger tunnelId;
if (fibUtil.enforceVxlanDatapathSemanticsforInternalRouterVpn(prefixInfo.getSubnetId(), vpnId, rd)) {
java.util.Optional<Long> optionalVni = fibUtil.getVniForVxlanNetwork(prefixInfo.getSubnetId());
if (!optionalVni.isPresent()) {
LOG.error("VNI not found for nexthop {} vrfEntry {} with subnetId {}", nextHopIp, vrfEntry, prefixInfo.getSubnetId());
return;
}
tunnelId = BigInteger.valueOf(optionalVni.get());
} else {
tunnelId = BigInteger.valueOf(label);
}
List<ActionInfo> actionInfos = new ArrayList<>();
actionInfos.add(new ActionSetFieldTunnelId(tunnelId));
String ifName = prefixInfo.getVpnInterfaceName();
String vpnName = fibUtil.getVpnNameFromId(vpnId);
if (vpnName == null) {
return;
}
String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, nextHopPrefixIp);
actionInfos.add(new ActionSetFieldEthernetDestination(actionInfos.size(), new MacAddress(macAddress)));
List<ActionInfo> egressActions;
if (egressActionMap.containsKey(egressInterface)) {
egressActions = egressActionMap.get(egressInterface);
} else {
egressActions = getEgressActionsForInterface(egressInterface, actionInfos.size());
egressActionMap.put(egressInterface, egressActions);
}
if (egressActions.isEmpty()) {
LOG.error("Failed to retrieve egress action for prefix {} route-paths {}" + " interface {}." + " Aborting remote FIB entry creation.", vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths(), egressInterface);
}
actionInfos.addAll(egressActions);
BucketInfo bucket = new BucketInfo(actionInfos);
bucket.setWeight(1);
listBucketInfo.add(bucket);
}));
LOG.trace("LOCAL: listbucket {}, rd {}, dpnId {}, routes {}", listBucketInfo, rd, dpnId, vpnExtraRoutes);
return listBucketInfo;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket in project netvirt by opendaylight.
the class NexthopManager method buildBucketForDcGwLbGroup.
private Bucket buildBucketForDcGwLbGroup(String ipAddress, BigInteger dpnId, int index) {
List<Action> listAction = new ArrayList<>();
// ActionKey 0 goes to mpls label.
int actionKey = 1;
listAction.add(new ActionPushMpls().buildAction());
listAction.add(new ActionRegMove(actionKey++, FibConstants.NXM_REG_MAPPING.get(index), 0, 19).buildAction());
String tunnelInterfaceName = getTunnelInterfaceName(dpnId, new IpAddress(ipAddress.toCharArray()));
List<Action> egressActions = getEgressActions(tunnelInterfaceName, actionKey++);
if (!egressActions.isEmpty()) {
listAction.addAll(getEgressActions(tunnelInterfaceName, actionKey++));
} else {
// clear off actions if there is no egress actions.
listAction = Collections.emptyList();
}
return MDSALUtil.buildBucket(listAction, MDSALUtil.GROUP_WEIGHT, index, MDSALUtil.WATCH_PORT, MDSALUtil.WATCH_GROUP);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket in project netvirt by opendaylight.
the class NexthopManager method updateDcGwLoadBalancingGroup.
/**
* This method is invoked when the tunnel status is updated.
* The bucket is directly removed/added based on the operational status of the tunnel.
*/
public void updateDcGwLoadBalancingGroup(List<String> availableDcGws, BigInteger dpnId, String destinationIp, boolean isTunnelUp) {
Preconditions.checkNotNull(availableDcGws, "There are no dc-gws present");
WriteTransaction configTx = dataBroker.newWriteOnlyTransaction();
// TODO : Place the logic to construct all possible DC-GW combination here.
int bucketId = availableDcGws.indexOf(destinationIp);
Optional<DpnLbNexthops> dpnLbNextHops = fibUtil.getDpnLbNexthops(dpnId, destinationIp);
if (!dpnLbNextHops.isPresent()) {
return;
}
List<String> nextHopKeys = dpnLbNextHops.get().getNexthopKey();
nextHopKeys.forEach(nextHopKey -> {
Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
if (!optionalNextHops.isPresent()) {
return;
}
Nexthops nexthops = optionalNextHops.get();
final String groupId = nexthops.getGroupId();
final long groupIdValue = Long.parseLong(groupId);
if (isTunnelUp) {
Bucket bucket = buildBucketForDcGwLbGroup(destinationIp, dpnId, bucketId);
LOG.trace("Added bucket {} to group {} on dpn {}.", bucket, groupId, dpnId);
mdsalApiManager.addBucketToTx(dpnId, groupIdValue, bucket, configTx);
} else {
LOG.trace("Removed bucketId {} from group {} on dpn {}.", bucketId, groupId, dpnId);
mdsalApiManager.removeBucketToTx(dpnId, groupIdValue, bucketId, configTx);
}
});
configTx.submit();
return;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket in project netvirt by opendaylight.
the class NexthopManager method getBucketsForLocalNexthop.
private List<BucketInfo> getBucketsForLocalNexthop(Long vpnId, BigInteger dpnId, VrfEntry vrfEntry, Routes routes) {
List<BucketInfo> listBucketInfo = new CopyOnWriteArrayList<>();
routes.getNexthopIpList().parallelStream().forEach(nextHopIp -> {
String localNextHopIP;
if (isIpv4Address(nextHopIp)) {
localNextHopIP = nextHopIp + NwConstants.IPV4PREFIX;
} else {
localNextHopIP = nextHopIp + NwConstants.IPV6PREFIX;
}
Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, localNextHopIP);
if (localNextHopInfo != null) {
long groupId = getLocalNextHopGroup(vpnId, localNextHopIP);
if (groupId == FibConstants.INVALID_GROUP_ID) {
LOG.error("Unable to allocate groupId for vpnId {} , prefix {} , interface {}", vpnId, vrfEntry.getDestPrefix(), localNextHopInfo.getVpnInterfaceName());
return;
}
List<ActionInfo> actionsInfos = Collections.singletonList(new ActionGroup(groupId));
BucketInfo bucket = new BucketInfo(actionsInfos);
bucket.setWeight(1);
listBucketInfo.add(bucket);
}
});
LOG.trace("LOCAL: listbucket {}, vpnId {}, dpnId {}, routes {}", listBucketInfo, vpnId, dpnId, routes);
return listBucketInfo;
}
Aggregations