Search in sources :

Example 11 with LocatorRecord

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;
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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)

Example 12 with LocatorRecord

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);
    }
}
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)

Example 13 with LocatorRecord

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;
}
Also used : MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)

Example 14 with LocatorRecord

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;
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)

Example 15 with LocatorRecord

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();
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) Rloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) SimpleAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) ExplicitLocatorPath(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPath)

Aggregations

LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)28 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)16 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)13 Test (org.junit.Test)9 Rloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc)9 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)8 ArrayList (java.util.ArrayList)5 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)5 ByteBuffer (java.nio.ByteBuffer)4 MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)4 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)3 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)3 MapRegisterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder)3 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)3 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder)3 LinkedHashMap (java.util.LinkedHashMap)2 Site (org.opendaylight.lispflowmapping.integrationtest.MultiSiteScenarioUtil.Site)2 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)2 ExplicitLocatorPath (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPath)2 GotMapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify)2