use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.
the class InstanceIdSerializerTest method deserialize__Simple.
@Test
public void deserialize__Simple() throws Exception {
Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer(//
"40 03 00 00 " + //
"02 20 00 0A " + // instance ID
"00 BB CC DD " + // AFI=1, IP=0x11223344
"00 01 11 22 33 44"), new LispAddressSerializerContext(null));
assertEquals(Ipv4BinaryAfi.class, address.getAddressType());
Ipv4Binary ipv4 = (Ipv4Binary) address.getAddress();
assertArrayEquals(new byte[] { 0x11, 0x22, 0x33, 0x44 }, ipv4.getIpv4Binary().getValue());
assertEquals(0x00BBCCDD, address.getVirtualNetworkId().getValue().longValue());
}
use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.
the class SourceDestKeySerializerTest method deserialize__Simple.
@Test
public void deserialize__Simple() throws Exception {
Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer(//
"40 03 00 00 " + //
"0C 20 00 10 " + // reserved + masks
"00 00 10 18 " + // AFI=1, IP=0x11223344
"00 01 11 22 33 44 " + // AFI=1, IP=0x22334455
"00 01 22 33 44 55"), new LispAddressSerializerContext(null));
assertEquals(SourceDestKeyLcaf.class, address.getAddressType());
SourceDestKey srcDestAddress = (SourceDestKey) address.getAddress();
assertEquals((byte) 0x10, MaskUtil.getMaskForAddress(srcDestAddress.getSourceDestKey().getSource()));
assertEquals((byte) 0x18, MaskUtil.getMaskForAddress(srcDestAddress.getSourceDestKey().getDest()));
assertEquals("17.34.51.68/16", String.valueOf(srcDestAddress.getSourceDestKey().getSource().getValue()));
assertEquals("34.51.68.85/24", String.valueOf(srcDestAddress.getSourceDestKey().getDest().getValue()));
}
use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.
the class MapRequestSerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
public MapRequest deserialize(ByteBuffer requestBuffer, InetAddress sourceRloc) {
try {
final byte typeAndFlags = requestBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapRequest) {
throw new LispSerializationException("Expected Map-Request packet (type 1), but was type " + type);
}
MapRequestBuilder builder = new MapRequestBuilder();
builder.setAuthoritative(ByteUtil.extractBit(typeAndFlags, Flags.AUTHORITATIVE));
builder.setMapDataPresent(ByteUtil.extractBit(typeAndFlags, Flags.MAP_DATA_PRESENT));
builder.setProbe(ByteUtil.extractBit(typeAndFlags, Flags.PROBE));
builder.setSmr(ByteUtil.extractBit(typeAndFlags, Flags.SMR));
final byte moreFlags = requestBuffer.get();
builder.setPitr(ByteUtil.extractBit(moreFlags, Flags.PITR));
builder.setSmrInvoked(ByteUtil.extractBit(moreFlags, Flags.SMR_INVOKED));
final int itrCount = ByteUtil.getUnsignedByte(requestBuffer) + 1;
final int recordCount = ByteUtil.getUnsignedByte(requestBuffer);
builder.setNonce(requestBuffer.getLong());
LispAddressSerializerContext ctx = new LispAddressSerializerContext(LispAddressSerializerContext.MASK_LEN_MISSING);
builder.setSourceEid(new SourceEidBuilder().setEid(LispAddressSerializer.getInstance().deserializeEid(requestBuffer, ctx)).build());
if (builder.getItrRloc() == null) {
builder.setItrRloc(new ArrayList<ItrRloc>());
}
for (int i = 0; i < itrCount; i++) {
builder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressSerializer.getInstance().deserializeRloc(requestBuffer)).build());
}
if (builder.getEidItem() == null) {
builder.setEidItem(new ArrayList<EidItem>());
}
for (int i = 0; i < recordCount; i++) {
builder.getEidItem().add(new EidItemBuilder().setEid(EidRecordSerializer.getInstance().deserialize(requestBuffer)).build());
}
if (builder.isMapDataPresent() && requestBuffer.hasRemaining()) {
try {
builder.setMapReply(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.MapReplyBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(requestBuffer)).build()).build();
} catch (RuntimeException re) {
LOG.warn("Couldn't deserialize Map-Reply encapsulated in Map-Request", re);
}
}
builder.setSourceRloc(LispAddressUtil.addressBinaryFromInet(sourceRloc));
return builder.build();
} catch (RuntimeException re) {
throw new LispSerializationException("Couldn't deserialize Map-Request (len=" + requestBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.
the class MappingRecordSerializer method deserializeToBuilder.
public MappingRecordBuilder deserializeToBuilder(ByteBuffer buffer) {
MappingRecordBuilder builder = new MappingRecordBuilder();
builder.setRecordTtl(buffer.getInt());
final byte locatorCount = (byte) ByteUtil.getUnsignedByte(buffer);
final short maskLength = ((short) ByteUtil.getUnsignedByte(buffer));
final byte actionAndAuthoritative = buffer.get();
Action act = Action.forValue(actionAndAuthoritative >> 5);
if (act == null) {
act = Action.NoAction;
}
builder.setAction(act);
builder.setAuthoritative(ByteUtil.extractBit(actionAndAuthoritative, Flags.AUTHORITATIVE));
buffer.position(buffer.position() + Length.RESERVED);
builder.setMapVersion(buffer.getShort());
LispAddressSerializerContext ctx = new LispAddressSerializerContext(maskLength);
builder.setEid(LispAddressSerializer.getInstance().deserializeEid(buffer, ctx));
builder.setLocatorRecord(new ArrayList<LocatorRecord>());
for (int i = 0; i < locatorCount; i++) {
builder.getLocatorRecord().add(LocatorRecordSerializer.getInstance().deserialize(buffer));
}
return builder;
}
use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.
the class InstanceIdSerializerTest method deserialize__Ipv6.
@Test
public void deserialize__Ipv6() throws Exception {
Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer(//
"40 03 00 00 " + //
"02 20 00 0A " + // instance ID
"00 BB CC DD " + // AFI=2,
"00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD"), new LispAddressSerializerContext(null));
// IPv6
assertArrayEquals(new byte[] { (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66, (byte) 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD }, ((Ipv6Binary) address.getAddress()).getIpv6Binary().getValue());
}
Aggregations