@@ -126,6 +126,53 @@ public EthernetPacket sendIcmpV6Echo(int portIdx, String dstIp, int icmpId, int
126126
127127 }
128128
129+ public EthernetPacket sendNeighborSolicitation (int portIdx , int timeout , String dstIp ) throws ServiceModeRequiredException {
130+ endTs = System .currentTimeMillis () + timeout * 1000 ;
131+ PortStatus portStatus = tRexClient .getPortStatus (portIdx ).get ();
132+
133+ srcMac = portStatus .getAttr ().getLayerConiguration ().getL2Configuration ().getSrc ();
134+
135+ Packet icmpv6NSPkt = buildICMPV6NSPkt (multicastMacFromIPv6 (dstIp ).toString (), dstIp , null );
136+
137+ tRexClient .startStreamsIntermediate (portIdx , Arrays .asList (buildStream (icmpv6NSPkt )));
138+
139+ Predicate <EthernetPacket > ipV6NAPktFilter = etherPkt -> {
140+ if (!etherPkt .contains (IcmpV6NeighborAdvertisementPacket .class )) {
141+ return false ;
142+ }
143+ IcmpV6NeighborAdvertisementHeader icmpV6NaHdr = etherPkt .get (IcmpV6NeighborAdvertisementPacket .class ).getHeader ();
144+
145+ String nodeIp = icmpV6NaHdr .getTargetAddress ().toString ().substring (1 );
146+
147+ IpV6Packet .IpV6Header ipV6Header = etherPkt .get (IpV6Packet .class ).getHeader ();
148+ String dstAddr = ipV6Header .getDstAddr ().toString ().substring (1 );
149+
150+ try {
151+ Inet6Address dstIPv6Addr = (Inet6Address ) Inet6Address .getByName (dstAddr );
152+ Inet6Address srcIPv6Addr = (Inet6Address ) Inet6Address .getByName (generateIPv6AddrFromMAC (srcMac ));
153+
154+ Inet6Address nodeIpv6 = (Inet6Address ) Inet6Address .getByName (nodeIp );
155+ Inet6Address targetIpv6inNS = (Inet6Address ) Inet6Address .getByName (dstIp );
156+ return icmpV6NaHdr .getSolicitedFlag () && nodeIpv6 .equals (targetIpv6inNS ) && dstIPv6Addr .equals (srcIPv6Addr );
157+ } catch (UnknownHostException ignored ) {}
158+ return false ;
159+ };
160+
161+ EthernetPacket na = null ;
162+ while (endTs > System .currentTimeMillis () && na == null ) {
163+ List <EthernetPacket > pkts = tRexClient .getRxQueue (portIdx , ipV6NAPktFilter );
164+ if (!pkts .isEmpty ()) {
165+ na = pkts .get (0 );
166+ }
167+ }
168+ tRexClient .removeRxQueue (portIdx );
169+ if (tRexClient .getPortStatus (portIdx ).get ().getState ().equals ("TX" )) {
170+ tRexClient .stopTraffic (portIdx );
171+ }
172+ tRexClient .removeAllStreams (portIdx );
173+ return na ;
174+ }
175+
129176 private Map <String , EthernetPacket > sendNSandIcmpV6Req (int portIdx , int timeDuration , String dstIp ) throws ServiceModeRequiredException {
130177 endTs = System .currentTimeMillis () + timeDuration * 1000 ;
131178 TRexClientResult <PortStatus > portStatusResult = tRexClient .getPortStatus (portIdx );
0 commit comments