Search in sources :

Example 11 with FlowTrace

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

the class CounterExample method buildFlowHistory.

/*
   * Creates a trace-based example of what happens
   * to a packet (e.g., why it is not reachable).
   */
FlowHistory buildFlowHistory(String testrigName, Collection<String> sourceRouters, Encoder enc, Map<String, Boolean> reach) {
    FlowHistory fh = new FlowHistory();
    for (String source : sourceRouters) {
        Boolean sourceVar = reach.get(source);
        if (!sourceVar) {
            Tuple<Flow, FlowTrace> tup = buildFlowTrace(enc, source);
            SortedSet<Edge> failedLinks = buildFailedLinks(enc);
            SortedSet<BgpAdvertisement> envRoutes = buildEnvRoutingTable(enc);
            Environment baseEnv = new Environment("BASE", testrigName, failedLinks, null, null, null, null, envRoutes);
            fh.addFlowTrace(tup.getFirst(), "BASE", baseEnv, tup.getSecond());
        }
    }
    return fh;
}
Also used : BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) FlowHistory(org.batfish.datamodel.FlowHistory) FlowTrace(org.batfish.datamodel.FlowTrace) Environment(org.batfish.datamodel.pojo.Environment) Edge(org.batfish.datamodel.Edge) GraphEdge(org.batfish.symbolic.GraphEdge) Flow(org.batfish.datamodel.Flow)

Example 12 with FlowTrace

use of org.batfish.datamodel.FlowTrace 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());
    });
}
Also used : Context(com.microsoft.z3.Context) Ip(org.batfish.datamodel.Ip) HeaderSpace(org.batfish.datamodel.HeaderSpace) OriginateVrf(org.batfish.z3.state.OriginateVrf) Flow(org.batfish.datamodel.Flow) IpWildcard(org.batfish.datamodel.IpWildcard) FlowTraceHop(org.batfish.datamodel.FlowTraceHop) FlowTrace(org.batfish.datamodel.FlowTrace) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Test(org.junit.Test)

Aggregations

FlowTrace (org.batfish.datamodel.FlowTrace)12 Edge (org.batfish.datamodel.Edge)8 Flow (org.batfish.datamodel.Flow)8 FlowTraceHop (org.batfish.datamodel.FlowTraceHop)8 Ip (org.batfish.datamodel.Ip)7 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 SortedMap (java.util.SortedMap)4 TreeSet (java.util.TreeSet)4 Interface (org.batfish.datamodel.Interface)4 NodeInterfacePair (org.batfish.datamodel.collections.NodeInterfacePair)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 SortedSet (java.util.SortedSet)3 TreeMap (java.util.TreeMap)3 BatfishException (org.batfish.common.BatfishException)3 FlowDisposition (org.batfish.datamodel.FlowDisposition)3 IpAccessList (org.batfish.datamodel.IpAccessList)3