use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class OspfTest method testOspfNonDefaultVrfAdjacency.
@Test
public void testOspfNonDefaultVrfAdjacency() {
OspfArea.Builder oab = _nf.ospfAreaBuilder().setNumber(1L);
Prefix adjacencyPrefix = Prefix.parse("1.0.0.0/31");
InterfaceAddress i1Address = new InterfaceAddress(adjacencyPrefix.getStartIp(), adjacencyPrefix.getPrefixLength());
InterfaceAddress i2Address = new InterfaceAddress(adjacencyPrefix.getEndIp(), adjacencyPrefix.getPrefixLength());
Configuration c1 = _cb.build();
Vrf v1 = _vb.setOwner(c1).build();
OspfProcess o1 = _opb.setVrf(v1).build();
OspfArea oa1 = oab.setOspfProcess(o1).build();
// Interface in default VRF on c1
_ib.setOwner(c1).setVrf(v1).setAddress(i1Address).setOspfArea(oa1).build();
Configuration c2 = _cb.build();
// default vrf
Vrf v2Default = _vb.setOwner(c2).build();
// default OSPF process
_opb.setVrf(v2Default).build();
Vrf v2Other = _vb.setName("v2Other").build();
OspfProcess o2Other = _opb.setVrf(v2Other).build();
OspfArea oa2 = oab.setOspfProcess(o2Other).build();
// Interface in VRF v2Other on c2
_ib.setOwner(c2).setVrf(v2Other).setAddress(i2Address).setOspfArea(oa2).build();
Map<String, Configuration> configurations = ImmutableMap.of(c1.getName(), c1, c2.getName(), c2);
Map<Ip, Set<String>> ipOwners = CommonUtil.computeIpOwners(configurations, true);
Topology topology = CommonUtil.synthesizeTopology(configurations);
CommonUtil.initRemoteOspfNeighbors(configurations, ipOwners, topology);
IpLink expectedIpEdge1 = new IpLink(i1Address.getIp(), i2Address.getIp());
IpLink expectedIpEdge2 = new IpLink(i2Address.getIp(), i1Address.getIp());
assertThat(o1, hasOspfNeighbors(hasKey(expectedIpEdge1)));
OspfNeighbor on1 = o1.getOspfNeighbors().get(expectedIpEdge1);
assertThat(o2Other, hasOspfNeighbors(hasKey(expectedIpEdge2)));
OspfNeighbor on2 = o2Other.getOspfNeighbors().get(expectedIpEdge2);
assertThat(on1, hasRemoteOspfNeighbor(sameInstance(on2)));
assertThat(on2, hasRemoteOspfNeighbor(sameInstance(on1)));
}
use of org.batfish.datamodel.Vrf 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.Vrf in project batfish by batfish.
the class VirtualRouterTest method createEmptyVirtualRouter.
/**
* Creates an empty {@link VirtualRouter} along with creating owner {@link Configuration} and
* {@link Vrf}
*
* @param nodeName Node name of the owner {@link Configuration}
* @return new instance of {@link VirtualRouter}
*/
private static VirtualRouter createEmptyVirtualRouter(NetworkFactory nf, String nodeName) {
Configuration config = BatfishTestUtils.createTestConfiguration(nodeName, FORMAT, "interface1");
Vrf.Builder vb = nf.vrfBuilder().setName(Configuration.DEFAULT_VRF_NAME);
Vrf vrf = vb.setOwner(config).build();
config.getVrfs().put(TEST_VIRTUAL_ROUTER_NAME, vrf);
VirtualRouter virtualRouter = new VirtualRouter(TEST_VIRTUAL_ROUTER_NAME, config);
virtualRouter.initRibs();
virtualRouter._sentBgpAdvertisements = new LinkedHashSet<>();
return virtualRouter;
}
use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class CiscoGrammarTest method testRfc1583Compatible.
@Test
public void testRfc1583Compatible() throws IOException {
String[] configurationNames = new String[] { "rfc1583Compatible", "rfc1583NoCompatible", "rfc1583Unconfigured" };
Map<String, Configuration> configurations = parseTextConfigs(configurationNames);
Boolean[] expectedResults = new Boolean[] { Boolean.TRUE, Boolean.FALSE, null };
for (int i = 0; i < configurationNames.length; i++) {
Configuration configuration = configurations.get(configurationNames[i]);
assertThat(configuration.getVrfs().size(), equalTo(1));
for (Vrf vrf : configuration.getVrfs().values()) {
assertThat(vrf.getOspfProcess().getRfc1583Compatible(), is(expectedResults[i]));
}
}
}
use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class CiscoGrammarTest method testNxosOspfNonDefaultVrf.
@Test
public void testNxosOspfNonDefaultVrf() throws IOException {
String testrigName = "nxos-ospf";
String hostname = "nxos-ospf-iface-in-vrf";
String ifaceName = "Ethernet1";
String vrfName = "OTHER-VRF";
long areaNum = 1L;
List<String> configurationNames = ImmutableList.of(hostname);
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
Map<String, Configuration> configurations = batfish.loadConfigurations();
/* Ensure bidirectional references between OSPF area and interface */
assertThat(configurations, hasKey(hostname));
Configuration c = configurations.get(hostname);
assertThat(c, hasVrfs(hasKey(vrfName)));
Vrf vrf = c.getVrfs().get(vrfName);
assertThat(vrf, hasOspfProcess(hasAreas(hasKey(areaNum))));
OspfArea area = vrf.getOspfProcess().getAreas().get(areaNum);
assertThat(area, OspfAreaMatchers.hasInterfaces(hasItem(ifaceName)));
assertThat(c, hasInterface(ifaceName, hasVrf(sameInstance(vrf))));
assertThat(c, hasInterface(ifaceName, hasOspfArea(sameInstance(area))));
assertThat(c, hasInterface(ifaceName, isOspfPassive(equalTo(false))));
assertThat(c, hasInterface(ifaceName, isOspfPointToPoint()));
}
Aggregations