@Test public void testOnPacketReceivedWithInvalidPacket() throws Exception { pktHandler.onPacketReceived(null); verify(pktProcessService, times(0)).transmitPacket(any(TransmitPacketInput.class)); byte[] pktArray = {}; PacketReceived packet = new PacketReceivedBuilder().setPayload(pktArray).build(); pktHandler.onPacketReceived(packet); verify(pktProcessService, times(0)).transmitPacket(any(TransmitPacketInput.class)); }
@Override public void onPacketReceived(PacketReceived packetReceived) { int ethType; int v6NxtHdr; if (packetReceived == null) { LOG.debug("Received null packet. Returning without any processing"); return; } byte[] data = packetReceived.getPayload(); if (data.length <= 0) { LOG.debug("Received packet with invalid length {}", data.length); return; } try { ethType = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ETHTYPE_START, Ipv6Constants.TWO_BYTES)); if (ethType == NwConstants.ETHTYPE_IPV6) { v6NxtHdr = BitBufferHelper.getByte(BitBufferHelper.getBits(data, Ipv6Constants.IP_V6_HDR_START + Ipv6Constants.IP_V6_NEXT_HDR, Ipv6Constants.ONE_BYTE)); if (v6NxtHdr == IPProtocols.IPV6ICMP.intValue()) { int icmpv6Type = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ICMPV6_HDR_START, Ipv6Constants.ONE_BYTE)); if (isOfInterest(icmpv6Type)) { packetProcessor.execute(new PacketHandler(icmpv6Type, packetReceived)); } } else { LOG.debug("IPv6 Pdu received on port {} with next-header {} ", packetReceived.getIngress(), v6NxtHdr); } } else { return; } } catch (BufferException e) { LOG.warn("Failed to decode packet: {}", e.getMessage()); return; } }
Ipv6PktHandler implements AutoCloseable, PacketProcessingListener { @Override public void onPacketReceived(PacketReceived packetReceived) { int ethType; int v6NxtHdr; if (packetReceived == null) { LOG.debug("Received null packet. Returning without any processing"); return; } byte[] data = packetReceived.getPayload(); if (data.length <= 0) { LOG.debug("Received packet with invalid length {}", data.length); return; } try { ethType = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ETHTYPE_START, Ipv6Constants.TWO_BYTES)); if (ethType == NwConstants.ETHTYPE_IPV6) { v6NxtHdr = BitBufferHelper.getByte(BitBufferHelper.getBits(data, Ipv6Constants.IP_V6_HDR_START + Ipv6Constants.IP_V6_NEXT_HDR, Ipv6Constants.ONE_BYTE)); if (v6NxtHdr == IPProtocols.IPV6ICMP.intValue()) { int icmpv6Type = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ICMPV6_HDR_START, Ipv6Constants.ONE_BYTE)); if (isOfInterest(icmpv6Type)) { packetProcessor.execute(new PacketHandler(icmpv6Type, packetReceived)); } } else { LOG.debug("IPv6 Pdu received on port {} with next-header {} ", packetReceived.getIngress(), v6NxtHdr); } } else { return; } } catch (BufferException e) { LOG.warn("Failed to decode packet: {}", e.getMessage()); return; } } }
Ipv6PktHandler implements AutoCloseable, PacketProcessingListener { @Override public void onPacketReceived(PacketReceived packetReceived) { int ethType; int v6NxtHdr; if (packetReceived == null) { LOG.debug("Received null packet. Returning without any processing"); return; } byte[] data = packetReceived.getPayload(); if (data.length <= 0) { LOG.debug("Received packet with invalid length {}", data.length); return; } try { ethType = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ETHTYPE_START, Ipv6Constants.TWO_BYTES)); if (ethType == NwConstants.ETHTYPE_IPV6) { v6NxtHdr = BitBufferHelper.getByte(BitBufferHelper.getBits(data, Ipv6Constants.IP_V6_HDR_START + Ipv6Constants.IP_V6_NEXT_HDR, Ipv6Constants.ONE_BYTE)); if (v6NxtHdr == IPProtocols.IPV6ICMP.intValue()) { int icmpv6Type = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ICMPV6_HDR_START, Ipv6Constants.ONE_BYTE)); if (isOfInterest(icmpv6Type)) { packetProcessor.execute(new PacketHandler(icmpv6Type, packetReceived)); } } else { LOG.debug("IPv6 Pdu received on port {} with next-header {} ", packetReceived.getIngress(), v6NxtHdr); } } else { return; } } catch (BufferException e) { LOG.warn("Failed to decode packet: {}", e.getMessage()); return; } } @Inject  Ipv6PktHandler(PacketProcessingService pktService, IfMgr ifMgr,Ipv6ServiceUtils ipv6ServiceUtils,
                          IpV6NAConfigHelper ipV6NAConfigHelper, IIpv6PacketListener ipv6PktListener); }
