Search in sources :

Example 11 with OspfArea

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)));
}
Also used : IpLink(org.batfish.datamodel.IpLink) OspfNeighbor(org.batfish.datamodel.OspfNeighbor) OspfNeighborMatchers.hasRemoteOspfNeighbor(org.batfish.datamodel.matchers.OspfNeighborMatchers.hasRemoteOspfNeighbor) OspfArea(org.batfish.datamodel.OspfArea) SortedSet(java.util.SortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ExplicitPrefixSet(org.batfish.datamodel.routing_policy.expr.ExplicitPrefixSet) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Ip(org.batfish.datamodel.Ip) OspfProcess(org.batfish.datamodel.OspfProcess) AbstractRouteMatchers.hasPrefix(org.batfish.datamodel.matchers.AbstractRouteMatchers.hasPrefix) Prefix(org.batfish.datamodel.Prefix) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) Test(org.junit.Test)

Example 12 with OspfArea

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()));
}
Also used : OspfArea(org.batfish.datamodel.OspfArea) InterfaceMatchers.hasOspfArea(org.batfish.datamodel.matchers.InterfaceMatchers.hasOspfArea) Configuration(org.batfish.datamodel.Configuration) InterfaceMatchers.hasVrf(org.batfish.datamodel.matchers.InterfaceMatchers.hasVrf) Vrf(org.batfish.datamodel.Vrf) ConfigurationMatchers.hasDefaultVrf(org.batfish.datamodel.matchers.ConfigurationMatchers.hasDefaultVrf) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 13 with OspfArea

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : IpLink(org.batfish.datamodel.IpLink) OspfNeighbor(org.batfish.datamodel.OspfNeighbor) OspfArea(org.batfish.datamodel.OspfArea) Configuration(org.batfish.datamodel.Configuration) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Ip(org.batfish.datamodel.Ip) OspfProcess(org.batfish.datamodel.OspfProcess) Vrf(org.batfish.datamodel.Vrf) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface)

Aggregations

OspfArea (org.batfish.datamodel.OspfArea)13 OspfProcess (org.batfish.datamodel.OspfProcess)7 Configuration (org.batfish.datamodel.Configuration)6 Ip (org.batfish.datamodel.Ip)5 Vrf (org.batfish.datamodel.Vrf)5 Prefix (org.batfish.datamodel.Prefix)4 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)4 Interface (org.batfish.datamodel.Interface)3 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)3 ExplicitPrefixSet (org.batfish.datamodel.routing_policy.expr.ExplicitPrefixSet)3 MatchPrefixSet (org.batfish.datamodel.routing_policy.expr.MatchPrefixSet)3 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)2 Edge (org.batfish.datamodel.Edge)2 IpLink (org.batfish.datamodel.IpLink)2 OspfAreaSummary (org.batfish.datamodel.OspfAreaSummary)2 OspfInterAreaRoute (org.batfish.datamodel.OspfInterAreaRoute)2 OspfIntraAreaRoute (org.batfish.datamodel.OspfIntraAreaRoute)2 OspfNeighbor (org.batfish.datamodel.OspfNeighbor)2 PrefixRange (org.batfish.datamodel.PrefixRange)2 Topology (org.batfish.datamodel.Topology)2