Search in sources :

Example 11 with NetworkFactory

use of org.batfish.datamodel.NetworkFactory in project batfish by batfish.

the class NodJobChunkingTest method setupConfigs.

private void setupConfigs() {
    _nf = new NetworkFactory();
    Configuration.Builder cb = _nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
    Interface.Builder ib = _nf.interfaceBuilder().setActive(true).setBandwidth(1E9d);
    Vrf.Builder vb = _nf.vrfBuilder();
    _srcNode1 = cb.build();
    _srcNode2 = cb.build();
    _srcVrf1 = vb.setOwner(_srcNode1).build();
    _srcVrf2 = vb.setOwner(_srcNode2).build();
    _originateVrf1 = new OriginateVrf(_srcNode1.getHostname(), _srcVrf1.getName());
    _originateVrf2 = new OriginateVrf(_srcNode2.getHostname(), _srcVrf2.getName());
    _dstNode = cb.build();
    Vrf dstVrf = vb.setOwner(_dstNode).build();
    Prefix p1 = Prefix.parse("1.0.0.0/31");
    ib.setOwner(_srcNode1).setVrf(_srcVrf1).setAddress(new InterfaceAddress(p1.getStartIp(), p1.getPrefixLength())).setOutgoingFilter(mkOutgoingFilter(_srcNode1, p1.getStartIp())).build();
    ib.setOwner(_dstNode).setVrf(dstVrf).setAddress(new InterfaceAddress(p1.getEndIp(), p1.getPrefixLength())).setSourceNats(ImmutableList.of()).build();
    Prefix p2 = Prefix.parse("2.0.0.0/31");
    ib.setOwner(_srcNode2).setVrf(_srcVrf2).setAddress(new InterfaceAddress(p2.getStartIp(), p2.getPrefixLength())).setOutgoingFilter(mkOutgoingFilter(_srcNode2, p2.getStartIp())).build();
    ib.setOwner(_dstNode).setVrf(dstVrf).setAddress(new InterfaceAddress(p2.getEndIp(), p2.getPrefixLength())).setSourceNats(ImmutableList.of()).build();
    // For the destination
    Prefix pDest = Prefix.parse("3.0.0.0/32");
    ib.setOwner(_dstNode).setVrf(dstVrf).setAddress(new InterfaceAddress(pDest.getEndIp(), pDest.getPrefixLength())).build();
    StaticRoute.Builder bld = StaticRoute.builder().setNetwork(pDest);
    _srcVrf1.getStaticRoutes().add(bld.setNextHopIp(p1.getEndIp()).build());
    _srcVrf2.getStaticRoutes().add(bld.setNextHopIp(p2.getEndIp()).build());
    _configs = ImmutableSortedMap.of(_srcNode1.getName(), _srcNode1, _srcNode2.getName(), _srcNode2, _dstNode.getName(), _dstNode);
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) NetworkFactory(org.batfish.datamodel.NetworkFactory) Vrf(org.batfish.datamodel.Vrf) OriginateVrf(org.batfish.z3.state.OriginateVrf) Prefix(org.batfish.datamodel.Prefix) OriginateVrf(org.batfish.z3.state.OriginateVrf) Interface(org.batfish.datamodel.Interface)

Example 12 with NetworkFactory

use of org.batfish.datamodel.NetworkFactory in project batfish by batfish.

the class NodJobTest method setupConfigs.

