Search in sources :

Example 46 with MappingRecordBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.

the class DSBEInputUtil method toMapping.

public static Mapping toMapping(MappingOrigin origin, Eid key, @Nullable MappingData mappingData) {
    MappingRecord record = (mappingData != null) ? mappingData.getRecord() : new MappingRecordBuilder().setEid(key).build();
    SiteId siteId = (record != null) ? record.getSiteId() : null;
    List<SiteId> siteIds = (siteId != null) ? Arrays.asList(siteId) : null;
    return new MappingBuilder().setEidUri(new EidUri(LispAddressStringifier.getURIString(key))).setOrigin(origin).setSiteId(siteIds).setMappingRecord(record).build();
}
Also used : SiteId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId) MappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingBuilder) XtrIdMappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.mapping.XtrIdMappingBuilder) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) EidUri(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri)

Example 47 with MappingRecordBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder 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 48 with MappingRecordBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.

the class MapResolverTest method isEqualIpVersionTest.

/**
 * Tests {@link MapResolver#isEqualIpVersion} method.
 */
@Test
@Ignore
public void isEqualIpVersionTest() {
    // input mapping
    final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
    final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
    final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
    Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
    Mockito.when(mapServiceMock.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock);
    Mockito.when(subscriberSetMock.contains(Mockito.any(Subscriber.class))).thenReturn(false);
    // ----------------------
    // with sourceRloc = null
    List<ItrRloc> itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv4BinaryAfi.class, IPV4_ADDRESS));
    ArgumentCaptor<Subscriber> captor = ArgumentCaptor.forClass(Subscriber.class);
    mapResolver.handleMapRequest(mapRequestBuilder.setSourceRloc(null).setItrRloc(itrRlocList).build());
    Mockito.verify(subscriberSetMock).add(captor.capture());
    // Since mapRequest's sourceRloc is null, first ItrRloc from the itrRlocList must be used.
    assertEquals(MacAfi.class, captor.getValue().getSrcRloc().getAddressType());
    // ----------------------
    // with sourceRloc address = itrRloc address
    itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv4BinaryAfi.class, IPV4_ADDRESS));
    MapRequest mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_1).setItrRloc(itrRlocList).build();
    captor = ArgumentCaptor.forClass(Subscriber.class);
    mapResolver.handleMapRequest(mapRequest);
    Mockito.verify(subscriberSetMock, Mockito.times(2)).add(captor.capture());
    assertEquals(IPV4_ADDRESS, captor.getValue().getSrcRloc().getAddress());
    // ----------------------
    // with sourceRloc address Afi = itrRloc address Afi (for Ipv4)
    itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv6Afi.class, IPV6_ADDRESS), newItrRloc(Ipv4Afi.class, IPV4_ADDRESS));
    mapRequest = mapRequestBuilder.setSourceRloc(IPV6_ADDRESS_BINARY).setItrRloc(itrRlocList).build();
    captor = ArgumentCaptor.forClass(Subscriber.class);
    mapResolver.handleMapRequest(mapRequest);
    Mockito.verify(subscriberSetMock, Mockito.times(3)).add(captor.capture());
    assertEquals(IPV6_ADDRESS, captor.getValue().getSrcRloc().getAddress());
    // ----------------------
    // with sourceRloc address Afi = itrRloc address Afi (for Ipv6)
    itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, null), newItrRloc(Ipv6Afi.class, IPV6_ADDRESS), newItrRloc(Ipv4Afi.class, IPV4_ADDRESS));
    mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_2).setItrRloc(itrRlocList).build();
    captor = ArgumentCaptor.forClass(Subscriber.class);
    mapResolver.handleMapRequest(mapRequest);
    Mockito.verify(subscriberSetMock, Mockito.times(4)).add(captor.capture());
    assertEquals(IPV4_ADDRESS, captor.getValue().getSrcRloc().getAddress());
    // ----------------------
    // with no common ip address nor Afi
    final Mac mac = new MacBuilder().setMac(new MacAddress("aa:bb:cc:dd:ee:ff")).build();
    itrRlocList = Lists.newArrayList(newItrRloc(MacAfi.class, mac), newItrRloc(NoAddressAfi.class, Mockito.mock(NoAddress.class)));
    mapRequest = mapRequestBuilder.setSourceRloc(IPV4_ADDRESS_BINARY_1).setItrRloc(itrRlocList).build();
    captor = ArgumentCaptor.forClass(Subscriber.class);
    mapResolver.handleMapRequest(mapRequest);
    Mockito.verify(subscriberSetMock, Mockito.times(5)).add(captor.capture());
    assertEquals(mac, captor.getValue().getSrcRloc().getAddress());
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) Ipv4BinaryAfi(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4BinaryAfi) MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Mac(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MacBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder) MacAfi(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi) NoAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddress) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 49 with MappingRecordBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.

