use of org.opendaylight.genius.mdsalutil.BucketInfo 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.genius.mdsalutil.BucketInfo 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.genius.mdsalutil.BucketInfo 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;
}
use of org.opendaylight.genius.mdsalutil.BucketInfo in project genius by opendaylight.
the class MdSalUtilTest method createGroupEntity.
public GroupEntity createGroupEntity(String nodeid, String inport, int vlanid) {
List<BucketInfo> listBucketInfo = new ArrayList<>();
List<ActionInfo> listActionInfo = new ArrayList<>();
if (vlanid > 0) {
listActionInfo.add(new ActionPushVlan());
listActionInfo.add(new ActionSetFieldVlanVid(vlanid));
}
listActionInfo.add(new ActionOutput(new Uri(inport), 65535));
listBucketInfo.add(new BucketInfo(listActionInfo));
String groupName = "Test Group";
BigInteger dpnId = new BigInteger(nodeid.split(":")[1]);
long id = getUniqueValue(nodeid, inport);
return MDSALUtil.buildGroupEntity(dpnId, id, groupName, GroupTypes.GroupIndirect, listBucketInfo);
}
Aggregations