@SuppressWarnings("unchecked") @Test public void testBidirectionalReachabilityFailure() throws IOException { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); Interface.Builder ib = nf.interfaceBuilder().setActive(true); HeaderSpace tcpHeaderSpace = HeaderSpace.builder().setIpProtocols(ImmutableList.of(IpProtocol.TCP)).build(); ExprAclLine permitTcpLine = ExprAclLine.accepting().setMatchCondition(match(tcpHeaderSpace)).build(); HeaderSpace udpHeaderSpace = HeaderSpace.builder().setIpProtocols(ImmutableList.of(IpProtocol.UDP)).build(); ExprAclLine permitUdpLine = ExprAclLine.accepting().setMatchCondition(match(udpHeaderSpace)).build(); Configuration source1 = cb.build(); Vrf vrf = nf.vrfBuilder().setOwner(source1).build(); ib.setOwner(source1).setVrf(vrf); Interface source1Iface = ib.setAddress(ConcreteInterfaceAddress.parse("2.0.0.1/29")).build(); source1Iface.setIncomingFilter( nf.aclBuilder().setOwner(source1).setLines(ImmutableList.of(permitTcpLine)).build()); vrf.setStaticRoutes( ImmutableSortedSet.of( StaticRoute.builder() .setNetwork(Prefix.parse("255.255.255.0/24")) .setAdministrativeCost(1) .setNextHopInterface(source1Iface.getName()) .setNextHopIp(Ip.parse("2.0.0.3")) .build())); Configuration source2 = cb.build(); vrf = nf.vrfBuilder().setOwner(source2).build(); ib.setOwner(source2).setVrf(vrf); Interface source2Iface1 = ib.setAddress(ConcreteInterfaceAddress.parse("1.0.0.0/31")).build(); Interface source2Iface2 = ib.setAddress(ConcreteInterfaceAddress.parse("2.0.0.2/29")).build(); Prefix source2Iface1RoutePrefix = Prefix.parse("9.9.9.9/32"); vrf.setStaticRoutes( ImmutableSortedSet.of( StaticRoute.builder() .setNetwork(source2Iface1RoutePrefix) .setAdministrativeCost(1) .setNextHopInterface(source2Iface1.getName()) .build(), StaticRoute.builder() .setNetwork(Prefix.parse("255.255.255.0/24")) .setAdministrativeCost(1) .setNextHopInterface(source2Iface2.getName()) .setNextHopIp(Ip.parse("2.0.0.3")) .build())); Configuration fw = cb.build(); ib.setOwner(fw).setVrf(nf.vrfBuilder().setOwner(fw).build()); ib.setAddress(ConcreteInterfaceAddress.parse("2.0.0.3/29")).build(); Interface fwI2 = ib.setAddress(ConcreteInterfaceAddress.parse("3.0.0.1/29")).build(); Interface fwI3 = ib.setAddress(ConcreteInterfaceAddress.parse("255.255.255.0/24")).build(); IpAccessList permitUdpAcl = nf.aclBuilder().setOwner(fw).setLines(ImmutableList.of(permitUdpLine)).build(); fwI2.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo( false, ImmutableList.of(fwI2.getName()), null, permitUdpAcl.getName())); Ip poolIp = Ip.parse("5.5.5.5"); fwI3.setOutgoingTransformation(always().apply(assignSourceIp(poolIp, poolIp)).build()); fwI3.setIncomingFilter( nf.aclBuilder().setOwner(fw).setLines(ImmutableList.of(ExprAclLine.REJECT_ALL)).build()); fwI3.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo(false, ImmutableList.of(fwI3.getName()), null, null)); SortedMap<String, Configuration> configurations = ImmutableSortedMap.of( source1.getHostname(), source1, source2.getHostname(), source2, fw.getHostname(), fw); Batfish batfish = getBatfish(configurations, temp); batfish.computeDataPlane(batfish.getSnapshot()); Location source1Loc = new InterfaceLocation(source1.getHostname(), source1Iface.getName()); Location source2Loc = new InterfaceLinkLocation(source2.getHostname(), source2Iface1.getName()); Location fwI2Loc = new InterfaceLinkLocation(fw.getHostname(), fwI2.getName()); Ip source1LocIp = Ip.parse("2.0.0.1"); Prefix source2LocPrefix = Prefix.parse("9.9.9.0/24"); Ip fwI2LocIp = Ip.parse("1.0.0.5"); IpSpaceAssignment assignment = IpSpaceAssignment.builder() .assign(source1Loc, source1LocIp.toIpSpace()) .assign(source2Loc, source2LocPrefix.toIpSpace()) .assign(fwI2Loc, fwI2LocIp.toIpSpace()) .build(); HeaderSpaceToBDD headerSpaceToBDD = new HeaderSpaceToBDD(PKT, ImmutableMap.of()); IpSpaceToBDD srcIpSpaceToBdd = headerSpaceToBDD.getSrcIpSpaceToBdd(); BDD source1LocIpBdd = PKT.getSrcIp().value(source1LocIp.asLong()); BDD source1LocSuccessBdd = source1LocIpBdd.and(headerSpaceToBDD.toBDD(tcpHeaderSpace)); BDD source1LocFailBdd = source1LocIpBdd.and(headerSpaceToBDD.toBDD(tcpHeaderSpace).not()); BDD source2LocPrefixBdd = srcIpSpaceToBdd.toBDD(source2LocPrefix); BDD source2LocSuccessBdd = srcIpSpaceToBdd.toBDD(source2Iface1RoutePrefix); BDD source2LocFailBdd = source2LocPrefixBdd.and(source2LocSuccessBdd.not()); BDD fwI2LocIpBdd = PKT.getSrcIp().value(fwI2LocIp.asLong()); BDD fwI2LocSuccessBdd = fwI2LocIpBdd.and(headerSpaceToBDD.toBDD(udpHeaderSpace)); BDD fwLocFailBdd = fwI2LocIpBdd.and(headerSpaceToBDD.toBDD(udpHeaderSpace).not()); Ip dstIp = Ip.parse("255.255.255.1"); BDD dstIpBdd = PKT.getDstIp().value(dstIp.asLong()); DataPlane dataPlane = batfish.loadDataPlane(batfish.getSnapshot()); BidirectionalReachabilityResult result = new BidirectionalReachabilityAnalysis( PKT, configurations, dataPlane.getForwardingAnalysis(), new IpsRoutedOutInterfacesFactory(dataPlane.getFibs()), assignment, matchDst(dstIp), ImmutableSet.of(), ImmutableSet.of(), configurations.keySet(), ALL_DISPOSITIONS) .getResult(); assertEquals( result.getStartLocationReturnPassSuccessBdds(), ImmutableMap.of( source1Loc, source1LocSuccessBdd.and(dstIpBdd), source2Loc, source2LocSuccessBdd.and(dstIpBdd), fwI2Loc, fwI2LocSuccessBdd.and(dstIpBdd))); assertEquals( result.getStartLocationReturnPassFailureBdds(), ImmutableMap.of( source1Loc, source1LocFailBdd.and(dstIpBdd), source2Loc, source2LocFailBdd.and(dstIpBdd), fwI2Loc, fwLocFailBdd.and(dstIpBdd))); }
public BidirectionalReachabilityResult getResult() { return new BidirectionalReachabilityResult( _forwardPassStartLocationToReturnPassSuccessBdds.get(), _forwardPassStartLocationToReturnPassFailureBdds.get()); }
BidirectionalReachabilityAnalysis { public BidirectionalReachabilityResult getResult() { return new BidirectionalReachabilityResult( _forwardPassStartLocationToReturnPassSuccessBdds.get(), _forwardPassStartLocationToReturnPassFailureBdds.get()); } }
BidirectionalReachabilityAnalysis { public BidirectionalReachabilityResult getResult() { return new BidirectionalReachabilityResult( _forwardPassStartLocationToReturnPassSuccessBdds.get(), _forwardPassStartLocationToReturnPassFailureBdds.get()); } BidirectionalReachabilityAnalysis(
      BDDPacket bddPacket,
      Map<String, Configuration> configs,
      ForwardingAnalysis forwardingAnalysis,
      IpsRoutedOutInterfacesFactory ipsRoutedOutInterfacesFactory,
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialForwardHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> forwardPassFinalNodes,
      Set<FlowDisposition> forwardPassActions); }
