Search in sources :

Example 6 with BdpAnswerElement

use of org.batfish.datamodel.answers.BdpAnswerElement 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)

Aggregations

Configuration (org.batfish.datamodel.Configuration)6 Topology (org.batfish.datamodel.Topology)6 BdpAnswerElement (org.batfish.datamodel.answers.BdpAnswerElement)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 BatfishLogger (org.batfish.common.BatfishLogger)5 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)4 Ip (org.batfish.datamodel.Ip)4 BgpProcess (org.batfish.datamodel.BgpProcess)3 Prefix (org.batfish.datamodel.Prefix)3 Vrf (org.batfish.datamodel.Vrf)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 SortedMap (java.util.SortedMap)2 SortedSet (java.util.SortedSet)2 AbstractRoute (org.batfish.datamodel.AbstractRoute)2 BgpAdvertisement (org.batfish.datamodel.BgpAdvertisement)2