Search in sources :

Example 1 with FibEntry

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

the class PacketPolicyToBddTest method testFibLookupOutgoingInterfaceIsOneOf.

@Test
public void testFibLookupOutgoingInterfaceIsOneOf() {
    String iface1 = "iface1";
    String iface2 = "iface2";
    FibLookupOutgoingInterfaceIsOneOf expr = new FibLookupOutgoingInterfaceIsOneOf(new LiteralVrfName("vrf"), ImmutableList.of(iface1, iface2));
    Prefix prefix1 = Prefix.parse("1.2.3.0/24");
    Prefix prefix2 = Prefix.parse("2.2.3.0/24");
    ConnectedRoute route1 = new ConnectedRoute(prefix1, iface1);
    ConnectedRoute route2 = new ConnectedRoute(prefix2, iface2);
    BDD prefix1Bdd = _bddPacket.getDstIpSpaceToBDD().toBDD(prefix1);
    BDD prefix2Bdd = _bddPacket.getDstIpSpaceToBDD().toBDD(prefix2);
    // empty fib
    {
        Fib fib = MockFib.builder().build();
        IpsRoutedOutInterfaces ipsRoutedOutInterfaces = new IpsRoutedOutInterfaces(fib);
        BoolExprToBdd toBdd = new BoolExprToBdd(_ipAccessListToBdd, ipsRoutedOutInterfaces);
        assertTrue(toBdd.visit(expr).isZero());
    }
    // single fib entry with missing matching Ips
    {
        Fib fib = MockFib.builder().setFibEntries(ImmutableMap.of(Ip.ZERO, ImmutableSet.of(new FibEntry(FibForward.of(Ip.ZERO, iface1), ImmutableList.of(route1))))).build();
        IpsRoutedOutInterfaces ipsRoutedOutInterfaces = new IpsRoutedOutInterfaces(fib);
        BoolExprToBdd toBdd = new BoolExprToBdd(_ipAccessListToBdd, ipsRoutedOutInterfaces);
        assertTrue(toBdd.visit(expr).isZero());
    }
    // single fib entry with matching Ips
    {
        Fib fib = MockFib.builder().setFibEntries(ImmutableMap.of(Ip.ZERO, ImmutableSet.of(new FibEntry(FibForward.of(Ip.ZERO, iface1), ImmutableList.of(route1))))).setMatchingIps(ImmutableMap.of(prefix1, prefix1.toIpSpace())).build();
        IpsRoutedOutInterfaces ipsRoutedOutInterfaces = new IpsRoutedOutInterfaces(fib);
        BoolExprToBdd toBdd = new BoolExprToBdd(_ipAccessListToBdd, ipsRoutedOutInterfaces);
        assertEquals(prefix1Bdd, toBdd.visit(expr));
    }
    // two fib entries
    {
        Fib fib = MockFib.builder().setFibEntries(ImmutableMap.of(Ip.ZERO, ImmutableSet.of(new FibEntry(FibForward.of(Ip.ZERO, iface1), ImmutableList.of(route1)), new FibEntry(FibForward.of(Ip.ZERO, iface2), ImmutableList.of(route2))))).setMatchingIps(ImmutableMap.of(prefix1, prefix1.toIpSpace(), prefix2, prefix2.toIpSpace())).build();
        IpsRoutedOutInterfaces ipsRoutedOutInterfaces = new IpsRoutedOutInterfaces(fib);
        BoolExprToBdd toBdd = new BoolExprToBdd(_ipAccessListToBdd, ipsRoutedOutInterfaces);
        assertEquals(prefix1Bdd.or(prefix2Bdd), toBdd.visit(expr));
    }
}
Also used : ConnectedRoute(org.batfish.datamodel.ConnectedRoute) BoolExprToBdd(org.batfish.bddreachability.PacketPolicyToBdd.BoolExprToBdd) BDD(net.sf.javabdd.BDD) IpSpaceToBDD(org.batfish.common.bdd.IpSpaceToBDD) LiteralVrfName(org.batfish.datamodel.packet_policy.LiteralVrfName) FibEntry(org.batfish.datamodel.FibEntry) Prefix(org.batfish.datamodel.Prefix) FibLookupOutgoingInterfaceIsOneOf(org.batfish.datamodel.packet_policy.FibLookupOutgoingInterfaceIsOneOf) MockFib(org.batfish.datamodel.MockFib) Fib(org.batfish.datamodel.Fib) IpsRoutedOutInterfaces(org.batfish.bddreachability.IpsRoutedOutInterfacesFactory.IpsRoutedOutInterfaces) Test(org.junit.Test)

