Search in sources :

Example 6 with Keyed

use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Keyed 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<>();
    // All locators to be added to the merge set are first stored in this list
    List<LocatorRecord> newLocatorList = new ArrayList<>();
    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<>();
        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);
    }
}
Also used : Rloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc) ArrayList(java.util.ArrayList) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 LinkedHashMap (java.util.LinkedHashMap)2 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)2 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)2 Rloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc)2 Container (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container)2 ContainerBuilder (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder)2 Keyed (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Keyed)2 KeyedBuilder (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedBuilder)2 KeyedKey (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedKey)2 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 MINUTES (java.util.concurrent.TimeUnit.MINUTES)1 Inject (javax.inject.Inject)1