private void setupConfigs() {
    NetworkFactory nf = new NetworkFactory();
    Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
    Interface.Builder ib = nf.interfaceBuilder().setActive(true).setBandwidth(1E9d);
    IpAccessList.Builder aclb = nf.aclBuilder();
    IpAccessListLine.Builder acllb = IpAccessListLine.builder();
    SourceNat.Builder snb = SourceNat.builder();
    Vrf.Builder vb = nf.vrfBuilder();
    _srcNode = cb.build();
    _dstNode = cb.build();
    _srcVrf = vb.setOwner(_srcNode).build();
    _originateVrf = new OriginateVrf(_srcNode.getHostname(), _srcVrf.getName());
    Vrf dstVrf = vb.setOwner(_dstNode).build();
    Prefix p1 = Prefix.parse("1.0.0.0/31");
    Ip poolIp1 = new Ip("1.0.0.10");
    // apply NAT to all packets
    IpAccessList sourceNat1Acl = aclb.setLines(ImmutableList.of(acllb.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.0/32"))).setAction(LineAction.ACCEPT).build())).setOwner(_srcNode).build();
    SourceNat sourceNat1 = // Would be easier to understand, and Nuno says it will likely be more efficient.
    snb.setPoolIpFirst(poolIp1).setPoolIpLast(poolIp1).setAcl(sourceNat1Acl).build();
    ib.setOwner(_srcNode).setVrf(_srcVrf).setAddress(new InterfaceAddress(p1.getStartIp(), p1.getPrefixLength())).setSourceNats(ImmutableList.of(sourceNat1)).build();
    ib.setOwner(_dstNode).setVrf(dstVrf).setAddress(new InterfaceAddress(p1.getEndIp(), p1.getPrefixLength())).setSourceNats(ImmutableList.of()).build();
    // For the destination
    Prefix pDest = Prefix.parse("2.0.0.0/32");
    ib.setOwner(_dstNode).setVrf(dstVrf).setAddress(new InterfaceAddress(pDest.getEndIp(), pDest.getPrefixLength())).build();
    StaticRoute.Builder bld = StaticRoute.builder().setNetwork(pDest);
    _srcVrf.getStaticRoutes().add(bld.setNextHopIp(p1.getEndIp()).build());
    _configs = ImmutableSortedMap.of(_srcNode.getName(), _srcNode, _dstNode.getName(), _dstNode);
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Ip(org.batfish.datamodel.Ip) Vrf(org.batfish.datamodel.Vrf) OriginateVrf(org.batfish.z3.state.OriginateVrf) Prefix(org.batfish.datamodel.Prefix) OriginateVrf(org.batfish.z3.state.OriginateVrf) SourceNat(org.batfish.datamodel.SourceNat) IpWildcard(org.batfish.datamodel.IpWildcard) NetworkFactory(org.batfish.datamodel.NetworkFactory) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) IpAccessList(org.batfish.datamodel.IpAccessList) Interface(org.batfish.datamodel.Interface)

Example 13 with NetworkFactory

use of org.batfish.datamodel.NetworkFactory in project batfish by batfish.

the class BatfishCompressionTest method diamondNetwork.

/**
 * This network should be compressed from: A --> B --> D, A --> C --> D to A --> {B,C} --> D.
 * i.e., B and C should be merged into one node.
 *
 * @return Configurations for the original (uncompressed) network.
 */
private SortedMap<String, Configuration> diamondNetwork() {
    NetworkFactory nf = new NetworkFactory();
    Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
    Configuration cA = cb.setHostname("A").build();
    Configuration cB = cb.setHostname("B").build();
    Configuration cC = cb.setHostname("C").build();
    Configuration cD = cb.setHostname("D").build();
    Vrf.Builder vb = nf.vrfBuilder().setName(Configuration.DEFAULT_VRF_NAME);
    Vrf vA = vb.setOwner(cA).build();
    Vrf vB = vb.setOwner(cB).build();
    Vrf vC = vb.setOwner(cC).build();
    Vrf vD = vb.setOwner(cD).build();
    Prefix pAB = Prefix.parse("10.12.0.0/31");
    Prefix pAC = Prefix.parse("10.13.0.0/31");
    Prefix pBD = Prefix.parse("10.24.0.0/31");
    Prefix pCD = Prefix.parse("10.34.0.0/31");
    Interface.Builder ib = nf.interfaceBuilder().setActive(true);
    // Add a route from A --> B
    ib.setOwner(cA).setVrf(vA).setAddress(new InterfaceAddress(pAB.getStartIp(), pAB.getPrefixLength())).build();
    // Interface iBA
    ib.setOwner(cB).setVrf(vA).setAddress(new InterfaceAddress(pAB.getEndIp(), pAB.getPrefixLength())).build();
    // Interface iAC
    ib.setOwner(cA).setVrf(vA).setAddress(new InterfaceAddress(pAC.getStartIp(), pAC.getPrefixLength())).build();
    // Interface iCA
    ib.setOwner(cC).setVrf(vC).setAddress(new InterfaceAddress(pAC.getEndIp(), pAC.getPrefixLength())).build();
    // Interface iBD
    ib.setOwner(cB).setVrf(vB).setAddress(new InterfaceAddress(pBD.getStartIp(), pBD.getPrefixLength())).build();
    // Interface iDB
    ib.setOwner(cD).setVrf(vD).setAddress(new InterfaceAddress(pBD.getEndIp(), pBD.getPrefixLength())).build();
    // Interface iCD
    ib.setOwner(cC).setVrf(vC).setAddress(new InterfaceAddress(pCD.getStartIp(), pCD.getPrefixLength())).build();
    // Interface iDC
    ib.setOwner(cD).setVrf(vD).setAddress(new InterfaceAddress(pCD.getEndIp(), pCD.getPrefixLength())).build();
    // For the destination
    Prefix pD = Prefix.parse("4.4.4.4/32");
    // Interface iD
    ib.setOwner(cD).setVrf(vD).setAddress(new InterfaceAddress(pD.getEndIp(), pD.getPrefixLength())).build();
    StaticRoute.Builder bld = StaticRoute.builder().setNetwork(pD);
    vA.getStaticRoutes().add(bld.setNextHopIp(pAB.getEndIp()).build());
    vA.getStaticRoutes().add(bld.setNextHopIp(pAC.getEndIp()).build());
    vB.getStaticRoutes().add(bld.setNextHopIp(pBD.getEndIp()).build());
    vC.getStaticRoutes().add(bld.setNextHopIp(pCD.getEndIp()).build());
    return new TreeMap<>(ImmutableSortedMap.of(cA.getName(), cA, cB.getName(), cB, cC.getName(), cC, cD.getName(), cD));
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) NetworkFactory(org.batfish.datamodel.NetworkFactory) Vrf(org.batfish.datamodel.Vrf) Prefix(org.batfish.datamodel.Prefix) TreeMap(java.util.TreeMap) Interface(org.batfish.datamodel.Interface)

Example 14 with NetworkFactory

use of org.batfish.datamodel.NetworkFactory 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));
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) NetworkFactory(org.batfish.datamodel.NetworkFactory) Vrf(org.batfish.datamodel.Vrf) Prefix(org.batfish.datamodel.Prefix) TreeMap(java.util.TreeMap) Interface(org.batfish.datamodel.Interface)

