use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReply in project lispflowmapping by opendaylight.
the class MapReplySerializationTest method deserialize__SomeFlags.
@Test
public void deserialize__SomeFlags() throws Exception {
MapReply mr = MapReplySerializer.getInstance().deserialize(hexToByteBuffer("2A 00 00 00 00 00 " + "00 00 00 00 00 00"));
assertEquals(true, mr.isProbe());
assertEquals(false, mr.isEchoNonceEnabled());
assertEquals(true, mr.isSecurityEnabled());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReply in project lispflowmapping by opendaylight.
the class MapReplySerializationTest method deserialize__MultipleRecordsWithoutRLOCs.
@Test
public void deserialize__MultipleRecordsWithoutRLOCs() throws Exception {
MapReply mr = MapReplySerializer.getInstance().deserialize(hexToByteBuffer("20 00 00 02 00 00 " + "00 00 00 00 00 00 00 00 00 01 00 20 00 00 00 00 " + "00 01 01 02 03 04 00 00 00 00 00 10 30 00 00 02 00 01 04 03 00 00"));
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, ((Ipv4PrefixBinary) mr.getMappingRecordItem().get(0).getMappingRecord().getEid().getAddress()).getIpv4AddressBinary().getValue());
// XXX Why here normalized and other cases not normalized?
assertArrayEquals(new byte[] { 4, 3, 0, 0 }, ((Ipv4PrefixBinary) mr.getMappingRecordItem().get(1).getMappingRecord().getEid().getAddress()).getIpv4AddressBinary().getValue());
assertEquals(false, mr.getMappingRecordItem().get(0).getMappingRecord().isAuthoritative());
assertEquals(true, mr.getMappingRecordItem().get(1).getMappingRecord().isAuthoritative());
assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
assertEquals(Action.NativelyForward, mr.getMappingRecordItem().get(1).getMappingRecord().getAction());
assertEquals(0, mr.getMappingRecordItem().get(0).getMappingRecord().getMapVersion().shortValue());
assertEquals(2, mr.getMappingRecordItem().get(1).getMappingRecord().getMapVersion().shortValue());
assertEquals(32, MaskUtil.getMaskForAddress(mr.getMappingRecordItem().get(0).getMappingRecord().getEid().getAddress()));
assertEquals(16, MaskUtil.getMaskForAddress(mr.getMappingRecordItem().get(1).getMappingRecord().getEid().getAddress()));
assertEquals(1, mr.getMappingRecordItem().get(0).getMappingRecord().getRecordTtl().byteValue());
assertEquals(0, mr.getMappingRecordItem().get(1).getMappingRecord().getRecordTtl().byteValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReply in project lispflowmapping by opendaylight.
the class MapReplySerializer method serialize.
public ByteBuffer serialize(MapReply mapReply) {
int size = Length.HEADER_SIZE;
for (MappingRecordItem eidToLocatorRecord : mapReply.getMappingRecordItem()) {
size += MappingRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord.getMappingRecord());
}
ByteBuffer replyBuffer = ByteBuffer.allocate(size);
replyBuffer.put((byte) ((MessageType.MapReply.getIntValue() << 4) | (BooleanUtils.isTrue(mapReply.isProbe()) ? Flags.PROBE : 0x00) | (BooleanUtils.isTrue(mapReply.isEchoNonceEnabled()) ? Flags.ECHO_NONCE_ENABLED : 0x00)));
replyBuffer.position(replyBuffer.position() + Length.RES);
if (mapReply.getMappingRecordItem() != null) {
replyBuffer.put((byte) mapReply.getMappingRecordItem().size());
} else {
replyBuffer.put((byte) 0);
}
replyBuffer.putLong(NumberUtil.asLong(mapReply.getNonce()));
if (mapReply.getMappingRecordItem() != null) {
for (MappingRecordItem eidToLocatorRecord : mapReply.getMappingRecordItem()) {
MappingRecordSerializer.getInstance().serialize(replyBuffer, eidToLocatorRecord.getMappingRecord());
}
}
return replyBuffer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReply in project lispflowmapping by opendaylight.
the class LispXtrSouthboundHandler method handleMapReply.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleMapReply(ByteBuffer buffer) {
try {
MapReply reply = MapReplySerializer.getInstance().deserialize(buffer);
XtrReplyMappingBuilder replyMappingBuilder = new XtrReplyMappingBuilder();
replyMappingBuilder.setMapReply(LispNotificationHelper.convertMapReply(reply));
lispSbPlugin.sendNotificationIfPossible(replyMappingBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Reply (len=" + buffer.capacity() + ")", re);
} catch (InterruptedException e) {
LOG.warn("Notification publication interrupted!");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReply in project lispflowmapping by opendaylight.
the class LispSouthboundRpcTest method sendMapReplyTest_inputNotNull.
/**
* Tests {@link LispSouthboundRPC#sendMapReply} method.
*/
@Test
public void sendMapReplyTest_inputNotNull() throws ExecutionException, InterruptedException {
final MapReply mapReply = getDefaultMapReplyBuilder().build();
final TransportAddress transportAddress = new TransportAddressBuilder().build();
final SendMapReplyInput sendMapReplyInputMock = Mockito.mock(SendMapReplyInput.class);
Mockito.when(sendMapReplyInputMock.getTransportAddress()).thenReturn(transportAddress);
Mockito.when(sendMapReplyInputMock.getMapReply()).thenReturn(mapReply);
assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), lispSouthboundRPC.sendMapReply(sendMapReplyInputMock).get().isSuccessful());
Mockito.verify(lispSouthboundPlugin).handleSerializedLispBuffer(transportAddress, MapReplySerializer.getInstance().serialize(mapReply), MessageType.MapReply);
}
Aggregations