import static org.junit.Assert.assertEquals;
import java.nio.ByteBuffer;
-import junitx.framework.ArrayAssert;
import org.junit.Test;
import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
@Test
public void deserialize__Simple() throws Exception {
- Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "00 BB CC DD " + // instance ID
- "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 "
+ + "02 20 00 0A "
+ + "00 BB CC DD " // instance ID
+ + "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
new LispAddressSerializerContext(null));
- assertEquals(Ipv4BinaryAfi.class, address.getAddressType());
+ assertEquals(Ipv4BinaryAfi.VALUE, address.getAddressType());
Ipv4Binary ipv4 = (Ipv4Binary) address.getAddress();
assertArrayEquals(new byte[] {0x11, 0x22, 0x33, 0x44}, ipv4.getIpv4Binary().getValue());
@Test(expected = LispSerializationException.class)
public void deserialize__ShorterBuffer() throws Exception {
- LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "AA BB "),
- new LispAddressSerializerContext(null));
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("""
+ 40 03 00 00 \
+ 02 20 00 0A \
+ AA BB \
+ """), new LispAddressSerializerContext(null));
}
@Test(expected = LispSerializationException.class)
public void deserialize__UnknownLCAFType() throws Exception {
- LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
- "AA 20 00 0A " + // Type AA is unknown
- "00 BB CC DD " + // instance ID
- "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
- new LispAddressSerializerContext(null));
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("""
+ 40 03 00 00 \
+ AA 20 00 0A \
+ 00 BB CC DD \
+ 00 01 11 22 33 44"""), // AFI=1, IP=0x11223344
+ new LispAddressSerializerContext(null));
}
@Test(expected = LispSerializationException.class)
public void deserialize__LongInstanceID() throws Exception {
- LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + // Type AA is unknown
- "AA BB CC DD " + // instance ID
- "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
- new LispAddressSerializerContext(null));
+ LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("""
+ 40 03 00 00 \
+ 02 20 00 0A \
+ AA BB CC DD \
+ 00 01 11 22 33 44"""), // AFI=1, IP=0x11223344
+ new LispAddressSerializerContext(null));
}
@Test
public void deserialize__Ipv6() throws Exception {
- Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "00 BB CC DD " + // instance ID
- "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD"), // AFI=2,
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 "
+ + "02 20 00 0A "
+ + "00 BB CC DD " // instance ID
+ + "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD"), // AFI=2,
new LispAddressSerializerContext(null));
// IPv6
@Test
public void serialize__Simple() throws Exception {
- Eid eid = LispAddressUtil.asIpv4Eid("17.34.51.68", (long) 0x00020304);
+ Eid eid = LispAddressUtil.asIpv4Eid("17.34.51.68", 0x00020304L);
ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eid));
LispAddressSerializer.getInstance().serialize(buf, eid);
- ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
- "02 20 00 0A " + //
- "00 02 03 04 " + // instance ID
- "00 01 11 22 33 44");
- ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 "
+ + "02 20 00 0A "
+ + "00 02 03 04 " // instance ID
+ + "00 01 11 22 33 44");
+ assertArrayEquals(expectedBuf.array(), buf.array());
}
}