Search in sources :

Example 1 with Hop

use of org.batfish.datamodel.flow.Hop in project batfish by batfish.

the class F5BigipStructuredGrammarTest method testSnatBidirectionalTraceroute.

@Test
public void testSnatBidirectionalTraceroute() throws IOException {
    String hostname = "f5_bigip_structured_snat";
    parseConfig(hostname);
    Batfish batfish = getBatfishForConfigurationNames(hostname);
    NetworkSnapshot snapshot = batfish.getSnapshot();
    batfish.computeDataPlane(snapshot);
    // SNAT via snat /Common/snat1
    Flow flow = Flow.builder().setDstIp(Ip.parse("192.0.2.1")).setDstPort(80).setIngressInterface("/Common/vlan1").setIngressNode(hostname).setIpProtocol(IpProtocol.TCP).setSrcIp(Ip.parse("8.8.8.8")).setSrcPort(50000).build();
    SortedMap<Flow, List<TraceAndReverseFlow>> flowTraces = batfish.getTracerouteEngine(snapshot).computeTracesAndReverseFlows(ImmutableSet.of(flow), false);
    List<TraceAndReverseFlow> traces = flowTraces.get(flow);
    assertThat(traces, hasSize(1));
    Flow reverseFlow = traces.get(0).getReverseFlow();
    assertThat(reverseFlow, equalTo(Flow.builder().setSrcIp(Ip.parse("192.0.2.1")).setSrcPort(80).setIngressInterface("/Common/vlan1").setIngressNode(hostname).setIpProtocol(IpProtocol.TCP).setDstIp(Ip.parse("10.200.1.2")).setDstPort(1024).build()));
    Set<FirewallSessionTraceInfo> sessions = traces.get(0).getNewFirewallSessions();
    SortedMap<Flow, List<TraceAndReverseFlow>> reverseFlowTraces = batfish.getTracerouteEngine(snapshot).computeTracesAndReverseFlows(ImmutableSet.of(reverseFlow), sessions, false);
    Optional<TransformationStepDetail> stepDetailOptional = reverseFlowTraces.get(reverseFlow).stream().map(TraceAndReverseFlow::getTrace).map(Trace::getHops).flatMap(Collection::stream).map(Hop::getSteps).flatMap(Collection::stream).map(Step::getDetail).filter(Predicates.instanceOf(TransformationStepDetail.class)).map(TransformationStepDetail.class::cast).filter(d -> d.getTransformationType() == TransformationType.DEST_NAT).findFirst();
    assertTrue("There is a DNAT transformation step.", stepDetailOptional.isPresent());
    TransformationStepDetail detail = stepDetailOptional.get();
    assertThat(detail.getFlowDiffs(), contains(FlowDiff.flowDiff(IpField.DESTINATION, Ip.parse("10.200.1.2"), Ip.parse("8.8.8.8")), FlowDiff.flowDiff(PortField.DESTINATION, 1024, 50000)));
}
Also used : IpField(org.batfish.datamodel.transformation.IpField) BgpNeighborMatchers.hasRemoteAs(org.batfish.datamodel.matchers.BgpNeighborMatchers.hasRemoteAs) BuiltinMonitor(org.batfish.representation.f5_bigip.BuiltinMonitor) PROFILE_CLIENT_SSL(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_CLIENT_SSL) BgpRouteMatchers.hasCommunities(org.batfish.datamodel.matchers.BgpRouteMatchers.hasCommunities) PROFILE_SOCKS(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_SOCKS) PHYSICAL(org.batfish.datamodel.InterfaceType.PHYSICAL) PROFILE_FTP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_FTP) Map(java.util.Map) TransformationStepDetail(org.batfish.datamodel.flow.TransformationStep.TransformationStepDetail) Route6FilterListMatchers(org.batfish.datamodel.matchers.Route6FilterListMatchers) POOL(org.batfish.representation.f5_bigip.F5BigipStructureType.POOL) IpAccessListMatchers(org.batfish.datamodel.matchers.IpAccessListMatchers) ROUTE(org.batfish.representation.f5_bigip.F5BigipStructureType.ROUTE) Dependency(org.batfish.datamodel.Interface.Dependency) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SwitchportMode(org.batfish.datamodel.SwitchportMode) FlowDiff(org.batfish.datamodel.FlowDiff) FlowDiffMatchers.isIpRewrite(org.batfish.datamodel.matchers.FlowDiffMatchers.isIpRewrite) Route(org.batfish.representation.f5_bigip.Route) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) BuiltinPersistence(org.batfish.representation.f5_bigip.BuiltinPersistence) NODE(org.batfish.representation.f5_bigip.F5BigipStructureType.NODE) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) PROFILE_HTML(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_HTML) MapMatchers.hasKeys(org.batfish.datamodel.matchers.MapMatchers.hasKeys) NetworkSnapshot(org.batfish.common.NetworkSnapshot) BgpProcessMatchers.hasMultipathEquivalentAsPathMatchMode(org.batfish.datamodel.matchers.BgpProcessMatchers.hasMultipathEquivalentAsPathMatchMode) BatfishTestUtils.configureBatfishTestSettings(org.batfish.main.BatfishTestUtils.configureBatfishTestSettings) InitInfoAnswerElement(org.batfish.datamodel.answers.InitInfoAnswerElement) InterfaceMatchers.hasInactiveReason(org.batfish.datamodel.matchers.InterfaceMatchers.hasInactiveReason) SerializationUtils(org.apache.commons.lang3.SerializationUtils) PROFILE_DHCPV4(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_DHCPV4) PROFILE_FASTHTTP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_FASTHTTP) PROFILE_TRAFFIC_ACCELERATION(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_TRAFFIC_ACCELERATION) PROFILE_DHCPV6(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_DHCPV6) ParseStatus(org.batfish.datamodel.answers.ParseStatus) VIRTUAL(org.batfish.representation.f5_bigip.F5BigipStructureType.VIRTUAL) PROFILE_GTP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_GTP) IpSpaceMatchers.containsIp(org.batfish.datamodel.matchers.IpSpaceMatchers.containsIp) MONITOR_HTTP(org.batfish.representation.f5_bigip.F5BigipStructureType.MONITOR_HTTP) Matchers.hasSize(org.hamcrest.Matchers.hasSize) PROFILE_DNS(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_DNS) Before(org.junit.Before) PROFILE_HTTP_PROXY_CONNECT(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_HTTP_PROXY_CONNECT) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) InterfaceType(org.batfish.datamodel.InterfaceType) Test(org.junit.Test) F5BigipFamily(org.batfish.datamodel.vendor_family.f5_bigip.F5BigipFamily) PROFILE_HTTP2(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_HTTP2) IpAccessListToBdd(org.batfish.common.bdd.IpAccessListToBdd) FirewallSessionTraceInfo(org.batfish.datamodel.flow.FirewallSessionTraceInfo) PROFILE_ANALYTICS(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_ANALYTICS) Assert.assertNull(org.junit.Assert.assertNull) ConfigurationMatchers.hasInterfaces(org.batfish.datamodel.matchers.ConfigurationMatchers.hasInterfaces) TrafficGroup(org.batfish.representation.f5_bigip.TrafficGroup) PERSISTENCE_SOURCE_ADDR(org.batfish.representation.f5_bigip.F5BigipStructureType.PERSISTENCE_SOURCE_ADDR) InterfaceMatchers.hasAddress(org.batfish.datamodel.matchers.InterfaceMatchers.hasAddress) Resources.readResource(org.batfish.common.util.Resources.readResource) PROFILE_PCP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_PCP) PROFILE_SIP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_SIP) Matchers.hasKey(org.hamcrest.Matchers.hasKey) Trace(org.batfish.datamodel.flow.Trace) PROFILE_DIAMETER(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_DIAMETER) Assert.assertThat(org.junit.Assert.assertThat) InactiveReason(org.batfish.datamodel.InactiveReason) TransformationType(org.batfish.datamodel.flow.TransformationStep.TransformationType) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) TransformationEvaluator.eval(org.batfish.datamodel.transformation.TransformationEvaluator.eval) Prefix6(org.batfish.datamodel.Prefix6) PROFILE_WEB_SECURITY(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_WEB_SECURITY) InterfaceMatchers.hasAllowedVlans(org.batfish.datamodel.matchers.InterfaceMatchers.hasAllowedVlans) NamedPort(org.batfish.datamodel.NamedPort) BuiltinProfile(org.batfish.representation.f5_bigip.BuiltinProfile) PROFILE_REQUEST_LOG(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_REQUEST_LOG) Builtin(org.batfish.representation.f5_bigip.Builtin) RouteFilterListMatchers.permits(org.batfish.datamodel.matchers.RouteFilterListMatchers.permits) MONITOR(org.batfish.representation.f5_bigip.F5BigipStructureType.MONITOR) TransformationResult(org.batfish.datamodel.transformation.TransformationEvaluator.TransformationResult) ImmutableSet(com.google.common.collect.ImmutableSet) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Collection(java.util.Collection) PERSISTENCE_COOKIE(org.batfish.representation.f5_bigip.F5BigipStructureType.PERSISTENCE_COOKIE) IpSpace(org.batfish.datamodel.IpSpace) OriginType(org.batfish.datamodel.OriginType) Settings(org.batfish.config.Settings) KernelRouteMatchers.isKernelRouteThat(org.batfish.datamodel.matchers.KernelRouteMatchers.isKernelRouteThat) PROFILE_MAP_T(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_MAP_T) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ConnectedRoute(org.batfish.datamodel.ConnectedRoute) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) DeviceGroupDevice(org.batfish.representation.f5_bigip.DeviceGroupDevice) Matchers.equalTo(org.hamcrest.Matchers.equalTo) IpAccessListMatchers.accepts(org.batfish.datamodel.matchers.IpAccessListMatchers.accepts) PROFILE_RTSP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_RTSP) Ip(org.batfish.datamodel.Ip) IntStream(java.util.stream.IntStream) DUMMY_SNAPSHOT_1(org.batfish.main.BatfishTestUtils.DUMMY_SNAPSHOT_1) PERSISTENCE(org.batfish.representation.f5_bigip.F5BigipStructureType.PERSISTENCE) IpAccessList(org.batfish.datamodel.IpAccessList) SNAT(org.batfish.representation.f5_bigip.F5BigipStructureType.SNAT) Function(java.util.function.Function) MONITOR_TCP(org.batfish.representation.f5_bigip.F5BigipStructureType.MONITOR_TCP) BDDSourceManager(org.batfish.common.bdd.BDDSourceManager) IpAccessListToBddImpl(org.batfish.common.bdd.IpAccessListToBddImpl) Configuration(org.batfish.datamodel.Configuration) BgpNeighborMatchers.hasLocalAs(org.batfish.datamodel.matchers.BgpNeighborMatchers.hasLocalAs) PROFILE_RESPONSE_ADAPT(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_RESPONSE_ADAPT) Nonnull(javax.annotation.Nonnull) BDDPacket(org.batfish.common.bdd.BDDPacket) FlowDiffMatchers.isPortRewrite(org.batfish.datamodel.matchers.FlowDiffMatchers.isPortRewrite) Matchers.empty(org.hamcrest.Matchers.empty) HaGroup(org.batfish.representation.f5_bigip.HaGroup) VrfMatchers.hasStaticRoutes(org.batfish.datamodel.matchers.VrfMatchers.hasStaticRoutes) UTF_8(java.nio.charset.StandardCharsets.UTF_8) INTERFACE(org.batfish.representation.f5_bigip.F5BigipStructureType.INTERFACE) VLAN_MEMBER_INTERFACE(org.batfish.representation.f5_bigip.F5BigipStructureType.VLAN_MEMBER_INTERFACE) PROFILE_TFTP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_TFTP) Ignore(org.junit.Ignore) PROFILE_WEBSOCKET(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_WEBSOCKET) InterfaceMatchers.hasNativeVlan(org.batfish.datamodel.matchers.InterfaceMatchers.hasNativeVlan) MONITOR_GATEWAY_ICMP(org.batfish.representation.f5_bigip.F5BigipStructureType.MONITOR_GATEWAY_ICMP) Prefix(org.batfish.datamodel.Prefix) Arrays(java.util.Arrays) Hop(org.batfish.datamodel.flow.Hop) InterfaceMatchers.hasBandwidth(org.batfish.datamodel.matchers.InterfaceMatchers.hasBandwidth) Matchers.not(org.hamcrest.Matchers.not) ROUTE_MAP(org.batfish.representation.f5_bigip.F5BigipStructureType.ROUTE_MAP) RouteFilterList(org.batfish.datamodel.RouteFilterList) InterfaceMatchers.hasSwitchPortMode(org.batfish.datamodel.matchers.InterfaceMatchers.hasSwitchPortMode) PROFILE(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE) Flow(org.batfish.datamodel.Flow) PROFILE_STATISTICS(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_STATISTICS) IpAccessListMatchers.rejects(org.batfish.datamodel.matchers.IpAccessListMatchers.rejects) Matchers.nullValue(org.hamcrest.Matchers.nullValue) PROFILE_HTTP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_HTTP) Bgpv4Route(org.batfish.datamodel.Bgpv4Route) PROFILE_PPTP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_PPTP) MacAddress(org.batfish.datamodel.MacAddress) DataPlane(org.batfish.datamodel.DataPlane) PROFILE_SPLITSESSIONCLIENT(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_SPLITSESSIONCLIENT) ConcreteUnicastAddressIp(org.batfish.representation.f5_bigip.ConcreteUnicastAddressIp) Set(java.util.Set) PROFILE_CLIENT_LDAP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_CLIENT_LDAP) InterfaceMatchers.hasInterfaceType(org.batfish.datamodel.matchers.InterfaceMatchers.hasInterfaceType) PROFILE_IPOTHER(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_IPOTHER) IBatfish(org.batfish.common.plugin.IBatfish) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) TRUNK(org.batfish.representation.f5_bigip.F5BigipStructureType.TRUNK) Step(org.batfish.datamodel.flow.Step) PROFILE_NETFLOW(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_NETFLOW) PROFILE_RADIUS(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_RADIUS) Matchers.contains(org.hamcrest.Matchers.contains) Route6FilterList(org.batfish.datamodel.Route6FilterList) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) UnicastAddress(org.batfish.representation.f5_bigip.UnicastAddress) IcmpType(org.batfish.datamodel.IcmpType) RULE(org.batfish.representation.f5_bigip.F5BigipStructureType.RULE) PROFILE_FIX(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_FIX) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) PROFILE_SCTP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_SCTP) PortField(org.batfish.datamodel.transformation.PortField) DATA_GROUP_INTERNAL(org.batfish.representation.f5_bigip.F5BigipStructureType.DATA_GROUP_INTERNAL) Virtual(org.batfish.representation.f5_bigip.Virtual) DataModelMatchers.hasUndefinedReference(org.batfish.datamodel.matchers.DataModelMatchers.hasUndefinedReference) PROFILE_REQUEST_ADAPT(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_REQUEST_ADAPT) VrfMatchers.hasKernelRoutes(org.batfish.datamodel.matchers.VrfMatchers.hasKernelRoutes) PROFILE_XML(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_XML) SELF(org.batfish.representation.f5_bigip.F5BigipStructureType.SELF) AbstractRouteDecoratorMatchers.hasAdministrativeCost(org.batfish.datamodel.matchers.AbstractRouteDecoratorMatchers.hasAdministrativeCost) SilentSyntaxCollection(org.batfish.grammar.silent_syntax.SilentSyntaxCollection) BgpProcessMatchers.hasRouterId(org.batfish.datamodel.matchers.BgpProcessMatchers.hasRouterId) InterfaceMatchers.isActive(org.batfish.datamodel.matchers.InterfaceMatchers.isActive) PROFILE_SERVER_LDAP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_SERVER_LDAP) VLAN(org.batfish.representation.f5_bigip.F5BigipStructureType.VLAN) PROFILE_ICAP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_ICAP) Predicates(com.google.common.base.Predicates) HaGroupPool(org.batfish.representation.f5_bigip.HaGroupPool) VIRTUAL_ADDRESS(org.batfish.representation.f5_bigip.F5BigipStructureType.VIRTUAL_ADDRESS) RouteFilterListMatchers.rejects(org.batfish.datamodel.matchers.RouteFilterListMatchers.rejects) TestrigText(org.batfish.main.TestrigText) EXACT_PATH(org.batfish.datamodel.MultipathEquivalentAsPathMatchMode.EXACT_PATH) StaticRoute(org.batfish.datamodel.StaticRoute) PROFILE_CERTIFICATE_AUTHORITY(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_CERTIFICATE_AUTHORITY) StandardCommunity(org.batfish.datamodel.bgp.community.StandardCommunity) PROFILE_HTTP_COMPRESSION(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_HTTP_COMPRESSION) PROFILE_WEB_ACCELERATION(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_WEB_ACCELERATION) KernelRoute(org.batfish.datamodel.KernelRoute) Direction(org.batfish.datamodel.routing_policy.Environment.Direction) InterfaceMatchers.hasVlan(org.batfish.datamodel.matchers.InterfaceMatchers.hasVlan) VirtualAddress(org.batfish.representation.f5_bigip.VirtualAddress) Result(org.batfish.datamodel.routing_policy.Result) Matchers.hasItem(org.hamcrest.Matchers.hasItem) ConfigurationMatchers.hasInterface(org.batfish.datamodel.matchers.ConfigurationMatchers.hasInterface) MONITOR_LDAP(org.batfish.representation.f5_bigip.F5BigipStructureType.MONITOR_LDAP) VrfMatchers.hasBgpProcess(org.batfish.datamodel.matchers.VrfMatchers.hasBgpProcess) PROFILE_QOE(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_QOE) ManagementIp(org.batfish.representation.f5_bigip.ManagementIp) Environment(org.batfish.datamodel.routing_policy.Environment) AbstractRouteDecoratorMatchers.hasMetric(org.batfish.datamodel.matchers.AbstractRouteDecoratorMatchers.hasMetric) IpProtocol(org.batfish.datamodel.IpProtocol) HaGroupTrunk(org.batfish.representation.f5_bigip.HaGroupTrunk) BGP_NEIGHBOR(org.batfish.representation.f5_bigip.F5BigipStructureType.BGP_NEIGHBOR) PREFIX_LIST(org.batfish.representation.f5_bigip.F5BigipStructureType.PREFIX_LIST) PROFILE_OCSP_STAPLING_PARAMS(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_OCSP_STAPLING_PARAMS) IntegerSpace(org.batfish.datamodel.IntegerSpace) PROFILE_TCP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_TCP) AGGREGATED(org.batfish.datamodel.InterfaceType.AGGREGATED) MONITOR_DNS(org.batfish.representation.f5_bigip.F5BigipStructureType.MONITOR_DNS) InterfaceMatchers.hasDependencies(org.batfish.datamodel.matchers.InterfaceMatchers.hasDependencies) F5BigipStructureType(org.batfish.representation.f5_bigip.F5BigipStructureType) PROFILE_ONE_CONNECT(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_ONE_CONNECT) DeviceGroupType(org.batfish.datamodel.vendor_family.f5_bigip.DeviceGroupType) PROFILE_ILX(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_ILX) PROFILE_MQTT(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_MQTT) BgpNeighborMatchers.hasDescription(org.batfish.datamodel.matchers.BgpNeighborMatchers.hasDescription) PROFILE_SMTPS(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_SMTPS) ImmutableMap(com.google.common.collect.ImmutableMap) PROFILE_REWRITE(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_REWRITE) PROFILE_IPSECALG(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_IPSECALG) BGP_PROCESS(org.batfish.representation.f5_bigip.F5BigipStructureType.BGP_PROCESS) PROFILE_SPLITSESSIONSERVER(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_SPLITSESSIONSERVER) Device(org.batfish.representation.f5_bigip.Device) DataModelMatchers.hasRoute6FilterLists(org.batfish.datamodel.matchers.DataModelMatchers.hasRoute6FilterLists) List(java.util.List) AbstractRouteDecoratorMatchers.hasPrefix(org.batfish.datamodel.matchers.AbstractRouteDecoratorMatchers.hasPrefix) DataModelMatchers.hasNumReferrers(org.batfish.datamodel.matchers.DataModelMatchers.hasNumReferrers) PROFILE_UDP(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_UDP) Warnings(org.batfish.common.Warnings) AGGREGATE(org.batfish.datamodel.Interface.DependencyType.AGGREGATE) InterfaceMatchers.hasSpeed(org.batfish.datamodel.matchers.InterfaceMatchers.hasSpeed) PERSISTENCE_SSL(org.batfish.representation.f5_bigip.F5BigipStructureType.PERSISTENCE_SSL) Optional(java.util.Optional) PROFILE_CLASSIFICATION(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_CLASSIFICATION) F5BigipConfiguration(org.batfish.representation.f5_bigip.F5BigipConfiguration) SortedMap(java.util.SortedMap) MONITOR_HTTPS(org.batfish.representation.f5_bigip.F5BigipStructureType.MONITOR_HTTPS) PROFILE_TCP_ANALYTICS(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_TCP_ANALYTICS) BatfishLogger(org.batfish.common.BatfishLogger) BatfishTestUtils(org.batfish.main.BatfishTestUtils) SNATPOOL(org.batfish.representation.f5_bigip.F5BigipStructureType.SNATPOOL) FilterResult(org.batfish.datamodel.FilterResult) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) Transformation(org.batfish.datamodel.transformation.Transformation) SNAT_TRANSLATION(org.batfish.representation.f5_bigip.F5BigipStructureType.SNAT_TRANSLATION) DeviceGroup(org.batfish.representation.f5_bigip.DeviceGroup) PROFILE_STREAM(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_STREAM) AbstractRoute(org.batfish.datamodel.AbstractRoute) DataModelMatchers.hasRouteFilterLists(org.batfish.datamodel.matchers.DataModelMatchers.hasRouteFilterLists) Batfish(org.batfish.main.Batfish) ExpectedException(org.junit.rules.ExpectedException) InterfaceMatchers.isSwitchport(org.batfish.datamodel.matchers.InterfaceMatchers.isSwitchport) Warning(org.batfish.common.Warning) BgpNeighborMatchers.hasLocalIp(org.batfish.datamodel.matchers.BgpNeighborMatchers.hasLocalIp) Iterator(java.util.Iterator) ConfigurationMatchers.hasDefaultVrf(org.batfish.datamodel.matchers.ConfigurationMatchers.hasDefaultVrf) Matchers.both(org.hamcrest.Matchers.both) AbstractRouteDecoratorMatchers.hasNextHopIp(org.batfish.datamodel.matchers.AbstractRouteDecoratorMatchers.hasNextHopIp) PROFILE_FASTL4(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_FASTL4) BgpProcessMatchers.hasActiveNeighbor(org.batfish.datamodel.matchers.BgpProcessMatchers.hasActiveNeighbor) BgpRouteMatchers.isBgpv4RouteThat(org.batfish.datamodel.matchers.BgpRouteMatchers.isBgpv4RouteThat) Rule(org.junit.Rule) PROFILE_SERVER_SSL(org.batfish.representation.f5_bigip.F5BigipStructureType.PROFILE_SERVER_SSL) TemporaryFolder(org.junit.rules.TemporaryFolder) Hop(org.batfish.datamodel.flow.Hop) NetworkSnapshot(org.batfish.common.NetworkSnapshot) Step(org.batfish.datamodel.flow.Step) FirewallSessionTraceInfo(org.batfish.datamodel.flow.FirewallSessionTraceInfo) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) Flow(org.batfish.datamodel.Flow) Trace(org.batfish.datamodel.flow.Trace) TransformationStepDetail(org.batfish.datamodel.flow.TransformationStep.TransformationStepDetail) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) IpAccessList(org.batfish.datamodel.IpAccessList) RouteFilterList(org.batfish.datamodel.RouteFilterList) Route6FilterList(org.batfish.datamodel.Route6FilterList) List(java.util.List) IBatfish(org.batfish.common.plugin.IBatfish) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 2 with Hop

