Search in sources :

Example 21 with MappingRecordItemBuilder

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

the class MapReplySerializationTest method serialize__EidRecordNullActionShouldTranslateToDefault.

@Test
public void serialize__EidRecordNullActionShouldTranslateToDefault() throws Exception {
    MapReplyBuilder mrBuilder = new MapReplyBuilder();
    mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
    recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
    recordBuilder.setAction(null);
    mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
    ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
    packet.position(18);
    // MapReplyAction.NoAction
    assertHexEquals((byte) 0x00, packet.get());
}
Also used : MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) 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) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 22 with MappingRecordItemBuilder

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

the class MapReplySerializationTest method serialize__LocatorRecordFields.

@Test
public void serialize__LocatorRecordFields() throws Exception {
    MapReplyBuilder mrBuilder = new MapReplyBuilder();
    mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    MappingRecordBuilder eidToLocatorBuilder = new MappingRecordBuilder();
    eidToLocatorBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
    eidToLocatorBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
    LocatorRecordBuilder locatorBuilder1 = new LocatorRecordBuilder();
    locatorBuilder1.setPriority((short) 0xF3);
    locatorBuilder1.setWeight((short) 0xF6);
    locatorBuilder1.setMulticastPriority((short) 0xA3);
    locatorBuilder1.setMulticastWeight((short) 0x06);
    locatorBuilder1.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.1"));
    locatorBuilder1.setLocalLocator(true);
    locatorBuilder1.setRlocProbed(true);
    locatorBuilder1.setRouted(true);
    eidToLocatorBuilder.getLocatorRecord().add(locatorBuilder1.build());
    LocatorRecordBuilder locatorBuilder2 = new LocatorRecordBuilder();
    locatorBuilder2.setPriority((short) 0x03);
    locatorBuilder2.setWeight((short) 0x06);
    locatorBuilder2.setMulticastPriority((short) 0x03);
    locatorBuilder2.setMulticastWeight((short) 0xF1);
    locatorBuilder2.setRloc(LispAddressUtil.asIpv4Rloc("0.0.0.2"));
    locatorBuilder2.setLocalLocator(false);
    locatorBuilder2.setRlocProbed(false);
    locatorBuilder2.setRouted(false);
    eidToLocatorBuilder.getLocatorRecord().add(locatorBuilder2.build());
    mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(eidToLocatorBuilder.build()).build());
    ByteBuffer packet = MapReplySerializer.getInstance().serialize(mrBuilder.build());
    // First locator record
    packet.position(12 + 16);
    assertHexEquals((byte) 0xF3, packet.get());
    assertHexEquals((byte) 0xF6, packet.get());
    assertHexEquals((byte) 0xA3, packet.get());
    assertHexEquals((byte) 0x06, packet.get());
    packet.position(packet.position() + 1);
    assertHexEquals((byte) 0x07, packet.get());
    // Second locator record
    packet.position(packet.position() + 6);
    assertHexEquals((byte) 0x03, packet.get());
    assertHexEquals((byte) 0x06, packet.get());
    assertHexEquals((byte) 0x03, packet.get());
    assertHexEquals((byte) 0xF1, packet.get());
    packet.position(packet.position() + 1);
    assertHexEquals((byte) 0x00, packet.get());
}
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) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) 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) ByteBuffer(java.nio.ByteBuffer) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) Test(org.junit.Test)

Example 23 with MappingRecordItemBuilder

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

the class LispAuthenticationTest method authenticate__MapNotifyNoAuthenticationData.

// @Test
// public void authenticate__MapNotifySHA1() throws Exception {
// MapNotify mapNotify = new MapNotify();
// mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(1)));
// 
// mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(73)));
// mapNotify.setNonce(6161616161L);
// mapNotify.setKeyId((short) 0x0001);
// byte[] wantedAuthenticationData = new byte[] { (byte) 0x66, (byte) 0x69,
// (byte) 0x2c, (byte) 0xb8, (byte) 0xb8, (byte) 0x58, (byte) 0x7c,
// (byte) 0x8f, (byte) 0x4c, (byte) 0xd4, (byte) 0x8b, (byte) 0x77, (byte)
// 0x46, (byte) 0xf0, (byte) 0x6b, (byte) 0x9f, (byte) 0x66,
// (byte) 0xd2, (byte) 0xaa, (byte) 0x2c };
// ArrayAssert.assertEquals(wantedAuthenticationData,
// LispAuthenticationUtil.createAuthenticationData(mapNotify, "password"));
// 
// }
// 
// @Test
// public void authenticate__MapNotifySHA256() throws Exception {
// MapNotify mapNotify = new MapNotify();
// mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(1)));
// 
// mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(new
// LispIpv4Address(73)));
// mapNotify.setNonce(6161616161L);
// mapNotify.setKeyId((short) 0x0002);
// byte[] wantedAuthenticationData = new byte[] { (byte) 0x4c, (byte) 0xf1,
// (byte) 0x5a, (byte) 0x4c, (byte) 0xdb, (byte) 0x8d, (byte) 0x88,
// (byte) 0x47, (byte) 0xf1, (byte) 0x7f, (byte) 0x27, (byte) 0x81, (byte)
// 0x1e, (byte) 0xbf, (byte) 0x22, (byte) 0xc7, (byte) 0xe6,
// (byte) 0x70, (byte) 0x16, (byte) 0x5e, (byte) 0xa1, (byte) 0x59, (byte)
// 0xe4, (byte) 0x06, (byte) 0x3f, (byte) 0xc2, (byte) 0x6a,
// (byte) 0x1c, (byte) 0x86, (byte) 0xa5, (byte) 0x8d, (byte) 0x63 };
// ArrayAssert.assertEquals(wantedAuthenticationData,
// LispAuthenticationUtil.createAuthenticationData(mapNotify, "password"));
// 
// }
@Test
public void authenticate__MapNotifyNoAuthenticationData() throws Exception {
    MapNotifyBuilder mapNotifyBuilder = new MapNotifyBuilder();
    mapNotifyBuilder.setKeyId((short) 0x0000);
    mapNotifyBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
    etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
    etlrBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("1.1.1.1/32"));
    etlrBuilder.setRecordTtl(55);
    mapNotifyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
    final ByteBuffer serializedMapNotifyMsg = MapNotifySerializer.getInstance().serialize(mapNotifyBuilder.build());
    ArrayAssert.assertEquals(new byte[0], LispAuthenticationUtil.createAuthenticationData(serializedMapNotifyMsg, "password"));
}
Also used : MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) ByteBuffer(java.nio.ByteBuffer) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) Test(org.junit.Test)

