Skip to content

Commit

Permalink
GH-1434: Use LWM2M v1.1 default object version way at client side.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jun 14, 2023
1 parent 3786149 commit b620141
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.core.request.ReadRequest;
import org.eclipse.leshan.core.response.ReadResponse;
import org.eclipse.leshan.core.util.StringUtils;

/**
* An Utility class which help to generate @{link Link} from {@link LwM2mObjectEnabler} and {@link LwM2mModel}.<br>
Expand Down Expand Up @@ -269,8 +268,14 @@ protected List<LwM2mAttribute<?>> getObjectAttributes(ObjectModel objectModel) {
}

protected Version getVersion(ObjectModel objectModel) {
if (StringUtils.isEmpty(objectModel.version) || ObjectModel.DEFAULT_VERSION.equals(objectModel.version)) {
return null;
if (versionRegistry.isCoreObject(objectModel.id, version)) {
if (versionRegistry.isDefaultVersion(new Version(objectModel.version), objectModel.id, version)) {
return null;
}
} else {
if (Version.V1_0.equals(new Version(objectModel.version))) {
return null;
}
}
return new Version(objectModel.version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public Version getDefaultVersion(int objectId, LwM2mVersion lwM2mVersion) {
return null;
}

public boolean isCoreObject(int objectId, LwM2mVersion lwM2mVersion) {
Map<Integer, Version> objectIdToVersion = lwm2mVerionToObjectRegistry.get(lwM2mVersion);
return objectIdToVersion.get(objectId) != null;
}

public boolean isDefaultVersion(Version objectVersion, int objectId, LwM2mVersion lwM2mVersion) {
Map<Integer, Version> objectIdToVersion = lwm2mVerionToObjectRegistry.get(lwM2mVersion);
if (objectIdToVersion != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ public void bootstrapWithDiscoverOnRoot(Protocol givenProtocol, String givenClie
LwM2mResponse firstResponse = bootstrapServer.getFirstResponseFor(bootstrapSession, firstRequest);
assertThat(firstResponse).isInstanceOfSatisfying(BootstrapDiscoverResponse.class, r -> {
assertThat(r).hasCode(ResponseCode.CONTENT);
assertThat(r.getObjectLinks()).isLikeLwM2mLinks(String.format(
"</>;lwm2m=1.0,</0>;ver=1.1,</0/0>;uri=\"coap://%s:%d\",</1>;ver=1.1,</2>,</3442/0>,</3>;ver=1.1,</3/0>",
bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
bootstrapServer.getEndpoint(givenProtocol).getURI().getPort()));
assertThat(r.getObjectLinks()).isLikeLwM2mLinks(
String.format("</>;lwm2m=1.0,</0/0>;uri=\"coap://%s:%d\",</1>,</2>,</3442/0>,</3/0>",
bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
bootstrapServer.getEndpoint(givenProtocol).getURI().getPort()));
});
}

Expand Down Expand Up @@ -398,10 +398,10 @@ public void bootstrapWithDiscoverOnRootThenRebootstrap(Protocol givenProtocol, S
LwM2mResponse firstResponse = bootstrapServer.getFirstResponseFor(bootstrapSession, firstRequest);
assertThat(firstResponse).isInstanceOfSatisfying(BootstrapDiscoverResponse.class, r -> {
assertThat(r).hasCode(ResponseCode.CONTENT);
assertThat(r.getObjectLinks()).isLikeLwM2mLinks(String.format(
"</>;lwm2m=1.0,</0>;ver=1.1,</0/0>;uri=\"coap://%s:%d\",</1>;ver=1.1,</2>,</3442/0>,</3>;ver=1.1,</3/0>",
bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
bootstrapServer.getEndpoint(givenProtocol).getURI().getPort()));
assertThat(r.getObjectLinks()).isLikeLwM2mLinks(
String.format("</>;lwm2m=1.0,</0/0>;uri=\"coap://%s:%d\",</1>,</2>,</3442/0>,</3/0>",
bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
bootstrapServer.getEndpoint(givenProtocol).getURI().getPort()));
});

// re-bootstrap
Expand All @@ -423,7 +423,7 @@ public void bootstrapWithDiscoverOnRootThenRebootstrap(Protocol givenProtocol, S
assertThat(secondResponse).isInstanceOfSatisfying(BootstrapDiscoverResponse.class, r -> {
assertThat(r).hasCode(ResponseCode.CONTENT);
assertThat(r.getObjectLinks()).isLikeLwM2mLinks(String.format(
"</>;lwm2m=1.0,</0>;ver=1.1,</0/0>;uri=\"coap://%s:%d\",</0/1>;ssid=2222;uri=\"coap://%s:%d\",</1>;ver=1.1,</1/0>;ssid=2222,</2>,</3442/0>,</3>;ver=1.1,</3/0>",
"</>;lwm2m=1.0,</0/0>;uri=\"coap://%s:%d\",</0/1>;ssid=2222;uri=\"coap://%s:%d\",</1/0>;ssid=2222,</2>,</3442/0>,</3/0>",
bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
bootstrapServer.getEndpoint(givenProtocol).getURI().getPort(),
server.getEndpoint(givenProtocol).getURI().getHost(),
Expand Down Expand Up @@ -467,7 +467,7 @@ public void bootstrapWithDiscoverOnDevice(Protocol givenProtocol, String givenCl
LwM2mResponse firstResponse = bootstrapServer.getFirstResponseFor(bootstrapSession, firstRequest);
assertThat(firstResponse).isInstanceOfSatisfying(BootstrapDiscoverResponse.class, r -> {
assertThat(r).hasCode(ResponseCode.CONTENT);
assertThat(r.getObjectLinks()).isLikeLwM2mLinks("</>;lwm2m=1.0,</3>;ver=1.1,</3/0>");
assertThat(r.getObjectLinks()).isLikeLwM2mLinks("</>;lwm2m=1.0,</3/0>");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public void can_discover_object(Protocol givenProtocol, String givenClientEndpoi
assertThat(response) //
.hasCode(CONTENT) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider) // */
.hasObjectLinksLike(
"</3>;ver=1.1,</3/0>,</3/0/0>,</3/0/1>,</3/0/2>,</3/0/11>,</3/0/14>,</3/0/15>,</3/0/16>");
.hasObjectLinksLike("</3>,</3/0>,</3/0/0>,</3/0/1>,</3/0/2>,</3/0/11>,</3/0/14>,</3/0/15>,</3/0/16>");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void awake_sleeping_awake_sleeping(Protocol givenProtocol, String givenCl
assertThat(client).isRegisteredAt(server);
Registration registration = server.getRegistrationFor(client);
assertThat(registration.getObjectLinks()).isLikeLinks(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1>;ver=1.1,</1/0>,</2>,</3>;ver=1.1,</3/0>,</3442/0>");
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>");

// Wait for client awake time expiration (20% margin)
assertThat(client).after((long) (AWAKETIME * 0.8), TimeUnit.MILLISECONDS).isAwakeOn(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void register_update_deregister(Protocol protocol, String clientEndpointP
assertThat(client).isRegisteredAt(server);
Registration registration = server.getRegistrationFor(client);
assertThat(registration.getObjectLinks()).isLikeLinks(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1>;ver=1.1,</1/0>,</2>,</3>;ver=1.1,</3/0>,</3442/0>");
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>");

// Check for update
client.waitForUpdateTo(server, SHORT_LIFETIME, TimeUnit.SECONDS);
Expand Down

0 comments on commit b620141

Please sign in to comment.