use of org.batfish.datamodel.flow.Hop in project batfish by batfish.

the class WorkMgrTest method testColumnComparatorTrace.

@Test
public void testColumnComparatorTrace() {
    String col = "col1";
    ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.TRACE, "colDesc");
    Comparator<Row> comparator = _manager.columnComparator(columnMetadata);
    Row r1 = Row.of(col, new Trace(FlowDisposition.ACCEPTED, ImmutableList.of()));
    Row r2 = Row.of(col, new Trace(FlowDisposition.ACCEPTED, ImmutableList.of(new Hop(new Node("a"), ImmutableList.of(LoopStep.INSTANCE)))));
    Row r3 = Row.of(col, new Trace(FlowDisposition.DELIVERED_TO_SUBNET, ImmutableList.of()));
    assertThat(comparator.compare(r1, r2), lessThan(0));
    assertThat(comparator.compare(r1, r3), lessThan(0));
    assertThat(comparator.compare(r2, r3), lessThan(0));
}
Also used : Trace(org.batfish.datamodel.flow.Trace) ColumnMetadata(org.batfish.datamodel.table.ColumnMetadata) Node(org.batfish.datamodel.pojo.Node) Hop(org.batfish.datamodel.flow.Hop) Matchers.containsString(org.hamcrest.Matchers.containsString) WorkMgr.generateFileDateString(org.batfish.coordinator.WorkMgr.generateFileDateString) TableViewRow(org.batfish.datamodel.table.TableViewRow) Row(org.batfish.datamodel.table.Row) Test(org.junit.Test)

