Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ TODO
[#20](https://github.com/netsec-ethz/scion-java-multiping/pull/20)
- Added output of global maxima (longest path, ...)
[#24](https://github.com/netsec-ethz/scion-java-multiping/pull/24)

- Added output and config of local port
[#26](https://github.com/netsec-ethz/scion-java-multiping/pull/26)
-
### Changed

- Output summary uses `\t` whitespaces for easier copying.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ arguments:
"tryICMP": false,
"isdAsInputFile": "ping-repeat-destinations.csv",
"outputFile": "ping-repeat-output.csv",
"localPort": 30041, // This is only used by the PingResponder
"localPort": 30041,
"consoleOutput": true
}
```
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/scion/multiping/PingAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.stream.Collectors;
import org.scion.jpan.*;
import org.scion.jpan.internal.PathRawParser;
import org.scion.jpan.internal.Shim;
import org.scion.multiping.util.*;

/**
Expand Down Expand Up @@ -91,6 +92,8 @@ enum Policy {
public static void main(String[] argsArray) throws IOException {
PRINT = true;

// Initialize port from config, but CLI overrides config file.
localPort = config.getLocalPortOr30041();
Policy policy = parseArgs(argsArray);

System.setProperty(Constants.PROPERTY_SHIM, startShim ? "true" : "false"); // disable SHIM
Expand All @@ -99,6 +102,8 @@ public static void main(String[] argsArray) throws IOException {
println(" Path policy = " + policy);
println(" ICMP=" + config.tryICMP);
println(" printOnlyICMP=" + SHOW_ONLY_ICMP);
println(" Local port=" + localPort);
println(" JPAN SHIM active=" + Shim.isInstalled());

long t1 = System.currentTimeMillis();
PingAll pingAll = new PingAll(policy, ScionProvider.defaultProvider(localPort));
Expand Down Expand Up @@ -128,6 +133,7 @@ private static Policy parseArgs(String[] argsArray) {
case "--help":
Main.printUsagePingAll();
System.exit(0);
break;
case "--shim":
startShim = true;
break;
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/org/scion/multiping/PingRepeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import org.scion.jpan.*;
import org.scion.jpan.internal.PathRawParser;
import org.scion.jpan.internal.Shim;
import org.scion.multiping.util.*;
import org.scion.multiping.util.Record;

Expand Down Expand Up @@ -54,6 +55,7 @@ public class PingRepeat {
private int nPingSuccess = 0;
private int nPingTimeout = 0;
private int nPingError = 0;
private static int localPort = -1;

private static Config config;
private static FileWriter fileWriter;
Expand All @@ -65,11 +67,14 @@ public PingRepeat() throws UnknownHostException {
}

public static void main(String[] args) throws IOException {
// System.setProperty(Constants.PROPERTY_DNS_SEARCH_DOMAINS, "ethz.ch.");

config = Config.read(FILE_CONFIG);
PRINT = config.consoleOutput;

localPort = config.hasLocalPort() ? config.localPort : -1;
println("Settings");
println(" Listening on port: " + localPort);
println(" JPAN SHIM is running: " + Shim.isInstalled());

// Output: ISD/AS, remote IP, time, hopCount, path, [pings]
fileWriter = new FileWriter(config.outputFile);

Expand Down Expand Up @@ -141,7 +146,12 @@ private void runRepeat(ParseAssignments.HostEntry remote) {
// output
int nHops = PathRawParser.create(rec.getPath().getRawPath()).getHopCount();
String out = rec.getRemoteIP() + " nPaths=" + nPaths + " nHops=" + nHops;
out += " time=" + bestAttempt.get().getPingMs() + "ms" + " ICMP=" + icmpMs;
if (bestAttempt.get().getState() == Record.Attempt.State.SUCCESS) {
out += " time=" + bestAttempt.get().getPingMs() + "ms";
} else {
out += " time=" + bestAttempt.get().getState();
}
out += " ICMP=" + icmpMs;
if (SHOW_PATH) {
out += " " + ScionUtil.toStringPath(rec.getPath().getMetadata());
}
Expand All @@ -161,7 +171,8 @@ private Record measureLatency(List<Path> paths, Ref<Record.Attempt> refBest) {
Record best = null;
double currentBestMs = Double.MAX_VALUE;
ResponseHandler handler = new ResponseHandler();
try (ScmpSenderAsync sender = Scmp.newSenderAsyncBuilder(handler).build()) {
try (ScmpSenderAsync sender =
Scmp.newSenderAsyncBuilder(handler).setLocalPort(localPort).build()) {
for (int attemptCount = 0; attemptCount < config.attemptRepeatCnt; attemptCount++) {
Instant start = Instant.now();
Map<Integer, Record> seqToPathMap = new HashMap<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scion/multiping/PingResponder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void main(String[] args) throws IOException {
PRINT = config.consoleOutput;

try (ScmpResponder responder =
Scmp.newResponderBuilder().setLocalPort(Constants.SCMP_PORT).build()) {
Scmp.newResponderBuilder().setLocalPort(config.getLocalPortOr30041()).build()) {
responder.setScmpErrorListener(PingResponder::printError);
responder.setOption(ScionSocketOptions.SCION_API_THROW_PARSER_FAILURE, true);
responder.setScmpEchoListener(PingResponder::print);
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/org/scion/multiping/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.*;

public class Config {
private static final int PORT_NOT_SET = -1;
public int attemptRepeatCnt = 5;
public int attemptDelayMs = 100;
public int roundRepeatCnt = 144; // 1 day
Expand All @@ -26,15 +27,23 @@ public class Config {
public boolean tryICMP = false;
public String isdAsInputFile;
public String outputFile;
public int localPort = 30041;
public int localPort = PORT_NOT_SET;
public boolean consoleOutput = true;

public boolean hasLocalPort() {
return localPort != PORT_NOT_SET;
}

public int getLocalPortOr30041() {
return hasLocalPort() ? localPort : 30041;
}

public static Config read(String path) {
Gson gson = new Gson();
try (Reader reader = new FileReader(path)) {
return gson.fromJson(reader, Config.class);
} catch (IOException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
}
}

Expand All @@ -47,7 +56,7 @@ void write(String path) {
try (Writer writer = new FileWriter(path)) {
gson.toJson(this, writer);
} catch (IOException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/scion/multiping/util/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ public double getPingMs() {
return pingMs;
}

public State getState() {
return state;
}

@Override
public String toString() {
return " time=" + round(pingMs, 2) + "ms";
Expand Down