Example 15 with NetworkFactory

use of org.batfish.datamodel.NetworkFactory 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));
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) NetworkFactory(org.batfish.datamodel.NetworkFactory) Vrf(org.batfish.datamodel.Vrf) Prefix(org.batfish.datamodel.Prefix) TreeMap(java.util.TreeMap) Interface(org.batfish.datamodel.Interface)

Aggregations

NetworkFactory (org.batfish.datamodel.NetworkFactory)15 Configuration (org.batfish.datamodel.Configuration)7 Interface (org.batfish.datamodel.Interface)7 Before (org.junit.Before)7 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)6 StaticRoute (org.batfish.datamodel.StaticRoute)6 Vrf (org.batfish.datamodel.Vrf)6 Prefix (org.batfish.datamodel.Prefix)5 TreeMap (java.util.TreeMap)3 Warnings (org.batfish.common.Warnings)2 Ip (org.batfish.datamodel.Ip)2 OriginateVrf (org.batfish.z3.state.OriginateVrf)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BatfishLogger (org.batfish.common.BatfishLogger)1 BgpProcess (org.batfish.datamodel.BgpProcess)1 BgpRoute (org.batfish.datamodel.BgpRoute)1 IpAccessList (org.batfish.datamodel.IpAccessList)1 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)1 IpWildcard (org.batfish.datamodel.IpWildcard)1 SourceNat (org.batfish.datamodel.SourceNat)1