@Test public void testBuildSessionsByIngressInterface() { Flow flow = Flow.builder() .setIngressNode("n1") .setIngressInterface("i1") .setIpProtocol(IpProtocol.TCP) .setSrcPort(22) .setDstPort(22) .setSrcIp(Ip.parse("1.1.1.1")) .setDstIp(Ip.parse("2.2.2.2")) .build(); SessionMatchExpr matchExpr = matchSessionReturnFlow(flow); SessionScope incomingI1 = new IncomingSessionScope(ImmutableSet.of("i1")); SessionAction action1 = new ForwardOutInterface("i1", null); SessionAction action2 = new ForwardOutInterface("i2", null); FirewallSessionTraceInfo n1i1Session = new FirewallSessionTraceInfo("n1", action1, incomingI1, matchExpr, null); FirewallSessionTraceInfo n1i1i2Session = new FirewallSessionTraceInfo( "n1", action2, new IncomingSessionScope(ImmutableSet.of("i1", "i2")), matchExpr, null); FirewallSessionTraceInfo n2i1Session = new FirewallSessionTraceInfo("n2", action1, incomingI1, matchExpr, null); FirewallSessionTraceInfo originatingVrfSession = new FirewallSessionTraceInfo( "n1", action1, new OriginatingSessionScope("vrf"), matchExpr, null); Set<FirewallSessionTraceInfo> sessions = ImmutableSet.of(n1i1Session, n1i1i2Session, n2i1Session, originatingVrfSession); Multimap<NodeInterfacePair, FirewallSessionTraceInfo> ifaceSessionsMap = buildSessionsByIngressInterface(sessions); NodeInterfacePair n1i1 = NodeInterfacePair.of("n1", "i1"); NodeInterfacePair n1i2 = NodeInterfacePair.of("n1", "i2"); NodeInterfacePair n2i1 = NodeInterfacePair.of("n2", "i1"); Multimap<NodeInterfacePair, FirewallSessionTraceInfo> expected = ImmutableMultimap.of( n1i1, n1i1Session, n1i1, n1i1i2Session, n1i2, n1i1i2Session, n2i1, n2i1Session); assertEquals(ifaceSessionsMap, expected); }
static Multimap<NodeInterfacePair, FirewallSessionTraceInfo> buildSessionsByIngressInterface( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMultimap.of(); } ImmutableMultimap.Builder<NodeInterfacePair, FirewallSessionTraceInfo> builder = ImmutableMultimap.builder(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { incomingSessionScope .getIncomingInterfaces() .forEach( incomingIface -> builder.put( NodeInterfacePair.of(session.getHostname(), incomingIface), session)); return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { return null; } })); return builder.build(); }
TracerouteUtils { static Multimap<NodeInterfacePair, FirewallSessionTraceInfo> buildSessionsByIngressInterface( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMultimap.of(); } ImmutableMultimap.Builder<NodeInterfacePair, FirewallSessionTraceInfo> builder = ImmutableMultimap.builder(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { incomingSessionScope .getIncomingInterfaces() .forEach( incomingIface -> builder.put( NodeInterfacePair.of(session.getHostname(), incomingIface), session)); return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { return null; } })); return builder.build(); } }
TracerouteUtils { static Multimap<NodeInterfacePair, FirewallSessionTraceInfo> buildSessionsByIngressInterface( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMultimap.of(); } ImmutableMultimap.Builder<NodeInterfacePair, FirewallSessionTraceInfo> builder = ImmutableMultimap.builder(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { incomingSessionScope .getIncomingInterfaces() .forEach( incomingIface -> builder.put( NodeInterfacePair.of(session.getHostname(), incomingIface), session)); return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { return null; } })); return builder.build(); }  }
TracerouteUtils { static Multimap<NodeInterfacePair, FirewallSessionTraceInfo> buildSessionsByIngressInterface( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMultimap.of(); } ImmutableMultimap.Builder<NodeInterfacePair, FirewallSessionTraceInfo> builder = ImmutableMultimap.builder(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { incomingSessionScope .getIncomingInterfaces() .forEach( incomingIface -> builder.put( NodeInterfacePair.of(session.getHostname(), incomingIface), session)); return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { return null; } })); return builder.build(); }  static TransformationStep transformationStep(
      TransformationType type, Flow inputFlow, Flow transformedFlow); }
TracerouteUtils { static Multimap<NodeInterfacePair, FirewallSessionTraceInfo> buildSessionsByIngressInterface( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMultimap.of(); } ImmutableMultimap.Builder<NodeInterfacePair, FirewallSessionTraceInfo> builder = ImmutableMultimap.builder(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { incomingSessionScope .getIncomingInterfaces() .forEach( incomingIface -> builder.put( NodeInterfacePair.of(session.getHostname(), incomingIface), session)); return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { return null; } })); return builder.build(); }  static TransformationStep transformationStep(
      TransformationType type, Flow inputFlow, Flow transformedFlow);  }