use of org.batfish.z3.state.OriginateVrf 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);
}
use of org.batfish.z3.state.OriginateVrf in project batfish by batfish.
the class NodJobChunkingTest method testChunking.
@Test
public void testChunking() {
NodJob nodJob = getNodJob();
Context z3Context = new Context();
SmtInput smtInput = nodJob.computeSmtInput(System.currentTimeMillis(), z3Context);
Map<OriginateVrf, Map<String, Long>> fieldConstraintsByOriginateVrf = nodJob.getOriginateVrfConstraints(z3Context, smtInput);
assertThat(fieldConstraintsByOriginateVrf.entrySet(), hasSize(2));
assertThat(fieldConstraintsByOriginateVrf, hasKey(_originateVrf1));
assertThat(fieldConstraintsByOriginateVrf, hasKey(_originateVrf2));
Map<String, Long> fieldConstraints1 = fieldConstraintsByOriginateVrf.get(_originateVrf1);
Map<String, Long> fieldConstraints2 = fieldConstraintsByOriginateVrf.get(_originateVrf2);
assertThat(fieldConstraints1, hasEntry(OriginateVrfInstrumentation.ORIGINATE_VRF_FIELD_NAME, new Long(0)));
assertThat(fieldConstraints1, hasEntry(BasicHeaderField.SRC_IP.getName(), new Ip("1.0.0.0").asLong()));
assertThat(fieldConstraints2, hasEntry(OriginateVrfInstrumentation.ORIGINATE_VRF_FIELD_NAME, new Long(1)));
assertThat(fieldConstraints2, hasEntry(BasicHeaderField.SRC_IP.getName(), new Ip("2.0.0.0").asLong()));
}
use of org.batfish.z3.state.OriginateVrf in project batfish by batfish.
the class NodJobTest method testNotNatted.
/**
* Test that traffic originating from 3.0.0.1 is not NATed
*/
@Test
public void testNotNatted() {
HeaderSpace headerSpace = new HeaderSpace();
headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.1")));
NodJob nodJob = getNodJob(headerSpace);
Context z3Context = new Context();
SmtInput smtInput = nodJob.computeSmtInput(System.currentTimeMillis(), z3Context);
Map<OriginateVrf, Map<String, Long>> fieldConstraintsByOriginateVrf = nodJob.getOriginateVrfConstraints(z3Context, smtInput);
assertThat(fieldConstraintsByOriginateVrf.entrySet(), hasSize(1));
assertThat(fieldConstraintsByOriginateVrf, hasKey(_originateVrf));
Map<String, Long> fieldConstraints = fieldConstraintsByOriginateVrf.get(_originateVrf);
assertThat(fieldConstraints, hasEntry(OriginateVrfInstrumentation.ORIGINATE_VRF_FIELD_NAME, new Long(0)));
assertThat(smtInput._variablesAsConsts, hasKey("SRC_IP"));
assertThat(fieldConstraints, hasKey(BasicHeaderField.SRC_IP.getName()));
assertThat(fieldConstraints, hasEntry(BasicHeaderField.ORIG_SRC_IP.getName(), new Ip("3.0.0.1").asLong()));
assertThat(fieldConstraints, hasEntry(BasicHeaderField.SRC_IP.getName(), new Ip("3.0.0.1").asLong()));
Set<Flow> flows = nodJob.getFlows(fieldConstraintsByOriginateVrf);
_bdpDataPlanePlugin.processFlows(flows, _dataPlane);
List<FlowTrace> flowTraces = _bdpDataPlanePlugin.getHistoryFlowTraces(_dataPlane);
flowTraces.forEach(trace -> {
assertThat(trace.getNotes(), is("ACCEPTED"));
List<FlowTraceHop> hops = trace.getHops();
assertThat(hops, hasSize(1));
FlowTraceHop hop = hops.get(0);
assertThat(hop.getTransformedFlow(), nullValue());
});
}
use of org.batfish.z3.state.OriginateVrf 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);
}
use of org.batfish.z3.state.OriginateVrf in project batfish by batfish.
the class DefaultTransitionGenerator method visitPostInVrf.
@Override
public void visitPostInVrf(PostInVrf.State postInVrf) {
// CopyOriginateVrf
_input.getEnabledInterfacesByNodeVrf().entrySet().stream().flatMap(enabledInterfacesByNodeEntry -> {
String hostname = enabledInterfacesByNodeEntry.getKey();
return enabledInterfacesByNodeEntry.getValue().entrySet().stream().map(enabledInterfacesByVrfEntry -> {
String vrf = enabledInterfacesByVrfEntry.getKey();
return new BasicRuleStatement(new OriginateVrf(hostname, vrf), new PostInVrf(hostname, vrf));
});
}).forEach(_rules::add);
// PostInInterfaceCorrespondingVrf
_input.getEnabledInterfacesByNodeVrf().entrySet().stream().flatMap(enabledInterfacesByNodeEntry -> {
String hostname = enabledInterfacesByNodeEntry.getKey();
return enabledInterfacesByNodeEntry.getValue().entrySet().stream().flatMap(enabledInterfacesByVrfEntry -> {
String vrfName = enabledInterfacesByVrfEntry.getKey();
return enabledInterfacesByVrfEntry.getValue().stream().map(ifaceName -> new BasicRuleStatement(new PostInInterface(hostname, ifaceName), new PostInVrf(hostname, vrfName)));
});
}).forEach(_rules::add);
}
Aggregations