use of org.batfish.datamodel.BgpRoute in project batfish by batfish.
the class IncrementLocalPreference method evaluate.
@Override
public int evaluate(Environment environment) {
BgpRoute oldRoute = (BgpRoute) environment.getOriginalRoute();
int oldLp = oldRoute.getLocalPreference();
int newVal = oldLp + _addend;
return newVal;
}
use of org.batfish.datamodel.BgpRoute in project batfish by batfish.
the class SetCommunity method execute.
@Override
public Result execute(Environment environment) {
Result result = new Result();
BgpRoute.Builder bgpRoute = (BgpRoute.Builder) environment.getOutputRoute();
SortedSet<Long> communities = _expr.allCommunities(environment);
bgpRoute.getCommunities().clear();
bgpRoute.getCommunities().addAll(communities);
if (environment.getWriteToIntermediateBgpAttributes()) {
environment.getIntermediateBgpAttributes().getCommunities().clear();
environment.getIntermediateBgpAttributes().getCommunities().addAll(communities);
}
return result;
}
use of org.batfish.datamodel.BgpRoute in project batfish by batfish.
the class MatchCommunitySet method evaluate.
@Override
public Result evaluate(Environment environment) {
Result result = new Result();
boolean match = false;
SortedSet<Long> inputCommunities = null;
if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder) {
BgpRoute.Builder bgpRouteBuilder = (BgpRoute.Builder) environment.getOutputRoute();
inputCommunities = bgpRouteBuilder.getCommunities();
} else if (environment.getReadFromIntermediateBgpAttributes()) {
inputCommunities = environment.getIntermediateBgpAttributes().getCommunities();
} else if (environment.getOriginalRoute() instanceof BgpRoute) {
BgpRoute bgpRoute = (BgpRoute) environment.getOriginalRoute();
inputCommunities = bgpRoute.getCommunities();
}
if (inputCommunities != null) {
match = _expr.matchSingleCommunity(environment, inputCommunities);
}
result.setBooleanValue(match);
return result;
}
use of org.batfish.datamodel.BgpRoute in project batfish by batfish.
the class BdpDataPlanePluginTest method testBgpAsPathMultipathHelper.
private void testBgpAsPathMultipathHelper(MultipathEquivalentAsPathMatchMode multipathEquivalentAsPathMatchMode, boolean primeBestPathInMultipathBgpRib, boolean expectRoute2, boolean expectRoute3a, boolean expectRoute3b, boolean expectRoute3c, boolean expectRoute3d) {
/*
* Properties of the routes
*/
// Should appear only for path-length match
List<SortedSet<Integer>> asPath2 = AsPath.ofSingletonAsSets(2, 4, 6).getAsSets();
// Should appear only for first-as match and path-length match
List<SortedSet<Integer>> asPath3a = AsPath.ofSingletonAsSets(3, 5, 6).getAsSets();
// Should never appear
List<SortedSet<Integer>> asPath3b = AsPath.ofSingletonAsSets(3, 4, 4, 6).getAsSets();
// Should always appear
AsPath bestAsPath = AsPath.ofSingletonAsSets(3, 4, 6);
List<SortedSet<Integer>> asPath3c = bestAsPath.getAsSets();
List<SortedSet<Integer>> asPath3d = bestAsPath.getAsSets();
Ip nextHop2 = new Ip("2.0.0.0");
Ip nextHop3a = new Ip("3.0.0.1");
Ip nextHop3b = new Ip("3.0.0.2");
Ip nextHop3c = new Ip("3.0.0.3");
Ip nextHop3d = new Ip("3.0.0.4");
/*
* Common attributes for all routes
*/
Prefix p = Prefix.ZERO;
BgpRoute.Builder b = new BgpRoute.Builder().setNetwork(p).setProtocol(RoutingProtocol.BGP).setOriginType(OriginType.INCOMPLETE);
/*
* Boilerplate virtual-router setup
*/
String hostname = "r1";
Configuration c = BatfishTestUtils.createTestConfiguration(hostname, ConfigurationFormat.CISCO_IOS);
BgpProcess proc = new BgpProcess();
c.getVrfs().computeIfAbsent(DEFAULT_VRF_NAME, Vrf::new).setBgpProcess(proc);
Map<String, Node> nodes = new HashMap<String, Node>();
Node node = new Node(c);
nodes.put(hostname, node);
VirtualRouter vr = new VirtualRouter(DEFAULT_VRF_NAME, c);
/*
* Instantiate routes
*/
BgpRoute route2 = b.setAsPath(asPath2).setNextHopIp(nextHop2).setOriginatorIp(nextHop2).setReceivedFromIp(nextHop2).build();
BgpRoute route3a = b.setAsPath(asPath3a).setNextHopIp(nextHop3a).setOriginatorIp(nextHop3a).setReceivedFromIp(nextHop3a).build();
BgpRoute route3b = b.setAsPath(asPath3b).setNextHopIp(nextHop3b).setOriginatorIp(nextHop3b).setReceivedFromIp(nextHop3b).build();
BgpRoute route3c = b.setAsPath(asPath3c).setNextHopIp(nextHop3c).setOriginatorIp(nextHop3c).setReceivedFromIp(nextHop3c).build();
BgpRoute route3d = b.setAsPath(asPath3d).setNextHopIp(nextHop3d).setOriginatorIp(nextHop3d).setReceivedFromIp(nextHop3d).build();
/*
* Set the as-path match mode prior to instantiating bgp multipath RIB
*/
proc.setMultipathEquivalentAsPathMatchMode(multipathEquivalentAsPathMatchMode);
BgpMultipathRib bmr = new BgpMultipathRib(vr);
/*
* Prime bgp multipath RIB with best path for the prefix
*/
if (primeBestPathInMultipathBgpRib) {
bmr.setBestAsPaths(Collections.singletonMap(p, bestAsPath));
}
/*
* Add routes to multipath RIB.
*/
bmr.mergeRoute(route2);
bmr.mergeRoute(route3a);
bmr.mergeRoute(route3b);
bmr.mergeRoute(route3c);
bmr.mergeRoute(route3d);
/*
* Initialize the matchers with respect to the output route set
*/
Set<BgpRoute> postMergeRoutes = bmr.getRoutes();
Matcher<BgpRoute> present = isIn(postMergeRoutes);
Matcher<BgpRoute> absent = not(present);
/*
* ASSERTIONS:
* Only the expected routes for the given match mode should be present at end
*/
assertThat(route2, expectRoute2 ? present : absent);
assertThat(route3a, expectRoute3a ? present : absent);
assertThat(route3b, expectRoute3b ? present : absent);
assertThat(route3c, expectRoute3c ? present : absent);
assertThat(route3c, expectRoute3d ? present : absent);
}
Aggregations