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());
}
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);
}
}
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());
}
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;
}
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());
}
Aggregations