Skip to content

Commit

Permalink
squash-24
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilmann Zäschke committed Aug 12, 2024
1 parent 5cf921d commit 032f7f0
Show file tree
Hide file tree
Showing 31 changed files with 1,270 additions and 655 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

### TODO for 0.3.0
- BUG: System.setProperty(Constants.PROPERTY_DAEMON, "127.0.0.1");
leads to exception about missing TRC (instead of complaining about missing ":30255")
-> DOes this work with an IPv6 address (separaeting the port?)
-> Think about making the port optional, it is standardized to 30255 anyway
-> Move port to separate environment variable????
- Make ResponsePath/RequestPath classes private. Make at least create() private...
- Demo that connects to Francois' website
- Fix @Disabled tests
- Support topofile port range
- `ResponsePath` is now package private (not public anymore)
- remove ScionAddress?
Expand All @@ -27,6 +34,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Support for bootstrapper TRC metadata. [#110](https://github.com/scionproto-contrib/jpan/pull/110)
- Added `copy(...)` method for paths. [#111](https://github.com/scionproto-contrib/jpan/pull/111)
- Support shortcut and on-path detection during path construction. Also:
- New option `SCION_RESOLVER_MINIMIZE_REQUESTS`
- Fixed MTU calculations for link level MTU
- Path lists are ordered by hop count
- Path lists contain no duplicates
[#104](https://github.com/scionproto-contrib/jpan/pull/104)

### Changed
- Clean up TODO and deprecation info. [#100](https://github.com/scionproto-contrib/jpan/pull/100)
Expand Down
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ attempt to get network information in the following order until it succeeds:
The reason that the daemon is checked last is that it has a default setting (`localhost:30255`)
while the other options are skipped if no property or environment variable is defined.

| Option | Java property | Environment variable | Default value |
|-------------------------------------|----------------------------------|-------------------------------|-----------------|
| Daemon port | `org.scion.daemon.port` | `SCION_DAEMON` | localhost:30255 |
| Bootstrap topology file path | `org.scion.bootstrap.topoFile` | `SCION_BOOTSTRAP_TOPO_FILE` | |
| Bootstrap server host | `org.scion.bootstrap.host` | `SCION_BOOTSTRAP_HOST` | |
| Bootstrap DNS NAPTR entry host name | `org.scion.bootstrap.naptr.name` | `SCION_BOOTSTRAP_NAPTR_NAME` | |
| Option | Java property | Environment variable | Default value |
|-------------------------------------|-------------------------------------|-------------------------------|-----------------|
| Daemon port | `org.scion.daemon.port` | `SCION_DAEMON` | localhost:30255 |
| Bootstrap topology file path | `org.scion.bootstrap.topoFile` | `SCION_BOOTSTRAP_TOPO_FILE` | |
| Bootstrap server host | `org.scion.bootstrap.host` | `SCION_BOOTSTRAP_HOST` | |
| Bootstrap DNS NAPTR entry host name | `org.scion.bootstrap.naptr.name` | `SCION_BOOTSTRAP_NAPTR_NAME` | |
| Bootstrap DNS NAPTR entry host name | `org.scion.test.useOsSearchDomains` | `SCION_USE_OS_SEARCH_DOMAINS` | true |

### DNS
Expand All @@ -345,10 +345,18 @@ is configurable, see next section.

### Other Options

| Option | Java property | Environment variable | Default value |
|----------------------------------------------------------------------------------------------------------------------|-------------------------|----------------------|--------------------|
| Path expiry margin. Before sending a packet a new path is requested if the path is about to expire within X seconds. | `org.scion.pathExpiryMargin` | `SCION_PATH_EXPIRY_MARGIN` | 10 |
| Location of `hosts` file. Multiple location can be specified separated by `;`. | `org.scion.hostsFiles` | `SCION_HOSTS_FILES` | `/etc/scion/hosts` |
| Option | Java property | Environment variable | Default value |
|----------------------------------------------------------------------------------------------------------------------|---------------------------------------|--------------------------------------|--------------------|
| Path expiry margin. Before sending a packet a new path is requested if the path is about to expire within X seconds. | `org.scion.pathExpiryMargin` | `SCION_PATH_EXPIRY_MARGIN` | 10 |
| Location of `hosts` file. Multiple location can be specified separated by `;`. | `org.scion.hostsFiles` | `SCION_HOSTS_FILES` | `/etc/scion/hosts` |
| Minimize segment requests to local AS at the cost of reduced range of path available. | `org.scion.resolver.minimizeRequests` | `SCION_RESOLVER_MINIMIZE_REQUESTS` | `false` |

`SCION_RESOLVER_MINIMIZE_REQUESTS` is a non-standard option that request CORE segments only of other
path can be constructed. This may reduce response time when requesting new paths. It is very likely,
but not guaranteed, that the shortest path (fewest hops) will be available.
If this property is not set (= default), CORE segments are always requested, resulting in additional
path options. While these additional path options almost always result in longer paths, they may have
other advantages.

## FAQ / Troubleshooting

Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/scion/jpan/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

public final class Constants {
public static final int SCMP_PORT = 30041;

/**
* @deprecated Dispatcher support will be removed soon.
*/
Expand All @@ -27,16 +28,19 @@ public final class Constants {

/** Address of bootstrap server (http), e.g. 192.168.42.42 */
public static final String PROPERTY_BOOTSTRAP_HOST = "org.scion.bootstrap.host";

/** Address of bootstrap server (http), e.g. 192.168.42.42 */
public static final String ENV_BOOTSTRAP_HOST = "SCION_BOOTSTRAP_HOST";

/** Host name of DNS entry with NAPTR record for bootstrap service. */
public static final String PROPERTY_BOOTSTRAP_NAPTR_NAME = "org.scion.bootstrap.naptr.name";

/** Host name of DNS entry with NAPTR record for bootstrap service. */
public static final String ENV_BOOTSTRAP_NAPTR_NAME = "SCION_BOOTSTRAP_NAPTR_NAME";

/** path/file name for topology file. */
public static final String PROPERTY_BOOTSTRAP_TOPO_FILE = "org.scion.bootstrap.topoFile";

/** path/file name for topology file. */
public static final String ENV_BOOTSTRAP_TOPO_FILE = "SCION_BOOTSTRAP_TOPO_FILE";

Expand All @@ -61,13 +65,22 @@ public final class Constants {
/** Time (in seconds) before expiration at which a paths is automatically renewed. */
public static final int DEFAULT_PATH_EXPIRY_MARGIN = 10;

/** Enable minimization of segment requests during path construction. */
public static final String PROPERTY_RESOLVER_MINIMIZE_REQUESTS =
"SCION_RESOLVER_MINIMIZE_REQUESTS";

/** Enable minimization of segment requests during path construction. */
public static final String ENV_RESOLVER_MINIMIZE_REQUESTS = "org.scion.resolver.minimizeRequests";

public static final boolean DEFAULT_RESOLVER_MINIMIZE_REQUESTS = false;

/**
* Disable usage of OS search domains for DNS lookup, e.g from /etc/resolv.conf. This needs to be
* Disable usage of OS search domains for DNS lookup, e.g. from /etc/resolv.conf. This needs to be
* disabled for JUnit testing.
*/
public static final String PROPERTY_USE_OS_SEARCH_DOMAINS = "SCION_USE_OS_SEARCH_DOMAINS";
public static final String PROPERTY_USE_OS_SEARCH_DOMAINS = "org.scion.test.useOsSearchDomains";

public static final String ENV_USE_OS_SEARCH_DOMAINS = "org.scion.test.useOsSearchDomains";
public static final String ENV_USE_OS_SEARCH_DOMAINS = "SCION_USE_OS_SEARCH_DOMAINS";
public static final boolean DEFAULT_USE_OS_SEARCH_DOMAINS = true;

/**
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/scion/jpan/ScionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class ScionService {
private final DaemonServiceGrpc.DaemonServiceBlockingStub daemonStub;
private final SegmentLookupServiceGrpc.SegmentLookupServiceBlockingStub segmentStub;

private final boolean minimizeRequests;
private final ManagedChannel channel;
private static final long ISD_AS_NOT_SET = -1;
private final AtomicLong localIsdAs = new AtomicLong(ISD_AS_NOT_SET);
Expand All @@ -89,6 +90,11 @@ protected enum Mode {
}

protected ScionService(String addressOrHost, Mode mode) {
minimizeRequests =
ScionUtil.getPropertyOrEnv(
Constants.PROPERTY_RESOLVER_MINIMIZE_REQUESTS,
Constants.ENV_RESOLVER_MINIMIZE_REQUESTS,
Constants.DEFAULT_RESOLVER_MINIMIZE_REQUESTS);
if (mode == Mode.DAEMON) {
LOG.info("Bootstrapping with daemon: target={}", addressOrHost);
channel = Grpc.newChannelBuilder(addressOrHost, InsecureChannelCredentials.create()).build();
Expand All @@ -109,7 +115,7 @@ protected ScionService(String addressOrHost, Mode mode) {
}
String csHost = bootstrapper.getLocalTopology().getControlServerAddress();
LOG.info("Bootstrapping with control service: {}", csHost);
localIsdAs.set(bootstrapper.getLocalTopology().getLocalIsdAs());
localIsdAs.set(bootstrapper.getLocalTopology().getIsdAs());
// TODO InsecureChannelCredentials: Implement authentication!
channel = Grpc.newChannelBuilder(csHost, InsecureChannelCredentials.create()).build();
daemonStub = null;
Expand Down Expand Up @@ -596,7 +602,16 @@ private Long parseTxtRecordToIA(String txtEntry) {

// Do not expose protobuf types on API!
List<Daemon.Path> getPathListCS(long srcIsdAs, long dstIsdAs) {
return Segments.getPaths(segmentStub, bootstrapper, srcIsdAs, dstIsdAs);
List<Daemon.Path> list =
Segments.getPaths(segmentStub, bootstrapper, srcIsdAs, dstIsdAs, minimizeRequests);
if (LOG.isInfoEnabled()) {
LOG.info(

Check warning on line 608 in src/main/java/org/scion/jpan/ScionService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/scion/jpan/ScionService.java#L608

Added line #L608 was not covered by tests
"Path found between {} and {}: {}",
ScionUtil.toStringIA(srcIsdAs),
ScionUtil.toStringIA(dstIsdAs),
list.size());

Check warning on line 612 in src/main/java/org/scion/jpan/ScionService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/scion/jpan/ScionService.java#L610-L612

Added lines #L610 - L612 were not covered by tests
}
return list;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/scion/jpan/ScionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,13 @@ static InetSocketAddress parseInetSocketAddress(String addrStr) {
}
}

public static boolean isWildcard(long isdAs) {
return isdAs == toWildcard(isdAs);
}

public static long toWildcard(long isdAs) {
return (isdAs >>> 48) << 48;
}

private ScionUtil() {}
}
66 changes: 56 additions & 10 deletions src/main/java/org/scion/jpan/internal/LocalTopology.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.scion.jpan.ScionRuntimeException;
Expand Down Expand Up @@ -51,11 +52,11 @@ public String getControlServerAddress() {
return controlServices.get(0).ipString;
}

public boolean isLocalAsCore() {
public boolean isCoreAs() {
return isCoreAs;
}

public long getLocalIsdAs() {
public long getIsdAs() {
return ScionUtil.parseIA(localIsdAs);
}

Expand All @@ -78,7 +79,7 @@ public List<String> getBorderRouterAddresses() {
return result;
}

public int getLocalMtu() {
public int getMtu() {
return this.localMtu;
}

Expand All @@ -101,9 +102,12 @@ private void parseTopologyFile(String topologyFile) {
JsonElement local =
underlay.has(("local")) ? underlay.get(("local")) : underlay.get(("public"));
JsonElement remote = underlay.get(("remote"));
long isdAs = ScionUtil.parseIA(ife.get("isd_as").getAsString());
int mtu = ife.get("mtu").getAsInt();
String linkTo = ife.get("link_to").getAsString();
interfaces.add(
new BorderRouterInterface(
ifEntry.getKey(), local.getAsString(), remote.getAsString()));
ifEntry.getKey(), local.getAsString(), remote.getAsString(), isdAs, mtu, linkTo));
}
borderRouters.add(new BorderRouter(e.getKey(), addr, interfaces));
}
Expand Down Expand Up @@ -142,34 +146,76 @@ public String toString() {
}

public List<ServiceNode> getControlServices() {
return controlServices;
return Collections.unmodifiableList(controlServices);
}

private static class BorderRouter {
public List<BorderRouter> getBorderRouters() {
return Collections.unmodifiableList(borderRouters);
}

public static class BorderRouter {
private final String name;
private final String internalAddress;
private final List<BorderRouterInterface> interfaces;

public BorderRouter(String name, String addr, List<BorderRouterInterface> interfaces) {
BorderRouter(String name, String addr, List<BorderRouterInterface> interfaces) {
this.name = name;
this.internalAddress = addr;
this.interfaces = interfaces;
}

public Iterable<BorderRouterInterface> getInterfaces() {
return interfaces;
}
}

private static class BorderRouterInterface {
public static class BorderRouterInterface {
public static final String PARENT = "parent";
public static final String CHILD = "child";
public static final String CORE = "core";
final int id;
final String publicUnderlay;
final String remoteUnderlay;
final long isdAs;
final int mtu;
final String linkTo;

public BorderRouterInterface(String id, String publicU, String remoteU) {
BorderRouterInterface(
String id, String publicU, String remoteU, long isdAs, int mtu, String linkTo) {
this.id = Integer.parseInt(id);
this.publicUnderlay = publicU;
this.remoteUnderlay = remoteU;
this.isdAs = isdAs;
this.mtu = mtu;
this.linkTo = linkTo;
}

public long getIsdAs() {
return isdAs;
}

public int getMtu() {
return mtu;
}

public int getId() {
return id;
}

public String getLinkTo() {
return linkTo;
}

public String getRemoteUnderlay() {
return remoteUnderlay;
}

public String getPublicUnderlay() {
return publicUnderlay;
}
}

static class ServiceNode {
public static class ServiceNode {
final String name;
final String ipString;

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/scion/jpan/internal/MultiMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ public boolean isEmpty() {
public void clear() {
map.clear();
}

public List<V> values() {
ArrayList<V> values = new ArrayList<>(map.size());
for (Map.Entry<K, ArrayList<V>> e : map.entrySet()) {
values.addAll(e.getValue());
}
return values;
}
}
20 changes: 7 additions & 13 deletions src/main/java/org/scion/jpan/internal/ScionBootstrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,21 @@
public class ScionBootstrapper {

private static final Logger LOG = LoggerFactory.getLogger(ScionBootstrapper.class.getName());
private static final String BASE_URL = "";
private static final String TOPOLOGY_ENDPOINT = "topology";
private static final Duration httpRequestTimeout = Duration.of(2, ChronoUnit.SECONDS);
private final String topologyResource;
private final LocalTopology topology;
private final LocalTopology localAS;
private final GlobalTopology world;

protected ScionBootstrapper(String topologyServiceAddress) {
this.topologyResource = topologyServiceAddress;
this.topology = initLocal();
this.localAS = initLocal();
this.world = initGlobal();
}

protected ScionBootstrapper(java.nio.file.Path file) {
this.topologyResource = file.toString();
this.topology = this.init(file);
this.localAS = this.init(file);
this.world = GlobalTopology.createEmpty();
}

Expand All @@ -75,7 +74,7 @@ public static synchronized ScionBootstrapper createViaTopoFile(java.nio.file.Pat
}

public LocalTopology getLocalTopology() {
return topology;
return localAS;
}

public GlobalTopology getGlobalTopology() {
Expand All @@ -95,12 +94,7 @@ private static String bootstrapViaDNS(String hostName) {
}

private LocalTopology initLocal() {
LocalTopology topo = LocalTopology.create(fetchFile(TOPOLOGY_ENDPOINT));
if (topo.getControlServices().isEmpty()) {
throw new ScionRuntimeException(
"No control servers found in topology provided by " + topologyResource);
}
return topo;
return LocalTopology.create(fetchFile(TOPOLOGY_ENDPOINT));
}

private GlobalTopology initGlobal() {
Expand Down Expand Up @@ -129,7 +123,7 @@ private LocalTopology init(java.nio.file.Path file) {
}
LocalTopology topo = LocalTopology.create(contentBuilder.toString());
if (topo.getControlServices().isEmpty()) {
throw new ScionRuntimeException("No control service found in topology filet: " + file);
throw new ScionRuntimeException("No control service found in topology file: " + file);

Check warning on line 126 in src/main/java/org/scion/jpan/internal/ScionBootstrapper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/scion/jpan/internal/ScionBootstrapper.java#L126

Added line #L126 was not covered by tests
}
return topo;
}
Expand All @@ -144,7 +138,7 @@ public void refreshTopology() {
public String fetchFile(String resource) {
try {
LOG.info("Fetching resource from bootstrap server: {} {}", topologyResource, resource);
URL url = new URL("http://" + topologyResource + "/" + BASE_URL + resource);
URL url = new URL("http://" + topologyResource + "/" + resource);
return fetchFile(url);
} catch (IOException e) {
throw new ScionRuntimeException(
Expand Down
Loading

0 comments on commit 032f7f0

Please sign in to comment.