Search in sources :

Example 1 with FibNextVrf

use of org.batfish.datamodel.FibNextVrf 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 2 with FibNextVrf

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

the class FlowTracer method buildRoutingStep.

@VisibleForTesting
static RoutingStep buildRoutingStep(String vrf, FibAction fibAction, Set<FibEntry> fibEntries) {
    RoutingStep.Builder routingStepBuilder = RoutingStep.builder();
    List<RouteInfo> routeInfos = fibEntriesToRouteInfos(fibEntries);
    RoutingStepDetail.Builder routingStepDetailBuilder = RoutingStepDetail.builder().setVrf(vrf).setRoutes(routeInfos);
    fibAction.accept(new FibActionVisitor<Void>() {

        @Override
        public Void visitFibForward(FibForward fibForward) {
            assert !routeInfos.isEmpty();
            RouteInfo primaryRouteInfo = routeInfos.get(0);
            if (primaryRouteInfo.getNextHop() instanceof NextHopVtep) {
                NextHopVtep nhVtep = (NextHopVtep) primaryRouteInfo.getNextHop();
                routingStepDetailBuilder.setForwardingDetail(ForwardedIntoVxlanTunnel.of(nhVtep.getVni(), nhVtep.getVtepIp()));
            } else {
                Optional<Ip> maybeResolvedNextHopIp = fibForward.getArpIp();
                if (!maybeResolvedNextHopIp.isPresent()) {
                    routingStepDetailBuilder.setForwardingDetail(ForwardedOutInterface.of(fibForward.getInterfaceName()));
                } else {
                    Ip resolvedNextHopIp = maybeResolvedNextHopIp.get();
                    routingStepDetailBuilder.setForwardingDetail(ForwardedOutInterface.of(fibForward.getInterfaceName(), resolvedNextHopIp)).setArpIp(resolvedNextHopIp);
                }
            }
            routingStepDetailBuilder.setOutputInterface(fibForward.getInterfaceName());
            routingStepBuilder.setAction(FORWARDED);
            return null;
        }

        @Override
        public Void visitFibNextVrf(FibNextVrf fibNextVrf) {
            routingStepDetailBuilder.setForwardingDetail(DelegatedToNextVrf.of(fibNextVrf.getNextVrf()));
            routingStepBuilder.setAction(FORWARDED_TO_NEXT_VRF);
            return null;
        }

        @Override
        public Void visitFibNullRoute(FibNullRoute fibNullRoute) {
            routingStepDetailBuilder.setForwardingDetail(Discarded.instance());
            routingStepBuilder.setAction(NULL_ROUTED);
            return null;
        }
    });
    return routingStepBuilder.setDetail(routingStepDetailBuilder.build()).build();
}
Also used : Optional(java.util.Optional) FibNullRoute(org.batfish.datamodel.FibNullRoute) FibLookupOverrideLookupIp(org.batfish.datamodel.packet_policy.FibLookupOverrideLookupIp) Ip(org.batfish.datamodel.Ip) RoutingStep(org.batfish.datamodel.flow.RoutingStep) FibNextVrf(org.batfish.datamodel.FibNextVrf) FibForward(org.batfish.datamodel.FibForward) RoutingStepDetail(org.batfish.datamodel.flow.RoutingStep.RoutingStepDetail) Builder(org.batfish.datamodel.flow.RoutingStep.Builder) RouteInfo(org.batfish.datamodel.flow.RouteInfo) NextHopVtep(org.batfish.datamodel.route.nh.NextHopVtep) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

FibNextVrf (org.batfish.datamodel.FibNextVrf)2 RouteInfo (org.batfish.datamodel.flow.RouteInfo)2 RoutingStep (org.batfish.datamodel.flow.RoutingStep)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (java.util.Optional)1 FibEntry (org.batfish.datamodel.FibEntry)1 FibForward (org.batfish.datamodel.FibForward)1 FibNullRoute (org.batfish.datamodel.FibNullRoute)1 Ip (org.batfish.datamodel.Ip)1 Prefix (org.batfish.datamodel.Prefix)1 Builder (org.batfish.datamodel.flow.RoutingStep.Builder)1 RoutingStepDetail (org.batfish.datamodel.flow.RoutingStep.RoutingStepDetail)1 FibLookupOverrideLookupIp (org.batfish.datamodel.packet_policy.FibLookupOverrideLookupIp)1 NextHopVtep (org.batfish.datamodel.route.nh.NextHopVtep)1 FlowTracer.buildRoutingStep (org.batfish.dataplane.traceroute.FlowTracer.buildRoutingStep)1 Test (org.junit.Test)1