Skip to content

Commit f8a7379

Browse files
tzaeschkeTilmann Zäschke
andauthored
Async TR, stop SHIM, 30041 (#14)
Co-authored-by: Tilmann Zäschke <[email protected]>
1 parent 59b9c5a commit f8a7379

File tree

2 files changed

+105
-9
lines changed

2 files changed

+105
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added async traceroute, stop SHIM, and use 30041
13+
[#14](https://github.com/netsec-ethz/scion-java-multiping/pull/14)
14+
1015
### Fixed
1116

1217
- ISD-AS assignment parser broken after website change
13-
[#12](https://github.com/netsec-ethz/scion-java-multiping/pull/12)
18+
[#13](https://github.com/netsec-ethz/scion-java-multiping/pull/13)
1419

1520
## [0.4.0] - 2025-04-04
1621

1722
### Added
23+
1824
- REPEAT setting in PingAll + some output cleanup
1925
[#9](https://github.com/netsec-ethz/scion-java-multiping/pull/9),
2026
[#10](https://github.com/netsec-ethz/scion-java-multiping/pull/10)

src/main/java/org/scion/multiping/PingAll.java

Lines changed: 98 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import java.net.InetSocketAddress;
2222
import java.nio.ByteBuffer;
2323
import java.util.*;
24+
import java.util.concurrent.ConcurrentHashMap;
25+
import java.util.concurrent.CountDownLatch;
26+
import java.util.concurrent.TimeUnit;
2427
import org.scion.jpan.*;
2528
import org.scion.jpan.internal.PathRawParser;
2629
import org.scion.multiping.util.*;
@@ -47,6 +50,9 @@ public class PingAll {
4750
private static final boolean SHOW_ONLY_ICMP = false;
4851
private static final Config config = new Config();
4952

53+
private static final int localPort = 30041;
54+
private static final boolean STOP_SHIM = true;
55+
5056
static {
5157
config.tryICMP = false;
5258
if (SHOW_ONLY_ICMP) {
@@ -71,20 +77,22 @@ public class PingAll {
7177
private enum Policy {
7278
/** Fastest path using SCMP traceroute */
7379
FASTEST_TR,
80+
/** Fastest path using SCMP async traceroute */
81+
FASTEST_ECHO,
82+
FASTEST_TR_ASYNC,
7483
/** Shortest path using SCMP traceroute */
7584
SHORTEST_TR,
7685
/** Fastest path using SCMP echo */
77-
FASTEST_ECHO,
78-
/** Fastest path using SCMP echo */
7986
SHORTEST_ECHO
8087
}
8188

82-
private static final Policy POLICY = Policy.SHORTEST_TR; // Policy.FASTEST_TR; // SHORTEST_TR;
89+
private static final Policy POLICY = Policy.FASTEST_TR_ASYNC;
8390
private static final boolean SHOW_PATH = !true;
8491

8592
public static void main(String[] args) throws IOException {
8693
PRINT = true;
8794
// System.setProperty(Constants.PROPERTY_DNS_SEARCH_DOMAINS, "ethz.ch.");
95+
System.setProperty(Constants.PROPERTY_SHIM, STOP_SHIM ? "false" : "true"); // disable SHIM
8896

8997
println("Settings:");
9098
println(" Path policy = " + POLICY);
@@ -142,7 +150,7 @@ private void runDemo(ParseAssignments.HostEntry remote) throws IOException {
142150
ScionService service = Scion.defaultService();
143151
// Dummy address. The traceroute will contact the control service IP instead.
144152
InetSocketAddress destinationAddress =
145-
new InetSocketAddress(InetAddress.getByAddress(new byte[] {1, 2, 3, 4}), 12345);
153+
new InetSocketAddress(InetAddress.getByAddress(new byte[] {0, 0, 0, 0}), 30041);
146154
int nPaths;
147155
Scmp.TimedMessage[] msg = new Scmp.TimedMessage[REPEAT];
148156
Ref<Path> bestPath = Ref.empty();
@@ -161,7 +169,7 @@ private void runDemo(ParseAssignments.HostEntry remote) throws IOException {
161169
nPaths = paths.size();
162170
msg[0] = findPaths(paths, bestPath);
163171
if (msg[0] != null && REPEAT > 1) {
164-
try (ScmpSender sender = Scmp.newSenderBuilder().build()) {
172+
try (ScmpSender sender = Scmp.newSenderBuilder().setLocalPort(localPort).build()) {
165173
for (int i = 1; i < msg.length; i++) {
166174
List<Scmp.TracerouteMessage> messages = sender.sendTracerouteRequest(bestPath.get());
167175
msg[i] = messages.get(messages.size() - 1);
@@ -221,6 +229,8 @@ private Scmp.TimedMessage findPaths(List<Path> paths, Ref<Path> bestOut) {
221229
switch (POLICY) {
222230
case FASTEST_TR:
223231
return findFastestTR(paths, bestOut);
232+
case FASTEST_TR_ASYNC:
233+
return findFastestTRasync(paths, bestOut);
224234
case SHORTEST_TR:
225235
return findShortestTR(paths, bestOut);
226236
case SHORTEST_ECHO:
@@ -234,7 +244,7 @@ private Scmp.EchoMessage findShortestEcho(List<Path> paths, Ref<Path> refBest) {
234244
Path path = PathPolicy.MIN_HOPS.filter(paths).get(0);
235245
refBest.set(path);
236246
ByteBuffer bb = ByteBuffer.allocate(0);
237-
try (ScmpSender sender = Scmp.newSenderBuilder().build()) {
247+
try (ScmpSender sender = Scmp.newSenderBuilder().setLocalPort(localPort).build()) {
238248
nPathTried++;
239249
Scmp.EchoMessage msg = sender.sendEchoRequest(path, bb);
240250
if (msg == null) {
@@ -261,7 +271,7 @@ private Scmp.EchoMessage findShortestEcho(List<Path> paths, Ref<Path> refBest) {
261271
private Scmp.TracerouteMessage findShortestTR(List<Path> paths, Ref<Path> refBest) {
262272
Path path = PathPolicy.MIN_HOPS.filter(paths).get(0);
263273
refBest.set(path);
264-
try (ScmpSender sender = Scmp.newSenderBuilder().build()) {
274+
try (ScmpSender sender = Scmp.newSenderBuilder().setLocalPort(localPort).build()) {
265275
nPathTried++;
266276
List<Scmp.TracerouteMessage> messages = sender.sendTracerouteRequest(path);
267277
if (messages.isEmpty()) {
@@ -292,7 +302,7 @@ private Scmp.TracerouteMessage findShortestTR(List<Path> paths, Ref<Path> refBes
292302

293303
private Scmp.TracerouteMessage findFastestTR(List<Path> paths, Ref<Path> refBest) {
294304
Scmp.TracerouteMessage best = null;
295-
try (ScmpSender sender = Scmp.newSenderBuilder().build()) {
305+
try (ScmpSender sender = Scmp.newSenderBuilder().setLocalPort(localPort).build()) {
296306
for (Path path : paths) {
297307
nPathTried++;
298308
List<Scmp.TracerouteMessage> messages = sender.sendTracerouteRequest(path);
@@ -327,4 +337,84 @@ private Scmp.TracerouteMessage findFastestTR(List<Path> paths, Ref<Path> refBest
327337
return null;
328338
}
329339
}
340+
341+
private Scmp.TracerouteMessage findFastestTRasync(List<Path> paths, Ref<Path> refBest) {
342+
ConcurrentHashMap<Integer, Scmp.TimedMessage> messages = new ConcurrentHashMap<>();
343+
CountDownLatch barrier = new CountDownLatch(paths.size());
344+
ScmpSenderAsync.ResponseHandler handler =
345+
new ScmpSenderAsync.ResponseHandler() {
346+
@Override
347+
public void onResponse(Scmp.TimedMessage msg) {
348+
barrier.countDown();
349+
messages.put(msg.getIdentifier(), msg);
350+
}
351+
352+
@Override
353+
public void onTimeout(Scmp.TimedMessage msg) {
354+
barrier.countDown();
355+
messages.put(msg.getIdentifier(), msg);
356+
}
357+
358+
@Override
359+
public void onError(Scmp.ErrorMessage msg) {
360+
barrier.countDown();
361+
}
362+
363+
@Override
364+
public void onException(Throwable t) {
365+
barrier.countDown();
366+
}
367+
};
368+
369+
Scmp.TracerouteMessage best = null;
370+
try (ScmpSenderAsync sender =
371+
Scmp.newSenderAsyncBuilder(handler).setLocalPort(localPort).build()) {
372+
for (Path path : paths) {
373+
nPathTried++;
374+
int id = sender.sendTracerouteLast(path);
375+
if (id == -1) {
376+
println(" -> local AS, no timing available");
377+
nPathSuccess++;
378+
nAsSuccess++;
379+
return null;
380+
}
381+
}
382+
383+
// Wait for all messages to be received
384+
try {
385+
if (!barrier.await(1100, TimeUnit.MILLISECONDS)) {
386+
throw new IllegalStateException("Missing messages: " + barrier.getCount() + "/" + paths.size());
387+
}
388+
} catch (InterruptedException e) {
389+
Thread.currentThread().interrupt();
390+
throw new IllegalStateException(e);
391+
}
392+
393+
} catch (IOException e) {
394+
println("ERROR: " + e.getMessage());
395+
nAsError++;
396+
return null;
397+
}
398+
399+
for (Scmp.TimedMessage tm : messages.values()) {
400+
Scmp.TracerouteMessage msg = (Scmp.TracerouteMessage) tm;
401+
seenAs.add(msg.getIsdAs());
402+
403+
if (msg.isTimedOut()) {
404+
nPathTimeout++;
405+
if (best == null) {
406+
best = msg;
407+
}
408+
continue;
409+
}
410+
411+
nPathSuccess++;
412+
413+
if (best == null || msg.getNanoSeconds() < best.getNanoSeconds()) {
414+
best = msg;
415+
refBest.set(msg.getRequest().getPath());
416+
}
417+
}
418+
return best;
419+
}
330420
}

0 commit comments

Comments
 (0)