Search in sources :

Example 31 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 computeNbSbIntersection.

private static MappingRecord computeNbSbIntersection(MappingRecord nbMapping, MappingRecord sbMapping) {
    // returns a MappingRecord which has the more specific EID, and intersection of locator records.
    // If locators intersection is empty, original NB mapping is returned.
    // The intersection is only computed for mappings with maskable EIDs.
    // Supports both maskable and non-maskable EIDs
    MappingRecordBuilder mrb = new MappingRecordBuilder(nbMapping);
    if (MaskUtil.isMaskable(sbMapping.getEid().getAddress()) && MaskUtil.isMaskable(nbMapping.getEid().getAddress())) {
        short sbMask = MaskUtil.getMaskForAddress(sbMapping.getEid().getAddress());
        short nbMask = MaskUtil.getMaskForAddress(nbMapping.getEid().getAddress());
        if (nbMapping.getEid().getAddress() instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey) {
            nbMask = SourceDestKeyHelper.getDstMask(nbMapping.getEid());
            if (nbMask < sbMask) {
                // We have to create a new SourceDest EID, where the source is same as the
                // one in NB record, and dest EID is the more specific from SB mapping record.
                SourceDestKey srcDstKey = ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey) nbMapping.getEid().getAddress()).getSourceDestKey();
                SourceDestKeyBuilder sdb = new SourceDestKeyBuilder(srcDstKey);
                sdb.setDest(new SimpleAddress(getIpPrefix(sbMapping.getEid().getAddress())));
                mrb.setEid(LispAddressUtil.asSrcDstEid(sdb.build(), nbMapping.getEid().getVirtualNetworkId()));
            }
        } else if (nbMask < sbMask) {
            // Both EIDs are IP prefixes. SB mapping is a subprefix so we have to update EID intersection
            mrb.setEid(sbMapping.getEid());
        }
    }
    // find and update locators intersection if not empty
    List<LocatorRecord> commonLocators = getCommonLocatorRecords(nbMapping, sbMapping);
    if (commonLocators != null && !commonLocators.isEmpty()) {
        mrb.setLocatorRecord(commonLocators);
    }
    return mrb.build();
}
Also used : SourceDestKeyBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder) Preconditions(com.google.common.base.Preconditions) 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) SourceDestKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKey) SimpleAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)

Example 32 with LocatorRecord

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord in project lispflowmapping by opendaylight.

the class MappingMergeUtilTest method getCommonLocatorRecords_priorityCheck.

/**
 * Tests {@link MappingMergeUtil#getCommonLocatorRecords} method, verifies that NB common locator's priority is set
 * to correct value (based on SB locator's priority).
 */
@Test
public void getCommonLocatorRecords_priorityCheck() {
    LocatorRecordBuilder nbLocatorRecordBuilder1 = new LocatorRecordBuilder().setRloc(IPV4_RLOC_1).setPriority((short) 1).setLocatorId("NB-locator-id");
    LocatorRecordBuilder sbLocatorRecordBuilder1 = new LocatorRecordBuilder().setRloc(IPV4_RLOC_1).setPriority((short) 255).setLocatorId("SB-locator-id");
    LocatorRecordBuilder nbLocatorRecordBuilder2 = new LocatorRecordBuilder().setRloc(IPV4_RLOC_2).setPriority((short) 1).setLocatorId("NB-locator-id");
    LocatorRecordBuilder sbLocatorRecordBuilder2 = new LocatorRecordBuilder().setRloc(IPV4_RLOC_2).setPriority((short) 254).setLocatorId("SB-locator-id");
    final MappingRecordBuilder nbMappingRecordBuilder = getDefaultMappingRecordBuilder();
    nbMappingRecordBuilder.getLocatorRecord().add(nbLocatorRecordBuilder1.build());
    nbMappingRecordBuilder.getLocatorRecord().add(nbLocatorRecordBuilder2.build());
    final MappingRecordBuilder sbMappingRecordBuilder = getDefaultMappingRecordBuilder();
    sbMappingRecordBuilder.getLocatorRecord().add(sbLocatorRecordBuilder1.build());
    sbMappingRecordBuilder.getLocatorRecord().add(sbLocatorRecordBuilder2.build());
    MappingData nbMappingData = getDefaultMappingData(nbMappingRecordBuilder.build());
    MappingData sbMappingData = getDefaultMappingData(sbMappingRecordBuilder.build());
    // result
    final MappingData result = MappingMergeUtil.computeNbSbIntersection(nbMappingData, sbMappingData);
    final Iterator<LocatorRecord> iterator = result.getRecord().getLocatorRecord().iterator();
    final LocatorRecord resultLocator_1 = iterator.next();
    final LocatorRecord resultLocator_2 = iterator.next();
    assertEquals(2, result.getRecord().getLocatorRecord().size());
    assertEquals("NB-locator-id", resultLocator_1.getLocatorId());
    // priority changed to 255
    assertEquals(255, (short) resultLocator_1.getPriority());
    assertEquals("NB-locator-id", resultLocator_2.getLocatorId());
    // priority remains original
    assertEquals(1, (short) resultLocator_2.getPriority());
}
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) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) Test(org.junit.Test)

Example 33 with LocatorRecord

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord in project lispflowmapping by opendaylight.

the class MappingRecordSerializer method serialize.

public void serialize(ByteBuffer replyBuffer, MappingRecord record) {
    replyBuffer.putInt(NumberUtil.asInt(record.getRecordTtl()));
    if (record.getLocatorRecord() != null) {
        replyBuffer.put((byte) record.getLocatorRecord().size());
    } else {
        replyBuffer.put((byte) 0);
    }
    if (record.getEid() != null && MaskUtil.getMaskForAddress(record.getEid().getAddress()) != -1) {
        replyBuffer.put((byte) NumberUtil.asShort(MaskUtil.getMaskForAddress(record.getEid().getAddress())));
    } else {
        replyBuffer.put((byte) 0);
    }
    Action act = Action.NoAction;
    if (record.getAction() != null) {
        act = record.getAction();
    }
    replyBuffer.put((byte) ((act.getIntValue() << 5) | ByteUtil.boolToBit(BooleanUtils.isTrue(record.isAuthoritative()), Flags.AUTHORITATIVE)));
    replyBuffer.position(replyBuffer.position() + Length.RESERVED);
    replyBuffer.putShort(NumberUtil.asShort(record.getMapVersion()));
    if (record.getEid() != null && record.getEid().getAddress() != null) {
        LispAddressSerializer.getInstance().serialize(replyBuffer, record.getEid());
    }
    if (record.getLocatorRecord() != null) {
        for (LocatorRecord locatorRecord : record.getLocatorRecord()) {
            LocatorRecordSerializer.getInstance().serialize(replyBuffer, locatorRecord);
        }
    }
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)

Example 34 with LocatorRecord

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord in project lispflowmapping by opendaylight.

the class LispAddressUtil method asLocatorRecords.

public static List<LocatorRecord> asLocatorRecords(List<Rloc> locators) {
    List<LocatorRecord> locatorRecords = new ArrayList<LocatorRecord>();
    for (Rloc locator : locators) {
        LocatorRecordBuilder locatorBuilder = new LocatorRecordBuilder();
        locatorBuilder.setLocalLocator(false).setRlocProbed(false).setWeight((short) 1).setPriority((short) 1).setMulticastWeight((short) 1).setMulticastPriority((short) 1).setRouted(true).setRloc(locator).setLocatorId("SFC_LISP").build();
        locatorRecords.add(locatorBuilder.build());
    }
    return locatorRecords;
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) ArrayList(java.util.ArrayList) Rloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)

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