Search in sources :

Example 16 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 MapNotifySerializationTest method serialize__Fields.

@Test
public void serialize__Fields() 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);
    ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mnBuilder.build());
    // Type + MSByte of reserved
    assertHexEquals((byte) 0x40, bb.get());
    // Rest of reserved
    assertEquals(0, bb.getShort());
    // Record Count
    assertEquals(2, bb.get());
    // Nonce
    assertEquals(6161616161L, bb.getLong());
    // Key ID
    assertHexEquals((short) 0x0001, bb.getShort());
    assertEquals(authenticationData.length, bb.getShort());
    byte[] actualAuthenticationData = new byte[20];
    bb.get(actualAuthenticationData);
    ArrayAssert.assertEquals(authenticationData, actualAuthenticationData);
    bb.position(bb.position() + 12);
    /* EID in first record */
    assertEquals(0x1, bb.getInt());
    bb.position(bb.position() + 12);
    /* EID in second record */
    assertEquals(73, bb.getInt());
    assertEquals(bb.position(), bb.capacity());
}
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) Test(org.junit.Test)

Example 17 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 MapNotifySerializationTest method serialize__NoAuthenticationData.

@Test
public void serialize__NoAuthenticationData() 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")).setRecordTtl(55).build()).build());
    ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mnBuilder.build());
    // jump to AuthenticationDataLength
    bb.position(bb.position() + 14);
    assertEquals(0, bb.getShort());
    assertEquals(55, bb.getInt());
    mnBuilder.setAuthenticationData(null);
    bb = MapNotifySerializer.getInstance().serialize(mnBuilder.build());
    // jump to AuthenticationDataLength
    bb.position(bb.position() + 14);
    assertEquals(0, bb.getShort());
    assertEquals(55, bb.getInt());
    mnBuilder.setAuthenticationData(new byte[0]);
    bb = MapNotifySerializer.getInstance().serialize(mnBuilder.build());
    // jump to AuthenticationDataLength
    bb.position(bb.position() + 14);
    assertEquals(0, bb.getShort());
    assertEquals(55, bb.getInt());
}
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) Test(org.junit.Test)

Example 18 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 MapRegisterSerializationTest method serialize__NoAuthenticationData.

@Test
public void serialize__NoAuthenticationData() throws Exception {
    MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
    mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(new MappingRecordBuilder().setRecordTtl(55).setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32")).build()).build());
    // mrBuilder.addEidToLocator(new EidToLocatorRecord().setPrefix(new
    // LispIpv4Address(1)).setRecordTtl(55));
    ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
    // jump to AuthenticationDataLength
    bb.position(bb.position() + 14);
    assertEquals(0, bb.getShort());
    assertEquals(55, bb.getInt());
    mrBuilder.setAuthenticationData(null);
    bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
    // jump to AuthenticationDataLength
    bb.position(bb.position() + 14);
    assertEquals(0, bb.getShort());
    assertEquals(55, bb.getInt());
    mrBuilder.setAuthenticationData(new byte[0]);
    bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
    // jump to AuthenticationDataLength
    bb.position(bb.position() + 14);
    assertEquals(0, bb.getShort());
    assertEquals(55, bb.getInt());
}
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) ByteBuffer(java.nio.ByteBuffer) MapRegisterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder) Test(org.junit.Test)

Example 19 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 MapRegisterSerializationTest method serialize__Fields.

@Test
public void serialize__Fields() throws Exception {
    MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
    mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
    recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
    recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
    mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
    recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32"));
    mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
    mrBuilder.setNonce(6161616161L);
    mrBuilder.setKeyId((short) 0x0001);
    mrBuilder.setWantMapNotify(true);
    mrBuilder.setProxyMapReply(true);
    mrBuilder.setXtrSiteIdPresent(true);
    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 };
    mrBuilder.setAuthenticationData(authenticationData);
    XtrId xtrId = new XtrId(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 });
    mrBuilder.setXtrId(xtrId);
    SiteId siteId = new SiteId(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 });
    mrBuilder.setSiteId(siteId);
    ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
    // Type + MSByte of reserved
    assertHexEquals((byte) 0x3a, bb.get());
    // Rest of reserved + want map notify
    assertEquals(1, bb.getShort());
    // Record Count
    assertEquals(2, bb.get());
    // Nonce
    assertEquals(6161616161L, bb.getLong());
    // Key ID
    assertHexEquals((short) 0x0001, bb.getShort());
    assertEquals(authenticationData.length, bb.getShort());
    byte[] actualAuthenticationData = new byte[20];
    bb.get(actualAuthenticationData);
    ArrayAssert.assertEquals(authenticationData, actualAuthenticationData);
    // EID in first record
    bb.position(bb.position() + 12);
    assertEquals(0x1, bb.getInt());
    // EID in second record
    bb.position(bb.position() + 12);
    assertEquals(73, bb.getInt());
    byte[] actualXtrId = new byte[Length.XTRID_SIZE];
    bb.get(actualXtrId);
    ArrayAssert.assertEquals(xtrId.getValue(), actualXtrId);
    byte[] actualSiteId = new byte[Length.SITEID_SIZE];
    bb.get(actualSiteId);
    ArrayAssert.assertEquals(siteId.getValue(), actualSiteId);
    assertEquals(bb.position(), bb.capacity());
}
Also used : MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) SiteId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId) 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) ByteBuffer(java.nio.ByteBuffer) MapRegisterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) XtrId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId) Test(org.junit.Test)

Example 20 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__SomeFlags.

@Test
public void serialize__SomeFlags() throws Exception {
    MapReplyBuilder mr = new MapReplyBuilder();
    mr.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
    recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
    mr.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
    mr.setProbe(true);
    mr.setEchoNonceEnabled(false);
    ByteBuffer packet = MapReplySerializer.getInstance().serialize(mr.build());
    byte firstByte = packet.get(0);
    assertHexEquals((byte) 0x28, firstByte);
    mr.setProbe(false);
    mr.setEchoNonceEnabled(true);
    packet = MapReplySerializer.getInstance().serialize(mr.build());
    firstByte = packet.get(0);
    assertHexEquals((byte) 0x24, firstByte);
}
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)

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