use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class MapRegisterSerializationTest method deserialize__serialize.
@Test
public void deserialize__serialize() throws Exception {
ByteBuffer bb = hexToByteBuffer("32 00 01 01 63 99 " + "83 64 23 06 a8 be 00 01 00 14 b8 c2 a2 e1 dc 4a " + "08 0c f6 01 b0 9d 70 5a d4 88 95 f8 73 dd 00 00 " + "05 a0 01 20 10 00 00 00 40 03 00 00 02 20 00 0a " + "00 00 00 01 00 01 c3 a8 c8 01 0a 32 ff 00 00 04 " + "00 01 ac 10 01 02 15 1a 39 80 e3 35 e6 c4 49 a6 " + "90 87 20 65 9a b7 00 00 00 00 00 00 00 00 ");
MapRegister mr = MapRegisterSerializer.getInstance().deserialize(bb, null);
assertTrue(mr.isXtrSiteIdPresent());
ArrayAssert.assertEquals(bb.array(), MapRegisterSerializer.getInstance().serialize(mr).array());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class MapRegisterSerializationTest method deserialize__IllegalAction.
@Test
public void deserialize__IllegalAction() throws Exception {
MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " + //
"00 00 00 00 00 00 00 01 00 14 ec 47 1e 53 25 91 " + //
"2f 68 10 75 13 dd 2c e8 6e 3c ac 94 ed e4 00 00 " + //
"00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " + //
"ff 00 00 05 00 01 c0 a8 88 0a"), null);
assertEquals(1, mr.getMappingRecordItem().size());
assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class LispAuthenticationTest method validate__NoAuthentication.
@Test
public void validate__NoAuthentication() throws Exception {
// LISP(Type = 3 Map-Register, P=1, M=1
// Record Counter: 1
// Nonce: (something)
// Key ID: 0x0000
// AuthDataLength: 0:
// EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
// No-Action
// Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
// Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
//
final ByteBuffer byteBuffer = hexToByteBuffer("38 00 01 01 FF BB " + "00 00 00 00 00 00 00 00 00 00 " + "00 00 " + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " + "ff 00 00 05 00 01 c0 a8 88 0a");
MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(byteBuffer, null);
assertTrue(validate(mapRegister, byteBuffer, EID, 0, PASSWORD));
assertTrue(validate(mapRegister, byteBuffer, EID, 0, WRONG_PASSWORD));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class MapRegisterSerializer method deserialize.
@SuppressWarnings("checkstyle:IllegalCatch")
public MapRegister deserialize(ByteBuffer registerBuffer, InetAddress sourceRloc) {
try {
final byte typeAndFlags = registerBuffer.get();
final int type = typeAndFlags >> 4;
if (MessageType.forValue(type) != MessageType.MapRegister) {
throw new LispSerializationException("Expected Map-Register packet (type 3), but was type " + type);
}
MapRegisterBuilder builder = new MapRegisterBuilder();
builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID);
builder.setProxyMapReply(ByteUtil.extractBit(typeAndFlags, Flags.PROXY));
builder.setXtrSiteIdPresent(xtrSiteIdPresent);
registerBuffer.position(registerBuffer.position() + Length.RES);
byte mergeAndMapReply = registerBuffer.get();
builder.setWantMapNotify(ByteUtil.extractBit(mergeAndMapReply, Flags.WANT_MAP_NOTIFY));
builder.setMergeEnabled(ByteUtil.extractBit(mergeAndMapReply, Flags.MERGE_ENABLED));
byte recordCount = (byte) ByteUtil.getUnsignedByte(registerBuffer);
builder.setNonce(registerBuffer.getLong());
builder.setKeyId(registerBuffer.getShort());
short authenticationLength = registerBuffer.getShort();
byte[] authenticationData = new byte[authenticationLength];
registerBuffer.get(authenticationData);
builder.setAuthenticationData(authenticationData);
if (xtrSiteIdPresent) {
List<MappingRecordBuilder> mrbs = new ArrayList<MappingRecordBuilder>();
for (int i = 0; i < recordCount; i++) {
mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(registerBuffer));
}
byte[] xtrIdBuf = new byte[Length.XTRID_SIZE];
registerBuffer.get(xtrIdBuf);
XtrId xtrId = new XtrId(xtrIdBuf);
byte[] siteIdBuf = new byte[Length.SITEID_SIZE];
registerBuffer.get(siteIdBuf);
SiteId siteId = new SiteId(siteIdBuf);
builder.setXtrId(xtrId);
builder.setSiteId(siteId);
for (MappingRecordBuilder mrb : mrbs) {
mrb.setXtrId(xtrId);
mrb.setSiteId(siteId);
mrb.setSourceRloc(LispAddressUtil.addressBinaryFromInet(sourceRloc));
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mrb.build()).build());
}
} else {
for (int i = 0; i < recordCount; i++) {
builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(registerBuffer)).build());
}
}
registerBuffer.limit(registerBuffer.position());
byte[] mapRegisterBytes = new byte[registerBuffer.position()];
registerBuffer.position(0);
registerBuffer.get(mapRegisterBytes);
return builder.build();
} catch (RuntimeException re) {
throw new LispSerializationException("Couldn't deserialize Map-Register (len=" + registerBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegister in project lispflowmapping by opendaylight.
the class MapRegisterSerializer method serialize.
public ByteBuffer serialize(MapRegister mapRegister) {
int size = Length.HEADER_SIZE;
if (mapRegister.getAuthenticationData() != null) {
size += mapRegister.getAuthenticationData().length;
}
if (mapRegister.isXtrSiteIdPresent() != null && mapRegister.isXtrSiteIdPresent()) {
size += Length.XTRID_SIZE + Length.SITEID_SIZE;
}
for (MappingRecordItem eidToLocatorRecord : mapRegister.getMappingRecordItem()) {
size += MappingRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord.getMappingRecord());
}
ByteBuffer registerBuffer = ByteBuffer.allocate(size);
registerBuffer.put((byte) ((byte) (MessageType.MapRegister.getIntValue() << 4) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isProxyMapReply()), Flags.PROXY) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isXtrSiteIdPresent()), Flags.XTRSITEID)));
registerBuffer.position(registerBuffer.position() + Length.RES);
registerBuffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isMergeEnabled()), Flags.MERGE_ENABLED) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRegister.isWantMapNotify()), Flags.WANT_MAP_NOTIFY)));
registerBuffer.put((byte) mapRegister.getMappingRecordItem().size());
registerBuffer.putLong(NumberUtil.asLong(mapRegister.getNonce()));
registerBuffer.putShort(NumberUtil.asShort(mapRegister.getKeyId()));
if (mapRegister.getAuthenticationData() != null) {
registerBuffer.putShort((short) mapRegister.getAuthenticationData().length);
registerBuffer.put(mapRegister.getAuthenticationData());
} else {
registerBuffer.putShort((short) 0);
}
for (MappingRecordItem eidToLocatorRecord : mapRegister.getMappingRecordItem()) {
MappingRecordSerializer.getInstance().serialize(registerBuffer, eidToLocatorRecord.getMappingRecord());
}
if (mapRegister.isXtrSiteIdPresent() != null && mapRegister.isXtrSiteIdPresent()) {
registerBuffer.put(mapRegister.getXtrId().getValue());
registerBuffer.put(mapRegister.getSiteId().getValue());
}
registerBuffer.clear();
return registerBuffer;
}
Aggregations