BidirectionalReachabilityAnalysis { public BidirectionalReachabilityResult getResult() { return new BidirectionalReachabilityResult( _forwardPassStartLocationToReturnPassSuccessBdds.get(), _forwardPassStartLocationToReturnPassFailureBdds.get()); } BidirectionalReachabilityAnalysis(
      BDDPacket bddPacket,
      Map<String, Configuration> configs,
      ForwardingAnalysis forwardingAnalysis,
      IpsRoutedOutInterfacesFactory ipsRoutedOutInterfacesFactory,
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialForwardHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> forwardPassFinalNodes,
      Set<FlowDisposition> forwardPassActions); BidirectionalReachabilityResult getResult(); }
BidirectionalReachabilityAnalysis { public BidirectionalReachabilityResult getResult() { return new BidirectionalReachabilityResult( _forwardPassStartLocationToReturnPassSuccessBdds.get(), _forwardPassStartLocationToReturnPassFailureBdds.get()); } BidirectionalReachabilityAnalysis(
      BDDPacket bddPacket,
      Map<String, Configuration> configs,
      ForwardingAnalysis forwardingAnalysis,
      IpsRoutedOutInterfacesFactory ipsRoutedOutInterfacesFactory,
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialForwardHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> forwardPassFinalNodes,
      Set<FlowDisposition> forwardPassActions); BidirectionalReachabilityResult getResult();  }