Search in sources :

Example 46 with MapRequest

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

the class MapRequestSerializationTest method deserialize__FlagsInSecondByte.

@Test
public void deserialize__FlagsInSecondByte() throws Exception {
    MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("16 80 00 01 3d 8d " + "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " + "00 01 01 02 03 04"), null);
    assertTrue(mr.isPitr());
    assertFalse(mr.isSmrInvoked());
    mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("19 40 00 01 3d 8d " + "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " + "00 01 01 02 03 04"), null);
    assertFalse(mr.isPitr());
    assertTrue(mr.isSmrInvoked());
}
Also used : MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest) Test(org.junit.Test)

Example 47 with MapRequest

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

the class MapRequestSerializationTest method deserialize__MultipleItrRlocs.

@Test
public void deserialize__MultipleItrRlocs() throws Exception {
    MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("10 00 " + // This means 3 ITR - RLOCs
    "02 " + "01 3d 8d 2a cd 39 c8 d6 08 00 00 " + // IPv4 (ITR-RLOC #1 of 3)
    "00 01 c0 a8 88 0a " + // IPv6 (ITR-RLOC #2 of 3)
    "00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 " + // 
    "00 01 11 22 34 56 " + // IPv4 (ITR-RLOC #3 of 3)
    "00 20 00 01 01 02 03 04"), null);
    assertEquals(3, mr.getItrRloc().size());
    assertArrayEquals(new byte[] { (byte) 192, (byte) 168, (byte) 136, (byte) 10 }, ((Ipv4Binary) mr.getItrRloc().get(0).getRloc().getAddress()).getIpv4Binary().getValue());
    assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, ((Ipv6Binary) mr.getItrRloc().get(1).getRloc().getAddress()).getIpv6Binary().getValue());
    assertArrayEquals(new byte[] { 17, 34, 52, 86 }, ((Ipv4Binary) mr.getItrRloc().get(2).getRloc().getAddress()).getIpv4Binary().getValue());
}
Also used : MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest) Ipv4Binary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary) Ipv6Binary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary) Test(org.junit.Test)

Example 48 with MapRequest

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

the class MapResolver method handleMapRequest.

public void handleMapRequest(MapRequest request) {
    LOG.trace("Map-Request received: {}", request);
    // SMRs and RLOC probes are directed towards xTRs and we're a Map-Resolver here, so ignore them
    if (request.isSmr() != null && request.isSmr()) {
        LOG.debug("Map-Resolver ignoring incoming SMR control message.");
        return;
    }
    if (request.isProbe() != null && request.isProbe()) {
        LOG.debug("Map-Resolver ignoring incoming RLOC probe control message.");
        return;
    }
    if (request.isSmrInvoked()) {
        LOG.debug("SMR-invoked request received.");
        LOG.trace("Map-Request object: {}", request);
        for (EidItem eidItem : request.getEidItem()) {
            final SmrEvent event = new SmrEvent(subscriberListFromItrRlocs(request.getItrRloc(), request.getSourceEid().getEid()), eidItem.getEid(), request.getNonce());
            smrNotificationListener.onSmrInvokedReceived(event);
        }
    }
    Eid srcEid = null;
    if (request.getSourceEid() != null) {
        srcEid = request.getSourceEid().getEid();
    }
    MapReplyBuilder replyBuilder = new MapReplyBuilder();
    replyBuilder.setEchoNonceEnabled(false);
    replyBuilder.setProbe(false);
    replyBuilder.setSecurityEnabled(false);
    replyBuilder.setNonce(request.getNonce());
    replyBuilder.setMappingRecordItem(new ArrayList<>());
    List<ItrRloc> itrRlocs = request.getItrRloc();
    final IpAddressBinary sourceRloc = request.getSourceRloc();
    for (EidItem eidRecord : request.getEidItem()) {
        MappingData mappingData = mapService.getMapping(srcEid, eidRecord.getEid());
        MappingRecord mapping;
        if (mappingData == null) {
            mapping = mapService.addNegativeMapping(eidRecord.getEid()).getRecord();
        } else {
            mapping = mappingData.getRecord();
        }
        if (itrRlocs != null && itrRlocs.size() != 0) {
            if (subscriptionService && isValidSourceEidForSubscriber(srcEid)) {
                final Rloc resolvedRloc = resolveRloc(itrRlocs, sourceRloc);
                updateSubscribers(resolvedRloc, eidRecord.getEid(), mapping.getEid(), srcEid, mapping.getRecordTtl());
            }
            mapping = updateLocators(mapping, itrRlocs);
        }
        mapping = fixIfNotSDRequest(mapping, eidRecord.getEid());
        mapping = fixTtlIfSmrInvoked(request, mapping);
        replyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mapping).build());
    }
    requestHandler.handleMapReply(replyBuilder.build());
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) IpAddressBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary) SmrEvent(org.opendaylight.lispflowmapping.interfaces.lisp.SmrEvent) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) 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) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) EidItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)

Example 49 with MapRequest

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

the class LispMappingServiceTest method handleMapRequestTest_NonProxy.

/**
 * Tests {@link LispMappingService#handleMapRequest} method request from non-proxy xTR.
 */
@Test
public void handleMapRequestTest_NonProxy() {
    final MapRequest mapRequest = Mockito.mock(MapRequest.class);
    final Pair<MapRequest, TransportAddress> pair = getDefaultMapRequestPair();
    final SendMapRequestInputBuilder smrib = new SendMapRequestInputBuilder().setMapRequest(pair.getLeft()).setTransportAddress(pair.getRight());
    Mockito.when(mapRequest.getEidItem()).thenReturn(Lists.newArrayList(EID_ITEM_BUILDER.build()));
    Mockito.when(tlsMapRequestMock.get()).thenReturn(pair);
    assertNull(lispMappingService.handleMapRequest(mapRequest));
    Mockito.verify(odlLispSbService).sendMapRequest(smrib.build());
}
Also used : SendMapRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestInputBuilder) MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequest) TransportAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress) Test(org.junit.Test)

Example 50 with MapRequest

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

Aggregations

MapRequest (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest)33 Test (org.junit.Test)24 GotMapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply)11 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)11 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)10 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequestBuilder)10 ItrRlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder)9 InetAddress (java.net.InetAddress)8 EidItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)6 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)6 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder)6 RlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder)6 GotMapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify)5 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)5 MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)5 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)5 SourceEidBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder)5 MapRequest (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequest)5 Ipv4Binary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary)4 XtrRequestMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrRequestMapping)4