use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.MatchSetOptionsType in project bgpcep by opendaylight.
the class MatchAsPathSetHandler method matchAsPathSetCondition.
private boolean matchAsPathSetCondition(final AsPath asPath, final String asPathSetName, final MatchSetOptionsType matchSetOptions) {
if (asPath == null) {
return false;
}
final AsPathSet asPathSetFilter = this.sets.getUnchecked(StringUtils.substringBetween(asPathSetName, "=\"", "\""));
final List<Segments> segments = asPath.getSegments();
if (asPathSetFilter == null || segments == null) {
return false;
}
final List<AsNumber> l1 = segments.stream().map(AsPathSegment::getAsSequence).filter(Objects::nonNull).flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList());
final List<AsNumber> l2 = segments.stream().map(AsPathSegment::getAsSet).filter(Objects::nonNull).flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList());
List<AsNumber> allAs = Stream.of(l1, l2).flatMap(Collection::stream).collect(Collectors.toList());
final List<AsNumber> asPathSetFilterList = asPathSetFilter.getAsPathSetMember();
if (matchSetOptions.equals(MatchSetOptionsType.ALL)) {
return allAs.containsAll(asPathSetFilterList) && asPathSetFilterList.containsAll(allAs);
}
final boolean noneInCommon = Collections.disjoint(allAs, asPathSetFilterList);
if (matchSetOptions.equals(MatchSetOptionsType.ANY)) {
return !noneInCommon;
}
// (matchSetOptions.equals(MatchSetOptionsType.INVERT))
return noneInCommon;
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.MatchSetOptionsType in project bgpcep by opendaylight.
the class MatchClusterIdSetHandler method matchClusterIdCondition.
private boolean matchClusterIdCondition(final ClusterIdentifier localClusterId, final ClusterId clusterId, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.match.cluster.id.set.condition.grouping.MatchClusterIdSetCondition matchClusterIdSetCondition) {
final ClusterIdSet clusterIdSet = this.sets.getUnchecked(StringUtils.substringBetween(matchClusterIdSetCondition.getClusterIdSet(), "=\"", "\""));
if (clusterIdSet == null) {
return false;
}
final MatchSetOptionsType matchOption = matchClusterIdSetCondition.getMatchSetOptions();
if (clusterId != null) {
List<ClusterIdentifier> newList = new ArrayList<>();
if (clusterIdSet.getClusterId() != null) {
newList.addAll(clusterIdSet.getClusterId());
}
if (clusterIdSet.getLocal() != null) {
newList.add(localClusterId);
}
final List<ClusterIdentifier> matchClusterList = clusterId.getCluster();
if (matchOption.equals(MatchSetOptionsType.ALL)) {
return matchClusterList.containsAll(newList) && newList.containsAll(matchClusterList);
}
final boolean noneInCommon = Collections.disjoint(matchClusterList, newList);
if (matchOption.equals(MatchSetOptionsType.ANY)) {
return !noneInCommon;
} else if (matchOption.equals(MatchSetOptionsType.INVERT)) {
return noneInCommon;
}
} else if (matchOption.equals(MatchSetOptionsType.INVERT)) {
return true;
}
return false;
}
Aggregations