use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder in project lispflowmapping by opendaylight.
the class MapReplySerializationTest method serialize__MultipleRecordsWithoutRLOCs.
@Test
public void serialize__MultipleRecordsWithoutRLOCs() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
recordBuilder.setEid(LispAddressUtil.asIpv6PrefixEid("0:0:0:0:0:0:0:8/128"));
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("8.2.4.5/32"));
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
assertEquals(2, packet.get(3));
// EID in first record
packet.position(24);
byte[] expected = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 };
byte[] actual = new byte[16];
packet.get(actual);
ArrayAssert.assertEquals(expected, actual);
// EID in second record
packet.position(packet.position() + 12);
assertEquals(0x08020405, packet.getInt());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder in project lispflowmapping by opendaylight.
the class MapReplySerializationTest method serialize__EidRecordDefaultAction.
@Test
public void serialize__EidRecordDefaultAction() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
packet.position(18);
// MapReplyAction.NoAction
assertHexEquals((byte) 0x00, packet.get());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder in project lispflowmapping by opendaylight.
the class MapReplySerializationTest method serialize__EidRecordFields.
@Test
public void serialize__EidRecordFields() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder eidToLocator1 = new MappingRecordBuilder();
eidToLocator1.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
eidToLocator1.setRecordTtl(7);
eidToLocator1.setAction(Action.SendMapRequest);
eidToLocator1.setAuthoritative(true);
eidToLocator1.setMapVersion((short) 3072);
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocator1.build()).build());
MappingRecordBuilder eidToLocator2 = new MappingRecordBuilder();
eidToLocator2.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.7/32"));
eidToLocator2.setRecordTtl(1000000);
eidToLocator2.setAction(Action.Drop);
eidToLocator2.setAuthoritative(false);
eidToLocator2.setMapVersion((short) 29);
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocator2.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
// First record
packet.position(12);
assertEquals(7, packet.getInt());
// skip Locator Count & Mask-len
packet.position(packet.position() + 2);
assertHexEquals((byte) 0x50, packet.get());
// skip Reserved byte
packet.position(packet.position() + 1);
assertEquals((short) 3072, packet.getShort());
// Second record
packet.position(packet.position() + 6);
assertEquals(1000000, packet.getInt());
// skip Locator Count & Mask-len
packet.position(packet.position() + 2);
assertHexEquals((byte) 0x60, packet.get());
// skip Reserved byte
packet.position(packet.position() + 1);
assertEquals((short) 29, packet.getShort());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder in project lispflowmapping by opendaylight.
the class LispMappingServiceTest method onRequestMappingTest.
/**
* Tests {@link LispMappingService#onRequestMapping} method.
*/
@Test
public void onRequestMappingTest() {
final RequestMapping requestMapping = Mockito.mock(RequestMapping.class);
final org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest mapRequest = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest.class);
final MapReply mapReply = new MapReplyBuilder().build();
Mockito.when(requestMapping.getMapRequest()).thenReturn(mapRequest);
Mockito.when(requestMapping.getTransportAddress()).thenReturn(TRANSPORT_ADDRESS_1);
Mockito.when(mapRequest.getEidItem()).thenReturn(Lists.newArrayList(EID_ITEM_BUILDER.build()));
Mockito.when(tlsMapReplyMock.get()).thenReturn(mapReply);
// result
final SendMapReplyInputBuilder smrib = new SendMapReplyInputBuilder().setMapReply(new MapReplyBuilder(mapReply).build()).setTransportAddress(TRANSPORT_ADDRESS_1);
lispMappingService.onRequestMapping(requestMapping);
Mockito.verify(odlLispSbService).sendMapReply(smrib.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder in project lispflowmapping by opendaylight.
the class LispMappingServiceTest method handleMapRequestTest.
/**
* Tests {@link LispMappingService#handleMapRequest} method.
*/
@Test
public void handleMapRequestTest() {
final MapRequest mapRequest = Mockito.mock(MapRequest.class);
final MapReply mapReply = new MapReplyBuilder().build();
Mockito.when(mapRequest.getEidItem()).thenReturn(Lists.newArrayList(EID_ITEM_BUILDER.build()));
Mockito.when(tlsMapRequestMock.get()).thenReturn(null);
Mockito.when(tlsMapReplyMock.get()).thenReturn(mapReply);
final MapReply result = lispMappingService.handleMapRequest(mapRequest);
Mockito.verify(tlsMapRequestMock).set(null);
Mockito.verify(tlsMapRequestMock).get();
Mockito.verifyNoMoreInteractions(tlsMapRequestMock);
Mockito.verify(mapResolverMock).handleMapRequest(mapRequest);
Mockito.verify(tlsMapReplyMock).set(Mockito.any(MapReply.class));
Mockito.verify(tlsMapReplyMock).get();
assertEquals(result, mapReply);
}
Aggregations