*/
package org.opendaylight.netvirt.cloudservicechain.utils;
-import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.stream.Collectors;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.MatchInfo;
import org.opendaylight.genius.mdsalutil.MetaDataUtil;
+import org.opendaylight.genius.mdsalutil.NWUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.mdsalutil.actions.ActionPopMpls;
import org.opendaylight.genius.mdsalutil.actions.ActionRegLoad;
import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
import org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel;
import org.opendaylight.genius.utils.ServiceIndex;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.netvirt.cloudservicechain.CloudServiceChainConstants;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
private static final Logger LOG = LoggerFactory.getLogger(VpnServiceChainUtils.class);
- private VpnServiceChainUtils() { }
+ private VpnServiceChainUtils() {
+
+ }
public static BigInteger getMetadataSCF(long scfTag) { // TODO: Move to a common place
return new BigInteger("FF", 16).and(BigInteger.valueOf(scfTag)).shiftLeft(32);
* @param lportTag Pseudo Logical Port tag
* @return the FlowEntity
*/
- public static FlowEntity buildLFibVpnPseudoPortFlow(BigInteger dpId, Long label, String nextHop, int lportTag) {
+ public static FlowEntity buildLFibVpnPseudoPortFlow(BigInteger dpId, Long label, int etherType, String nextHop,
+ int lportTag) {
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.MPLS_UNICAST);
matches.add(new MatchMplsLabel(label));
- List<ActionInfo> actionsInfos = Collections.singletonList(new ActionPopMpls());
+ List<ActionInfo> actionsInfos = Collections.singletonList(new ActionPopMpls(etherType));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionWriteMetadata(
MetaDataUtil.getMetaDataForLPortDispatcher(lportTag,
.forEach(routePath -> {
Long label = routePath.getLabel();
String nextHop = routePath.getNexthopAddress();
- FlowEntity flowEntity = buildLFibVpnPseudoPortFlow(dpId, label, nextHop, lportTag);
- if (addOrRemove == NwConstants.ADD_FLOW) {
- mdsalMgr.installFlow(flowEntity);
- } else {
- mdsalMgr.removeFlow(flowEntity);
+ try {
+ int etherType = NWUtil.getEtherTypeFromIpPrefix(vrfEntry.getDestPrefix());
+ FlowEntity flowEntity = buildLFibVpnPseudoPortFlow(dpId, label, etherType, nextHop,
+ lportTag);
+ if (addOrRemove == NwConstants.ADD_FLOW) {
+ mdsalMgr.installFlow(flowEntity);
+ } else {
+ mdsalMgr.removeFlow(flowEntity);
+ }
+ LOG.debug(
+ "LFIBEntry for label={}, destination={}, nexthop={} {} successfully in dpn={}",
+ label, vrfEntry.getDestPrefix(), nextHop,
+ addOrRemove == NwConstants.DEL_FLOW ? "removed" : "installed", dpId);
+ } catch (IllegalArgumentException ex) {
+ LOG.warn("Unable to get etherType for IP Prefix {}", vrfEntry.getDestPrefix());
}
- LOG.debug(
- "LFIBEntry for label={}, destination={}, nexthop={} {} successfully in dpn={}",
- label, vrfEntry.getDestPrefix(), nextHop,
- addOrRemove == NwConstants.DEL_FLOW ? "removed" : "installed", dpId);
}));
}
}
* this kind of flows.
*/
public static String getL3VpnToScfLportDispatcherFlowRef(Integer lportTag) {
- return new StringBuffer(64).append(CloudServiceChainConstants.VPN_PSEUDO_VPN2SCF_FLOWID_PREFIX).append(lportTag)
+ return new StringBuilder(64).append(CloudServiceChainConstants.VPN_PSEUDO_VPN2SCF_FLOWID_PREFIX)
+ .append(lportTag)
.append(NwConstants.FLOWID_SEPARATOR)
.append(ServiceIndex.getIndex(NwConstants.SCF_SERVICE_NAME,
NwConstants.SCF_SERVICE_INDEX))
*
*/
public static String getScfToL3VpnLportDispatcherFlowRef(Integer lportTag) {
- return new StringBuffer().append(CloudServiceChainConstants.VPN_PSEUDO_SCF2VPN_FLOWID_PREFIX).append(lportTag)
+ return new StringBuilder().append(CloudServiceChainConstants.VPN_PSEUDO_SCF2VPN_FLOWID_PREFIX).append(lportTag)
.append(NwConstants.FLOWID_SEPARATOR)
.append(ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME,
NwConstants.L3VPN_SERVICE_INDEX))
.flatMap(dpn -> dpn.getVpnInterfaces().stream())
.map(VpnInterfaces::getInterfaceName)
.collect(Collectors.toList());
- } catch (ReadFailedException e) {
+ } catch (InterruptedException | ExecutionException e) {
LOG.warn("getAllVpnInterfaces for vpn {}: Failure on read operation", vpnName, e);
return Collections.emptyList();
}