Example 3 with Hop

use of org.batfish.datamodel.flow.Hop in project batfish by batfish.

the class BidirectionalReachabilityAnalysisTest method testRequiredTransitNodes_traceroute.

@Test
public void testRequiredTransitNodes_traceroute() throws IOException {
    SortedMap<String, Configuration> configs = makeRequiredTransitNodesNetwork();
    Batfish batfish = getBatfish(configs, temp);
    batfish.computeDataPlane(batfish.getSnapshot());
    BiConsumer<Flow, List<String>> assertTraceHops = (flow, expectedHops) -> {
        List<Trace> traces = batfish.getTracerouteEngine(batfish.getSnapshot()).computeTraces(ImmutableSet.of(flow), false).get(flow);
        assertEquals(1, traces.size());
        Trace trace = traces.get(0);
        assertEquals(FlowDisposition.ACCEPTED, trace.getDisposition());
        List<String> hops = trace.getHops().stream().map(Hop::getNode).map(Node::getName).collect(ImmutableList.toImmutableList());
        assertEquals(expectedHops, hops);
    };
    Builder fb = Flow.builder().setIngressVrf(Configuration.DEFAULT_VRF_NAME);
    // test forward traces
    fb.setIngressNode(RTN_SRC).setSrcIp(RTN_TRANSIT_SRC_IP);
    assertTraceHops.accept(fb.setDstIp(RTN_TRANSIT_DST_IP).build(), ImmutableList.of(RTN_SRC, RTN_TRANSIT, RTN_DST));
    assertTraceHops.accept(fb.setDstIp(RTN_OTHER_DST_IP).build(), ImmutableList.of(RTN_SRC, RTN_OTHER, RTN_DST));
    // test reverse traces
    fb.setIngressNode(RTN_DST).setSrcIp(RTN_TRANSIT_DST_IP);
    assertTraceHops.accept(fb.setDstIp(RTN_TRANSIT_SRC_IP).build(), ImmutableList.of(RTN_DST, RTN_TRANSIT, RTN_SRC));
    assertTraceHops.accept(fb.setDstIp(RTN_OTHER_SRC_IP).build(), ImmutableList.of(RTN_DST, RTN_OTHER, RTN_SRC));
}
Also used : Hop(org.batfish.datamodel.flow.Hop) NULL_ROUTED(org.batfish.datamodel.FlowDisposition.NULL_ROUTED) Interface(org.batfish.datamodel.Interface) BDDFirewallSessionTraceInfoMatchers.hasAction(org.batfish.bddreachability.BDDFirewallSessionTraceInfoMatchers.hasAction) Flow(org.batfish.datamodel.Flow) NodeInterfaceDeliveredToSubnet(org.batfish.symbolic.state.NodeInterfaceDeliveredToSubnet) AclIpSpace(org.batfish.datamodel.AclIpSpace) BDD(net.sf.javabdd.BDD) Map(java.util.Map) AclLineMatchExprs(org.batfish.datamodel.acl.AclLineMatchExprs) NodeInterfaceExitsNetwork(org.batfish.symbolic.state.NodeInterfaceExitsNetwork) ClassRule(org.junit.ClassRule) BDDFirewallSessionTraceInfoMatchers.hasTransformation(org.batfish.bddreachability.BDDFirewallSessionTraceInfoMatchers.hasTransformation) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) DataPlane(org.batfish.datamodel.DataPlane) StateExpr(org.batfish.symbolic.state.StateExpr) Matchers.allOf(org.hamcrest.Matchers.allOf) Set(java.util.Set) NEIGHBOR_UNREACHABLE(org.batfish.datamodel.FlowDisposition.NEIGHBOR_UNREACHABLE) Matchers.contains(org.hamcrest.Matchers.contains) Key(org.batfish.bddreachability.BDDReverseTransformationRangesImpl.Key) EXITS_NETWORK(org.batfish.datamodel.FlowDisposition.EXITS_NETWORK) NodeInterfaceInsufficientInfo(org.batfish.symbolic.state.NodeInterfaceInsufficientInfo) OUTGOING(org.batfish.bddreachability.BDDReverseTransformationRangesImpl.TransformationType.OUTGOING) Transformation.always(org.batfish.datamodel.transformation.Transformation.always) OriginateVrf(org.batfish.symbolic.state.OriginateVrf) BiConsumer(java.util.function.BiConsumer) DELIVERED_TO_SUBNET(org.batfish.datamodel.FlowDisposition.DELIVERED_TO_SUBNET) Transitions.constraint(org.batfish.bddreachability.transition.Transitions.constraint) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ConcreteInterfaceAddress(org.batfish.datamodel.ConcreteInterfaceAddress) ForwardOutInterface(org.batfish.datamodel.flow.ForwardOutInterface) Location(org.batfish.specifier.Location) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) DENIED_IN(org.batfish.datamodel.FlowDisposition.DENIED_IN) FirewallSessionInterfaceInfo(org.batfish.datamodel.FirewallSessionInterfaceInfo) NetworkFactory(org.batfish.datamodel.NetworkFactory) StaticRoute(org.batfish.datamodel.StaticRoute) BDDFirewallSessionTraceInfoMatchers.hasSessionFlows(org.batfish.bddreachability.BDDFirewallSessionTraceInfoMatchers.hasSessionFlows) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) InterfaceType(org.batfish.datamodel.InterfaceType) Test(org.junit.Test) BDDReachabilityAnalysisSessionFactory.computeInitializedSesssions(org.batfish.bddreachability.BDDReachabilityAnalysisSessionFactory.computeInitializedSesssions) Transitions.compose(org.batfish.bddreachability.transition.Transitions.compose) DENIED_OUT(org.batfish.datamodel.FlowDisposition.DENIED_OUT) ACCEPTED(org.batfish.datamodel.FlowDisposition.ACCEPTED) AclIpSpace.difference(org.batfish.datamodel.AclIpSpace.difference) Assert.assertEquals(org.junit.Assert.assertEquals) HeaderSpace(org.batfish.datamodel.HeaderSpace) ExprAclLine(org.batfish.datamodel.ExprAclLine) IpProtocol(org.batfish.datamodel.IpProtocol) NodeInterfaceNeighborUnreachable(org.batfish.symbolic.state.NodeInterfaceNeighborUnreachable) TransformationStep.assignSourceIp(org.batfish.datamodel.transformation.TransformationStep.assignSourceIp) Trace(org.batfish.datamodel.flow.Trace) AclLineMatchExprs.matchDst(org.batfish.datamodel.acl.AclLineMatchExprs.matchDst) Assert.assertThat(org.junit.Assert.assertThat) Builder(org.batfish.datamodel.Flow.Builder) PreInInterface(org.batfish.symbolic.state.PreInInterface) SUCCESS_DISPOSITIONS(org.batfish.datamodel.FlowDisposition.SUCCESS_DISPOSITIONS) Transition(org.batfish.bddreachability.transition.Transition) Vrf(org.batfish.datamodel.Vrf) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) FlowDisposition(org.batfish.datamodel.FlowDisposition) IpSpaceToBDD(org.batfish.common.bdd.IpSpaceToBDD) IpSpace(org.batfish.datamodel.IpSpace) Objects(java.util.Objects) BDDFirewallSessionTraceInfoMatchers.hasIncomingInterfaces(org.batfish.bddreachability.BDDFirewallSessionTraceInfoMatchers.hasIncomingInterfaces) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) BidirectionalReachabilityAnalysis.computeReturnPassQueryConstraints(org.batfish.bddreachability.BidirectionalReachabilityAnalysis.computeReturnPassQueryConstraints) NO_ROUTE(org.batfish.datamodel.FlowDisposition.NO_ROUTE) SortedMap(java.util.SortedMap) Ip(org.batfish.datamodel.Ip) Action(org.batfish.datamodel.FirewallSessionInterfaceInfo.Action) TransitionVisitor(org.batfish.bddreachability.transition.TransitionVisitor) HeaderSpaceToBDD(org.batfish.common.bdd.HeaderSpaceToBDD) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) ForwardingAnalysis(org.batfish.datamodel.ForwardingAnalysis) BeforeClass(org.junit.BeforeClass) OriginateInterfaceLink(org.batfish.symbolic.state.OriginateInterfaceLink) AclLineMatchExprs.match(org.batfish.datamodel.acl.AclLineMatchExprs.match) InterfaceLocation(org.batfish.specifier.InterfaceLocation) IpAccessList(org.batfish.datamodel.IpAccessList) ImmutableList(com.google.common.collect.ImmutableList) FirewallSessionVrfInfo(org.batfish.datamodel.FirewallSessionVrfInfo) TRUE(org.batfish.datamodel.acl.AclLineMatchExprs.TRUE) Configuration(org.batfish.datamodel.Configuration) UniverseIpSpace(org.batfish.datamodel.UniverseIpSpace) Batfish(org.batfish.main.Batfish) INCOMING(org.batfish.bddreachability.BDDReverseTransformationRangesImpl.TransformationType.INCOMING) Nonnull(javax.annotation.Nonnull) BDDPacket(org.batfish.common.bdd.BDDPacket) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Matchers.empty(org.hamcrest.Matchers.empty) IpSpaceAssignment(org.batfish.specifier.IpSpaceAssignment) BidirectionalReachabilityResult(org.batfish.question.bidirectionalreachability.BidirectionalReachabilityResult) Assert.assertNotNull(org.junit.Assert.assertNotNull) InterfaceLinkLocation(org.batfish.specifier.InterfaceLinkLocation) Rule(org.junit.Rule) BatfishTestUtils.getBatfish(org.batfish.main.BatfishTestUtils.getBatfish) Node(org.batfish.datamodel.pojo.Node) VrfAccept(org.batfish.symbolic.state.VrfAccept) INSUFFICIENT_INFO(org.batfish.datamodel.FlowDisposition.INSUFFICIENT_INFO) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) TemporaryFolder(org.junit.rules.TemporaryFolder) Prefix(org.batfish.datamodel.Prefix) Trace(org.batfish.datamodel.flow.Trace) Configuration(org.batfish.datamodel.Configuration) Node(org.batfish.datamodel.pojo.Node) Builder(org.batfish.datamodel.Flow.Builder) List(java.util.List) IpAccessList(org.batfish.datamodel.IpAccessList) ImmutableList(com.google.common.collect.ImmutableList) Batfish(org.batfish.main.Batfish) BatfishTestUtils.getBatfish(org.batfish.main.BatfishTestUtils.getBatfish) Flow(org.batfish.datamodel.Flow) Test(org.junit.Test)