Example 2 with FibEntry

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

the class FlowTracerTest method testBuildRoutingStepFibForward.

@Test
public void testBuildRoutingStepFibForward() {
    Prefix prefix = Prefix.parse("12.12.12.12/30");
    FibForward fibForward = FibForward.of(Ip.parse("1.1.1.1"), "iface1");
    Set<FibEntry> fibEntries = ImmutableSet.of(new FibEntry(fibForward, ImmutableList.of(StaticRoute.testBuilder().setNextHopIp(Ip.parse("2.2.2.2")).setNetwork(prefix).setAdministrativeCost(1).build())));
    RoutingStep routingStep = buildRoutingStep("myvrf", fibForward, fibEntries);
    assertThat(routingStep.getAction(), equalTo(StepAction.FORWARDED));
    assertThat(routingStep.getDetail().getVrf(), equalTo("myvrf"));
    assertThat(routingStep.getDetail().getRoutes(), equalTo(ImmutableList.of(new RouteInfo(RoutingProtocol.STATIC, prefix, NextHopIp.of(Ip.parse("2.2.2.2")), 1, 0))));
    assertThat(routingStep.getDetail().getArpIp(), equalTo(Ip.parse("1.1.1.1")));
    assertThat(routingStep.getDetail().getOutputInterface(), equalTo("iface1"));
}
Also used : FibForward(org.batfish.datamodel.FibForward) FibEntry(org.batfish.datamodel.FibEntry) Prefix(org.batfish.datamodel.Prefix) RoutingStep(org.batfish.datamodel.flow.RoutingStep) FlowTracer.buildRoutingStep(org.batfish.dataplane.traceroute.FlowTracer.buildRoutingStep) RouteInfo(org.batfish.datamodel.flow.RouteInfo) Test(org.junit.Test)

Example 3 with FibEntry

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

the class FlowTracerTest method testFibLookupForwarded.

