use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest__withSubscribersToRemove.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
@Ignore
public void handleMapRequest__withSubscribersToRemove() {
// input mapping
final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
Mockito.when(mapServiceMock.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock);
Subscriber subscriberMock = new Subscriber(mapRequestBuilder.getItrRloc().get(0).getRloc(), mapRequestBuilder.getSourceEid().getEid(), Subscriber.DEFAULT_SUBSCRIBER_TIMEOUT);
subscriberMock.setSubscriberTtlByRecordTtl(mappingRecordBuilder.getRecordTtl());
Mockito.when(subscriberSetMock.contains(subscriberMock)).thenReturn(true);
// result
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
// check if a subscriber is re-instantiating when there already is one in the subscriber set
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(subscriberSetMock).remove(subscriberMock);
Mockito.verify(subscriberSetMock).add(subscriberMock);
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
Mockito.verify(mapServiceMock).addData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS, subscriberSetMock);
// verify that itrRloc is subscribed to dst address
mappingRecordBuilder.setEid(SOURCE_DEST_KEY_EID);
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(IPV4_PREFIX_EID_2).build());
mappingData = getDefaultMappingData(mappingRecordBuilder.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_2)).thenReturn(mappingData);
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(mapServiceMock).getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID), SubKeys.SUBSCRIBERS);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest_withMultipleEids.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
public void handleMapRequest_withMultipleEids() {
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(IPV6_PREFIX_EID).build());
final LocatorRecordBuilder locatorRecordBuilder_1 = getDefaultLocatorBuilder();
final LocatorRecordBuilder locatorRecordBuilder_2 = getDefaultLocatorBuilder();
locatorRecordBuilder_2.setRloc(LispAddressUtil.asIpv6Rloc(IPV6_STRING));
// input mapping
final MappingRecordBuilder mappingRecordBuilder_1 = getDefaultMappingRecordBuilder();
mappingRecordBuilder_1.getLocatorRecord().add(locatorRecordBuilder_1.build());
final MappingData mappingData_1 = getDefaultMappingData(mappingRecordBuilder_1.build());
final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
mappingRecordBuilder_2.getLocatorRecord().add(locatorRecordBuilder_2.build());
mappingRecordBuilder_2.setEid(IPV6_PREFIX_EID);
final MappingData mappingData_2 = getDefaultMappingData(mappingRecordBuilder_2.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), mapRequestBuilder.getEidItem().get(0).getEid())).thenReturn(mappingData_1);
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), mapRequestBuilder.getEidItem().get(1).getEid())).thenReturn(mappingData_2);
// result
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder_1.build()).build());
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder_2.build()).build());
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MappingService method convertFromBinaryIfNecessary.
private static List<LocatorRecord> convertFromBinaryIfNecessary(List<LocatorRecord> originalLocators) {
List<LocatorRecord> convertedLocators = null;
for (LocatorRecord record : originalLocators) {
if (LispAddressUtil.addressNeedsConversionFromBinary(record.getRloc().getAddress())) {
LocatorRecordBuilder lrb = new LocatorRecordBuilder(record);
lrb.setRloc(LispAddressUtil.convertFromBinary(record.getRloc()));
if (convertedLocators == null) {
convertedLocators = new ArrayList<LocatorRecord>();
}
convertedLocators.add(lrb.build());
}
}
if (convertedLocators != null) {
return convertedLocators;
}
return originalLocators;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class MapResolver method updateLocators.
// Process locators according to configured policy
private MappingRecord updateLocators(MappingRecord mapping, List<ItrRloc> itrRlocs) {
// no fixing if elpPolicy is default
if (elpPolicy.equalsIgnoreCase("default")) {
return mapping;
}
List<LocatorRecord> locatorRecords = mapping.getLocatorRecord();
// if no updated is needed, just return the mapping
if (!locatorsNeedFixing(locatorRecords)) {
return mapping;
}
MappingRecordBuilder recordBuilder = new MappingRecordBuilder(mapping);
recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
try {
for (LocatorRecord record : locatorRecords) {
Rloc container = record.getRloc();
// done
if ((!(container.getAddress() instanceof ExplicitLocatorPath)) || elpPolicy.equalsIgnoreCase("default") || itrRlocs == null) {
recordBuilder.getLocatorRecord().add(new LocatorRecordBuilder().setLocalLocator(record.isLocalLocator()).setRlocProbed(record.isRlocProbed()).setWeight(record.getWeight()).setPriority(record.getPriority()).setMulticastWeight(record.getMulticastWeight()).setMulticastPriority(record.getMulticastPriority()).setRouted(record.isRouted()).setRloc(container).setLocatorId(record.getLocatorId()).build());
continue;
}
ExplicitLocatorPath teAddress = ((ExplicitLocatorPath) container.getAddress());
SimpleAddress nextHop = getNextELPHop(teAddress, itrRlocs);
if (nextHop != null) {
java.lang.Short priority = record.getPriority();
if (elpPolicy.equalsIgnoreCase("both")) {
recordBuilder.getLocatorRecord().add(new LocatorRecordBuilder().setLocalLocator(record.isLocalLocator()).setRlocProbed(record.isRlocProbed()).setWeight(record.getWeight()).setPriority(record.getPriority()).setMulticastWeight(record.getMulticastWeight()).setMulticastPriority(record.getMulticastPriority()).setRouted(record.isRouted()).setRloc(container).setLocatorId(record.getLocatorId()).build());
// XXX Complex cases like several ELPs with different priorities are not handled
if (priority != 254 || priority != 255) {
priority++;
}
}
// Build and add the simple RLOC
recordBuilder.getLocatorRecord().add(new LocatorRecordBuilder().setLocalLocator(record.isLocalLocator()).setRlocProbed(record.isRlocProbed()).setWeight(record.getWeight()).setPriority(priority).setMulticastWeight(record.getMulticastWeight()).setMulticastPriority(record.getMulticastPriority()).setRouted(record.isRouted()).setRloc(LispAddressUtil.toRloc(nextHop)).setLocatorId(record.getLocatorId()).build());
}
}
} catch (ClassCastException cce) {
LOG.error("Class Cast Exception while building EidToLocatorRecord: {}", ExceptionUtils.getStackTrace(cce));
}
return recordBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder in project lispflowmapping by opendaylight.
the class LispSouthboundHandlerTest method mapReply__VerifyIPv6EidAndLocator.
@Test
@Ignore
public void mapReply__VerifyIPv6EidAndLocator() throws Exception {
mappingRecordBuilder.setEid(LispAddressUtil.asIpv6PrefixEid("0:0:0:0:0:0:0:1/128"));
mappingRecordBuilder.getLocatorRecord().add(new LocatorRecordBuilder().setRloc(LispAddressUtil.asIpv6Rloc("0:0:0:0:0:0:0:2")).build());
stubHandleRequest();
byte[] result = handleMapRequestAsByteArray(mapRequestPacket);
assertEquals(64, result.length);
byte[] expectedIpv6Eid = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
ArrayAssert.assertEquals(expectedIpv6Eid, Arrays.copyOfRange(result, 24, 40));
byte[] expectedIpv6Rloc = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 };
ArrayAssert.assertEquals(expectedIpv6Rloc, Arrays.copyOfRange(result, 48, 64));
}
Aggregations