Example 4 with Hop

use of org.batfish.datamodel.flow.Hop in project batfish by batfish.

the class TracerouteEngineImplTest method testTransformationSteps.

@Test
public void testTransformationSteps() throws IOException {
    NetworkFactory nf = new NetworkFactory();
    Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build();
    Vrf vrf = nf.vrfBuilder().setOwner(c).build();
    Ip ip21 = Ip.parse("2.0.0.1");
    Ip ip22 = Ip.parse("2.0.0.2");
    Ip ip33 = Ip.parse("3.0.0.3");
    Ip ip41 = Ip.parse("4.0.0.2");
    Prefix prefix2 = Prefix.parse("2.0.0.0/24");
    Interface.Builder ib = nf.interfaceBuilder().setType(InterfaceType.PHYSICAL).setOwner(c).setVrf(vrf);
    Interface inInterface = ib.setAddress(ConcreteInterfaceAddress.parse("1.0.0.1/24")).setIncomingTransformation(when(matchDst(ip21)).apply(NOOP_DEST_NAT).setOrElse(when(matchDst(prefix2)).apply(assignDestinationIp(ip33, ip33)).build()).build()).build();
    ib.setAddress(ConcreteInterfaceAddress.parse("4.0.0.1/24")).setOutgoingTransformation(when(matchSrc(ip21)).apply(NOOP_SOURCE_NAT).setOrElse(when(matchSrc(prefix2)).apply(assignSourceIp(ip33, ip33)).build()).build()).build();
    Batfish batfish = BatfishTestUtils.getBatfish(ImmutableSortedMap.of(c.getHostname(), c), _tempFolder);
    NetworkSnapshot snapshot = batfish.getSnapshot();
    batfish.computeDataPlane(snapshot);
    // Test flows matched by dest nat rules that permit but don't transform
    Flow flow = builder().setIngressNode(c.getHostname()).setIngressInterface(inInterface.getName()).setSrcIp(ip22).setDstIp(ip21).build();
    List<Trace> traces = computeTraces(batfish, snapshot, flow, false);
    assertThat(traces, hasSize(1));
    Trace trace = traces.get(0);
    assertThat(trace.getDisposition(), equalTo(NO_ROUTE));
    assertThat(trace.getHops(), hasSize(1));
    Hop hop = trace.getHops().get(0);
    assertThat(hop.getSteps(), hasSize(3));
    List<Step<?>> steps = hop.getSteps();
    assertThat(steps.get(1), equalTo(new TransformationStep(new TransformationStepDetail(DEST_NAT, ImmutableSortedSet.of()), StepAction.PERMITTED)));
    // Test flows matched and transformed by dest nat rules
    flow = builder().setIngressNode(c.getHostname()).setIngressInterface(inInterface.getName()).setSrcIp(ip21).setDstIp(ip22).build();
    traces = computeTraces(batfish, snapshot, flow, false);
    assertThat(traces, hasSize(1));
    trace = traces.get(0);
    assertThat(trace.getDisposition(), equalTo(NO_ROUTE));
    assertThat(trace.getHops(), hasSize(1));
    hop = trace.getHops().get(0);
    assertThat(hop.getSteps(), hasSize(3));
    steps = hop.getSteps();
    assertThat(steps.get(1), equalTo(new TransformationStep(new TransformationStepDetail(DEST_NAT, flowDiffs(flow, flow.toBuilder().setDstIp(ip33).build())), StepAction.TRANSFORMED)));
    // Test flows not matched by dest nat rules
    flow = builder().setIngressNode(c.getHostname()).setIngressInterface(inInterface.getName()).setSrcIp(ip21).setDstIp(ip33).build();
    traces = computeTraces(batfish, snapshot, flow, false);
    assertThat(traces, hasSize(1));
    trace = traces.get(0);
    assertThat(trace.getDisposition(), equalTo(NO_ROUTE));
    assertThat(trace.getHops(), hasSize(1));
    hop = trace.getHops().get(0);
    assertThat(hop.getSteps(), hasSize(2));
    // Test flows matched by source nat rules that permit but don't transform
    flow = builder().setIngressNode(c.getHostname()).setIngressInterface(inInterface.getName()).setSrcIp(ip21).setDstIp(ip41).build();
    traces = computeTraces(batfish, snapshot, flow, false);
    assertThat(traces, hasSize(1));
    trace = traces.get(0);
    assertThat(trace.getDisposition(), equalTo(DELIVERED_TO_SUBNET));
    assertThat(trace.getHops(), hasSize(1));
    hop = trace.getHops().get(0);
    assertThat(hop.getSteps(), hasSize(5));
    steps = hop.getSteps();
    // source nat step
    assertThat(steps.get(2), equalTo(new TransformationStep(new TransformationStepDetail(SOURCE_NAT, ImmutableSortedSet.of()), StepAction.PERMITTED)));
    // Test flows matched and transformed by source nat rules
    flow = builder().setIngressNode(c.getHostname()).setIngressInterface(inInterface.getName()).setSrcIp(ip22).setDstIp(ip41).build();
    traces = computeTraces(batfish, snapshot, flow, false);
    assertThat(traces, hasSize(1));
    trace = traces.get(0);
    assertThat(trace.getDisposition(), equalTo(DELIVERED_TO_SUBNET));
    assertThat(trace.getHops(), hasSize(1));
    hop = trace.getHops().get(0);
    assertThat(hop.getSteps(), hasSize(5));
    steps = hop.getSteps();
    // source nat step
    assertThat(steps.get(2), equalTo(new TransformationStep(new TransformationStepDetail(SOURCE_NAT, flowDiffs(flow, flow.toBuilder().setSrcIp(ip33).build())), StepAction.TRANSFORMED)));
    // Test flows that match no source nat rule
    flow = builder().setIngressNode(c.getHostname()).setIngressInterface(inInterface.getName()).setSrcIp(ip33).setDstIp(ip41).build();
    traces = computeTraces(batfish, snapshot, flow, false);
    assertThat(traces, hasSize(1));
    trace = traces.get(0);
    assertThat(trace.getDisposition(), equalTo(DELIVERED_TO_SUBNET));
    assertThat(trace.getHops(), hasSize(1));
    hop = trace.getHops().get(0);
    assertThat(hop.getSteps(), hasSize(4));
}
Also used : Configuration(org.batfish.datamodel.Configuration) TransformationStep.assignDestinationIp(org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp) FlowMatchers.hasSrcIp(org.batfish.datamodel.matchers.FlowMatchers.hasSrcIp) TransformationStep.assignSourceIp(org.batfish.datamodel.transformation.TransformationStep.assignSourceIp) FlowMatchers.hasDstIp(org.batfish.datamodel.matchers.FlowMatchers.hasDstIp) Ip(org.batfish.datamodel.Ip) Hop(org.batfish.datamodel.flow.Hop) NetworkSnapshot(org.batfish.common.NetworkSnapshot) FlowMatchers.hasIngressVrf(org.batfish.datamodel.matchers.FlowMatchers.hasIngressVrf) Vrf(org.batfish.datamodel.Vrf) Prefix(org.batfish.datamodel.Prefix) MatchSessionStep(org.batfish.datamodel.flow.MatchSessionStep) DeliveredStep(org.batfish.datamodel.flow.DeliveredStep) RoutingStep(org.batfish.datamodel.flow.RoutingStep) Step(org.batfish.datamodel.flow.Step) ExitOutputIfaceStep(org.batfish.datamodel.flow.ExitOutputIfaceStep) EnterInputIfaceStep(org.batfish.datamodel.flow.EnterInputIfaceStep) SetupSessionStep(org.batfish.datamodel.flow.SetupSessionStep) ArpErrorStep(org.batfish.datamodel.flow.ArpErrorStep) TransformationStep(org.batfish.datamodel.flow.TransformationStep) OriginateStep(org.batfish.datamodel.flow.OriginateStep) FilterStep(org.batfish.datamodel.flow.FilterStep) Flow(org.batfish.datamodel.Flow) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) FlowTracer.matchSessionReturnFlow(org.batfish.dataplane.traceroute.FlowTracer.matchSessionReturnFlow) TraceAndReverseFlowMatchers.hasReverseFlow(org.batfish.datamodel.matchers.TraceAndReverseFlowMatchers.hasReverseFlow) Trace(org.batfish.datamodel.flow.Trace) TraceAndReverseFlowMatchers.hasTrace(org.batfish.datamodel.matchers.TraceAndReverseFlowMatchers.hasTrace) TransformationStepDetail(org.batfish.datamodel.flow.TransformationStep.TransformationStepDetail) TransformationStep(org.batfish.datamodel.flow.TransformationStep) NetworkFactory(org.batfish.datamodel.NetworkFactory) Interface(org.batfish.datamodel.Interface) FlowMatchers.hasIngressInterface(org.batfish.datamodel.matchers.FlowMatchers.hasIngressInterface) ForwardOutInterface(org.batfish.datamodel.flow.ForwardOutInterface) MatchSrcInterface(org.batfish.datamodel.acl.MatchSrcInterface) NextHopInterface(org.batfish.datamodel.route.nh.NextHopInterface) IBatfish(org.batfish.common.plugin.IBatfish) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 5 with Hop

