use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class BdpDataPlanePluginTest method testBgpCompareOriginId.
@Test
public void testBgpCompareOriginId() {
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);
Prefix p = Prefix.ZERO;
BgpRoute.Builder b = new BgpRoute.Builder().setNetwork(p).setProtocol(RoutingProtocol.IBGP);
/*
* Initialize with different originator ips, which should not affect comparison of routes with
* different origin type.
*/
Map<OriginType, List<BgpRoute>> routesByOriginType = new LinkedHashMap<>();
for (OriginType originType : OriginType.values()) {
List<BgpRoute> routes = routesByOriginType.computeIfAbsent(originType, o -> new ArrayList<>());
routes.add(b.setOriginatorIp(Ip.ZERO).setReceivedFromIp(Ip.ZERO).setOriginType(originType).build());
routes.add(b.setOriginatorIp(Ip.MAX).setReceivedFromIp(Ip.MAX).setOriginType(originType).build());
}
/*
* Whenever origin type is different, it should be overriding factor in preference.
*/
for (OriginType o1 : OriginType.values()) {
List<BgpRoute> lhsList = routesByOriginType.get(o1);
for (OriginType o2 : OriginType.values()) {
List<BgpRoute> rhsList = routesByOriginType.get(o2);
for (BgpRoute lhs : lhsList) {
for (BgpRoute rhs : rhsList) {
if (o1.getPreference() > o2.getPreference()) {
assertThat(bbr.comparePreference(lhs, rhs), greaterThan(0));
assertThat(bmr.comparePreference(lhs, rhs), greaterThan(0));
} else if (o1.getPreference() < o2.getPreference()) {
assertThat(bbr.comparePreference(lhs, rhs), lessThan(0));
assertThat(bmr.comparePreference(lhs, rhs), lessThan(0));
}
}
}
}
}
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class BdpDataPlanePluginTest method testBgpNeighborReachability.
@Test
public void testBgpNeighborReachability() throws IOException {
// Only connect one neighbor (n2) to core router
SortedMap<String, Configuration> configs = generateNetworkWithDuplicates();
Batfish batfish = BatfishTestUtils.getBatfish(configs, _folder);
DataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
dataPlanePlugin.computeDataPlane(false);
// N2 has proper neighbor relationship
Collection<BgpNeighbor> n2Neighbors = configs.get("n2").getVrfs().get(DEFAULT_VRF_NAME).getBgpProcess().getNeighbors().values();
assertThat(n2Neighbors, hasSize(1));
assertThat(n2Neighbors.iterator().next().getRemoteBgpNeighbor(), is(notNullValue()));
// N1 does not have a full session established, because it's not reachable
Collection<BgpNeighbor> n1Neighbors = configs.get("n1").getVrfs().get(DEFAULT_VRF_NAME).getBgpProcess().getNeighbors().values();
assertThat(n1Neighbors, hasSize(1));
assertThat(n1Neighbors.iterator().next().getRemoteBgpNeighbor(), is(nullValue()));
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class RouteReflectionTest method generateRoutesTwoReflectors.
private SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> generateRoutesTwoReflectors(boolean useSameClusterIds) {
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 rr1Edge1IfaceIp = new Ip("10.1.12.2");
Ip rr1Rr2IfaceIp = new Ip("10.1.23.2");
Ip rr1LoopbackIp = new Ip("2.0.0.2");
Ip rr2IbgpIfaceIp = new Ip("10.1.23.3");
Ip rr2LoopbackIp = new Ip("2.0.0.3");
StaticRoute.Builder sb = StaticRoute.builder();
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();
vEdge1.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(rr1Edge1IfaceIp).setNetwork(new Prefix(rr1LoopbackIp, 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(rr1LoopbackIp).setExportPolicy(edge1IbgpExportPolicy.getName()).build();
Configuration rr1 = _cb.setHostname(RR1_NAME).build();
Vrf vRr1 = _vb.setOwner(rr1).build();
_ib.setOwner(rr1).setVrf(vRr1);
_ib.setAddress(new InterfaceAddress(rr1Edge1IfaceIp, EDGE_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(rr1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(rr1Rr2IfaceIp, EDGE_PREFIX_LENGTH)).build();
vRr1.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(edge1IbgpIfaceIp).setNetwork(new Prefix(edge1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build(), sb.setNextHopIp(rr2IbgpIfaceIp).setNetwork(new Prefix(rr2LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build()));
BgpProcess rr1Proc = _pb.setRouterId(rr1LoopbackIp).setVrf(vRr1).build();
RoutingPolicy rr1ExportPolicy = _defaultExportPolicyBuilder.setOwner(rr1).build();
_nb.setOwner(rr1).setVrf(vRr1).setBgpProcess(rr1Proc).setClusterId(rr1LoopbackIp.asLong()).setRemoteAs(2).setLocalIp(rr1LoopbackIp).setExportPolicy(rr1ExportPolicy.getName()).setRouteReflectorClient(true).setPeerAddress(edge1LoopbackIp).build();
_nb.setRouteReflectorClient(false).setPeerAddress(rr2LoopbackIp).build();
Configuration rr2 = _cb.setHostname(RR2_NAME).build();
Vrf vRr2 = _vb.setOwner(rr2).build();
_ib.setOwner(rr2).setVrf(vRr2);
_ib.setAddress(new InterfaceAddress(rr2LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build();
_ib.setAddress(new InterfaceAddress(rr2IbgpIfaceIp, EDGE_PREFIX_LENGTH)).build();
BgpProcess rr2Proc = _pb.setRouterId(rr2LoopbackIp).setVrf(vRr2).build();
RoutingPolicy edge2IbgpExportPolicy = _defaultExportPolicyBuilder.setOwner(rr2).build();
vRr2.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(rr1Rr2IfaceIp).setNetwork(new Prefix(rr1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build()));
Ip rr2ClusterIdForRr1 = useSameClusterIds ? rr1LoopbackIp : rr2LoopbackIp;
_nb.setOwner(rr2).setVrf(vRr2).setBgpProcess(rr2Proc).setClusterId(rr2ClusterIdForRr1.asLong()).setLocalIp(rr2LoopbackIp).setPeerAddress(rr1LoopbackIp).setRouteReflectorClient(true).setExportPolicy(edge2IbgpExportPolicy.getName()).build();
SortedMap<String, Configuration> configurations = new ImmutableSortedMap.Builder<String, Configuration>(String::compareTo).put(edge1.getName(), edge1).put(rr1.getName(), rr1).put(rr2.getName(), rr2).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()), new BdpAnswerElement());
return engine.getRoutes(dp);
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class CiscoGrammarTest method testBgpMultipathRelax.
@Test
public void testBgpMultipathRelax() throws IOException {
String testrigName = "bgp-multipath-relax";
List<String> configurationNames = ImmutableList.of("arista_disabled", "arista_enabled", "nxos_disabled", "nxos_enabled");
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
Map<String, Configuration> configurations = batfish.loadConfigurations();
Map<Ip, Set<String>> ipOwners = CommonUtil.computeIpOwners(configurations, true);
CommonUtil.initRemoteBgpNeighbors(configurations, ipOwners);
MultipathEquivalentAsPathMatchMode aristaDisabled = configurations.get("arista_disabled").getDefaultVrf().getBgpProcess().getMultipathEquivalentAsPathMatchMode();
MultipathEquivalentAsPathMatchMode aristaEnabled = configurations.get("arista_enabled").getDefaultVrf().getBgpProcess().getMultipathEquivalentAsPathMatchMode();
MultipathEquivalentAsPathMatchMode nxosDisabled = configurations.get("nxos_disabled").getDefaultVrf().getBgpProcess().getMultipathEquivalentAsPathMatchMode();
MultipathEquivalentAsPathMatchMode nxosEnabled = configurations.get("nxos_enabled").getDefaultVrf().getBgpProcess().getMultipathEquivalentAsPathMatchMode();
assertThat(aristaDisabled, equalTo(MultipathEquivalentAsPathMatchMode.EXACT_PATH));
assertThat(aristaEnabled, equalTo(MultipathEquivalentAsPathMatchMode.PATH_LENGTH));
assertThat(nxosDisabled, equalTo(MultipathEquivalentAsPathMatchMode.EXACT_PATH));
assertThat(nxosEnabled, equalTo(MultipathEquivalentAsPathMatchMode.PATH_LENGTH));
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class CiscoGrammarTest method testParsingRecoveryNoInfiniteLoopDuringAdaptivePredictionAtEof.
@Test
public void testParsingRecoveryNoInfiniteLoopDuringAdaptivePredictionAtEof() throws IOException {
String testrigName = "parsing-recovery";
String hostname = "ios-blankish-file";
List<String> configurationNames = ImmutableList.of(hostname);
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
batfish.getSettings().setDisableUnrecognized(false);
Map<String, Configuration> configurations = batfish.loadConfigurations();
/* Hostname is unknown, but a file should be generated nonetheless */
assertThat(configurations.entrySet(), hasSize(1));
}
Aggregations