@Test public void testBuildSessionsByOriginatingVrf() { 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 originatingVrf1 = new OriginatingSessionScope("vrf1"); SessionScope originatingVrf2 = new OriginatingSessionScope("vrf2"); SessionAction action1 = new ForwardOutInterface("i1", null); SessionAction action2 = new ForwardOutInterface("i2", null); FirewallSessionTraceInfo n1Vrf1Session1 = new FirewallSessionTraceInfo("n1", action1, originatingVrf1, matchExpr, null); FirewallSessionTraceInfo n1Vrf1Session2 = new FirewallSessionTraceInfo("n1", action2, originatingVrf1, matchExpr, null); FirewallSessionTraceInfo n1Vrf2Session = new FirewallSessionTraceInfo("n1", action1, originatingVrf2, matchExpr, null); FirewallSessionTraceInfo n2Vrf1Session = new FirewallSessionTraceInfo("n2", action1, originatingVrf1, matchExpr, null); FirewallSessionTraceInfo incomingSession = new FirewallSessionTraceInfo( "n1", action1, new IncomingSessionScope(ImmutableSet.of("i1")), matchExpr, null); Set<FirewallSessionTraceInfo> sessions = ImmutableSet.of( n1Vrf1Session1, n1Vrf1Session2, n1Vrf2Session, n2Vrf1Session, incomingSession); Map<String, Multimap<String, FirewallSessionTraceInfo>> vrfSessionsMap = buildSessionsByOriginatingVrf(sessions); Map<String, Multimap<String, FirewallSessionTraceInfo>> expected = ImmutableMap.of( "n1", ImmutableMultimap.of( "vrf1", n1Vrf1Session1, "vrf1", n1Vrf1Session2, "vrf2", n1Vrf2Session), "n2", ImmutableMultimap.of("vrf1", n2Vrf1Session)); assertEquals(vrfSessionsMap, expected); }
static Map<String, Multimap<String, FirewallSessionTraceInfo>> buildSessionsByOriginatingVrf( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMap.of(); } Map<String, ImmutableMultimap.Builder<String, FirewallSessionTraceInfo>> builder = new HashMap<>(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { builder .computeIfAbsent( session.getHostname(), k -> ImmutableMultimap.builder()) .put(originatingSessionScope.getOriginatingVrf(), session); return null; } })); return builder.entrySet().stream() .collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> e.getValue().build())); }
TracerouteUtils { static Map<String, Multimap<String, FirewallSessionTraceInfo>> buildSessionsByOriginatingVrf( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMap.of(); } Map<String, ImmutableMultimap.Builder<String, FirewallSessionTraceInfo>> builder = new HashMap<>(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { builder .computeIfAbsent( session.getHostname(), k -> ImmutableMultimap.builder()) .put(originatingSessionScope.getOriginatingVrf(), session); return null; } })); return builder.entrySet().stream() .collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> e.getValue().build())); } }
TracerouteUtils { static Map<String, Multimap<String, FirewallSessionTraceInfo>> buildSessionsByOriginatingVrf( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMap.of(); } Map<String, ImmutableMultimap.Builder<String, FirewallSessionTraceInfo>> builder = new HashMap<>(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { builder .computeIfAbsent( session.getHostname(), k -> ImmutableMultimap.builder()) .put(originatingSessionScope.getOriginatingVrf(), session); return null; } })); return builder.entrySet().stream() .collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> e.getValue().build())); }  }
TracerouteUtils { static Map<String, Multimap<String, FirewallSessionTraceInfo>> buildSessionsByOriginatingVrf( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMap.of(); } Map<String, ImmutableMultimap.Builder<String, FirewallSessionTraceInfo>> builder = new HashMap<>(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { builder .computeIfAbsent( session.getHostname(), k -> ImmutableMultimap.builder()) .put(originatingSessionScope.getOriginatingVrf(), session); return null; } })); return builder.entrySet().stream() .collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> e.getValue().build())); }  static TransformationStep transformationStep(
      TransformationType type, Flow inputFlow, Flow transformedFlow); }
TracerouteUtils { static Map<String, Multimap<String, FirewallSessionTraceInfo>> buildSessionsByOriginatingVrf( @Nullable Set<FirewallSessionTraceInfo> sessions) { if (sessions == null) { return ImmutableMap.of(); } Map<String, ImmutableMultimap.Builder<String, FirewallSessionTraceInfo>> builder = new HashMap<>(); sessions.forEach( session -> session .getSessionScope() .accept( new SessionScopeVisitor<Void>() { @Override public Void visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return null; } @Override public Void visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { builder .computeIfAbsent( session.getHostname(), k -> ImmutableMultimap.builder()) .put(originatingSessionScope.getOriginatingVrf(), session); return null; } })); return builder.entrySet().stream() .collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> e.getValue().build())); }  static TransformationStep transformationStep(
      TransformationType type, Flow inputFlow, Flow transformedFlow);  }