use of org.batfish.datamodel.flow.Hop in project batfish by batfish.

the class TracerouteEngineImplTest method testBidirectionalTracerouteWithDeliveredStep.

@Test
public void testBidirectionalTracerouteWithDeliveredStep() throws IOException {
    // Construct network
    NetworkFactory nf = new NetworkFactory();
    Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
    Configuration c1 = cb.setHostname("c1").build();
    Vrf vrf1 = nf.vrfBuilder().setOwner(c1).build();
    nf.interfaceBuilder().setType(InterfaceType.PHYSICAL).setName("c1_out").setOwner(c1).setVrf(vrf1).setAddress(ConcreteInterfaceAddress.parse("10.0.0.1/24")).build();
    String c1ToFw = "c1_to_fw";
    nf.interfaceBuilder().setType(InterfaceType.PHYSICAL).setName(c1ToFw).setOwner(c1).setVrf(vrf1).setAddress(ConcreteInterfaceAddress.parse("1.1.1.1/24")).build();
    vrf1.getStaticRoutes().add(StaticRoute.testBuilder().setNetwork(Prefix.parse("20.0.0.2/32")).setNextHopInterface(c1ToFw).setNextHopIp(Ip.parse("1.1.1.2")).setAdministrativeCost(1).build());
    Configuration fw = cb.setConfigurationFormat(ConfigurationFormat.CISCO_ASA).setHostname("fw").build();
    Vrf fwVrf = nf.vrfBuilder().setOwner(fw).build();
    String fwToC1Name = "fw_to_c1";
    nf.interfaceBuilder().setType(InterfaceType.PHYSICAL).setName(fwToC1Name).setOwner(fw).setVrf(fwVrf).setAddress(ConcreteInterfaceAddress.parse("1.1.1.2/24")).build();
    // set up another interface with session
    String fwOutName = "fwOut";
    nf.interfaceBuilder().setType(InterfaceType.PHYSICAL).setName(fwOutName).setOwner(fw).setVrf(fwVrf).setAddress(ConcreteInterfaceAddress.parse("20.0.0.1/24")).setFirewallSessionInterfaceInfo(new FirewallSessionInterfaceInfo(Action.POST_NAT_FIB_LOOKUP, ImmutableSet.of(fwOutName), null, null)).build();
    // set up a static route for the reverse flow
    fwVrf.getStaticRoutes().add(StaticRoute.testBuilder().setNetwork(Prefix.parse("10.0.0.0/24")).setAdministrativeCost(1).setNextHopIp(Ip.parse("1.1.1.1")).build());
    // Compute data plane
    SortedMap<String, Configuration> configs = ImmutableSortedMap.of(c1.getHostname(), c1, fw.getHostname(), fw);
    Batfish batfish = BatfishTestUtils.getBatfish(configs, _tempFolder);
    NetworkSnapshot snapshot = batfish.getSnapshot();
    batfish.computeDataPlane(snapshot);
    TracerouteEngine tracerouteEngine = batfish.getTracerouteEngine(snapshot);
    Flow flow = builder().setIngressNode(c1.getHostname()).setIngressVrf(vrf1.getName()).setSrcIp(Ip.parse("10.0.0.2")).setDstIp(Ip.parse("20.0.0.2")).setIpProtocol(IpProtocol.TCP).setSrcPort(12345).setDstPort(12346).build();
    List<TraceAndReverseFlow> forwardTracerouteResult = tracerouteEngine.computeTracesAndReverseFlows(ImmutableSet.of(flow), false).get(flow);
    assertThat(forwardTracerouteResult, hasSize(1));
    Flow reverseFlow = forwardTracerouteResult.get(0).getReverseFlow();
    assertNotNull(reverseFlow);
    Set<FirewallSessionTraceInfo> newSessions = forwardTracerouteResult.get(0).getNewFirewallSessions();
    // reverse direction
    List<TraceAndReverseFlow> reverseResult = tracerouteEngine.computeTracesAndReverseFlows(ImmutableSet.of(reverseFlow), newSessions, false).get(reverseFlow);
    assertThat(reverseResult, hasSize(1));
    List<Hop> reverseHops = reverseResult.get(0).getTrace().getHops();
    assertThat(reverseHops, hasSize(2));
    assertThat(reverseHops.get(0).getSteps(), hasSize(4));
    assertTrue(reverseHops.get(0).getSteps().get(0) instanceof EnterInputIfaceStep);
    assertTrue(reverseHops.get(0).getSteps().get(1) instanceof MatchSessionStep);
    assertTrue(reverseHops.get(0).getSteps().get(2) instanceof RoutingStep);
    assertTrue(reverseHops.get(0).getSteps().get(3) instanceof ExitOutputIfaceStep);
    assertThat(reverseHops.get(1).getSteps(), hasSize(4));
    assertTrue(reverseHops.get(1).getSteps().get(0) instanceof EnterInputIfaceStep);
    assertTrue(reverseHops.get(1).getSteps().get(1) instanceof RoutingStep);
    assertTrue(reverseHops.get(1).getSteps().get(2) instanceof ExitOutputIfaceStep);
    assertTrue(reverseHops.get(1).getSteps().get(3) instanceof DeliveredStep);
}
Also used : Configuration(org.batfish.datamodel.Configuration) EnterInputIfaceStep(org.batfish.datamodel.flow.EnterInputIfaceStep) TracerouteEngine(org.batfish.common.plugin.TracerouteEngine) Hop(org.batfish.datamodel.flow.Hop) NetworkSnapshot(org.batfish.common.NetworkSnapshot) FlowMatchers.hasIngressVrf(org.batfish.datamodel.matchers.FlowMatchers.hasIngressVrf) Vrf(org.batfish.datamodel.Vrf) RoutingStep(org.batfish.datamodel.flow.RoutingStep) FirewallSessionInterfaceInfo(org.batfish.datamodel.FirewallSessionInterfaceInfo) FirewallSessionTraceInfo(org.batfish.datamodel.flow.FirewallSessionTraceInfo) Flow(org.batfish.datamodel.Flow) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) FlowTracer.matchSessionReturnFlow(org.batfish.dataplane.traceroute.FlowTracer.matchSessionReturnFlow) TraceAndReverseFlowMatchers.hasReverseFlow(org.batfish.datamodel.matchers.TraceAndReverseFlowMatchers.hasReverseFlow) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) MatchSessionStep(org.batfish.datamodel.flow.MatchSessionStep) DeliveredStep(org.batfish.datamodel.flow.DeliveredStep) NetworkFactory(org.batfish.datamodel.NetworkFactory) ExitOutputIfaceStep(org.batfish.datamodel.flow.ExitOutputIfaceStep) IBatfish(org.batfish.common.plugin.IBatfish) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Aggregations