@Test
public void testFibLookupForwarded() {
    NetworkFactory nf = new NetworkFactory();
    Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build();
    String hostname = c.getHostname();
    Vrf.Builder vb = nf.vrfBuilder().setOwner(c);
    Vrf srcVrf = vb.build();
    nf.interfaceBuilder().setName("iface1").setAddress(ConcreteInterfaceAddress.parse("123.12.1.12/24")).setVrf(srcVrf).setOwner(c).build();
    String srcVrfName = srcVrf.getName();
    Flow flow = Flow.builder().setDstIp(Ip.parse("1.1.1.1")).setIngressNode(c.getHostname()).setIngressVrf(srcVrfName).build();
    Ip dstIp = flow.getDstIp();
    ImmutableList.Builder<TraceAndReverseFlow> traces = ImmutableList.builder();
    Ip finalNhip = Ip.parse("12.12.12.12");
    String finalNhif = "iface1";
    Fib srcFib = MockFib.builder().setFibEntries(ImmutableMap.of(dstIp, ImmutableSet.of(new FibEntry(FibForward.of(finalNhip, finalNhif), ImmutableList.of(StaticRoute.testBuilder().setAdmin(1).setNetwork(Prefix.ZERO).setNextHopIp(Ip.parse("1.2.3.4")).build())), new FibEntry(FibForward.of(finalNhip, finalNhif), ImmutableList.of(StaticRoute.testBuilder().setAdmin(1).setNetwork(Prefix.ZERO).setNextHopIp(Ip.parse("2.3.4.5")).build()))))).build();
    ImmutableMap<String, Configuration> configs = ImmutableMap.of(c.getHostname(), c);
    TracerouteEngineImplContext ctxt = new TracerouteEngineImplContext(MockDataPlane.builder().setForwardingAnalysis(MockForwardingAnalysis.withDeliveredToSubnetIps(c.getHostname(), srcVrf.getName(), "iface1", dstIp.toIpSpace())).build(), Topology.EMPTY, ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of(hostname, ImmutableMap.of(srcVrfName, srcFib)), false, configs);
    FlowTracer flowTracer = initialFlowTracer(ctxt, hostname, null, flow, traces::add);
    flowTracer.fibLookup(dstIp, hostname, srcVrfName, srcFib);
    List<TraceAndReverseFlow> finalTraces = traces.build();
    assertThat(traces.build(), contains(hasTrace(hasDisposition(DELIVERED_TO_SUBNET))));
    assertThat(finalTraces.get(0).getTrace().getHops(), hasSize(1));
    Hop hop = finalTraces.get(0).getTrace().getHops().get(0);
    assertThat(hop.getSteps().get(0), instanceOf(RoutingStep.class));
    RoutingStep routingStep = (RoutingStep) hop.getSteps().get(0);
    assertThat(routingStep.getAction(), equalTo(StepAction.FORWARDED));
    assertThat(routingStep.getDetail(), equalTo(RoutingStepDetail.builder().setVrf(srcVrfName).setForwardingDetail(ForwardedOutInterface.of(finalNhif, finalNhip)).setOutputInterface(finalNhif).setArpIp(finalNhip).setRoutes(ImmutableList.of(new RouteInfo(RoutingProtocol.STATIC, Prefix.ZERO, NextHopIp.of(Ip.parse("1.2.3.4")), 1, 0), new RouteInfo(RoutingProtocol.STATIC, Prefix.ZERO, NextHopIp.of(Ip.parse("2.3.4.5")), 1, 0))).build()));
}
Also used : Configuration(org.batfish.datamodel.Configuration) ImmutableList(com.google.common.collect.ImmutableList) NextHopIp(org.batfish.datamodel.route.nh.NextHopIp) TransformationStep.assignDestinationIp(org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp) Ip(org.batfish.datamodel.Ip) FibEntry(org.batfish.datamodel.FibEntry) Hop(org.batfish.datamodel.flow.Hop) FibNextVrf(org.batfish.datamodel.FibNextVrf) Vrf(org.batfish.datamodel.Vrf) RoutingStep(org.batfish.datamodel.flow.RoutingStep) FlowTracer.buildRoutingStep(org.batfish.dataplane.traceroute.FlowTracer.buildRoutingStep) Flow(org.batfish.datamodel.Flow) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) FlowTracer.matchSessionReturnFlow(org.batfish.dataplane.traceroute.FlowTracer.matchSessionReturnFlow) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) NetworkFactory(org.batfish.datamodel.NetworkFactory) RouteInfo(org.batfish.datamodel.flow.RouteInfo) FlowTracer.initialFlowTracer(org.batfish.dataplane.traceroute.FlowTracer.initialFlowTracer) Fib(org.batfish.datamodel.Fib) MockFib(org.batfish.datamodel.MockFib) Test(org.junit.Test)

Example 4 with FibEntry

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

the class FlowTracerTest method testBuildRoutingStepFibNextVrf.