Example 24 with MappingRecordItemBuilder

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

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

the class MapServer method handleMapRegister.

@SuppressWarnings("unchecked")
public void handleMapRegister(MapRegister mapRegister) {
    boolean mappingUpdated = false;
    boolean merge = ConfigIni.getInstance().mappingMergeIsSet() && mapRegister.isMergeEnabled();
    MappingRecord oldMapping;
    if (merge) {
        if (!mapRegister.isXtrSiteIdPresent() || mapRegister.getXtrId() == null) {
            LOG.error("Merge bit is set in Map-Register, but xTR-ID is not present. Will not merge.");
            merge = false;
        } else if (Arrays.equals(mapRegister.getXtrId().getValue(), ALL_ZEROES_XTR_ID)) {
            LOG.warn("Merge bit is set in Map-Register, but xTR-ID is all zeroes.");
        }
    }
    for (MappingRecordItem record : mapRegister.getMappingRecordItem()) {
        MappingRecord mapping = record.getMappingRecord();
        Eid eid = mapping.getEid();
        MappingData mappingData = new MappingData(mapping, System.currentTimeMillis());
        mappingData.setMergeEnabled(merge);
        mappingData.setXtrId(mapRegister.getXtrId());
        oldMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
        mapService.addMapping(MappingOrigin.Southbound, eid, getSiteId(mapRegister), mappingData);
        if (merge) {
            MappingRecord newMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
            if (MappingRecordUtil.mappingChanged(oldMapping, newMapping)) {
                // If there is a SB mapping change with merge on, Map-Notify will be sent to ALL xTRs, not jus the
                // one registering (merging is done in the MappingSystem code)
                mappingUpdated = true;
            }
        }
    }
    if (BooleanUtils.isTrue(mapRegister.isWantMapNotify())) {
        LOG.trace("MapRegister wants MapNotify");
        MapNotifyBuilder builder = new MapNotifyBuilder();
        List<TransportAddress> rlocs = null;
        if (merge) {
            Set<IpAddressBinary> notifyRlocs = new HashSet<IpAddressBinary>();
            List<MappingRecordItem> mergedMappings = new ArrayList<MappingRecordItem>();
            for (MappingRecordItem record : mapRegister.getMappingRecordItem()) {
                MappingRecord mapping = record.getMappingRecord();
                MappingRecord currentRecord = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, mapping.getEid()));
                mergedMappings.add(new MappingRecordItemBuilder().setMappingRecord(currentRecord).build());
                Set<IpAddressBinary> sourceRlocs = (Set<IpAddressBinary>) mapService.getData(MappingOrigin.Southbound, mapping.getEid(), SubKeys.SRC_RLOCS);
                if (sourceRlocs != null) {
                    notifyRlocs.addAll(sourceRlocs);
                }
            }
            MapNotifyBuilderHelper.setFromMapRegisterAndMappingRecordItems(builder, mapRegister, mergedMappings);
            // send map-notify to merge group only when mapping record is changed
            if (mappingUpdated) {
                rlocs = getTransportAddresses(notifyRlocs);
            }
        } else {
            MapNotifyBuilderHelper.setFromMapRegister(builder, mapRegister);
        }
        List<MappingRecordItem> mappings = builder.getMappingRecordItem();
        if (mappings != null && mappings.get(0) != null && mappings.get(0).getMappingRecord() != null && mappings.get(0).getMappingRecord().getEid() != null) {
            MappingAuthkey authkey = mapService.getAuthenticationKey(mappings.get(0).getMappingRecord().getEid());
            if (authkey != null) {
                builder.setAuthenticationData(LispAuthenticationUtil.createAuthenticationData(builder.build(), authkey.getKeyString()));
            }
        }
        notifyHandler.handleMapNotify(builder.build(), rlocs);
    }
}
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) Set(java.util.Set) HashSet(java.util.HashSet) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) TransportAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress) ArrayList(java.util.ArrayList) IpAddressBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) HashSet(java.util.HashSet)

Aggregations

MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)34 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)27 Test (org.junit.Test)25 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)23 MapReplyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder)15 ByteBuffer (java.nio.ByteBuffer)14 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)9 MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)9 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)8 MapRegisterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder)8 ArrayList (java.util.ArrayList)5 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)5 SiteId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId)4 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)4 LispSerializationException (org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)3 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)3 XtrId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId)3 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)3 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)3 ItrRlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder)3