use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder 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.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class LispNotificationHelperTest method getMappingTest_SiteIdNotPresent.
/**
* Tests {@link LispNotificationHelper#getMapping} method with invalid address, isXtrSiteIdPresent == false.
*/
@Test
public void getMappingTest_SiteIdNotPresent() {
final MappingBuilder mappingBuilder_1 = new MappingBuilder().setMappingRecord(new MappingRecordBuilder().setEid(EID_IPV4).build()).setEidUri(new EidUri("ipv4:" + IPV4_STRING)).setOrigin(MappingOrigin.Southbound);
final MappingBuilder mappingBuilder_2 = new MappingBuilder().setMappingRecord(new MappingRecordBuilder().setEid(EID_IPV6).build()).setEidUri(new EidUri("ipv6:" + IPV6_STRING)).setOrigin(MappingOrigin.Southbound);
assertEquals(Lists.newArrayList(mappingBuilder_1.build(), mappingBuilder_2.build()), LispNotificationHelper.getMapping(getDefaultAddMapping(false)));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MappingService method convertFromBinaryIfNecessary.
private static MappingRecord convertFromBinaryIfNecessary(MappingRecord originalRecord) {
List<LocatorRecord> originalLocators = originalRecord.getLocatorRecord();
List<LocatorRecord> convertedLocators = null;
if (originalLocators != null) {
// If convertedLocators is non-null, while originalLocators is also non-null, conversion has been made
convertedLocators = convertFromBinaryIfNecessary(originalLocators);
}
if (LispAddressUtil.addressNeedsConversionFromBinary(originalRecord.getEid().getAddress()) || (originalLocators != null && convertedLocators != null)) {
MappingRecordBuilder mrb = new MappingRecordBuilder(originalRecord);
mrb.setEid(LispAddressUtil.convertFromBinary(originalRecord.getEid()));
if (convertedLocators != null) {
mrb.setLocatorRecord(convertedLocators);
}
return mrb.build();
}
return originalRecord;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder 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.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MappingDataListener method convertToBinaryIfNecessary.
private static Mapping convertToBinaryIfNecessary(Mapping mapping) {
MappingRecord originalRecord = mapping.getMappingRecord();
List<LocatorRecord> originalLocators = originalRecord.getLocatorRecord();
List<LocatorRecord> convertedLocators = null;
if (originalLocators != null) {
// If convertedLocators is non-null, while originalLocators is also non-null, conversion has been made
convertedLocators = convertToBinaryIfNecessary(originalLocators);
}
if (LispAddressUtil.addressNeedsConversionToBinary(originalRecord.getEid().getAddress()) || (originalLocators != null && convertedLocators != null)) {
MappingRecordBuilder mrb = new MappingRecordBuilder(originalRecord);
mrb.setEid(LispAddressUtil.convertToBinary(originalRecord.getEid()));
if (convertedLocators != null) {
mrb.setLocatorRecord(convertedLocators);
}
return new MappingBuilder(mapping).setMappingRecord(mrb.build()).build();
}
return mapping;
}
Aggregations