Hop (org.batfish.datamodel.flow.Hop)31 Flow (org.batfish.datamodel.Flow)26 TraceAndReverseFlow (org.batfish.datamodel.flow.TraceAndReverseFlow)25 Configuration (org.batfish.datamodel.Configuration)21 Test (org.junit.Test)19 Trace (org.batfish.datamodel.flow.Trace)18 RoutingStep (org.batfish.datamodel.flow.RoutingStep)17 Vrf (org.batfish.datamodel.Vrf)16 NetworkFactory (org.batfish.datamodel.NetworkFactory)15 Ip (org.batfish.datamodel.Ip)14 ExitOutputIfaceStep (org.batfish.datamodel.flow.ExitOutputIfaceStep)14 MatchSessionStep (org.batfish.datamodel.flow.MatchSessionStep)14 FlowTracer.matchSessionReturnFlow (org.batfish.dataplane.traceroute.FlowTracer.matchSessionReturnFlow)14 ArpErrorStep (org.batfish.datamodel.flow.ArpErrorStep)13 DeliveredStep (org.batfish.datamodel.flow.DeliveredStep)13 SetupSessionStep (org.batfish.datamodel.flow.SetupSessionStep)13 Step (org.batfish.datamodel.flow.Step)13 TransformationStep (org.batfish.datamodel.flow.TransformationStep)13 Interface (org.batfish.datamodel.Interface)12 ImmutableList (com.google.common.collect.ImmutableList)11