Search in sources :

Example 1 with Subscriber

use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.

the class LispMapCacheStringifier method prettyPrintSMCMappings.

@SuppressWarnings("unchecked")
public static String prettyPrintSMCMappings(ILispDAO dao) {
    final StringBuilder sb = new StringBuilder();
    final IRowVisitor mappingVisitor = (new IRowVisitor() {

        public void visitRow(Object keyId, String valueKey, Object value) {
            switch(valueKey) {
                case SubKeys.RECORD:
                    MappingData md = (MappingData) value;
                    sb.append(Stringifier.getString(md.getRecord(), 2));
                    sb.append("\n");
                    break;
                case SubKeys.SUBSCRIBERS:
                    Set<Subscriber> subscribers = (Set<Subscriber>) value;
                    sb.append(prettyPrintSubscriberSet(subscribers, 4));
                    sb.append("\n");
                    break;
                default:
                    break;
            }
        }
    });
    dao.getAll(new IRowVisitor() {

        String lastKey = "";

        public void visitRow(Object keyId, String valueKey, Object value) {
            String key = keyId.getClass().getSimpleName() + "#" + keyId;
            if (!lastKey.equals(key)) {
                sb.append("Instance ID " + keyId + "\n");
            }
            if (valueKey.equals(SubKeys.VNI)) {
                ((ILispDAO) value).getAll(mappingVisitor);
            }
            lastKey = key;
        }
    });
    return sb.toString();
}
Also used : IRowVisitor(org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor) Set(java.util.Set) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData)

Example 2 with Subscriber

use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.

the class MappingServiceIntegrationTest method newSubscriber.

private static Subscriber newSubscriber(Eid srcEid, String srcRlocIp) {
    final int timeout = 5;
    final Rloc srcRloc = LispAddressUtil.asIpv4Rloc(srcRlocIp);
    return new Subscriber(srcRloc, srcEid, timeout);
}
Also used : Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) 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 3 with Subscriber

use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber 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 4 with Subscriber

use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber in project lispflowmapping by opendaylight.

the class MappingSystem method notifyChildren.

private void notifyChildren(Eid eid, MappingRecord mapping, MappingChange mappingChange) {
    // Update/created only happens for NB mappings. We assume no overlapping prefix support for NB mappings - so
    // this NB mapping should not have any children. Both for NB first and NB&SB cases all subscribers for SB
    // prefixes that are equal or more specific to this NB prefix have to be notified of the potential change.
    // Each subscriber is notified for the prefix that it is currently subscribed to, and MS should return to them
    // a Map-Reply with the same prefix and update mapping in cases of EID_INTERSECTION_RLOC_NB_FIRST which is a
    // new option we are creating TODO
    Set<Eid> childPrefixes = getSubtree(MappingOrigin.Southbound, eid);
    if (childPrefixes == null || childPrefixes.isEmpty()) {
        return;
    }
    childPrefixes.remove(eid);
    for (Eid prefix : childPrefixes) {
        Set<Subscriber> subscribers = getSubscribers(prefix);
        // No reason to send a notification when no subscribers exist
        if (subscribers != null) {
            publishNotification(mapping, prefix, subscribers, null, mappingChange);
        }
    }
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)

Example 5 with Subscriber

use of org.opendaylight.lispflowmapping.interfaces.dao.Subscriber 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

Subscriber (org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)14 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)8 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)6 SourceDestKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey)4 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)4 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 Set (java.util.Set)2 IRowVisitor (org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor)2 MapRequest (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest)2 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)2 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)2 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)2 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)2 InstanceIdType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType)1 MacAfi (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi)1 SourceDestKeyLcaf (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf)1 Mac (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac)1 MacBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder)1 NoAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddress)1