1
1
/*
2
- * Copyright 2020 AVSystem <[email protected] >
2
+ * Copyright 2020-2021 AVSystem <[email protected] >
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
21
21
import com .beust .jcommander .IStringConverter ;
22
22
import com .beust .jcommander .Parameter ;
23
23
import com .beust .jcommander .ParameterException ;
24
+ import java .time .Duration ;
25
+ import java .util .Arrays ;
26
+ import java .util .List ;
27
+ import java .util .regex .Matcher ;
28
+ import java .util .regex .Pattern ;
24
29
import org .apache .commons .codec .DecoderException ;
25
30
import org .apache .commons .codec .binary .Hex ;
26
31
27
32
public class DemoArgs {
33
+ public static final class AccessEntry {
34
+ public int ssid ;
35
+ public int oid ;
36
+ public int iid ;
37
+ public int accessMask ;
38
+ }
39
+
40
+ public static AccessEntry convertAccessEntry (String value ) {
41
+ Pattern pattern = Pattern .compile ("/(\\ d+)/(\\ d+),(\\ d+),(\\ d+)" );
42
+ Matcher matcher = pattern .matcher (value );
43
+ if (matcher .matches ()) {
44
+ AccessEntry accessEntry = new AccessEntry ();
45
+ accessEntry .oid = Integer .parseInt (matcher .group (1 ));
46
+ accessEntry .iid = Integer .parseInt (matcher .group (2 ));
47
+ accessEntry .ssid = Integer .parseInt (matcher .group (3 ));
48
+ accessEntry .accessMask = Integer .parseInt (matcher .group (4 ));
49
+ return accessEntry ;
50
+ }
51
+ return null ;
52
+ }
53
+
54
+ private static class AccessEntryConverter implements IStringConverter <AccessEntry > {
55
+ @ Override
56
+ public AccessEntry convert (String value ) {
57
+ AccessEntry accessEntry = DemoArgs .convertAccessEntry (value );
58
+ if (accessEntry != null ) {
59
+ return accessEntry ;
60
+ }
61
+ throw new ParameterException (
62
+ "incorrect value of access entry argument: \" "
63
+ + value
64
+ + "\" , the format is: /OID/IID,SSID,mask" );
65
+ }
66
+ }
67
+
28
68
private static class Lwm2mVersionConverter implements IStringConverter <Lwm2mVersion > {
29
69
@ Override
30
70
public Lwm2mVersion convert (String value ) {
@@ -35,7 +75,7 @@ public Lwm2mVersion convert(String value) {
35
75
}
36
76
throw new ParameterException (
37
77
"incorrect value of version argument, expected one of: "
38
- + Lwm2mVersion .values ());
78
+ + Arrays . toString ( Lwm2mVersion .values () ));
39
79
}
40
80
}
41
81
@@ -49,7 +89,7 @@ public SecurityMode convert(String value) {
49
89
}
50
90
throw new ParameterException (
51
91
"incorrect value of security mode argument, expected one of: "
52
- + SecurityMode .values ());
92
+ + Arrays . toString ( SecurityMode .values () ));
53
93
}
54
94
}
55
95
@@ -64,6 +104,13 @@ public byte[] convert(String value) {
64
104
}
65
105
}
66
106
107
+ private static class DurationConverter implements IStringConverter <Duration > {
108
+ @ Override
109
+ public Duration convert (String value ) {
110
+ return Duration .ofMillis ((long ) (Double .parseDouble (value ) * 1000 ));
111
+ }
112
+ }
113
+
67
114
@ Parameter (
68
115
names = {"-u" , "--server-uri" },
69
116
description = "Server URI to connect to" )
@@ -89,11 +136,51 @@ public byte[] convert(String value) {
89
136
converter = HexStringConverter .class )
90
137
public byte [] pskOrPrivKey ;
91
138
139
+ @ Parameter (
140
+ names = {"-C" , "--client-cert-file" },
141
+ description =
142
+ "DER-formatted client certificate file to load. Mutually exclusive with -i." )
143
+ public String clientCertFile ;
144
+
145
+ @ Parameter (
146
+ names = {"-K" , "--key-file" },
147
+ description =
148
+ "DER-formatted PKCS#8 private key complementary to the certificate specified with -C. Mutually exclusive with -k." )
149
+ public String keyFile ;
150
+
92
151
@ Parameter (
93
152
names = {"-e" , "--endpoint-name" },
94
153
description = "endpoint name to use" )
95
154
public String endpointName = "anjay-jni" ;
96
155
156
+ @ Parameter (
157
+ names = {"-b" , "--bootstrap" },
158
+ description = "treat first URI as Bootstrap Server" )
159
+ public boolean bootstrap ;
160
+
161
+ @ Parameter (
162
+ names = "--bootstrap=client-initiated-only" ,
163
+ description =
164
+ "treat first URI as Bootstrap Server (the legacy LwM2M 1.0-style Server-Initiated bootstrap mode is not available)" )
165
+ public boolean bootstrapClientInitiatedOnly = false ;
166
+
167
+ @ Parameter (
168
+ names = {"-H" , "--bootstrap-holdoff" },
169
+ description = "number of seconds to wait before attempting Client Initiated Bootstrap" )
170
+ public Integer bootstrapHoldoff = 0 ;
171
+
172
+ @ Parameter (
173
+ names = {"-T" , "--bootstrap-timeout" },
174
+ description =
175
+ "number of seconds to keep the Bootstrap Server Account for after successful bootstrapping, or 0 for infinity" )
176
+ public Integer bootstrapTimeout = 0 ;
177
+
178
+ @ Parameter (
179
+ names = {"-a" , "--access-entry" },
180
+ description = "create ACL entry for specified /OID/IID and SSID" ,
181
+ listConverter = AccessEntryConverter .class )
182
+ public List <AccessEntry > accessEntries = null ;
183
+
97
184
@ Parameter (
98
185
names = "--dm-persistence-file" ,
99
186
description =
@@ -123,12 +210,37 @@ public byte[] convert(String value) {
123
210
converter = Lwm2mVersionConverter .class )
124
211
public Lwm2mVersion maximumVersion = Lwm2mVersion .VERSION_1_1 ;
125
212
213
+ @ Parameter (
214
+ names = "--cache-size" ,
215
+ description =
216
+ "Size, in bytes, of a buffer reserved for caching sent responses to detect retransmissions. Setting it to 0 disables caching mechanism." )
217
+ public Integer cacheSize = 0 ;
218
+
126
219
@ Parameter (
127
220
names = {"--fw-cert-file" },
128
221
description =
129
222
"Require certificate validation against specified file when downloading firmware over encrypted channels" )
130
223
public String fwCertFile = null ;
131
224
225
+ @ Parameter (
226
+ names = "--ack-random-factor" ,
227
+ description = "Configures ACK_RANDOM_FACTOR (defined in RFC7252)" )
228
+ public Double ackRandomFactor = 1.5 ;
229
+
230
+ @ Parameter (
231
+ names = "--ack-timeout" ,
232
+ description = "Configures ACK_TIMEOUT (defined in RFC7252) in seconds" ,
233
+ converter = DurationConverter .class )
234
+ public Duration ackTimeout = Duration .ofSeconds (2 );
235
+
236
+ @ Parameter (
237
+ names = "--max-retransmit" ,
238
+ description = "Configures MAX_RETRANSMIT (defined in RFC7252)" )
239
+ public Integer maxRetransmit = 4 ;
240
+
241
+ @ Parameter (names = "--nstart" , description = "Configures NSTART (defined in RFC7252)" )
242
+ public Integer nstart = 1 ;
243
+
132
244
@ Parameter (
133
245
names = {"-h" , "--help" },
134
246
description = "shows this message and exits" ,
0 commit comments