Search in sources :

Example 21 with MapNotify

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

the class MapNotifySerializationTest method deserialize__Locators.

@Test
public void deserialize__Locators() throws Exception {
    MapNotify mn = MapNotifySerializer.getInstance().deserialize(hexToByteBuffer("40 00 01 01 " + "FF BB 00 00 00 00 00 00 00 01 00 14 f1 b8 ab f0 " + "66 bb 2e ef 12 70 74 46 6f 6b 8e ca bf 1e 68 40 " + "00 00 00 0a " + // Locator Count
    "03 " + "20 10 00 00 00 00 01 99 10 fe 01 " + // Locator 1
    "01 64 1f 00 " + // priorities + weights
    "00 05 " + // Flags
    "00 01 c0 a8 88 0a " + // Locator 2
    "67 00 30 34 " + // priorities + weights
    "00 02 " + // Flags
    "00 01 cc aa AA 11 " + // Locator 3
    "60 11 34 A4 " + // priorities + weights
    "00 03 " + // Flags
    "00 01 c0 a8 88 0a "));
    assertEquals(1, mn.getMappingRecordItem().size());
    MappingRecordItem eidToLocator = mn.getMappingRecordItem().get(0);
    assertEquals(3, eidToLocator.getMappingRecord().getLocatorRecord().size());
    LocatorRecord loc0 = eidToLocator.getMappingRecord().getLocatorRecord().get(0);
    LocatorRecord loc1 = eidToLocator.getMappingRecord().getLocatorRecord().get(1);
    LocatorRecord loc2 = eidToLocator.getMappingRecord().getLocatorRecord().get(2);
    assertEquals((byte) 0x01, loc0.getPriority().byteValue());
    assertEquals((byte) 0x67, loc1.getPriority().byteValue());
    assertEquals((byte) 0x60, loc2.getPriority().byteValue());
    assertEquals((byte) 0x64, loc0.getWeight().byteValue());
    assertEquals((byte) 0x00, loc1.getWeight().byteValue());
    assertEquals((byte) 0x11, loc2.getWeight().byteValue());
    assertEquals((byte) 0x1F, loc0.getMulticastPriority().byteValue());
    assertEquals((byte) 0x30, loc1.getMulticastPriority().byteValue());
    assertEquals((byte) 0x34, loc2.getMulticastPriority().byteValue());
    assertEquals((byte) 0x00, loc0.getMulticastWeight().byteValue());
    assertEquals((byte) 0x34, loc1.getMulticastWeight().byteValue());
    assertEquals((byte) 0xA4, loc2.getMulticastWeight().byteValue());
    assertTrue(loc0.isLocalLocator());
    assertFalse(loc1.isLocalLocator());
    assertFalse(loc2.isLocalLocator());
    assertFalse(loc0.isRlocProbed());
    assertTrue(loc1.isRlocProbed());
    assertTrue(loc2.isRlocProbed());
    assertTrue(loc0.isRouted());
    assertFalse(loc1.isRouted());
    assertTrue(loc2.isRouted());
    assertEquals(LispAddressUtil.asIpv4Rloc("192.168.136.10"), loc0.getRloc());
    assertEquals(LispAddressUtil.asIpv4Rloc("204.170.170.17"), loc1.getRloc());
}
Also used : MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) MapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) Test(org.junit.Test)

Example 22 with MapNotify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotify 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 23 with MapNotify

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

Example 24 with MapNotify

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

the class LispMappingServiceTest method handleMapNotifyTest.

/**
 * Tests {@link LispMappingService#handleMapNotify} method.
 */
@Test
@SuppressWarnings("unchecked")
public void handleMapNotifyTest() {
    final MapNotify mapNotify = Mockito.mock(MapNotify.class);
    final List<TransportAddress> list = Mockito.mock(ArrayList.class);
    lispMappingService.handleMapNotify(mapNotify, list);
    Mockito.verify(tlsMapNotifyMock).set(Mockito.any(MutablePair.class));
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) TransportAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress) GotMapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify) MapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify) Test(org.junit.Test)

Example 25 with MapNotify

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

the class MapNotifySerializer method serialize.

public ByteBuffer serialize(MapNotify mapNotify) {
    int size = Length.HEADER_SIZE;
    if (mapNotify.getAuthenticationData() != null) {
        size += mapNotify.getAuthenticationData().length;
    }
    if (mapNotify.isXtrSiteIdPresent() != null && mapNotify.isXtrSiteIdPresent()) {
        size += org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length.XTRID_SIZE + org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length.SITEID_SIZE;
    }
    for (MappingRecordItem mappingRecord : mapNotify.getMappingRecordItem()) {
        size += MappingRecordSerializer.getInstance().getSerializationSize(mappingRecord.getMappingRecord());
    }
    ByteBuffer replyBuffer = ByteBuffer.allocate(size);
    replyBuffer.put((byte) ((byte) (MessageType.MapNotify.getIntValue() << 4) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapNotify.isXtrSiteIdPresent()), Flags.XTRSITEID)));
    replyBuffer.position(replyBuffer.position() + Length.RES);
    replyBuffer.put(ByteUtil.boolToBit(BooleanUtils.isTrue(mapNotify.isMergeEnabled()), Flags.MERGE_ENABLED));
    if (mapNotify.getMappingRecordItem() != null) {
        replyBuffer.put((byte) mapNotify.getMappingRecordItem().size());
    } else {
        replyBuffer.put((byte) 0);
    }
    replyBuffer.putLong(NumberUtil.asLong(mapNotify.getNonce()));
    replyBuffer.putShort(NumberUtil.asShort(mapNotify.getKeyId()));
    if (mapNotify.getAuthenticationData() != null) {
        replyBuffer.putShort((short) mapNotify.getAuthenticationData().length);
        replyBuffer.put(mapNotify.getAuthenticationData());
    } else {
        replyBuffer.putShort((short) 0);
    }
    if (mapNotify.getMappingRecordItem() != null) {
        for (MappingRecordItem mappingRecord : mapNotify.getMappingRecordItem()) {
            MappingRecordSerializer.getInstance().serialize(replyBuffer, mappingRecord.getMappingRecord());
        }
    }
    if (mapNotify.isXtrSiteIdPresent() != null && mapNotify.isXtrSiteIdPresent()) {
        replyBuffer.put(mapNotify.getXtrId().getValue());
        replyBuffer.put(mapNotify.getSiteId().getValue());
    }
    replyBuffer.clear();
    return replyBuffer;
}
Also used : MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) ByteBuffer(java.nio.ByteBuffer)

Aggregations

MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)19 Test (org.junit.Test)12 GotMapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapNotify)10 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)7 MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)6 MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)5 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)5 GotMapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply)4 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)4 MapRequest (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest)4 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)4 TransportAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress)4 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)3 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)3 TransportAddressBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)2 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)2 SendMapNotifyInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder)2