use of org.batfish.datamodel.BgpProcess 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);
}
use of org.batfish.datamodel.BgpProcess in project batfish by batfish.
the class BdpDataPlanePluginTest method testContainsRoute.
@Test
public void testContainsRoute() {
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);
BgpBestPathRib bbr = BgpBestPathRib.initial(vr);
BgpMultipathRib bmr = new BgpMultipathRib(vr);
Ip ip1 = new Ip("1.0.0.0");
Ip ip2 = new Ip("2.2.0.0");
BgpRoute.Builder b1 = new BgpRoute.Builder().setNextHopIp(Ip.ZERO).setOriginType(OriginType.INCOMPLETE).setOriginatorIp(Ip.ZERO).setProtocol(RoutingProtocol.BGP).setReceivedFromIp(Ip.ZERO);
BgpRoute.Builder b2 = new BgpRoute.Builder().setNextHopIp(Ip.ZERO).setOriginType(OriginType.INCOMPLETE).setOriginatorIp(Ip.MAX).setProtocol(RoutingProtocol.BGP).setReceivedFromIp(Ip.ZERO);
/*
* Toss a bunch of different routes in each RIB. In the best-path rib, only lower originatorIp
* routes should remain. In the multipath RIB, all routes should remain.
*/
for (int i = 8; i <= Prefix.MAX_PREFIX_LENGTH; i++) {
Prefix p = new Prefix(ip1, i);
b1.setNetwork(p);
b2.setNetwork(p);
bbr.mergeRoute(b1.build());
bbr.mergeRoute(b2.build());
bmr.mergeRoute(b1.build());
bmr.mergeRoute(b2.build());
}
for (int i = 16; i <= Prefix.MAX_PREFIX_LENGTH; i++) {
Prefix p = new Prefix(ip2, i);
b1.setNetwork(p);
b2.setNetwork(p);
bbr.mergeRoute(b1.build());
bbr.mergeRoute(b2.build());
bmr.mergeRoute(b1.build());
bmr.mergeRoute(b2.build());
}
for (int i = 8; i <= Prefix.MAX_PREFIX_LENGTH; i++) {
Prefix p = new Prefix(ip1, i);
assertTrue(bbr.containsRoute(b1.setNetwork(p).build()));
b1.setNetwork(p);
b2.setNetwork(p);
assertTrue(bbr.containsRoute(b1.build()));
assertFalse(bbr.containsRoute(b2.build()));
assertTrue(bmr.containsRoute(b1.build()));
assertTrue(bmr.containsRoute(b2.build()));
}
for (int i = 16; i <= Prefix.MAX_PREFIX_LENGTH; i++) {
Prefix p = new Prefix(ip2, i);
b1.setNetwork(p);
b2.setNetwork(p);
assertTrue(bbr.containsRoute(b1.build()));
assertFalse(bbr.containsRoute(b2.build()));
assertTrue(bmr.containsRoute(b1.build()));
assertTrue(bmr.containsRoute(b2.build()));
}
}
use of org.batfish.datamodel.BgpProcess in project batfish by batfish.
the class RouteReflectionTest method generateRoutesOneReflector.
/*
* See documentation of calling functions for information description of produced network
*/
private SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> generateRoutesOneReflector(boolean edge1RouteReflectorClient, boolean edge2RouteReflectorClient) {
Ip as1PeeringIp = new Ip("10.12.11.1");
Ip edge1EbgpIfaceIp = new Ip("10.12.11.2");
Ip edge1IbgpIfaceIp = new Ip("10.1.12.1");
Ip edge1LoopbackIp = new Ip("2.0.0.1");
Ip rrEdge1IfaceIp = new Ip("10.1.12.2");
Ip rrEdge2IfaceIp = new Ip("10.1.23.2");
Ip rrLoopbackIp = new Ip("2.0.0.2");
Ip as3PeeringIp = new Ip("10.23.31.3");
Ip edge2EbgpIfaceIp = new Ip("10.23.31.2");
Ip edge2IbgpIfaceIp = new Ip("10.1.23.3");
Ip edge2LoopbackIp = new Ip("2.0.0.3");
Configuration edge1 = _cb.setHostname(EDGE1_NAME).build();
Vrf vEdge1 = _vb.setOwner(edge1).build();
_ib.setOwner(edge1).setVrf(vEdge1);
_ib.setAddress(new InterfaceAddress(edge1EbgpIfaceIp, EDGE_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(edge1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(edge1IbgpIfaceIp, EDGE_PREFIX_LENGTH)).build();
StaticRoute.Builder sb = StaticRoute.builder();
vEdge1.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(rrEdge1IfaceIp).setNetwork(new Prefix(rrLoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build()));
BgpProcess edge1Proc = _pb.setRouterId(edge1LoopbackIp).setVrf(vEdge1).build();
RoutingPolicy edge1EbgpExportPolicy = _nullExportPolicyBuilder.setOwner(edge1).build();
_nb.setOwner(edge1).setVrf(vEdge1).setBgpProcess(edge1Proc).setClusterId(edge1LoopbackIp.asLong()).setRemoteAs(1).setLocalIp(edge1EbgpIfaceIp).setPeerAddress(as1PeeringIp).setExportPolicy(edge1EbgpExportPolicy.getName()).build();
RoutingPolicy edge1IbgpExportPolicy = _defaultExportPolicyBuilder.setOwner(edge1).build();
_nb.setRemoteAs(2).setLocalIp(edge1LoopbackIp).setPeerAddress(rrLoopbackIp).setExportPolicy(edge1IbgpExportPolicy.getName()).build();
Configuration rr = _cb.setHostname(RR_NAME).build();
Vrf vRr = _vb.setOwner(rr).build();
_ib.setOwner(rr).setVrf(vRr);
_ib.setAddress(new InterfaceAddress(rrEdge1IfaceIp, EDGE_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(rrLoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(rrEdge2IfaceIp, EDGE_PREFIX_LENGTH)).build();
vRr.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(edge1IbgpIfaceIp).setNetwork(new Prefix(edge1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build(), sb.setNextHopIp(edge2IbgpIfaceIp).setNetwork(new Prefix(edge2LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build()));
BgpProcess rrProc = _pb.setRouterId(rrLoopbackIp).setVrf(vRr).build();
RoutingPolicy rrExportPolicy = _defaultExportPolicyBuilder.setOwner(rr).build();
_nb.setOwner(rr).setVrf(vRr).setBgpProcess(rrProc).setClusterId(rrLoopbackIp.asLong()).setRemoteAs(2).setLocalIp(rrLoopbackIp).setExportPolicy(rrExportPolicy.getName());
if (edge1RouteReflectorClient) {
_nb.setRouteReflectorClient(true);
}
_nb.setPeerAddress(edge1LoopbackIp).build();
_nb.setRouteReflectorClient(false);
if (edge2RouteReflectorClient) {
_nb.setRouteReflectorClient(true);
}
_nb.setPeerAddress(edge2LoopbackIp).build();
_nb.setRouteReflectorClient(false);
Configuration edge2 = _cb.setHostname(EDGE2_NAME).build();
Vrf vEdge2 = _vb.setOwner(edge2).build();
_ib.setOwner(edge2).setVrf(vEdge2);
_ib.setAddress(new InterfaceAddress(edge2EbgpIfaceIp, EDGE_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(edge2LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(edge2IbgpIfaceIp, EDGE_PREFIX_LENGTH)).build();
vEdge2.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(rrEdge2IfaceIp).setNetwork(new Prefix(rrLoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build()));
BgpProcess edge2Proc = _pb.setRouterId(edge2LoopbackIp).setVrf(vEdge2).build();
RoutingPolicy edge2EbgpExportPolicy = _nullExportPolicyBuilder.setOwner(edge2).build();
_nb.setOwner(edge2).setVrf(vEdge2).setBgpProcess(edge2Proc).setClusterId(edge2LoopbackIp.asLong()).setRemoteAs(3).setLocalIp(edge2EbgpIfaceIp).setPeerAddress(as3PeeringIp).setExportPolicy(edge2EbgpExportPolicy.getName()).build();
RoutingPolicy edge2IbgpExportPolicy = _defaultExportPolicyBuilder.setOwner(edge2).build();
_nb.setRemoteAs(2).setLocalIp(edge2LoopbackIp).setPeerAddress(rrLoopbackIp).setExportPolicy(edge2IbgpExportPolicy.getName()).build();
SortedMap<String, Configuration> configurations = new ImmutableSortedMap.Builder<String, Configuration>(String::compareTo).put(edge1.getName(), edge1).put(rr.getName(), rr).put(edge2.getName(), edge2).build();
BdpEngine engine = new BdpEngine(new MockBdpSettings(), new BatfishLogger(BatfishLogger.LEVELSTR_OUTPUT, false), (s, i) -> new AtomicInteger());
Topology topology = CommonUtil.synthesizeTopology(configurations);
BdpDataPlane dp = engine.computeDataPlane(false, configurations, topology, ImmutableSet.of(_ab.setAsPath(AsPath.ofSingletonAsSets(1)).setDstIp(edge1EbgpIfaceIp).setDstNode(edge1.getName()).setNetwork(AS1_PREFIX).setNextHopIp(as1PeeringIp).setOriginatorIp(as1PeeringIp).setSrcIp(as1PeeringIp).setSrcNode("as1Edge").build(), _ab.setAsPath(AsPath.ofSingletonAsSets(3)).setDstIp(edge2EbgpIfaceIp).setDstNode(edge2.getName()).setNetwork(AS3_PREFIX).setNextHopIp(as3PeeringIp).setOriginatorIp(as3PeeringIp).setSrcIp(as3PeeringIp).setSrcNode("as3Edge").build()), new BdpAnswerElement());
return engine.getRoutes(dp);
}
use of org.batfish.datamodel.BgpProcess in project batfish by batfish.
the class VirtualRouterTest method setup.
@Before
public void setup() {
NetworkFactory nf = new NetworkFactory();
_testVirtualRouter = createEmptyVirtualRouter(nf, TEST_VIRTUAL_ROUTER_NAME);
BgpProcess bgpProcess = nf.bgpProcessBuilder().setVrf(_testVirtualRouter._vrf).setRouterId(TEST_SRC_IP).build();
_neighborConfiguration = nf.configurationBuilder().setConfigurationFormat(FORMAT).setHostname(NEIGHBOR_HOST_NAME).build();
_bgpNeighborBuilder = nf.bgpNeighborBuilder().setOwner(_neighborConfiguration).setPeerAddress(TEST_DEST_IP).setLocalIp(TEST_SRC_IP).setLocalAs(TEST_AS1).setBgpProcess(bgpProcess);
_bgpRouteBuilder = new BgpRoute.Builder().setNetwork(TEST_NETWORK).setProtocol(RoutingProtocol.BGP).setOriginType(OriginType.INCOMPLETE).setOriginatorIp(TEST_SRC_IP);
_ipOwners = ImmutableMap.of(TEST_SRC_IP, ImmutableSet.of(TEST_VIRTUAL_ROUTER_NAME));
_routingPolicyBuilder = nf.routingPolicyBuilder().setOwner(_testVirtualRouter._c);
}
use of org.batfish.datamodel.BgpProcess in project batfish by batfish.
the class FlatJuniperGrammarTest method testBgpClusterId.
@Test
public void testBgpClusterId() throws IOException {
String testrigName = "rr";
String configName = "rr";
Ip neighbor1Ip = new Ip("2.2.2.2");
Ip neighbor2Ip = new Ip("4.4.4.4");
List<String> configurationNames = ImmutableList.of(configName);
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
Map<String, Configuration> configurations = batfish.loadConfigurations();
Configuration rr = configurations.get(configName);
BgpProcess proc = rr.getDefaultVrf().getBgpProcess();
BgpNeighbor neighbor1 = proc.getNeighbors().get(new Prefix(neighbor1Ip, Prefix.MAX_PREFIX_LENGTH));
BgpNeighbor neighbor2 = proc.getNeighbors().get(new Prefix(neighbor2Ip, Prefix.MAX_PREFIX_LENGTH));
assertThat(neighbor1, hasClusterId(new Ip("3.3.3.3").asLong()));
assertThat(neighbor2, hasClusterId(new Ip("1.1.1.1").asLong()));
}
Aggregations