@@ -104,8 +104,12 @@ public static void main(String[] args) throws IOException {
104
104
println (" printOnlyICMP=" + SHOW_ONLY_ICMP );
105
105
106
106
PingAll demo = new PingAll ();
107
- List <ParseAssignments .HostEntry > list = DownloadAssignmentsFromWeb .getList ();
108
- for (ParseAssignments .HostEntry e : list ) {
107
+ List <ParseAssignments .HostEntry > allASes = DownloadAssignmentsFromWeb .getList ();
108
+ // remove entry for local AS
109
+ long localAS = Scion .defaultService ().getLocalIsdAs ();
110
+ allASes = allASes .stream ().filter (e -> e .getIsdAs () != localAS ).collect (Collectors .toList ());
111
+ // Process all ASes
112
+ for (ParseAssignments .HostEntry e : allASes ) {
109
113
print (ScionUtil .toStringIA (e .getIsdAs ()) + " \" " + e .getName () + "\" " );
110
114
demo .runDemo (e );
111
115
listedAs .add (e .getIsdAs ());
@@ -120,27 +124,26 @@ public static void main(String[] args) throws IOException {
120
124
}
121
125
122
126
// max:
123
- Result maxPing =
124
- results .stream ().max ((o1 , o2 ) -> (int ) (o1 .getPingMs () - o2 .getPingMs ())).get ();
125
- Result maxHops = results .stream ().max (Comparator .comparingInt (Result ::getHopCount )).get ();
126
- Result maxPaths = results .stream ().max (Comparator .comparingInt (Result ::getPathCount )).get ();
127
+ Result maxPing = max (Result ::isSuccess , (o1 , o2 ) -> (int ) (o1 .getPingMs () - o2 .getPingMs ()));
128
+ Result maxHops = max (r -> r .getHopCount () > 0 , Comparator .comparingInt (Result ::getHopCount ));
129
+ Result maxPaths = max (r -> r .getPathCount () > 0 , Comparator .comparingInt (Result ::getPathCount ));
127
130
128
131
// avg/median:
129
- double avgPing = avg (results , Result ::isSuccess , Result ::getPingMs );
130
- double avgHops = avg (results , r -> r .getHopCount () > 0 , Result ::getHopCount );
131
- double avgPaths = avg (results , r -> r .getPathCount () > 0 , Result ::getPathCount );
132
- double medianPing = median (results , Result ::isSuccess , Result ::getPingMs ). orElse (- 1.0 );
133
- int medianHops = median (results , r -> r .getHopCount () > 0 , Result ::getHopCount ). orElse (- 1 );
134
- int medianPaths = median (results , r -> r .getPathCount () > 0 , Result ::getPathCount ). orElse (- 1 );
132
+ double avgPing = avg (Result ::isSuccess , Result ::getPingMs );
133
+ double avgHops = avg (r -> r .getHopCount () > 0 , Result ::getHopCount );
134
+ double avgPaths = avg (r -> r .getPathCount () > 0 , Result ::getPathCount );
135
+ double medianPing = median (Result ::isSuccess , Result ::getPingMs );
136
+ double medianHops = median (r -> r .getHopCount () > 0 , Result ::getHopCount );
137
+ double medianPaths = median (r -> r .getPathCount () > 0 , Result ::getPathCount );
135
138
136
139
println ("" );
137
140
println ("Max hops = " + maxHops .getHopCount () + ": " + maxHops );
138
141
println ("Max ping [ms] = " + round (maxPing .getPingMs (), 2 ) + ": " + maxPing );
139
142
println ("Max paths = " + maxPaths .getPathCount () + ": " + maxPaths );
140
143
141
- println ("Median hops = " + medianHops );
144
+ println ("Median hops = " + ( int ) medianHops );
142
145
println ("Median ping [ms] = " + round (medianPing , 2 ));
143
- println ("Median paths = " + medianPaths );
146
+ println ("Median paths = " + ( int ) medianPaths );
144
147
145
148
println ("Avg hops = " + round (avgHops , 1 ));
146
149
println ("Avg ping [ms] = " + round (avgPing , 2 ));
@@ -439,14 +442,23 @@ public void onException(Throwable t) {
439
442
return best ;
440
443
}
441
444
442
- private static double avg (
443
- List <Result > list , Predicate <Result > filter , ToDoubleFunction <Result > mapper ) {
444
- return list .stream ().filter (filter ).mapToDouble (mapper ).average ().orElse (-1 );
445
+ private static double avg (Predicate <Result > filter , ToDoubleFunction <Result > mapper ) {
446
+ return results .stream ().filter (filter ).mapToDouble (mapper ).average ().orElse (-1 );
445
447
}
446
448
447
- private static <T > Optional <T > median (
448
- List <Result > list , Predicate <Result > filter , Function <Result , T > mapper ) {
449
- List <T > list2 = list .stream ().filter (filter ).map (mapper ).sorted ().collect (Collectors .toList ());
450
- return list2 .isEmpty () ? Optional .empty () : Optional .of (list2 .get (list2 .size () / 2 ));
449
+ private static Result max (Predicate <Result > filter , Comparator <Result > comparator ) {
450
+ return results .stream ().filter (filter ).max (comparator ).orElseThrow (NoSuchElementException ::new );
451
+ }
452
+
453
+ private static <T > double median (Predicate <Result > filter , Function <Result , T > mapper ) {
454
+ List <T > list =
455
+ results .stream ().filter (filter ).map (mapper ).sorted ().collect (Collectors .toList ());
456
+ if (list .isEmpty ()) {
457
+ return -1 ;
458
+ }
459
+ if (list .get (0 ) instanceof Double ) {
460
+ return (Double ) list .get (list .size () / 2 );
461
+ }
462
+ return (Integer ) list .get (list .size () / 2 );
451
463
}
452
464
}
0 commit comments