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__EidRecordNullActionShouldTranslateToDefault.
@Test
public void serialize__EidRecordNullActionShouldTranslateToDefault() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
recordBuilder.setAction(null);
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__LocatorRecordFields.
@Test
public void serialize__LocatorRecordFields() throws Exception {
MapReplyBuilder mrBuilder = new MapReplyBuilder();
mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder eidToLocatorBuilder = new MappingRecordBuilder();
eidToLocatorBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
eidToLocatorBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
LocatorRecordBuilder locatorBuilder1 = new LocatorRecordBuilder();
locatorBuilder1.setPriority((short) 0xF3);
locatorBuilder1.setWeight((short) 0xF6);
locatorBuilder1.setMulticastPriority((short) 0xA3);
locatorBuilder1.setMulticastWeight((short) 0x06);
locatorBuilder1.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.1"));
locatorBuilder1.setLocalLocator(true);
locatorBuilder1.setRlocProbed(true);
locatorBuilder1.setRouted(true);
eidToLocatorBuilder.getLocatorRecord().add(locatorBuilder1.build());
LocatorRecordBuilder locatorBuilder2 = new LocatorRecordBuilder();
locatorBuilder2.setPriority((short) 0x03);
locatorBuilder2.setWeight((short) 0x06);
locatorBuilder2.setMulticastPriority((short) 0x03);
locatorBuilder2.setMulticastWeight((short) 0xF1);
locatorBuilder2.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.2"));
locatorBuilder2.setLocalLocator(false);
locatorBuilder2.setRlocProbed(false);
locatorBuilder2.setRouted(false);
eidToLocatorBuilder.getLocatorRecord().add(locatorBuilder2.build());
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocatorBuilder.build()).build());
ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
// First locator record
packet.position(12 + 16);
assertHexEquals((byte) 0xF3, packet.get());
assertHexEquals((byte) 0xF6, packet.get());
assertHexEquals((byte) 0xA3, packet.get());
assertHexEquals((byte) 0x06, packet.get());
packet.position(packet.position() + 1);
assertHexEquals((byte) 0x07, packet.get());
// Second locator record
packet.position(packet.position() + 6);
assertHexEquals((byte) 0x03, packet.get());
assertHexEquals((byte) 0x06, packet.get());
assertHexEquals((byte) 0x03, packet.get());
assertHexEquals((byte) 0xF1, packet.get());
packet.position(packet.position() + 1);
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 MapRequestSerializationTest method serialize__AllWithMapReply.
@Test
public void serialize__AllWithMapReply() throws Exception {
MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
mapRequestBuilder.setProbe(true);
mapRequestBuilder.setMapDataPresent(true);
mapRequestBuilder.setPitr(true);
mapRequestBuilder.setNonce((long) 13);
mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(("10.0.0.1"))).build());
mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("1.2.3.4")).build());
mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv6Rloc("1:2:3:4:5:6:7:8")).build());
mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("1.2.3.4/32")).build());
MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/0"));
recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
LocatorRecordBuilder locatorBuilder = new LocatorRecordBuilder();
locatorBuilder.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.2"));
recordBuilder.getLocatorRecord().add(locatorBuilder.build());
MapReplyBuilder mapreplyBuilder = new MapReplyBuilder();
mapreplyBuilder.setMappingRecord(recordBuilder.build());
mapRequestBuilder.setMapReply(mapreplyBuilder.build());
ByteBuffer expected = hexToByteBuffer("16 80 01 01 00 00 " + "00 00 00 00 00 0D 00 01 0a 00 00 01 00 01 01 02 03 04 00 02 00 01 00 02 00 03 00 04 00 05 00 06 " + // map
"00 07 00 08 00 20 00 01 01 02 03 04 " + "00 00 00 00 01 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 02");
assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mapRequestBuilder.build()).array());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder in project lispflowmapping by opendaylight.
the class MapResolver method handleMapRequest.
public void handleMapRequest(MapRequest request) {
LOG.trace("Map-Request received: {}", request);
// SMRs and RLOC probes are directed towards xTRs and we're a Map-Resolver here, so ignore them
if (request.isSmr() != null && request.isSmr()) {
LOG.debug("Map-Resolver ignoring incoming SMR control message.");
return;
}
if (request.isProbe() != null && request.isProbe()) {
LOG.debug("Map-Resolver ignoring incoming RLOC probe control message.");
return;
}
if (request.isSmrInvoked()) {
LOG.debug("SMR-invoked request received.");
LOG.trace("Map-Request object: {}", request);
for (EidItem eidItem : request.getEidItem()) {
final SmrEvent event = new SmrEvent(subscriberListFromItrRlocs(request.getItrRloc(), request.getSourceEid().getEid()), eidItem.getEid(), request.getNonce());
smrNotificationListener.onSmrInvokedReceived(event);
}
}
Eid srcEid = null;
if (request.getSourceEid() != null) {
srcEid = request.getSourceEid().getEid();
}
MapReplyBuilder replyBuilder = new MapReplyBuilder();
replyBuilder.setEchoNonceEnabled(false);
replyBuilder.setProbe(false);
replyBuilder.setSecurityEnabled(false);
replyBuilder.setNonce(request.getNonce());
replyBuilder.setMappingRecordItem(new ArrayList<>());
List<ItrRloc> itrRlocs = request.getItrRloc();
final IpAddressBinary sourceRloc = request.getSourceRloc();
for (EidItem eidRecord : request.getEidItem()) {
MappingData mappingData = mapService.getMapping(srcEid, eidRecord.getEid());
MappingRecord mapping;
if (mappingData == null) {
mapping = mapService.addNegativeMapping(eidRecord.getEid()).getRecord();
} else {
mapping = mappingData.getRecord();
}
if (itrRlocs != null && itrRlocs.size() != 0) {
if (subscriptionService && isValidSourceEidForSubscriber(srcEid)) {
final Rloc resolvedRloc = resolveRloc(itrRlocs, sourceRloc);
updateSubscribers(resolvedRloc, eidRecord.getEid(), mapping.getEid(), srcEid, mapping.getRecordTtl());
}
mapping = updateLocators(mapping, itrRlocs);
}
mapping = fixIfNotSDRequest(mapping, eidRecord.getEid());
mapping = fixTtlIfSmrInvoked(request, mapping);
replyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mapping).build());
}
requestHandler.handleMapReply(replyBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest__withNoMapping.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
public void handleMapRequest__withNoMapping() {
final MappingRecordBuilder mappingRecordBuilder = new MappingRecordBuilder().setAuthoritative(false).setMapVersion((short) 0).setEid(IPV4_PREFIX_EID_1).setAction(LispMessage.NEGATIVE_MAPPING_ACTION).setRecordTtl(TTL_RLOC_TIMED_OUT);
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(null);
Mockito.when(mapServiceMock.addNegativeMapping(IPV4_PREFIX_EID_1)).thenReturn(getDefaultMappingData(mappingRecordBuilder.build()));
// result
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
Aggregations