@@ -74,11 +74,14 @@ public class PingAll {
74
74
private int nPathSuccess = 0 ;
75
75
private int nPathTimeout = 0 ;
76
76
77
- private static final Set <Long > listedAs = new HashSet <>();
78
- private static final Set <Long > seenAs = new HashSet <>();
79
- private static final List <Result > results = new ArrayList <>();
77
+ private final Set <Long > listedAs = new HashSet <>();
78
+ private final Set <Long > seenAs = new HashSet <>();
79
+ private final List <Result > results = new ArrayList <>();
80
80
81
- private enum Policy {
81
+ private final ScmpProvider service ;
82
+ private Policy policy = Policy .FASTEST_TR_ASYNC ;
83
+
84
+ enum Policy {
82
85
/** Fastest path using SCMP traceroute */
83
86
FASTEST_TR ,
84
87
/** Fastest path using SCMP async traceroute */
@@ -90,28 +93,37 @@ private enum Policy {
90
93
SHORTEST_ECHO
91
94
}
92
95
93
- private static final Policy POLICY = Policy .FASTEST_TR_ASYNC ;
96
+ private static Policy DEFAULT_POLICY = Policy .FASTEST_TR_ASYNC ;
94
97
private static final boolean SHOW_PATH = false ;
95
98
99
+ PingAll (Policy policy , ScmpProvider service ) {
100
+ this .policy = policy ;
101
+ this .service = service ;
102
+ }
103
+
96
104
public static void main (String [] args ) throws IOException {
97
105
PRINT = true ;
98
106
// System.setProperty(Constants.PROPERTY_DNS_SEARCH_DOMAINS, "ethz.ch.");
99
107
System .setProperty (Constants .PROPERTY_SHIM , STOP_SHIM ? "false" : "true" ); // disable SHIM
100
108
101
109
println ("Settings:" );
102
- println (" Path policy = " + POLICY );
110
+ println (" Path policy = " + DEFAULT_POLICY );
103
111
println (" ICMP=" + config .tryICMP );
104
112
println (" printOnlyICMP=" + SHOW_ONLY_ICMP );
105
113
106
- PingAll demo = new PingAll ();
107
- List <ParseAssignments .HostEntry > allASes = DownloadAssignmentsFromWeb .getList ();
114
+ PingAll pingAll = new PingAll (DEFAULT_POLICY , ScmpProvider .defaultProvider (localPort ));
115
+ pingAll .run ();
116
+ }
117
+
118
+ void run () throws IOException {
119
+ List <ParseAssignments .HostEntry > allASes = service .getIsdAsEntries ();
108
120
// remove entry for local AS
109
121
long localAS = Scion .defaultService ().getLocalIsdAs ();
110
122
allASes = allASes .stream ().filter (e -> e .getIsdAs () != localAS ).collect (Collectors .toList ());
111
123
// Process all ASes
112
124
for (ParseAssignments .HostEntry e : allASes ) {
113
125
print (ScionUtil .toStringIA (e .getIsdAs ()) + " \" " + e .getName () + "\" " );
114
- demo . runDemo (e );
126
+ runAS (e );
115
127
listedAs .add (e .getIsdAs ());
116
128
}
117
129
@@ -151,26 +163,25 @@ public static void main(String[] args) throws IOException {
151
163
152
164
println ("" );
153
165
println ("AS Stats:" );
154
- println (" all = " + demo . nAsTried );
155
- println (" success = " + demo . nAsSuccess );
156
- println (" no path = " + demo . nAsNoPathFound );
157
- println (" timeout = " + demo . nAsTimeout );
158
- println (" error = " + demo . nAsError );
166
+ println (" all = " + nAsTried );
167
+ println (" success = " + nAsSuccess );
168
+ println (" no path = " + nAsNoPathFound );
169
+ println (" timeout = " + nAsTimeout );
170
+ println (" error = " + nAsError );
159
171
println (" not listed = " + nSeenButNotListed );
160
172
println ("Path Stats:" );
161
- println (" all = " + demo . nPathTried );
162
- println (" success = " + demo . nPathSuccess );
163
- println (" timeout = " + demo . nPathTimeout );
173
+ println (" all = " + nPathTried );
174
+ println (" success = " + nPathSuccess );
175
+ println (" timeout = " + nPathTimeout );
164
176
println ("ICMP Stats:" );
165
177
println (" all = " + ICMP .nIcmpTried );
166
178
println (" success = " + ICMP .nIcmpSuccess );
167
179
println (" timeout = " + ICMP .nIcmpTimeout );
168
180
println (" error = " + ICMP .nIcmpError );
169
181
}
170
182
171
- private void runDemo (ParseAssignments .HostEntry remote ) throws IOException {
183
+ private void runAS (ParseAssignments .HostEntry remote ) throws IOException {
172
184
nAsTried ++;
173
- ScionService service = Scion .defaultService ();
174
185
// Dummy address. The traceroute will contact the control service IP instead.
175
186
InetSocketAddress destinationAddress =
176
187
new InetSocketAddress (InetAddress .getByAddress (new byte [] {0 , 0 , 0 , 0 }), 30041 );
@@ -191,9 +202,16 @@ private void runDemo(ParseAssignments.HostEntry remote) throws IOException {
191
202
}
192
203
nPaths = paths .size ();
193
204
msg [0 ] = findPaths (paths , bestPath );
194
- if (msg [0 ] != null && REPEAT > 1 ) {
195
- try (ScmpSender sender = Scmp .newSenderBuilder ().setLocalPort (localPort ).build ()) {
205
+ if (bestPath .get () == null ) {
206
+ nAsTimeout ++;
207
+ }
208
+ // bestPath is null if all paths have timed out
209
+ if (msg [0 ] != null && bestPath .get () != null && REPEAT > 1 ) {
210
+ try (ScmpProvider .Sync sender = service .getSync ()) {
196
211
for (int i = 1 ; i < msg .length ; i ++) {
212
+ if (bestPath .get () == null ) {
213
+ break ;
214
+ }
197
215
List <Scmp .TracerouteMessage > messages = sender .sendTracerouteRequest (bestPath .get ());
198
216
msg [i ] = messages .get (messages .size () - 1 );
199
217
}
@@ -249,7 +267,7 @@ private void runDemo(ParseAssignments.HostEntry remote) throws IOException {
249
267
}
250
268
251
269
private Scmp .TimedMessage findPaths (List <Path > paths , Ref <Path > bestOut ) {
252
- switch (POLICY ) {
270
+ switch (policy ) {
253
271
case FASTEST_TR :
254
272
return findFastestTR (paths , bestOut );
255
273
case FASTEST_TR_ASYNC :
@@ -267,7 +285,7 @@ private Scmp.EchoMessage findShortestEcho(List<Path> paths, Ref<Path> refBest) {
267
285
Path path = PathPolicy .MIN_HOPS .filter (paths ).get (0 );
268
286
refBest .set (path );
269
287
ByteBuffer bb = ByteBuffer .allocate (0 );
270
- try (ScmpSender sender = Scmp . newSenderBuilder (). setLocalPort ( localPort ). build ()) {
288
+ try (ScmpProvider . Sync sender = service . getSync ()) {
271
289
nPathTried ++;
272
290
Scmp .EchoMessage msg = sender .sendEchoRequest (path , bb );
273
291
if (msg == null ) {
@@ -294,7 +312,7 @@ private Scmp.EchoMessage findShortestEcho(List<Path> paths, Ref<Path> refBest) {
294
312
private Scmp .TracerouteMessage findShortestTR (List <Path > paths , Ref <Path > refBest ) {
295
313
Path path = PathPolicy .MIN_HOPS .filter (paths ).get (0 );
296
314
refBest .set (path );
297
- try (ScmpSender sender = Scmp . newSenderBuilder (). setLocalPort ( localPort ). build ()) {
315
+ try (ScmpProvider . Sync sender = service . getSync ()) {
298
316
nPathTried ++;
299
317
List <Scmp .TracerouteMessage > messages = sender .sendTracerouteRequest (path );
300
318
if (messages .isEmpty ()) {
@@ -325,7 +343,7 @@ private Scmp.TracerouteMessage findShortestTR(List<Path> paths, Ref<Path> refBes
325
343
326
344
private Scmp .TracerouteMessage findFastestTR (List <Path > paths , Ref <Path > refBest ) {
327
345
Scmp .TracerouteMessage best = null ;
328
- try (ScmpSender sender = Scmp . newSenderBuilder (). setLocalPort ( localPort ). build ()) {
346
+ try (ScmpProvider . Sync sender = service . getSync ()) {
329
347
for (Path path : paths ) {
330
348
nPathTried ++;
331
349
List <Scmp .TracerouteMessage > messages = sender .sendTracerouteRequest (path );
@@ -390,8 +408,7 @@ public void onException(Throwable t) {
390
408
};
391
409
392
410
Scmp .TracerouteMessage best = null ;
393
- try (ScmpSenderAsync sender =
394
- Scmp .newSenderAsyncBuilder (handler ).setLocalPort (localPort ).build ()) {
411
+ try (ScmpProvider .Async sender = service .getAsync (handler )) {
395
412
for (Path path : paths ) {
396
413
nPathTried ++;
397
414
int id = sender .sendTracerouteLast (path );
@@ -442,15 +459,15 @@ public void onException(Throwable t) {
442
459
return best ;
443
460
}
444
461
445
- private static double avg (Predicate <Result > filter , ToDoubleFunction <Result > mapper ) {
462
+ private double avg (Predicate <Result > filter , ToDoubleFunction <Result > mapper ) {
446
463
return results .stream ().filter (filter ).mapToDouble (mapper ).average ().orElse (-1 );
447
464
}
448
465
449
- private static Result max (Predicate <Result > filter , Comparator <Result > comparator ) {
466
+ private Result max (Predicate <Result > filter , Comparator <Result > comparator ) {
450
467
return results .stream ().filter (filter ).max (comparator ).orElseThrow (NoSuchElementException ::new );
451
468
}
452
469
453
- private static <T > double median (Predicate <Result > filter , Function <Result , T > mapper ) {
470
+ private <T > double median (Predicate <Result > filter , Function <Result , T > mapper ) {
454
471
List <T > list =
455
472
results .stream ().filter (filter ).map (mapper ).sorted ().collect (Collectors .toList ());
456
473
if (list .isEmpty ()) {
0 commit comments