Fixed bugs in getUnsigned methods of NetUtils class.
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / utils / NetUtilsTest.java
1 /*
2  * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.sal.utils;
10
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.Arrays;
14
15 import org.junit.Assert;
16 import org.junit.Test;
17
18 public class NetUtilsTest {
19
20     @Test
21     public void testByteArrayMethods() {
22         int ip = 8888;
23         Assert.assertTrue(NetUtils
24                 .byteArray4ToInt(NetUtils.intToByteArray4(ip)) == ip);
25
26         ip = 0xffffffff;
27         Assert.assertTrue(NetUtils
28                 .byteArray4ToInt(NetUtils.intToByteArray4(ip)) == ip);
29
30         ip = 0;
31         Assert.assertTrue(NetUtils
32                 .byteArray4ToInt(NetUtils.intToByteArray4(ip)) == ip);
33
34         ip = 0x1fffffff;
35         Assert.assertTrue(NetUtils
36                 .byteArray4ToInt(NetUtils.intToByteArray4(ip)) == ip);
37
38         ip = 0xfffffff;
39         Assert.assertTrue(NetUtils
40                 .byteArray4ToInt(NetUtils.intToByteArray4(ip)) == ip);
41
42         ip = 0xf000ffff;
43         Assert.assertTrue(NetUtils
44                 .byteArray4ToInt(NetUtils.intToByteArray4(ip)) == ip);
45
46         byte ba[] = { (byte) 0xf, (byte) 0xf, (byte) 0xf, (byte) 0xff };
47         Assert.assertTrue(Arrays.equals(ba, NetUtils.intToByteArray4(NetUtils
48                 .byteArray4ToInt(ba))));
49
50         byte ba1[] = { (byte) 255, (byte) 255, (byte) 255, (byte) 255 };
51         Assert.assertTrue(Arrays.equals(ba1, NetUtils.intToByteArray4(NetUtils
52                 .byteArray4ToInt(ba1))));
53
54         byte ba2[] = { (byte) 255, (byte) 0, (byte) 0, (byte) 0 };
55         Assert.assertTrue(Arrays.equals(ba2, NetUtils.intToByteArray4(NetUtils
56                 .byteArray4ToInt(ba2))));
57
58         byte ba3[] = { (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
59         Assert.assertTrue(Arrays.equals(ba3, NetUtils.intToByteArray4(NetUtils
60                 .byteArray4ToInt(ba3))));
61
62         byte ba4[] = { (byte) 255, (byte) 128, (byte) 0, (byte) 0 };
63         Assert.assertTrue(Arrays.equals(ba4, NetUtils.intToByteArray4(NetUtils
64                 .byteArray4ToInt(ba4))));
65     }
66
67     @Test
68     public void testByteArrayMethodsForLong() {
69         // Test of longToByteArray6 method.
70         byte ba[] = {
71             (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44,
72             (byte) 0x55, (byte) 0x66
73         };
74         long mac = 0x112233445566L;
75         Assert.assertTrue(Arrays.equals(ba, NetUtils.longToByteArray6(mac)));
76
77         byte ba1[] = {
78             (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
79             (byte) 0xff, (byte) 0xff
80         };
81         long mac1 = 0xffffffffffffL;
82         Assert.assertTrue(Arrays.equals(ba1, NetUtils.longToByteArray6(mac1)));
83
84         byte ba2[] = {
85             (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
86             (byte) 0x00, (byte) 0x00
87         };
88         long mac2 = 0x000000000000L;
89         Assert.assertTrue(Arrays.equals(ba2, NetUtils.longToByteArray6(mac2)));
90
91         byte ba3[] = {
92             (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00,
93             (byte) 0x00, (byte) 0x00
94         };
95         long mac3 = 0xffffff000000L;
96         Assert.assertTrue(Arrays.equals(ba3, NetUtils.longToByteArray6(mac3)));
97
98         byte ba4[] = {
99             (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xff,
100             (byte) 0xff, (byte) 0xff
101         };
102         long mac4 = 0x000000ffffffL;
103         Assert.assertTrue(Arrays.equals(ba4, NetUtils.longToByteArray6(mac4)));
104
105         // Convert a long number to a byte array,
106         // and revert it to the long number again.
107         Assert.assertTrue(NetUtils
108                 .byteArray6ToLong(NetUtils.longToByteArray6(mac)) == mac);
109
110         Assert.assertTrue(NetUtils
111                 .byteArray6ToLong(NetUtils.longToByteArray6(mac1)) == mac1);
112
113         Assert.assertTrue(NetUtils
114                 .byteArray6ToLong(NetUtils.longToByteArray6(mac2)) == mac2);
115
116         Assert.assertTrue(NetUtils
117                 .byteArray6ToLong(NetUtils.longToByteArray6(mac3)) == mac3);
118
119         Assert.assertTrue(NetUtils
120                 .byteArray6ToLong(NetUtils.longToByteArray6(mac4)) == mac4);
121
122         // Convert a byte array to a long nubmer,
123         // and revert it to the byte array again.
124         Assert.assertTrue(Arrays.equals(ba,
125                     NetUtils.longToByteArray6(NetUtils.byteArray6ToLong(ba))));
126
127         Assert.assertTrue(Arrays.equals(ba1,
128                     NetUtils.longToByteArray6(NetUtils.byteArray6ToLong(ba1))));
129
130         Assert.assertTrue(Arrays.equals(ba2,
131                     NetUtils.longToByteArray6(NetUtils.byteArray6ToLong(ba2))));
132
133         Assert.assertTrue(Arrays.equals(ba3,
134                     NetUtils.longToByteArray6(NetUtils.byteArray6ToLong(ba3))));
135
136         Assert.assertTrue(Arrays.equals(ba4,
137                     NetUtils.longToByteArray6(NetUtils.byteArray6ToLong(ba4))));
138
139         // Test of paramter validation of byteArray6ToLong method.
140         byte array5[] = {
141             (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44
142         };
143         Assert.assertEquals(0, NetUtils.byteArray6ToLong(array5));
144
145         byte array7[] = {
146             (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44,
147             (byte) 0x55, (byte) 0x66, (byte) 0x77
148         };
149         Assert.assertEquals(0, NetUtils.byteArray6ToLong(array7));
150
151         byte arrayNull[] = null;
152         Assert.assertEquals(0, NetUtils.byteArray6ToLong(arrayNull));
153     }
154
155     @Test
156     public void testInetMethods() throws UnknownHostException {
157         int ip = 0xfffffff0;
158         InetAddress inet = InetAddress.getByName("255.255.255.240");
159         Assert.assertTrue(inet.equals(NetUtils.getInetAddress(ip)));
160
161         ip = 0;
162         inet = InetAddress.getByName("0.0.0.0");
163         Assert.assertTrue(inet.equals(NetUtils.getInetAddress(ip)));
164
165         ip = 0x9ffff09;
166         inet = InetAddress.getByName("9.255.255.9");
167         Assert.assertTrue(inet.equals(NetUtils.getInetAddress(ip)));
168     }
169
170     @Test
171     public void testMasksV4() throws UnknownHostException {
172
173         InetAddress mask = InetAddress.getByName("128.0.0.0");
174         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(1, false)));
175
176         mask = InetAddress.getByName("192.0.0.0");
177         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(2, false)));
178
179         mask = InetAddress.getByName("224.0.0.0");
180         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(3, false)));
181
182         mask = InetAddress.getByName("240.0.0.0");
183         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(4, false)));
184
185         mask = InetAddress.getByName("248.0.0.0");
186         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(5, false)));
187
188         mask = InetAddress.getByName("252.0.0.0");
189         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(6, false)));
190
191         mask = InetAddress.getByName("254.0.0.0");
192         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(7, false)));
193
194         mask = InetAddress.getByName("255.0.0.0");
195         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(8, false)));
196
197         mask = InetAddress.getByName("255.128.0.0");
198         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(9, false)));
199
200         mask = InetAddress.getByName("255.192.0.0");
201         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(10, false)));
202
203         mask = InetAddress.getByName("255.224.0.0");
204         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(11, false)));
205
206         mask = InetAddress.getByName("255.240.0.0");
207         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(12, false)));
208
209         mask = InetAddress.getByName("255.248.0.0");
210         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(13, false)));
211
212         mask = InetAddress.getByName("255.252.0.0");
213         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(14, false)));
214
215         mask = InetAddress.getByName("255.254.0.0");
216         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(15, false)));
217
218         mask = InetAddress.getByName("255.255.0.0");
219         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(16, false)));
220
221         mask = InetAddress.getByName("255.255.128.0");
222         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(17, false)));
223
224         mask = InetAddress.getByName("255.255.192.0");
225         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(18, false)));
226
227         mask = InetAddress.getByName("255.255.224.0");
228         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(19, false)));
229
230         mask = InetAddress.getByName("255.255.240.0");
231         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(20, false)));
232
233         mask = InetAddress.getByName("255.255.248.0");
234         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(21, false)));
235
236         mask = InetAddress.getByName("255.255.252.0");
237         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(22, false)));
238
239         mask = InetAddress.getByName("255.255.254.0");
240         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(23, false)));
241
242         mask = InetAddress.getByName("255.255.255.0");
243         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(24, false)));
244
245         mask = InetAddress.getByName("255.255.255.128");
246         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(25, false)));
247
248         mask = InetAddress.getByName("255.255.255.192");
249         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(26, false)));
250
251         mask = InetAddress.getByName("255.255.255.224");
252         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(27, false)));
253
254         mask = InetAddress.getByName("255.255.255.240");
255         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(28, false)));
256
257         mask = InetAddress.getByName("255.255.255.248");
258         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(29, false)));
259
260         mask = InetAddress.getByName("255.255.255.252");
261         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(30, false)));
262
263         mask = InetAddress.getByName("255.255.255.254");
264         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(31, false)));
265
266         mask = InetAddress.getByName("255.255.255.255");
267         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(32, false)));
268     }
269
270     @Test
271     public void testMasksV6() throws UnknownHostException {
272
273         InetAddress mask = InetAddress.getByName("ff00::0");
274         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(8, true)));
275
276         mask = InetAddress.getByName("8000::0");
277         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(1, true)));
278
279         mask = InetAddress.getByName("f800::0");
280         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(5, true)));
281
282         mask = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe");
283         Assert.assertTrue(mask.equals(NetUtils.getInetNetworkMask(127, true)));
284     }
285
286     @Test
287     public void testGetSubnetLen() {
288
289         byte address[] = { (byte) 128, (byte) 0, (byte) 0, 0 };
290         Assert.assertTrue(NetUtils.getSubnetMaskLength(address) == 1);
291
292         byte address1[] = { (byte) 255, 0, 0, 0 };
293         Assert.assertTrue(NetUtils.getSubnetMaskLength(address1) == 8);
294
295         byte address2[] = { (byte) 255, (byte) 255, (byte) 248, 0 };
296         Assert.assertTrue(NetUtils.getSubnetMaskLength(address2) == 21);
297
298         byte address4[] = { (byte) 255, (byte) 255, (byte) 255, (byte) 254 };
299         Assert.assertTrue(NetUtils.getSubnetMaskLength(address4) == 31);
300
301         byte address5[] = { (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255,
302                 (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255,
303                 (byte) 255 };
304         Assert.assertTrue(NetUtils.getSubnetMaskLength(address5) == 128);
305
306         byte address6[] = { (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255,
307                 (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255,
308                 (byte) 254 };
309         Assert.assertTrue(NetUtils.getSubnetMaskLength(address6) == 127);
310
311         byte address7[] = { (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255,
312                 (byte) 255, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
313         Assert.assertTrue(NetUtils.getSubnetMaskLength(address7) == 64);
314
315         byte address8[] = { (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255,
316                 (byte) 254, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
317         Assert.assertTrue(NetUtils.getSubnetMaskLength(address8) == 63);
318
319         byte address9[] = { (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 128,
320                 (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
321         Assert.assertTrue(NetUtils.getSubnetMaskLength(address9) == 49);
322
323         byte address10[] = { (byte) 128, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
324                 (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
325         Assert.assertTrue(NetUtils.getSubnetMaskLength(address10) == 1);
326
327         byte address11[] = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
328                 (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
329         Assert.assertTrue(NetUtils.getSubnetMaskLength(address11) == 0);
330     }
331
332     @Test
333     public void testGetSubnetPrefix() throws UnknownHostException {
334         InetAddress ip = InetAddress.getByName("192.128.64.252");
335         int maskLen = 25;
336         Assert.assertTrue(NetUtils.getSubnetPrefix(ip, maskLen).equals(
337                 InetAddress.getByName("192.128.64.128")));
338     }
339
340     @Test
341     public void testIsIPv6Valid() throws UnknownHostException {
342         Assert.assertTrue(NetUtils
343                 .isIPv6AddressValid("fe80:0000:0000:0000:0204:61ff:fe9d:f156")); //normal ipv6
344         Assert.assertTrue(NetUtils
345                 .isIPv6AddressValid("fe80:0:0:0:204:61ff:fe9d:f156")); //no leading zeroes
346         Assert.assertTrue(NetUtils
347                 .isIPv6AddressValid("fe80::204:61ff:fe9d:f156")); //zeroes to ::
348         Assert
349                 .assertTrue(NetUtils
350                         .isIPv6AddressValid("fe80:0000:0000:0000:0204:61ff:254.157.241.86")); // ipv4 ending
351         Assert.assertTrue(NetUtils
352                 .isIPv6AddressValid("fe80:0:0:0:0204:61ff:254.157.241.86")); // no leading zeroes, ipv4 end
353         Assert.assertTrue(NetUtils
354                 .isIPv6AddressValid("fe80::204:61ff:254.157.241.86")); // zeroes ::, no leading zeroes
355
356         Assert.assertTrue(NetUtils.isIPv6AddressValid("2001::")); //link-local prefix
357         Assert.assertTrue(NetUtils.isIPv6AddressValid("::1")); //localhost
358         Assert.assertTrue(NetUtils.isIPv6AddressValid("fe80::")); //global-unicast
359         Assert.assertFalse(NetUtils.isIPv6AddressValid("abcd")); //not valid
360         Assert.assertFalse(NetUtils.isIPv6AddressValid("1")); //not valid
361         Assert.assertFalse(NetUtils
362                 .isIPv6AddressValid("fe80:0:0:0:204:61ff:fe9d")); //not valid, too short
363         Assert.assertFalse(NetUtils
364                 .isIPv6AddressValid("fe80:::0:0:0:204:61ff:fe9d")); //not valid
365         Assert.assertFalse(NetUtils.isIPv6AddressValid("192.168.1.1")); //not valid,ipv4
366         Assert
367                 .assertFalse(NetUtils
368                         .isIPv6AddressValid("2001:0000:1234:0000:10001:C1C0:ABCD:0876")); //not valid, extra number
369         Assert
370                 .assertFalse(NetUtils
371                         .isIPv6AddressValid("20010:0000:1234:0000:10001:C1C0:ABCD:0876")); //not valid, extra number
372
373         Assert
374                 .assertTrue(NetUtils
375                         .isIPv6AddressValid("2001:0DB8:0000:CD30:0000:0000:0000:0000/60")); //full with mask
376         Assert.assertTrue(NetUtils.isIPv6AddressValid("2001:0DB8:0:CD30::/64")); //shortened with mask
377         Assert.assertTrue(NetUtils.isIPv6AddressValid("2001:0DB8:0:CD30::/0")); //0 subnet with mask
378         Assert.assertTrue(NetUtils.isIPv6AddressValid("::1/128")); //localhost 128 mask
379
380         Assert.assertFalse(NetUtils.isIPv6AddressValid("124.15.6.89/60")); //invalid, ip with mask
381         Assert
382                 .assertFalse(NetUtils
383                         .isIPv6AddressValid("2001:0DB8:0000:CD30:0000:0000:0000:0000/130")); //invalid, mask >128
384         Assert
385                 .assertFalse(NetUtils
386                         .isIPv6AddressValid("2001:0DB8:0:CD30::/-5")); //invalid, mask < 0
387         Assert.assertFalse(NetUtils
388                 .isIPv6AddressValid("fe80:::0:0:0:204:61ff:fe9d/64")); //not valid ip, valid netmask
389         Assert.assertFalse(NetUtils
390                 .isIPv6AddressValid("fe80:::0:0:0:204:61ff:fe9d/-1")); //not valid both
391
392     }
393
394     @Test
395     public void testInetAddressConflict() throws UnknownHostException {
396
397         // test a ipv4 testAddress in the same subnet as the filter
398         // the method should return false as there is no conflict
399         Assert.assertFalse(NetUtils.inetAddressConflict(
400                 InetAddress.getByName("9.9.1.1"),
401                 InetAddress.getByName("9.9.1.0"), null,
402                 InetAddress.getByName("255.255.255.0")));
403
404         // test a ipv4 testAddress not in the same subnet as the filter
405         // the method should return true as there is a conflict
406         Assert.assertTrue(NetUtils.inetAddressConflict(
407                 InetAddress.getByName("9.9.2.1"),
408                 InetAddress.getByName("9.9.1.0"), null,
409                 InetAddress.getByName("255.255.255.0")));
410
411         // test a ipv4 testAddress more generic than the filter
412         // the method should return true as there is a conflict
413         Assert.assertTrue(NetUtils.inetAddressConflict(
414                 InetAddress.getByName("9.9.1.1"),
415                 InetAddress.getByName("9.9.1.0"),
416                 InetAddress.getByName("255.255.0.0"),
417                 InetAddress.getByName("255.255.255.0")));
418
419         // test a ipv4 testAddress less generic than the filter and in the same
420         // subnet as the filter
421         // the method should return false as there is no conflict
422         Assert.assertFalse(NetUtils.inetAddressConflict(
423                 InetAddress.getByName("9.9.1.0"),
424                 InetAddress.getByName("9.9.0.0"),
425                 InetAddress.getByName("255.255.255.0"),
426                 InetAddress.getByName("255.255.0.0")));
427
428         // test a ipv4 testAddress less generic than the filter and not in the
429         // same subnet as the filter
430         // the method should return true as there is a conflict
431         Assert.assertTrue(NetUtils.inetAddressConflict(
432                 InetAddress.getByName("9.8.1.0"),
433                 InetAddress.getByName("9.9.0.0"),
434                 InetAddress.getByName("255.255.255.0"),
435                 InetAddress.getByName("255.255.0.0")));
436
437     }
438
439     @Test
440     public void testIPAddressValidity() {
441         Assert.assertFalse(NetUtils.isIPAddressValid(null));
442         Assert.assertFalse(NetUtils.isIPAddressValid("abc"));
443         Assert.assertFalse(NetUtils.isIPAddressValid("1.1.1"));
444         Assert.assertFalse(NetUtils.isIPAddressValid("1.1.1.1/49"));
445
446         Assert.assertTrue(NetUtils.isIPAddressValid("1.1.1.1"));
447         Assert.assertTrue(NetUtils.isIPAddressValid("1.1.1.1/32"));
448         Assert.assertTrue(NetUtils
449                 .isIPAddressValid("2001:420:281:1004:407a:57f4:4d15:c355"));
450     }
451
452     @Test
453     public void testGetUnsignedByte() {
454         Assert.assertEquals(0,   NetUtils.getUnsignedByte((byte) 0x00));
455         Assert.assertEquals(1,   NetUtils.getUnsignedByte((byte) 0x01));
456         Assert.assertEquals(127, NetUtils.getUnsignedByte((byte) 0x7f));
457
458         Assert.assertEquals(128, NetUtils.getUnsignedByte((byte) 0x80));
459         Assert.assertEquals(255, NetUtils.getUnsignedByte((byte) 0xff));
460     }
461
462     @Test
463     public void testGetUnsignedShort() {
464         Assert.assertEquals(0,     NetUtils.getUnsignedShort((short) 0x0000));
465         Assert.assertEquals(1,     NetUtils.getUnsignedShort((short) 0x0001));
466         Assert.assertEquals(32767, NetUtils.getUnsignedShort((short) 0x7fff));
467
468         Assert.assertEquals(32768, NetUtils.getUnsignedShort((short) 0x8000));
469         Assert.assertEquals(65535, NetUtils.getUnsignedShort((short) 0xffff));
470     }
471 }