Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix traffic class configuration #36

Merged
merged 1 commit into from
Mar 25, 2024
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
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
Loading