Search in sources :

Example 1 with MapNotifyBuilder

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

the class MapNotifySerializationTest method serialize__deserialize.

@Test
public void serialize__deserialize() throws Exception {
    MapNotifyBuilder mnBuilder = new MapNotifyBuilder();
    mnBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    mnBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(new MappingRecordBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32")).build()).build());
    mnBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(new MappingRecordBuilder().setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32")).build()).build());
    mnBuilder.setNonce(6161616161L);
    mnBuilder.setKeyId((short) 0x0001);
    byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88, (byte) 0x2d, (byte) 0x4d, (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64, (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba, (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
    mnBuilder.setAuthenticationData(authenticationData);
    MapNotify mn = mnBuilder.build();
    ArrayAssert.assertEquals(MapNotifySerializer.getInstance().serialize(mn).array(), MapNotifySerializer.getInstance().serialize(MapNotifySerializer.getInstance().deserialize(MapNotifySerializer.getInstance().serialize(mn))).array());
}
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) MapNotify(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) Test(org.junit.Test)

Example 2 with MapNotifyBuilder

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

the class MapNotifySerializer method deserialize.

@SuppressWarnings("checkstyle:IllegalCatch")
public MapNotify deserialize(ByteBuffer notifyBuffer) {
    try {
        final byte typeAndFlags = notifyBuffer.get();
        final int type = typeAndFlags >> 4;
        if (MessageType.forValue(type) != MessageType.MapNotify) {
            throw new LispSerializationException("Expected Map-Notify packet (type 4), but was type " + type);
        }
        MapNotifyBuilder builder = new MapNotifyBuilder();
        builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
        boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID);
        builder.setXtrSiteIdPresent(xtrSiteIdPresent);
        notifyBuffer.position(notifyBuffer.position() + Length.RES);
        builder.setMergeEnabled(ByteUtil.extractBit(notifyBuffer.get(), Flags.MERGE_ENABLED));
        byte recordCount = (byte) ByteUtil.getUnsignedByte(notifyBuffer);
        builder.setNonce(notifyBuffer.getLong());
        builder.setKeyId(notifyBuffer.getShort());
        short authenticationLength = notifyBuffer.getShort();
        byte[] authenticationData = new byte[authenticationLength];
        notifyBuffer.get(authenticationData);
        builder.setAuthenticationData(authenticationData);
        if (xtrSiteIdPresent) {
            List<MappingRecordBuilder> mrbs = new ArrayList<MappingRecordBuilder>();
            for (int i = 0; i < recordCount; i++) {
                mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(notifyBuffer));
            }
            byte[] xtrIdBuf = new byte[MapRegisterSerializer.Length.XTRID_SIZE];
            notifyBuffer.get(xtrIdBuf);
            XtrId xtrId = new XtrId(xtrIdBuf);
            byte[] siteIdBuf = new byte[MapRegisterSerializer.Length.SITEID_SIZE];
            notifyBuffer.get(siteIdBuf);
            SiteId siteId = new SiteId(siteIdBuf);
            builder.setXtrId(xtrId);
            builder.setSiteId(siteId);
            for (MappingRecordBuilder mrb : mrbs) {
                mrb.setXtrId(xtrId);
                mrb.setSiteId(siteId);
                builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mrb.build()).build());
            }
        } else {
            for (int i = 0; i < recordCount; i++) {
                builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(notifyBuffer)).build());
            }
        }
        notifyBuffer.limit(notifyBuffer.position());
        return builder.build();
    } catch (RuntimeException re) {
        throw new LispSerializationException("Couldn't deserialize Map-Notify (len=" + notifyBuffer.capacity() + ")", re);
    }
}
Also used : SiteId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId) 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) ArrayList(java.util.ArrayList) LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) XtrId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId)

Example 3 with MapNotifyBuilder

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

the class LispMappingServiceTest method onAddMappingTest_noTransportAddress.

/**
 * Tests {@link LispMappingService#onAddMapping} method with no TransportAddress.
 */
@Test
public void onAddMappingTest_noTransportAddress() {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegister mapRegister = Mockito.mock(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegister.class);
    final AddMapping addMapping = Mockito.mock(AddMapping.class);
    final MapNotify mapNotify = new MapNotifyBuilder().setKeyId((short) 1).build();
    Mockito.when(addMapping.getMapRegister()).thenReturn(mapRegister);
    Mockito.when(mapRegister.getMappingRecordItem()).thenReturn(Lists.newArrayList(MAPPING_RECORD_ITEM_BUILDER.build()));
    Mockito.when(tlsMapNotifyMock.get()).thenReturn(new MutablePair<>(mapNotify, null));
    Mockito.when(addMapping.getTransportAddress()).thenReturn(TRANSPORT_ADDRESS_1);
    // result
    final SendMapNotifyInputBuilder smnib = new SendMapNotifyInputBuilder().setMapNotify(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder().setKeyId((short) 1).build()).setTransportAddress(TRANSPORT_ADDRESS);
    lispMappingService.onAddMapping(addMapping);
    Mockito.verify(odlLispSbService).sendMapNotify(smnib.build());
}
Also used : SendMapNotifyInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder) 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) AddMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) Test(org.junit.Test)

Example 4 with MapNotifyBuilder

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

the class MapServerTest method getDefaultMapNotifyBuilder.

private static MapNotifyBuilder getDefaultMapNotifyBuilder(MapRegister mr) {
    final MapNotifyBuilder mapNotifyBuilder = new MapNotifyBuilder().setXtrSiteIdPresent(mr.isXtrSiteIdPresent()).setSiteId(mr.getSiteId()).setXtrId(mr.getXtrId()).setNonce(mr.getNonce()).setKeyId(mr.getKeyId()).setMergeEnabled(mr.isMergeEnabled()).setMappingRecordItem(new ArrayList<>()).setAuthenticationData(new byte[] {});
    mapNotifyBuilder.getMappingRecordItem().add(getDefaultMappingRecordItemBuilder().build());
    return mapNotifyBuilder;
}
Also used : ArrayList(java.util.ArrayList) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)

Example 5 with MapNotifyBuilder

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

the class LispMappingService method sendMapNotify.

private void sendMapNotify(MapNotify mapNotify, TransportAddress address) {
    SendMapNotifyInputBuilder smnib = new SendMapNotifyInputBuilder();
    smnib.setMapNotify(new MapNotifyBuilder(mapNotify).build());
    smnib.setTransportAddress(address);
    getLispSB().sendMapNotify(smnib.build());
}
Also used : SendMapNotifyInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)

Aggregations

MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)13 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)9 Test (org.junit.Test)8 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)8 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)7 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)3 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)2 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)2 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)2 TransportAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress)2 SendMapNotifyInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Before (org.junit.Before)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1 LispSerializationException (org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)1 ConcurrentLispSouthboundStats (org.opendaylight.lispflowmapping.southbound.ConcurrentLispSouthboundStats)1 LispSouthboundPlugin (org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin)1 MapRegisterCache (org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache)1