Skip to content

Commit

Permalink
Fix traffic class configuration (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: Tilmann Zäschke <tilmann.zaeschke@inf.ethz.ch>
  • Loading branch information
tzaeschke and Tilmann Zäschke authored Mar 25, 2024
1 parent 324b243 commit 643fac2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Small fixes for 0.1.0 release. [#32](https://github.com/netsec-ethz/scion-java-client/pull/32)
- Fix NPE after 2nd send() in unconnected channel + cleanup.
[#33](https://github.com/netsec-ethz/scion-java-client/pull/33)
- Fixed traffic class not set. [#36](https://github.com/netsec-ethz/scion-java-client/pull/36)

### Removed

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/scion/AbstractDatagramChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,15 @@ protected void buildHeader(

byte[] rawPath = path.getRawPath();
ScionHeaderParser.write(
buffer, payloadLength, rawPath.length, srcIA, srcAddress, dstIA, dstAddress, hdrType);
buffer,
payloadLength,
rawPath.length,
srcIA,
srcAddress,
dstIA,
dstAddress,
hdrType,
cfgTrafficClass);
ScionHeaderParser.writePath(buffer, rawPath);

if (hdrType == InternalConstants.HdrTypes.UDP) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/scion/internal/ScionHeaderParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,16 @@ public static void write(
byte[] srcAddress,
long dstIsdAs,
byte[] dstAddress,
InternalConstants.HdrTypes hdrType) {
InternalConstants.HdrTypes hdrType,
int trafficClass) {
int sl = srcAddress.length / 4 - 1;
int dl = dstAddress.length / 4 - 1;

int i0 = 0;
int i1 = 0;
int i2 = 0;
i0 = writeInt(i0, 0, 4, 0); // version = 0
i0 = writeInt(i0, 4, 8, 0); // TrafficClass = 0
i0 = writeInt(i0, 4, 8, trafficClass); // TrafficClass = 0
i0 = writeInt(i0, 12, 20, 1); // FlowID = 1
data.putInt(i0);
i1 = writeInt(i1, 0, 8, hdrType.code); // NextHdr = 17 is for UDP OverlayHeader
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/scion/api/DatagramChannelApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ void setOption_TrafficClass() throws IOException {
mock.setSendCallback(
(buffer, address) -> {
assertEquals(
0, ScionPacketInspector.readPacket(buffer).getScionHeader().getTrafficClass());
42, ScionPacketInspector.readPacket(buffer).getScionHeader().getTrafficClass());
return 0;
});
channel.send(buf, dummyAddress);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/scion/internal/HeaderComposeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void testCompose() throws IOException {
srcAddress,
dstIA,
dstAddress,
InternalConstants.HdrTypes.UDP);
InternalConstants.HdrTypes.UDP,
0);
ScionHeaderParser.writePath(p, path);

// Overlay header
Expand Down

0 comments on commit 643fac2

Please sign in to comment.