use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId 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.actions.ActionSetFieldTunnelId in project netvirt by opendaylight.
the class BgpRouteVrfEntryHandler method addTunnelInterfaceActions.
@Override
protected void addTunnelInterfaceActions(NexthopManager.AdjacencyResult adjacencyResult, long vpnId, VrfEntry vrfEntry, List<ActionInfo> actionInfos, String rd) {
Class<? extends TunnelTypeBase> tunnelType = VpnExtraRouteHelper.getTunnelType(getNextHopManager().getInterfaceManager(), adjacencyResult.getInterfaceName());
if (tunnelType == null) {
LOG.debug("Tunnel type not found for vrfEntry {}", vrfEntry);
return;
}
String nextHopIp = adjacencyResult.getNextHopIp();
if (tunnelType.equals(TunnelTypeMplsOverGre.class)) {
java.util.Optional<Long> optionalLabel = FibUtil.getLabelForNextHop(vrfEntry, nextHopIp);
if (!optionalLabel.isPresent()) {
LOG.warn("NextHopIp {} not found in vrfEntry {}", nextHopIp, vrfEntry);
return;
}
long label = optionalLabel.get();
LOG.debug("addTunnelInterfaceActions: Push label action for prefix {} rd {} l3vni {} nextHop {}", vrfEntry.getDestPrefix(), rd, vrfEntry.getL3vni(), nextHopIp);
actionInfos.add(new ActionPushMpls());
actionInfos.add(new ActionSetFieldMplsLabel(label));
actionInfos.add(new ActionNxLoadInPort(BigInteger.ZERO));
} else if (tunnelType.equals(TunnelTypeVxlan.class)) {
actionInfos.add(new ActionSetFieldTunnelId(BigInteger.valueOf(vrfEntry.getL3vni())));
LOG.debug("addTunnelInterfaceActions: adding set tunnel id action for prefix {} rd {} l3vni {}" + " nextHop {} ", vrfEntry.getDestPrefix(), rd, vrfEntry.getL3vni(), nextHopIp);
addRewriteDstMacAction(vpnId, vrfEntry, null, /*prefixInfo*/
actionInfos);
}
}
use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId in project genius by opendaylight.
the class AlivenessProtocolHandlerLLDP method getInterfaceActions.
private List<ActionInfo> getInterfaceActions(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState, long portNum) throws InterruptedException, ExecutionException {
Class<? extends InterfaceType> intfType;
if (interfaceState != null) {
intfType = interfaceState.getType();
} else {
LOG.error("Could not retrieve port type for interface to construct actions");
return Collections.emptyList();
}
List<ActionInfo> actionInfos = new ArrayList<>();
// Set the LLDP service Id which is 0
if (Tunnel.class.equals(intfType)) {
actionInfos.add(new ActionSetFieldTunnelId(BigInteger.ZERO));
}
actionInfos.add(new ActionOutput(new Uri(Long.toString(portNum))));
return actionInfos;
}
use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId in project genius by opendaylight.
the class ActionInfoBuilderTest method set_field_tunnel_idActionWithBigActionValues.
@Test
public void set_field_tunnel_idActionWithBigActionValues() {
ActionInfo actionInfo = new ActionSetFieldTunnelId(BigInteger.valueOf(123));
assertEquals("new ActionSetFieldTunnelId(0, 123bi)", generator.getExpression(actionInfo));
}
use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId in project genius by opendaylight.
the class DirectTunnelUtils method getEgressActionInfosForInterface.
private static List<ActionInfo> getEgressActionInfosForInterface(String tunnelType, String portNo, Long tunnelKey, int actionKeyStart) {
List<ActionInfo> result = new ArrayList<>();
switch(tunnelType) {
case ITMConstants.TUNNEL_TYPE_GRE:
case ITMConstants.TUNNEL_TYPE_MPLSoGRE:
// Invoke IFM RPC and pass it on to the caller.
LOG.warn("Interface Type {} not handled by ITM", tunnelType);
break;
case ITMConstants.TUNNEL_TYPE_VXLAN:
// TODO tunnel_id to encode GRE key, once it is supported
// Until then, tunnel_id should be "cleaned", otherwise it stores the value coming from a VXLAN tunnel
result.add(new ActionSetFieldTunnelId(actionKeyStart++, BigInteger.valueOf(tunnelKey != null ? tunnelKey : 0L)));
result.add(new ActionOutput(actionKeyStart, new Uri(portNo)));
break;
default:
LOG.warn("Interface Type {} not handled yet", tunnelType);
break;
}
return result;
}
Aggregations