use of org.batfish.datamodel.OspfArea 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.OspfArea 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()));
}
use of org.batfish.datamodel.OspfArea in project batfish by batfish.
the class CommonUtil method initRemoteOspfNeighbors.
public static void initRemoteOspfNeighbors(Map<String, Configuration> configurations, Map<Ip, Set<String>> ipOwners, Topology topology) {
for (Entry<String, Configuration> e : configurations.entrySet()) {
String hostname = e.getKey();
Configuration c = e.getValue();
for (Entry<String, Vrf> e2 : c.getVrfs().entrySet()) {
Vrf vrf = e2.getValue();
OspfProcess proc = vrf.getOspfProcess();
if (proc != null) {
proc.setOspfNeighbors(new TreeMap<>());
String vrfName = e2.getKey();
for (Entry<Long, OspfArea> e3 : proc.getAreas().entrySet()) {
long areaNum = e3.getKey();
OspfArea area = e3.getValue();
for (String ifaceName : area.getInterfaces()) {
Interface iface = c.getInterfaces().get(ifaceName);
if (iface.getOspfPassive()) {
continue;
}
SortedSet<Edge> ifaceEdges = topology.getInterfaceEdges().get(new NodeInterfacePair(hostname, ifaceName));
boolean hasNeighbor = false;
Ip localIp = iface.getAddress().getIp();
if (ifaceEdges != null) {
for (Edge edge : ifaceEdges) {
if (edge.getNode1().equals(hostname)) {
String remoteHostname = edge.getNode2();
String remoteIfaceName = edge.getInt2();
Configuration remoteNode = configurations.get(remoteHostname);
Interface remoteIface = remoteNode.getInterfaces().get(remoteIfaceName);
if (remoteIface.getOspfPassive()) {
continue;
}
Vrf remoteVrf = remoteIface.getVrf();
String remoteVrfName = remoteVrf.getName();
OspfProcess remoteProc = remoteVrf.getOspfProcess();
if (remoteProc != null) {
if (remoteProc.getOspfNeighbors() == null) {
remoteProc.setOspfNeighbors(new TreeMap<>());
}
OspfArea remoteArea = remoteProc.getAreas().get(areaNum);
if (remoteArea != null && remoteArea.getInterfaces().contains(remoteIfaceName)) {
Ip remoteIp = remoteIface.getAddress().getIp();
IpLink localKey = new IpLink(localIp, remoteIp);
OspfNeighbor neighbor = proc.getOspfNeighbors().get(localKey);
if (neighbor == null) {
hasNeighbor = true;
// initialize local neighbor
neighbor = new OspfNeighbor(localKey);
neighbor.setArea(areaNum);
neighbor.setVrf(vrfName);
neighbor.setOwner(c);
neighbor.setInterface(iface);
proc.getOspfNeighbors().put(localKey, neighbor);
// initialize remote neighbor
IpLink remoteKey = new IpLink(remoteIp, localIp);
OspfNeighbor remoteNeighbor = new OspfNeighbor(remoteKey);
remoteNeighbor.setArea(areaNum);
remoteNeighbor.setVrf(remoteVrfName);
remoteNeighbor.setOwner(remoteNode);
remoteNeighbor.setInterface(remoteIface);
remoteProc.getOspfNeighbors().put(remoteKey, remoteNeighbor);
// link neighbors
neighbor.setRemoteOspfNeighbor(remoteNeighbor);
remoteNeighbor.setRemoteOspfNeighbor(neighbor);
}
}
}
}
}
}
if (!hasNeighbor) {
IpLink key = new IpLink(localIp, Ip.ZERO);
OspfNeighbor neighbor = new OspfNeighbor(key);
neighbor.setArea(areaNum);
neighbor.setVrf(vrfName);
neighbor.setOwner(c);
neighbor.setInterface(iface);
proc.getOspfNeighbors().put(key, neighbor);
}
}
}
}
}
}
}
Aggregations