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