Search in sources :

Example 26 with Vrf

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)));
}
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 27 with Vrf

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);
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) BdpAnswerElement(org.batfish.datamodel.answers.BdpAnswerElement) Configuration(org.batfish.datamodel.Configuration) BatfishLogger(org.batfish.common.BatfishLogger) BgpProcess(org.batfish.datamodel.BgpProcess) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Ip(org.batfish.datamodel.Ip) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Vrf(org.batfish.datamodel.Vrf) AbstractRouteMatchers.hasPrefix(org.batfish.datamodel.matchers.AbstractRouteMatchers.hasPrefix) Prefix(org.batfish.datamodel.Prefix) Topology(org.batfish.datamodel.Topology) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 28 with Vrf

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;
}
Also used : Configuration(org.batfish.datamodel.Configuration) Vrf(org.batfish.datamodel.Vrf)

Example 29 with Vrf

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]));
        }
    }
}
Also used : 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) InterfaceMatchers.isOspfPointToPoint(org.batfish.datamodel.matchers.InterfaceMatchers.isOspfPointToPoint) Test(org.junit.Test)

Example 30 with Vrf

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()));
}
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)

Aggregations

Vrf (org.batfish.datamodel.Vrf)43 Configuration (org.batfish.datamodel.Configuration)40 Interface (org.batfish.datamodel.Interface)26 Ip (org.batfish.datamodel.Ip)21 Topology (org.batfish.datamodel.Topology)21 Test (org.junit.Test)19 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)18 Prefix (org.batfish.datamodel.Prefix)16 Edge (org.batfish.datamodel.Edge)12 StaticRoute (org.batfish.datamodel.StaticRoute)12 TreeMap (java.util.TreeMap)10 NetworkFactory (org.batfish.datamodel.NetworkFactory)9 OspfProcess (org.batfish.datamodel.OspfProcess)8 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)7 Set (java.util.Set)7 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)7 IpWildcard (org.batfish.datamodel.IpWildcard)7 SynthesizerInputMatchers.hasArpTrueEdge (org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge)7 ImmutableList (com.google.common.collect.ImmutableList)6 IOException (java.io.IOException)6