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));
}
}
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"));
}
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()));
}
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());
}
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));
}
}
Aggregations