use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment 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;
}
Aggregations