use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord in project lispflowmapping by opendaylight.
the class MappingMergeUtil method getCommonLocatorRecords.
private static List<LocatorRecord> getCommonLocatorRecords(MappingRecord nbMapping, MappingRecord sbMapping) {
// Return null when NB is a negative mapping
if (nbMapping.getLocatorRecord() == null || nbMapping.getLocatorRecord().isEmpty()) {
return null;
}
List<LocatorRecord> sbLocators = sbMapping.getLocatorRecord();
// We assume locators are unique and don't show up several times (with different or identical p/w/mp/mw),
// so we create a HashMap of the locators from the SB mapping record, keyed by the Rloc
Map<Rloc, LocatorRecord> sbLocatorMap = new HashMap<Rloc, LocatorRecord>();
for (LocatorRecord locator : sbLocators) {
sbLocatorMap.put(locator.getRloc(), locator);
}
// Gradually building final list of common locators, in order that they appear in NB Mapping
List<LocatorRecord> commonLocators = new ArrayList<LocatorRecord>();
for (LocatorRecord nbLocator : nbMapping.getLocatorRecord()) {
Rloc nbRloc = nbLocator.getRloc();
if (sbLocatorMap.containsKey(nbRloc)) {
if (sbLocatorMap.get(nbRloc).getPriority() == (short) 255) {
// if SB locator has p == 255 then common locator takes all NB fields except for p
// which must be set to 255
LocatorRecordBuilder lrb = new LocatorRecordBuilder(nbLocator);
lrb.setPriority((short) 255);
commonLocators.add(lrb.build());
} else {
commonLocators.add(nbLocator);
}
}
}
return commonLocators;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord in project lispflowmapping by opendaylight.
the class MappingMergeUtil method mergeLocatorRecords.
private static void mergeLocatorRecords(MappingRecordBuilder mrb, MappingRecord newRecord) {
List<LocatorRecord> locators = mrb.getLocatorRecord();
// We assume locators are unique and sorted and don't show up several times (with different or identical
// p/w/mp/mw), so we create a LinkedHashMap (which preserves order) of the locators from the existing merged
// record, keyed by the Rloc
Map<Rloc, LocatorRecord> locatorMap = new LinkedHashMap<Rloc, LocatorRecord>();
// All locators to be added to the merge set are first stored in this list
List<LocatorRecord> newLocatorList = new ArrayList<LocatorRecord>();
for (LocatorRecord locator : locators) {
locatorMap.put(locator.getRloc(), locator);
}
for (LocatorRecord newLocator : newRecord.getLocatorRecord()) {
Rloc newRloc = newLocator.getRloc();
if (locatorMap.containsKey(newRloc)) {
// overlapping locator
if (!locatorMap.get(newRloc).equals(newLocator)) {
LocatorRecord mergedLocator = mergeLocators(locatorMap.get(newRloc), newLocator);
newLocatorList.add(mergedLocator);
}
} else {
// new locator
newLocatorList.add(newLocator);
}
}
// Build new merged and sorted locator set if need be
if (!newLocatorList.isEmpty()) {
List<LocatorRecord> mergedLocators = new ArrayList<LocatorRecord>();
int mlocIt = 0;
int locIt = 0;
while (mlocIt < newLocatorList.size() && locIt < locators.size()) {
int cmp = compareLocators(locators.get(locIt), newLocatorList.get(mlocIt));
if (cmp < 0) {
mergedLocators.add(locators.get(locIt));
locIt++;
} else if (cmp > 0) {
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
} else {
// when a locator appears in both lists, keep the new (merged) one and skip the old
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
locIt++;
}
}
while (locIt < locators.size()) {
mergedLocators.add(locators.get(locIt));
locIt++;
}
while (mlocIt < newLocatorList.size()) {
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
}
mrb.setLocatorRecord(mergedLocators);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord 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.locatorrecords.LocatorRecord 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.LocatorRecord 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();
}
Aggregations