use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class BatfishCompressionTest method compressibleNetwork.
/**
* Build a network that can be easily compressed.
*/
private SortedMap<String, Configuration> compressibleNetwork() {
NetworkFactory nf = new NetworkFactory();
Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
_compressedNode1 = cb.build();
_compressedNode2 = cb.build();
_compressedNode3 = cb.build();
Vrf.Builder vb = nf.vrfBuilder().setName(Configuration.DEFAULT_VRF_NAME);
Vrf v1 = vb.setOwner(_compressedNode1).build();
Vrf v3 = vb.setOwner(_compressedNode3).build();
// add a vrf to c2 too
vb.setOwner(_compressedNode2).build();
Prefix p = Prefix.parse("10.23.0.0/31");
Interface.Builder ib = nf.interfaceBuilder().setActive(true);
ib.setOwner(_compressedNode1).setVrf(v1).setAddress(new InterfaceAddress(p.getStartIp(), p.getPrefixLength())).build();
ib.setOwner(_compressedNode3).setVrf(v3).setAddress(new InterfaceAddress(p.getStartIp(), p.getPrefixLength())).build();
StaticRoute staticRoute = StaticRoute.builder().setNetwork(p).setNextHopIp(p.getEndIp()).build();
v1.getStaticRoutes().add(staticRoute);
v3.getStaticRoutes().add(staticRoute);
return new TreeMap<>(ImmutableSortedMap.of(_compressedNode1.getName(), _compressedNode1, _compressedNode2.getName(), _compressedNode2, _compressedNode3.getName(), _compressedNode3));
}
use of org.batfish.datamodel.Vrf in project batfish by batfish.
the class BatfishCompressionTest method simpleNetwork.
private SortedMap<String, Configuration> simpleNetwork() {
NetworkFactory nf = new NetworkFactory();
Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
Configuration c1 = cb.build();
Configuration c2 = cb.build();
Configuration c3 = cb.build();
Vrf.Builder vb = nf.vrfBuilder().setName(Configuration.DEFAULT_VRF_NAME);
Vrf v1 = vb.setOwner(c1).build();
Vrf v2 = vb.setOwner(c2).build();
Vrf v3 = vb.setOwner(c3).build();
Prefix p12 = Prefix.parse("10.12.0.0/31");
Prefix p23 = Prefix.parse("10.23.0.0/31");
Interface.Builder ib = nf.interfaceBuilder().setActive(true);
ib.setOwner(c1).setVrf(v1).setAddress(new InterfaceAddress(p12.getStartIp(), p12.getPrefixLength())).build();
ib.setOwner(c2).setVrf(v2).setAddress(new InterfaceAddress(p12.getEndIp(), p12.getPrefixLength())).build();
ib.setAddress(new InterfaceAddress(p23.getStartIp(), p23.getPrefixLength())).build();
ib.setOwner(c3).setVrf(v3).setAddress(new InterfaceAddress(p23.getEndIp(), p23.getPrefixLength())).build();
StaticRoute s13 = StaticRoute.builder().setNetwork(p23).setNextHopIp(p12.getEndIp()).build();
v1.getStaticRoutes().add(s13);
StaticRoute s31 = StaticRoute.builder().setNetwork(p12).setNextHopIp(p23.getStartIp()).build();
v3.getStaticRoutes().add(s31);
return new TreeMap<>(ImmutableSortedMap.of(c1.getName(), c1, c2.getName(), c2, c3.getName(), c3));
}
use of org.batfish.datamodel.Vrf 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