Search in sources :

Example 6 with SourceDestKeyBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder in project lispflowmapping by opendaylight.

the class SourceDestKeySerializerTest method serialize__Simple.

@Test
public void serialize__Simple() throws Exception {
    SourceDestKeyBuilder addressBuilder = new SourceDestKeyBuilder();
    addressBuilder.setSource(new SimpleAddress(new IpPrefix(new Ipv4Prefix("17.34.51.68/8"))));
    addressBuilder.setDest(new SimpleAddress(new IpPrefix(new Ipv4Prefix("34.51.68.85/16"))));
    EidBuilder eb = new EidBuilder();
    eb.setAddressType(SourceDestKeyLcaf.class);
    eb.setVirtualNetworkId(null);
    eb.setAddress((Address) new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder().setSourceDestKey(addressBuilder.build()).build());
    ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eb.build()));
    LispAddressSerializer.getInstance().serialize(buf, eb.build());
    ByteBuffer expectedBuf = hexToByteBuffer(// 
    "40 03 00 00 " + // 
    "0C 00 00 10 " + // reserved + masks
    "00 00 08 10 " + // AFI=1, IP=0x11223344
    "00 01 11 22 33 44 " + // AFI=1, IP=0x22334455
    "00 01 22 33 44 55");
    ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
}
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) ByteBuffer(java.nio.ByteBuffer) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) EidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder) SimpleAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Test(org.junit.Test)

Example 7 with SourceDestKeyBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder 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)

Aggregations

SourceDestKeyBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder)7 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)6 Test (org.junit.Test)2 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)2 SourceDestKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey)2 SourceDestKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKey)2 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)2 EidBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder)2 Preconditions (com.google.common.base.Preconditions)1 ByteBuffer (java.nio.ByteBuffer)1 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)1 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)1 GotMapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply)1 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)1 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)1 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)1 SourceEidBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder)1