*/
try {
Long routerId = naptEntryEvent.getRouterId();
- LOG.trace("handleEvent : Time Elapsed before procesing snat ({}:{}) packet is {} ms,"
- + "routerId: {},isPktProcessed:{}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(),
- System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(),
- routerId, naptEntryEvent.isPktProcessed());
+ String internalIpAddress = naptEntryEvent.getIpAddress();
+ int internalPort = naptEntryEvent.getPortNumber();
+ String sourceIPPortKey = routerId + NatConstants.COLON_SEPARATOR
+ + internalIpAddress + NatConstants.COLON_SEPARATOR + internalPort;
+ LOG.trace("handleEvent : Time Elapsed before procesing snat ({}:{}) packet is {} ms,routerId: {},"
+ + "isPktProcessed:{}",
+ internalIpAddress, internalPort,
+ (System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime()), routerId,
+ naptEntryEvent.isPktProcessed());
//Get the DPN ID
BigInteger dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
long bgpVpnId = NatConstants.INVALID_ID;
if (dpnId == null) {
- LOG.warn("handleEvent : dpnId is null. Assuming the router ID {} as the BGP VPN ID and proceeding....",
- routerId);
+ LOG.warn("handleEvent : dpnId is null. Assuming the router ID {} as the BGP VPN ID and "
+ + "proceeding....", routerId);
bgpVpnId = routerId;
LOG.debug("handleEvent : BGP VPN ID {}", bgpVpnId);
String vpnName = NatUtil.getRouterName(dataBroker, bgpVpnId);
String routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
if (routerName == null) {
- LOG.error("handleEvent : Unable to find router for VpnName {}", vpnName);
+ NaptPacketInHandler.removeIncomingPacketMap(sourceIPPortKey);
+ LOG.error("handleEvent: Unable to find router for VpnName {}. Droping packet for SNAT ({})"
+ + "session", vpnName, sourceIPPortKey);
return;
}
routerId = NatUtil.getVpnId(dataBroker, routerName);
LOG.debug("handleEvent : Router ID {}", routerId);
dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
if (dpnId == null) {
- LOG.error("handleEvent : dpnId is null for the router {}", routerId);
+ NaptPacketInHandler.removeIncomingPacketMap(sourceIPPortKey);
+ LOG.error("handleEvent: Unable to find router for VpnName {}. Droping packet for SNAT ({})"
+ + "session", vpnName, sourceIPPortKey);
return;
}
}
String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
if (extGwMacAddress != null) {
LOG.debug("handleEvent : External Gateway MAC address {} found for External Router ID {}",
- extGwMacAddress, routerId);
+ extGwMacAddress, routerId);
} else {
- LOG.error("handleEvent : No External Gateway MAC address found for External Router ID {}",
- routerId);
+ NaptPacketInHandler.removeIncomingPacketMap(sourceIPPortKey);
+ LOG.error("handleEvent: No External Gateway MAC address found for External Router ID {}."
+ + "Droping packet for SNAT ({}) session", routerId, sourceIPPortKey);
return;
}
+
//Get the external network ID from the ExternalRouter model
Uuid networkId = NatUtil.getNetworkIdFromRouterId(dataBroker, routerId);
if (networkId == null) {
- LOG.error("handleEvent : networkId is null");
+ NaptPacketInHandler.removeIncomingPacketMap(sourceIPPortKey);
+ LOG.error("handleEvent: networkId is null. Droping packet for SNAT ({}) session",
+ sourceIPPortKey);
return;
}
//Get the VPN ID from the ExternalNetworks model
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
if (vpnUuid == null) {
- LOG.error("handleEvent : vpnUuid is null");
+ NaptPacketInHandler.removeIncomingPacketMap(sourceIPPortKey);
+ LOG.error("handleEvent: vpnUuid is null. Droping packet for SNAT ({}) session",
+ sourceIPPortKey);
return;
}
Long vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
- //Get the internal IpAddress, internal port number from the event
- String internalIpAddress = naptEntryEvent.getIpAddress();
- int internalPort = naptEntryEvent.getPortNumber();
SessionAddress internalAddress = new SessionAddress(internalIpAddress, internalPort);
NAPTEntryEvent.Protocol protocol = naptEntryEvent.getProtocol();
naptManager.getExternalAddressMapping(routerId, internalAddress,
naptEntryEvent.getProtocol());
if (externalAddress == null) {
- LOG.error("handleEvent : externalAddress is null");
+ NaptPacketInHandler.removeIncomingPacketMap(sourceIPPortKey);
+ LOG.error("handleEvent: externalAddress is null. Droping packet for SNAT ({}) session",
+ sourceIPPortKey);
return;
}
public class NaptPacketInHandler implements PacketProcessingListener {
private static final Logger LOG = LoggerFactory.getLogger(NaptPacketInHandler.class);
- private final ConcurrentMap<String,NatPacketProcessingState> incomingPacketMap = new ConcurrentHashMap<>();
+ private static final ConcurrentMap<String,NatPacketProcessingState> INCOMING_PKT_MAP = new ConcurrentHashMap<>();
private final NaptEventHandler naptEventHandler;
private final ExecutorService firstPacketExecutorService = SpecialExecutors.newBlockingBoundedFastThreadPool(
NatConstants.SNAT_PACKET_THEADPOOL_SIZE, Integer.MAX_VALUE, "Napt-firstPacket", NaptPacketInHandler.class);
String sourceIPPortKey = routerId + NatConstants.COLON_SEPARATOR
+ internalIPAddress + NatConstants.COLON_SEPARATOR + portNumber;
- NatPacketProcessingState state = incomingPacketMap.get(sourceIPPortKey);
+ NatPacketProcessingState state = INCOMING_PKT_MAP.get(sourceIPPortKey);
if (state == null) {
state = new NatPacketProcessingState(System.currentTimeMillis(), -1);
- incomingPacketMap.put(sourceIPPortKey, state);
+ INCOMING_PKT_MAP.put(sourceIPPortKey, state);
LOG.trace("onPacketReceived : Processing new SNAT({}) Packet", sourceIPPortKey);
//send to Event Queue
}
}
- public void removeIncomingPacketMap(String sourceIPPortKey) {
- incomingPacketMap.remove(sourceIPPortKey);
+ public static void removeIncomingPacketMap(String sourceIPPortKey) {
+ INCOMING_PKT_MAP.remove(sourceIPPortKey);
LOG.debug("removeIncomingPacketMap : sourceIPPortKey {} mapping is removed from map", sourceIPPortKey);
}