@Test
public void testBuildRoutingStepFibNextVrf() {
    Prefix prefix = Prefix.parse("12.12.12.12/30");
    FibNextVrf fibNextVrf = FibNextVrf.of("iface1");
    Set<FibEntry> fibEntries = ImmutableSet.of(new FibEntry(fibNextVrf, ImmutableList.of(StaticRoute.testBuilder().setNextHopIp(Ip.parse("2.2.2.2")).setNetwork(prefix).setAdministrativeCost(1).build())));
    RoutingStep routingStep = buildRoutingStep("vrf", fibNextVrf, fibEntries);
    assertThat(routingStep.getAction(), equalTo(StepAction.FORWARDED_TO_NEXT_VRF));
    assertThat(routingStep.getDetail().getVrf(), equalTo("vrf"));
    assertThat(routingStep.getDetail().getRoutes(), equalTo(ImmutableList.of(new RouteInfo(RoutingProtocol.STATIC, prefix, NextHopIp.of(Ip.parse("2.2.2.2")), 1, 0))));
    assertThat(routingStep.getDetail().getArpIp(), nullValue());
    assertThat(routingStep.getDetail().getOutputInterface(), nullValue());
}
Also used : FibNextVrf(org.batfish.datamodel.FibNextVrf) FibEntry(org.batfish.datamodel.FibEntry) Prefix(org.batfish.datamodel.Prefix) RoutingStep(org.batfish.datamodel.flow.RoutingStep) FlowTracer.buildRoutingStep(org.batfish.dataplane.traceroute.FlowTracer.buildRoutingStep) RouteInfo(org.batfish.datamodel.flow.RouteInfo) Test(org.junit.Test)

Example 5 with FibEntry

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

the class FlowTracerTest method testSessionSetupForIngressInterfaces.

@Test
public void testSessionSetupForIngressInterfaces() {
    /*
     * Test that sessions are set up correctly according to egress interface's
     * FirewallSessionInterfaceInfo, which controls whether sessions can be set up by flows from a
     * given source interface and whether they can be set up by flows originating from the device.
     */
    NetworkFactory nf = new NetworkFactory();
    Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build();
    Vrf vrf = nf.vrfBuilder().setOwner(c).build();
    Interface.Builder ifaceBuilder = nf.interfaceBuilder().setOwner(c).setVrf(vrf);
    Interface eth1 = ifaceBuilder.setName("eth1").build();
    Interface eth2 = ifaceBuilder.setName("eth2").build();
    Interface eth3 = ifaceBuilder.setName("eth3").build();
    // Make a TCP flow with dst IP 1.1.1.1 (must set protocol for sessions to be set up).
    // Create traceroute context where that IP will be forwarded out eth3.
    Ip dstIp = Ip.parse("1.1.1.1");
    Flow.Builder flowBuilder = Flow.builder().setIngressNode(c.getHostname()).setIpProtocol(IpProtocol.TCP).setSrcPort(22).setDstPort(22).setDstIp(dstIp);
    StaticRoute route = StaticRoute.testBuilder().setAdmin(1).setNetwork(dstIp.toPrefix()).setNextHopInterface(eth3.getName()).build();
    DataPlane mockDataPlane = MockDataPlane.builder().setForwardingAnalysis(MockForwardingAnalysis.withDeliveredToSubnetIps(c.getHostname(), vrf.getName(), eth3.getName(), dstIp.toIpSpace())).build();
    Fib fib = MockFib.builder().setFibEntries(ImmutableMap.of(dstIp, ImmutableSet.of(new FibEntry(FibForward.of(dstIp, eth3.getName()), ImmutableList.of(route))))).build();
    TracerouteEngineImplContext ctxt = new TracerouteEngineImplContext(mockDataPlane, Topology.EMPTY, ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of(c.getHostname(), ImmutableMap.of(vrf.getName(), fib)), false, ImmutableMap.of(c.getHostname(), c));
    // Create test flows
    Flow fromEth1 = flowBuilder.setIngressInterface(eth1.getName()).build();
    Flow fromEth2 = flowBuilder.setIngressInterface(eth2.getName()).build();
    Flow fromDevice = flowBuilder.setIngressInterface(null).setIngressVrf(vrf.getName()).build();
    {
        // eth3 should set up sessions for flows from any ingress interface or originating from device
        eth3.setFirewallSessionInterfaceInfo(new FirewallSessionInterfaceInfo(Action.PRE_NAT_FIB_LOOKUP, ImmutableSet.of(eth3.getName()), null, null, null));
        assertTrue(setsUpNewSession(c, vrf.getName(), eth1.getName(), fromEth1, ctxt));
        assertTrue(setsUpNewSession(c, vrf.getName(), eth2.getName(), fromEth2, ctxt));
        assertTrue(setsUpNewSession(c, vrf.getName(), null, fromDevice, ctxt));
    }
    {
        // eth3 should set up sessions for flows from eth1 only
        eth3.setFirewallSessionInterfaceInfo(new FirewallSessionInterfaceInfo(Action.PRE_NAT_FIB_LOOKUP, ImmutableSet.of(eth3.getName()), ImmutableSet.of(eth1.getName()), null, null));
        assertTrue(setsUpNewSession(c, vrf.getName(), eth1.getName(), fromEth1, ctxt));
        assertFalse(setsUpNewSession(c, vrf.getName(), eth2.getName(), fromEth2, ctxt));
        assertFalse(setsUpNewSession(c, vrf.getName(), null, fromDevice, ctxt));
    }
    {
        // eth3 should set up sessions for flows originating from device only
        eth3.setFirewallSessionInterfaceInfo(new FirewallSessionInterfaceInfo(Action.PRE_NAT_FIB_LOOKUP, ImmutableSet.of(eth3.getName()), ImmutableSet.of(SOURCE_ORIGINATING_FROM_DEVICE), null, null));
        assertFalse(setsUpNewSession(c, vrf.getName(), eth1.getName(), fromEth1, ctxt));
        assertFalse(setsUpNewSession(c, vrf.getName(), eth2.getName(), fromEth2, ctxt));
        assertTrue(setsUpNewSession(c, vrf.getName(), null, fromDevice, ctxt));
    }
}
Also used : DataPlane(org.batfish.datamodel.DataPlane) MockDataPlane(org.batfish.datamodel.MockDataPlane) StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) NextHopIp(org.batfish.datamodel.route.nh.NextHopIp) TransformationStep.assignDestinationIp(org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp) Ip(org.batfish.datamodel.Ip) FibEntry(org.batfish.datamodel.FibEntry) FibNextVrf(org.batfish.datamodel.FibNextVrf) Vrf(org.batfish.datamodel.Vrf) FirewallSessionInterfaceInfo(org.batfish.datamodel.FirewallSessionInterfaceInfo) Flow(org.batfish.datamodel.Flow) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) FlowTracer.matchSessionReturnFlow(org.batfish.dataplane.traceroute.FlowTracer.matchSessionReturnFlow) NetworkFactory(org.batfish.datamodel.NetworkFactory) Interface(org.batfish.datamodel.Interface) ForwardedOutInterface(org.batfish.datamodel.flow.ForwardedOutInterface) ForwardOutInterface(org.batfish.datamodel.flow.ForwardOutInterface) Fib(org.batfish.datamodel.Fib) MockFib(org.batfish.datamodel.MockFib) Test(org.junit.Test)

