Search in sources :

Example 6 with ItrRloc

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

the class MappingServiceIntegrationTest method queryForAddress.

private MapReply queryForAddress(Eid eid, String srcEid) throws SocketTimeoutException {
    MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
    mapRequestBuilder.setNonce((long) 4);
    mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
    mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
    mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
    if (srcEid != null) {
        mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(srcEid)).build());
    } else {
        mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build());
    }
    mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
    mapRequestBuilder.setAuthoritative(false);
    mapRequestBuilder.setMapDataPresent(false);
    mapRequestBuilder.setPitr(false);
    mapRequestBuilder.setProbe(false);
    mapRequestBuilder.setSmr(false);
    mapRequestBuilder.setSmrInvoked(false);
    sendMapRequest(mapRequestBuilder.build());
    return receiveMapReply();
}
Also used : ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) SourceEidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder) EidItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder) EidItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)

Example 7 with ItrRloc

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

the class MapResolverTest method handleMapRequest__withSubscribersToRemove.

/**
 * Tests {@link MapResolver#handleMapRequest} method.
 */
@Test
@Ignore
public void handleMapRequest__withSubscribersToRemove() {
    // input mapping
    final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
    final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
    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);
    Subscriber subscriberMock = new Subscriber(mapRequestBuilder.getItrRloc().get(0).getRloc(), mapRequestBuilder.getSourceEid().getEid(), Subscriber.DEFAULT_SUBSCRIBER_TIMEOUT);
    subscriberMock.setSubscriberTtlByRecordTtl(mappingRecordBuilder.getRecordTtl());
    Mockito.when(subscriberSetMock.contains(subscriberMock)).thenReturn(true);
    // result
    final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
    mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
    // check if a subscriber is re-instantiating when there already is one in the subscriber set
    mapResolver.handleMapRequest(mapRequestBuilder.build());
    Mockito.verify(subscriberSetMock).remove(subscriberMock);
    Mockito.verify(subscriberSetMock).add(subscriberMock);
    Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
    Mockito.verify(mapServiceMock).addData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS, subscriberSetMock);
    // verify that itrRloc is subscribed to dst address
    mappingRecordBuilder.setEid(SOURCE_DEST_KEY_EID);
    mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(IPV4_PREFIX_EID_2).build());
    mappingData = getDefaultMappingData(mappingRecordBuilder.build());
    Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_2)).thenReturn(mappingData);
    mapResolver.handleMapRequest(mapRequestBuilder.build());
    Mockito.verify(mapServiceMock).getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID), SubKeys.SUBSCRIBERS);
}
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) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) EidItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with ItrRloc

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc 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)

Example 9 with ItrRloc

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

the class MapResolver method resolveRloc.

private Rloc resolveRloc(List<ItrRloc> itrRlocList, IpAddressBinary srcRloc) {
    if (srcRloc == null) {
        return itrRlocList.get(0).getRloc();
    }
    byte[] srcRlocByte;
    if (srcRloc.getIpv4AddressBinary() != null) {
        srcRlocByte = srcRloc.getIpv4AddressBinary().getValue();
    } else {
        srcRlocByte = srcRloc.getIpv6AddressBinary().getValue();
    }
    Rloc equalIpvRloc = null;
    for (ItrRloc itrRloc : itrRlocList) {
        final Rloc rloc = itrRloc.getRloc();
        final byte[] itrRlocByte = LispAddressUtil.ipAddressToByteArray(rloc.getAddress());
        // return an Rloc equal to the source Rloc
        if (itrRlocByte != null && LispAddressUtil.compareIpAddressByteArrays(srcRlocByte, itrRlocByte) == 0) {
            return rloc;
        }
        // else lookup the first Rloc with identical Ip version
        if (equalIpvRloc == null && isEqualIpVersion(srcRloc, rloc)) {
            equalIpvRloc = rloc;
        }
    }
    if (equalIpvRloc != null) {
        return equalIpvRloc;
    } else {
        // if none of the above, return the first Rloc
        return itrRlocList.get(0).getRloc();
    }
}
Also used : ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) 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)

Example 10 with ItrRloc

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

the class MapResolver method updateSubscribers.

private void updateSubscribers(Rloc itrRloc, Eid reqEid, Eid mapEid, Eid srcEid, Integer recordTtl) {
    Subscriber subscriber = new Subscriber(itrRloc, srcEid, Subscriber.recordTtlToSubscriberTime(recordTtl));
    Eid subscribedEid = mapEid;
    // mapping will be pushed to dst as well (see sendSMRs in MapServer)
    if (mapEid.getAddressType().equals(SourceDestKeyLcaf.class) && !reqEid.getAddressType().equals(SourceDestKeyLcaf.class)) {
        subscribedEid = SourceDestKeyHelper.getDstBinary(mapEid);
    }
    mapService.subscribe(subscriber, subscribedEid);
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) SourceDestKeyLcaf(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf)

Aggregations

ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)17 ItrRlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder)16 Test (org.junit.Test)11 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder)9 EidItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)8 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)7 SourceEidBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder)7 MapRequest (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest)6 RlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder)6 ByteBuffer (java.nio.ByteBuffer)5 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)5 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)5 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequestBuilder)5 InetAddress (java.net.InetAddress)4 Subscriber (org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)3 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)3 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)3 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)3 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2