use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder in project lispflowmapping by opendaylight.
the class LispSouthboundHandler method handleMapRegister.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleMapRegister(ByteBuffer inBuffer, InetAddress sourceAddress, int port) {
try {
Map.Entry<MapRegisterCacheKey, byte[]> artificialEntry = null;
MapRegisterCacheKey cacheKey = null;
MapRegisterCacheValue cacheValue = null;
if (lispSbPlugin.isMapRegisterCacheEnabled()) {
artificialEntry = MapRegisterPartialDeserializer.deserializePartially(inBuffer, sourceAddress);
cacheKey = artificialEntry == null ? null : artificialEntry.getKey();
cacheValue = resolveCacheValue(artificialEntry);
}
if (cacheValue != null) {
lispSbPlugin.getStats().incrementCacheHits();
MapRegisterCacheMetadata mapRegisterMeta = cacheValue.getMapRegisterCacheMetadata();
LOG.debug("Map register message site-ID: {} xTR-ID: {} from cache.", mapRegisterMeta.getSiteId(), mapRegisterMeta.getXtrId());
cacheValue = refreshEntry(cacheKey);
if (cacheValue != null) {
lispSbPlugin.sendNotificationIfPossible(createMappingKeepAlive(cacheValue));
if (cacheValue.getMapRegisterCacheMetadata().isWantMapNotify()) {
sendMapNotifyMsg(inBuffer, sourceAddress, port, cacheValue);
}
}
} else {
lispSbPlugin.getStats().incrementCacheMisses();
MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer, sourceAddress);
MappingAuthkey mappingAuthkey = null;
if (authenticationEnabled) {
mappingAuthkey = tryToAuthenticateMessage(mapRegister, inBuffer);
if (mappingAuthkey == null) {
return;
}
}
AddMappingBuilder addMappingBuilder = new AddMappingBuilder();
addMappingBuilder.setMapRegister(LispNotificationHelper.convertMapRegister(mapRegister));
TransportAddressBuilder transportAddressBuilder = new TransportAddressBuilder();
transportAddressBuilder.setIpAddress(LispNotificationHelper.getIpAddressBinaryFromInetAddress(sourceAddress));
transportAddressBuilder.setPort(new PortNumber(port));
addMappingBuilder.setTransportAddress(transportAddressBuilder.build());
lispSbPlugin.sendNotificationIfPossible(addMappingBuilder.build());
if (artificialEntry != null) {
final MapRegisterCacheMetadataBuilder cacheMetadataBldNew = new MapRegisterCacheMetadataBuilder();
cacheMetadataBldNew.setEidLispAddress(provideEidPrefixesFromMessage(mapRegister));
cacheMetadataBldNew.setXtrId(mapRegister.getXtrId());
cacheMetadataBldNew.setSiteId(mapRegister.getSiteId());
cacheMetadataBldNew.setWantMapNotify(mapRegister.isWantMapNotify());
cacheMetadataBldNew.setMergeEnabled(mapRegister.isMergeEnabled());
cacheMetadataBldNew.setTimestamp(System.currentTimeMillis());
final MapRegisterCacheValueBuilder cacheValueBldNew = new MapRegisterCacheValueBuilder();
cacheValueBldNew.setPacketData(artificialEntry.getValue());
cacheValueBldNew.setMappingAuthkey(mappingAuthkey);
cacheValueBldNew.setMapRegisterCacheMetadata(cacheMetadataBldNew.build());
lispSbPlugin.getMapRegisterCache().addEntry(cacheKey, cacheValueBldNew.build());
}
}
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Register (len=" + inBuffer.capacity() + ")", re);
} catch (InterruptedException e) {
LOG.warn("Notification publication interrupted!");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder in project lispflowmapping by opendaylight.
the class LispSouthboundHandler method handleMapNotify.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleMapNotify(ByteBuffer inBuffer, InetAddress sourceAddress, int port) {
try {
MapNotify mapNotify = MapNotifySerializer.getInstance().deserialize(inBuffer);
GotMapNotifyBuilder gotMapNotifyBuilder = new GotMapNotifyBuilder();
gotMapNotifyBuilder.setMapNotify(LispNotificationHelper.convertMapNotify(mapNotify));
TransportAddressBuilder transportAddressBuilder = new TransportAddressBuilder();
transportAddressBuilder.setIpAddress(LispNotificationHelper.getIpAddressBinaryFromInetAddress(sourceAddress));
transportAddressBuilder.setPort(new PortNumber(port));
gotMapNotifyBuilder.setTransportAddress(transportAddressBuilder.build());
lispSbPlugin.sendNotificationIfPossible(gotMapNotifyBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Notify (len=" + inBuffer.capacity() + ")", re);
} catch (InterruptedException e) {
LOG.warn("Notification publication interrupted!");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder in project lispflowmapping by opendaylight.
the class LispXtrSouthboundHandler method handleMapRequest.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleMapRequest(ByteBuffer inBuffer, InetAddress sourceAddress) {
try {
MapRequest request = MapRequestSerializer.getInstance().deserialize(inBuffer, sourceAddress);
InetAddress finalSourceAddress = MapRequestUtil.selectItrRloc(request);
if (finalSourceAddress == null) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Request, no ITR Rloc found!");
}
XtrRequestMappingBuilder requestMappingBuilder = new XtrRequestMappingBuilder();
requestMappingBuilder.setMapRequest(LispNotificationHelper.convertMapRequest(request));
TransportAddressBuilder transportAddressBuilder = new TransportAddressBuilder();
transportAddressBuilder.setIpAddress(LispNotificationHelper.getIpAddressBinaryFromInetAddress(finalSourceAddress));
transportAddressBuilder.setPort(new PortNumber(LispMessage.PORT_NUM));
requestMappingBuilder.setTransportAddress(transportAddressBuilder.build());
lispSbPlugin.sendNotificationIfPossible(requestMappingBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Request (len=" + inBuffer.capacity() + ")", re);
} catch (InterruptedException e) {
LOG.warn("Notification publication interrupted!");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder in project lispflowmapping by opendaylight.
the class LispSouthboundRpcTest method sendMapReplyTest_inputNotNull.
/**
* Tests {@link LispSouthboundRPC#sendMapReply} method.
*/
@Test
public void sendMapReplyTest_inputNotNull() throws ExecutionException, InterruptedException {
final MapReply mapReply = getDefaultMapReplyBuilder().build();
final TransportAddress transportAddress = new TransportAddressBuilder().build();
final SendMapReplyInput sendMapReplyInputMock = Mockito.mock(SendMapReplyInput.class);
Mockito.when(sendMapReplyInputMock.getTransportAddress()).thenReturn(transportAddress);
Mockito.when(sendMapReplyInputMock.getMapReply()).thenReturn(mapReply);
assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), lispSouthboundRPC.sendMapReply(sendMapReplyInputMock).get().isSuccessful());
Mockito.verify(lispSouthboundPlugin).handleSerializedLispBuffer(transportAddress, MapReplySerializer.getInstance().serialize(mapReply), MessageType.MapReply);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder in project lispflowmapping by opendaylight.
the class LispSouthboundRpcTest method sendMapNotifyTest_inputNotNull.
/**
* Tests {@link LispSouthboundRPC#sendMapNotify} method.
*/
@Test
public void sendMapNotifyTest_inputNotNull() throws ExecutionException, InterruptedException {
final MapNotify mapNotify = getDefaultMapNotifyBuilder().build();
final TransportAddress transportAddress = new TransportAddressBuilder().build();
final SendMapNotifyInput sendMapNotifyInputMock = Mockito.mock(SendMapNotifyInput.class);
Mockito.when(sendMapNotifyInputMock.getTransportAddress()).thenReturn(transportAddress);
Mockito.when(sendMapNotifyInputMock.getMapNotify()).thenReturn(mapNotify);
assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), lispSouthboundRPC.sendMapNotify(sendMapNotifyInputMock).get().isSuccessful());
Mockito.verify(lispSouthboundPlugin).handleSerializedLispBuffer(transportAddress, MapNotifySerializer.getInstance().serialize(mapNotify), MessageType.MapNotify);
}
Aggregations