@Test public void testonPacketReceivedNeighborAdvertisementWithValidPayload() throws Exception { VirtualPort intf = Mockito.mock(VirtualPort.class); when(intf.getNetworkID()).thenReturn(new Uuid("eeec9dba-d831-4ad7-84b9-00d7f65f0555")); when(ifMgrInstance.getInterfaceNameFromTag(anyLong())).thenReturn("ddec9dba-d831-4ad7-84b9-00d7f65f052f"); when(ifMgrInstance.obtainV6Interface(any())).thenReturn(intf); InstanceIdentifier<Node> ncId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId("openflow:1"))).build(); NodeConnectorRef ncRef = new NodeConnectorRef(ncId); Uint64 mdata = Uint64.valueOf(0x1000000); Metadata metadata = new MetadataBuilder().setMetadata(mdata).build(); MatchBuilder matchbuilder = new MatchBuilder().setMetadata(metadata); byte[] data = ipv6TestUtils.buildPacket( "FA 16 3E F7 69 4E", "FA 16 3E A9 38 94", "86 DD", "60 00 00 00", "00 20", "3A", "FF", "20 01 0D B8 00 00 00 02 00 00 00 00 00 00 11 11", "10 01 0D B8 00 00 00 02 F8 16 3E FF FE F7 69 4E", "88", "00", "C9 9F", "00 00 00 00", "20 01 0D B8 00 00 00 02 00 00 00 00 00 00 11 11", "02", "01", "FA 16 3E A9 38 94" ); pktHandler.onPacketReceived(new PacketReceivedBuilder().setPayload(data).setIngress(ncRef) .setMatch(matchbuilder.build()).setTableId(new TableId((short) 45)).build()); waitForPacketProcessing(); NeighborAdvertisePacket naPdu = new Ipv6NaDecoder(data).decode(); NeighborAdvertisePacket naPacket = new NeighborAdvertisePacketBuilder(naPdu) .addAugmentation(PacketMetadata.class, new PacketMetadataBuilder().setOfTableId((long) 45) .setMetadata(mdata).setInterface("ddec9dba-d831-4ad7-84b9-00d7f65f052f").build()) .build(); verify(ipv6PktListener).onNaReceived(naPacket); }
@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();  }