use of org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException in project lispflowmapping by opendaylight.
the class LispSouthboundHandler method extractEncapsulatedSourcePort.
@SuppressWarnings("checkstyle:IllegalCatch")
private int extractEncapsulatedSourcePort(ByteBuffer inBuffer) {
try {
inBuffer.position(PacketHeader.Length.LISP_ENCAPSULATION);
int ipType = (inBuffer.get() >> 4);
if (ipType == 4) {
inBuffer.position(inBuffer.position() + PacketHeader.Length.IPV4 - 1);
} else if (ipType == 6) {
inBuffer.position(inBuffer.position() + PacketHeader.Length.IPV6_NO_EXT - 1);
} else {
throw new LispMalformedPacketException("Couldn't deserialize Map-Request: inner packet has unknown IP version: " + ipType);
}
int encapsulatedSourcePort = inBuffer.getShort() & 0xFFFF;
inBuffer.position(inBuffer.position() + PacketHeader.Length.UDP - 2);
return encapsulatedSourcePort;
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Request (len=" + inBuffer.capacity() + ")", re);
}
}
use of org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException 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.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException 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.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException 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.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException in project lispflowmapping by opendaylight.
the class LispXtrSouthboundHandler method handleMapReply.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleMapReply(ByteBuffer buffer) {
try {
MapReply reply = MapReplySerializer.getInstance().deserialize(buffer);
XtrReplyMappingBuilder replyMappingBuilder = new XtrReplyMappingBuilder();
replyMappingBuilder.setMapReply(LispNotificationHelper.convertMapReply(reply));
lispSbPlugin.sendNotificationIfPossible(replyMappingBuilder.build());
} catch (RuntimeException re) {
throw new LispMalformedPacketException("Couldn't deserialize Map-Reply (len=" + buffer.capacity() + ")", re);
} catch (InterruptedException e) {
LOG.warn("Notification publication interrupted!");
}
}
Aggregations