@Test public void testOperation() { ExplicitAsPathSet expr = new ExplicitAsPathSet(new RegexAsPathSetElem("13$")); assertTrue(expr.matches(buildEnvironment(AsPath.ofSingletonAsSets(13L)))); assertTrue(expr.matches(buildEnvironment(AsPath.ofSingletonAsSets(11L, 12L, 13L)))); assertTrue(expr.matches(buildEnvironment(AsPath.ofSingletonAsSets(13L, 113L)))); assertFalse(expr.matches(buildEnvironment(AsPath.ofSingletonAsSets(11L, 12L, 13L, 14L)))); expr = new ExplicitAsPathSet(new RegexAsPathSetElem(" 13$")); assertTrue(expr.matches(buildEnvironment(AsPath.ofSingletonAsSets(13L)))); assertTrue(expr.matches(buildEnvironment(AsPath.ofSingletonAsSets(11L, 12L, 13L)))); assertFalse(expr.matches(buildEnvironment(AsPath.ofSingletonAsSets(13L, 113L)))); assertFalse(expr.matches(buildEnvironment(AsPath.ofSingletonAsSets(11L, 12L, 13L, 14L)))); }
@Override public boolean matches(Environment environment) { AsPath asPath = null; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); asPath = bgpRouteBuilder.getAsPath(); } else if (environment.getReadFromIntermediateBgpAttributes()) { asPath = environment.getIntermediateBgpAttributes().getAsPath(); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); asPath = bgpRoute.getAsPath(); } if (asPath == null) { return false; } String asPathStr = asPath.size() == 0 ? "" : " " + asPath.getAsPathString(); return _elems.stream() .map(AsPathSetElem::regex) .anyMatch(r -> Pattern.compile(r).matcher(asPathStr).find()); }
ExplicitAsPathSet extends AsPathSetExpr { @Override public boolean matches(Environment environment) { AsPath asPath = null; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); asPath = bgpRouteBuilder.getAsPath(); } else if (environment.getReadFromIntermediateBgpAttributes()) { asPath = environment.getIntermediateBgpAttributes().getAsPath(); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); asPath = bgpRoute.getAsPath(); } if (asPath == null) { return false; } String asPathStr = asPath.size() == 0 ? "" : " " + asPath.getAsPathString(); return _elems.stream() .map(AsPathSetElem::regex) .anyMatch(r -> Pattern.compile(r).matcher(asPathStr).find()); } }
ExplicitAsPathSet extends AsPathSetExpr { @Override public boolean matches(Environment environment) { AsPath asPath = null; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); asPath = bgpRouteBuilder.getAsPath(); } else if (environment.getReadFromIntermediateBgpAttributes()) { asPath = environment.getIntermediateBgpAttributes().getAsPath(); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); asPath = bgpRoute.getAsPath(); } if (asPath == null) { return false; } String asPathStr = asPath.size() == 0 ? "" : " " + asPath.getAsPathString(); return _elems.stream() .map(AsPathSetElem::regex) .anyMatch(r -> Pattern.compile(r).matcher(asPathStr).find()); } ExplicitAsPathSet(AsPathSetElem... elems);  ExplicitAsPathSet(Iterable<AsPathSetElem> elems); }
ExplicitAsPathSet extends AsPathSetExpr { @Override public boolean matches(Environment environment) { AsPath asPath = null; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); asPath = bgpRouteBuilder.getAsPath(); } else if (environment.getReadFromIntermediateBgpAttributes()) { asPath = environment.getIntermediateBgpAttributes().getAsPath(); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); asPath = bgpRoute.getAsPath(); } if (asPath == null) { return false; } String asPathStr = asPath.size() == 0 ? "" : " " + asPath.getAsPathString(); return _elems.stream() .map(AsPathSetElem::regex) .anyMatch(r -> Pattern.compile(r).matcher(asPathStr).find()); } ExplicitAsPathSet(AsPathSetElem... elems);  ExplicitAsPathSet(Iterable<AsPathSetElem> elems); @Override boolean equals(Object obj); @JsonProperty(PROP_ELEMS) @Nonnull List<AsPathSetElem> getElems(); @Override int hashCode(); @Override boolean matches(Environment environment); void setElems(List<AsPathSetElem> elems); }
ExplicitAsPathSet extends AsPathSetExpr { @Override public boolean matches(Environment environment) { AsPath asPath = null; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); asPath = bgpRouteBuilder.getAsPath(); } else if (environment.getReadFromIntermediateBgpAttributes()) { asPath = environment.getIntermediateBgpAttributes().getAsPath(); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); asPath = bgpRoute.getAsPath(); } if (asPath == null) { return false; } String asPathStr = asPath.size() == 0 ? "" : " " + asPath.getAsPathString(); return _elems.stream() .map(AsPathSetElem::regex) .anyMatch(r -> Pattern.compile(r).matcher(asPathStr).find()); } ExplicitAsPathSet(AsPathSetElem... elems);  ExplicitAsPathSet(Iterable<AsPathSetElem> elems); @Override boolean equals(Object obj); @JsonProperty(PROP_ELEMS) @Nonnull List<AsPathSetElem> getElems(); @Override int hashCode(); @Override boolean matches(Environment environment); void setElems(List<AsPathSetElem> elems);  }