the class MapResolverTest method handleMapRequest__withNoMapping.

/**
 * Tests {@link MapResolver#handleMapRequest} method.
 */
@Test
public void handleMapRequest__withNoMapping() {
    final MappingRecordBuilder mappingRecordBuilder = new MappingRecordBuilder().setAuthoritative(false).setMapVersion((short) 0).setEid(IPV4_PREFIX_EID_1).setAction(LispMessage.NEGATIVE_MAPPING_ACTION).setRecordTtl(TTL_RLOC_TIMED_OUT);
    Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(null);
    Mockito.when(mapServiceMock.addNegativeMapping(IPV4_PREFIX_EID_1)).thenReturn(getDefaultMappingData(mappingRecordBuilder.build()));
    // result
    final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
    mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
    mapResolver.handleMapRequest(mapRequestBuilder.build());
    Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
Also used : MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) Test(org.junit.Test)

Example 50 with MappingRecordBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.

the class MapResolverTest method handleMapRequest_withBothPolicy.

/**
 * Tests {@link MapResolver#handleMapRequest} method.
 */
@Test
public void handleMapRequest_withBothPolicy() {
    mapResolver = new MapResolver(mapServiceMock, true, "both", lispMappingServiceMock);
    final List<IpAddress> ipAddressList = new ArrayList<>();
    // hop 1
    ipAddressList.add(IPV4_ADDRESS_1);
    // hop 2
    ipAddressList.add(IPV4_ADDRESS_2);
    final Rloc rloc = LispAddressUtil.asTeLcafRloc(ipAddressList);
    final LocatorRecordBuilder locatorRecordBuilder_1 = getDefaultLocatorBuilder();
    final LocatorRecordBuilder locatorRecordBuilder_2 = getDefaultLocatorBuilder().setRloc(rloc);
    // input mapping
    final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_2.build());
    final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
    final MapRequestBuilder mrb = getDefaultMapRequestBuilder();
    mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_1)).build());
    mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2)).build());
    Mockito.when(mapServiceMock.getMapping(mrb.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
    // result
    final LocatorRecordBuilder locatorRecordBuilder_3 = getDefaultLocatorBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2)).setPriority((short) 1);
    final MappingRecordBuilder resultMappingRecordBuilder = getDefaultMappingRecordBuilder();
    // as Ipv4
    resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
    // as ELP
    resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_2.build());
    // added to the result
    resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_3.build());
    final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
    mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(resultMappingRecordBuilder.build()).build());
    // invocation
    mapResolver.handleMapRequest(mrb.build());
    Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) ArrayList(java.util.ArrayList) 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) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder) Test(org.junit.Test)

Aggregations

MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)57 Test (org.junit.Test)30 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)27 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)20 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)16 ByteBuffer (java.nio.ByteBuffer)14 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)14 MapReplyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder)14 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)13 ArrayList (java.util.ArrayList)8 SiteId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId)8 MapRegisterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder)8 MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)7 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)7 Rloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc)6 MappingBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingBuilder)6 Subscriber (org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)5 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)5 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)5 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)5