Ipv6PktHandler implements AutoCloseable, PacketProcessingListener { @Override public void onPacketReceived(PacketReceived packetReceived) { int ethType; int v6NxtHdr; if (packetReceived == null) { LOG.debug("Received null packet. Returning without any processing"); return; } byte[] data = packetReceived.getPayload(); if (data.length <= 0) { LOG.debug("Received packet with invalid length {}", data.length); return; } try { ethType = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ETHTYPE_START, Ipv6Constants.TWO_BYTES)); if (ethType == NwConstants.ETHTYPE_IPV6) { v6NxtHdr = BitBufferHelper.getByte(BitBufferHelper.getBits(data, Ipv6Constants.IP_V6_HDR_START + Ipv6Constants.IP_V6_NEXT_HDR, Ipv6Constants.ONE_BYTE)); if (v6NxtHdr == IPProtocols.IPV6ICMP.intValue()) { int icmpv6Type = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ICMPV6_HDR_START, Ipv6Constants.ONE_BYTE)); if (isOfInterest(icmpv6Type)) { packetProcessor.execute(new PacketHandler(icmpv6Type, packetReceived)); } } else { LOG.debug("IPv6 Pdu received on port {} with next-header {} ", packetReceived.getIngress(), v6NxtHdr); } } else { return; } } catch (BufferException e) { LOG.warn("Failed to decode packet: {}", e.getMessage()); return; } } @Inject  Ipv6PktHandler(PacketProcessingService pktService, IfMgr ifMgr,Ipv6ServiceUtils ipv6ServiceUtils,
                          IpV6NAConfigHelper ipV6NAConfigHelper, IIpv6PacketListener ipv6PktListener); @Override void onPacketReceived(PacketReceived packetReceived); long getPacketProcessedCounter(); @Override @PreDestroy void close(); }
Ipv6PktHandler implements AutoCloseable, PacketProcessingListener { @Override public void onPacketReceived(PacketReceived packetReceived) { int ethType; int v6NxtHdr; if (packetReceived == null) { LOG.debug("Received null packet. Returning without any processing"); return; } byte[] data = packetReceived.getPayload(); if (data.length <= 0) { LOG.debug("Received packet with invalid length {}", data.length); return; } try { ethType = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ETHTYPE_START, Ipv6Constants.TWO_BYTES)); if (ethType == NwConstants.ETHTYPE_IPV6) { v6NxtHdr = BitBufferHelper.getByte(BitBufferHelper.getBits(data, Ipv6Constants.IP_V6_HDR_START + Ipv6Constants.IP_V6_NEXT_HDR, Ipv6Constants.ONE_BYTE)); if (v6NxtHdr == IPProtocols.IPV6ICMP.intValue()) { int icmpv6Type = BitBufferHelper.getInt(BitBufferHelper.getBits(data, Ipv6Constants.ICMPV6_HDR_START, Ipv6Constants.ONE_BYTE)); if (isOfInterest(icmpv6Type)) { packetProcessor.execute(new PacketHandler(icmpv6Type, packetReceived)); } } else { LOG.debug("IPv6 Pdu received on port {} with next-header {} ", packetReceived.getIngress(), v6NxtHdr); } } else { return; } } catch (BufferException e) { LOG.warn("Failed to decode packet: {}", e.getMessage()); return; } } @Inject  Ipv6PktHandler(PacketProcessingService pktService, IfMgr ifMgr,Ipv6ServiceUtils ipv6ServiceUtils,
                          IpV6NAConfigHelper ipV6NAConfigHelper, IIpv6PacketListener ipv6PktListener); @Override void onPacketReceived(PacketReceived packetReceived); long getPacketProcessedCounter(); @Override @PreDestroy void close();  }