@Test public void testonPacketReceivedNeighborSolicitationWithValidPayload() 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); VirtualPort routerIntf = Mockito.mock(VirtualPort.class); when(ifMgrInstance.getRouterV6InterfaceForNetwork(any())).thenReturn(routerIntf); List<Ipv6Address> ipv6AddrList = new ArrayList<>(); when(routerIntf.getMacAddress()).thenReturn("08:00:27:FE:8F:95"); Ipv6Address llAddr = Ipv6Util.getIpv6LinkLocalAddressFromMac(new MacAddress("08:00:27:FE:8F:95")); ipv6AddrList.add(llAddr); when(routerIntf.getIpv6Addresses()).thenReturn(ipv6AddrList); when(pktProcessService.transmitPacket(any())).thenReturn(Mockito.mock(ListenableFuture.class)); 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); pktHandler.onPacketReceived(new PacketReceivedBuilder().setPayload(ipv6TestUtils.buildPacket( "33 33 FF FE 8F 95", "08 00 27 D4 10 BB", "86 DD", "60 00 00 00", "00 20", "3A", "FF", "FE 80 00 00 00 00 00 00 0A 00 27 FF FE D4 10 BB", "FF 02 00 00 00 00 00 00 00 00 00 01 FF FE 8F 95", "87", "00", "A9 57", "00 00 00 00", "FE 80 00 00 00 00 00 00 0A 00 27 FF FE FE 8F 95", "01", "01", "08 00 27 D4 10 BB" )).setIngress(ncRef).setMatch(matchbuilder.build()).build()); waitForPacketProcessing(); verify(pktProcessService, times(1)).transmitPacket(any(TransmitPacketInput.class)); byte[] expectedPayload = ipv6TestUtils.buildPacket( "08 00 27 D4 10 BB", "08 00 27 FE 8F 95", "86 DD", "60 00 00 00", "00 20", "3A", "FF", "FE 80 00 00 00 00 00 00 0A 00 27 FF FE FE 8F 95", "FE 80 00 00 00 00 00 00 0A 00 27 FF FE D4 10 BB", "88", "00", "17 D6", "E0 00 00 00", "FE 80 00 00 00 00 00 00 0A 00 27 FF FE FE 8F 95", "02", "01", "08 00 27 FE 8F 95" ); verify(pktProcessService).transmitPacket(new TransmitPacketInputBuilder().setPayload(expectedPayload) .setNode(new NodeRef(ncId)).setEgress(ncRef).build()); }
@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();  }