Aggregations

FibEntry (org.batfish.datamodel.FibEntry)18 Test (org.junit.Test)15 Fib (org.batfish.datamodel.Fib)14 Ip (org.batfish.datamodel.Ip)12 RoutingStep (org.batfish.datamodel.flow.RoutingStep)11 FibNextVrf (org.batfish.datamodel.FibNextVrf)10 Flow (org.batfish.datamodel.Flow)10 MockFib (org.batfish.datamodel.MockFib)10 Configuration (org.batfish.datamodel.Configuration)9 TraceAndReverseFlow (org.batfish.datamodel.flow.TraceAndReverseFlow)9 FlowTracer.buildRoutingStep (org.batfish.dataplane.traceroute.FlowTracer.buildRoutingStep)9 NetworkFactory (org.batfish.datamodel.NetworkFactory)8 Hop (org.batfish.datamodel.flow.Hop)8 Vrf (org.batfish.datamodel.Vrf)7 NextHopIp (org.batfish.datamodel.route.nh.NextHopIp)7 TransformationStep.assignDestinationIp (org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp)7 FlowTracer.matchSessionReturnFlow (org.batfish.dataplane.traceroute.FlowTracer.matchSessionReturnFlow)7 ConnectedRoute (org.batfish.datamodel.ConnectedRoute)6 Prefix (org.batfish.datamodel.Prefix)6 StaticRoute (org.batfish.datamodel.StaticRoute)6