4949public class IPv6NeighborDiscoveryService {
5050
5151 private TRexClient tRexClient ;
52- private String srcMac ;
5352
5453 public IPv6NeighborDiscoveryService (TRexClient tRexClient ) {
5554 this .tRexClient = tRexClient ;
@@ -67,7 +66,7 @@ public Map<String, Ipv6Node> scan(int portIdx, int timeDuration, String dstIP, S
6766 throw new ServiceModeRequiredException ();
6867 }
6968
70- srcMac = portStatus .getAttr ().getLayerConiguration ().getL2Configuration ().getSrc ();
69+ String srcMac = portStatus .getAttr ().getLayerConiguration ().getL2Configuration ().getSrc ();
7170
7271 Packet pingPkt =
7372 buildICMPV6EchoReq (
@@ -92,8 +91,8 @@ public Map<String, Ipv6Node> scan(int portIdx, int timeDuration, String dstIP, S
9291 String nodeIp = ipV6Packet .getHeader ().getSrcAddr ().toString ().substring (1 );
9392 String nodeMac = getLinkLayerAddress (ipV6Packet );
9493
95- nsNaStreams .add (buildStream (buildICMPV6NSPkt (nodeMac , nodeIp , srcIP )));
96- nsNaStreams .add (buildStream (buildICMPV6NAPkt (nodeMac , nodeIp , srcIP )));
94+ nsNaStreams .add (buildStream (buildICMPV6NSPkt (srcMac , nodeMac , nodeIp , srcIP )));
95+ nsNaStreams .add (buildStream (buildICMPV6NAPkt (srcMac , nodeMac , nodeIp , srcIP )));
9796 });
9897 }
9998
@@ -134,8 +133,15 @@ private Ipv6Node toIpv6Node(EthernetPacket ethernetPacket) {
134133
135134 public EthernetPacket sendIcmpV6Echo (
136135 int portIdx , String dstIp , int icmpId , int icmpSeq , int timeOut ) {
136+ PortStatus portStatus = tRexClient .getPortStatus (portIdx ).get ();
137+ String srcMac = portStatus .getAttr ().getLayerConiguration ().getL2Configuration ().getSrc ();
138+ return sendIcmpV6Echo (portIdx , srcMac , dstIp , icmpId , icmpSeq , timeOut );
139+ }
140+
141+ public EthernetPacket sendIcmpV6Echo (
142+ int portIdx , String srcMac , String dstIp , int icmpId , int icmpSeq , int timeOut ) {
137143 Map <String , EthernetPacket > stringEthernetPacketMap =
138- sendNSandIcmpV6Req (portIdx , timeOut , dstIp );
144+ sendNSandIcmpV6Req (portIdx , timeOut , srcMac , dstIp );
139145
140146 Optional <Map .Entry <String , EthernetPacket >> icmpMulticastResponse =
141147 stringEthernetPacketMap .entrySet ().stream ().findFirst ();
@@ -167,12 +173,17 @@ public EthernetPacket sendIcmpV6Echo(
167173 }
168174
169175 public EthernetPacket sendNeighborSolicitation (int portIdx , int timeout , String dstIp ) {
170- long endTs = System .currentTimeMillis () + timeout * 1000 ;
171176 PortStatus portStatus = tRexClient .getPortStatus (portIdx ).get ();
177+ String srcMac = portStatus .getAttr ().getLayerConiguration ().getL2Configuration ().getSrc ();
178+ return sendNeighborSolicitation (portIdx , timeout , srcMac , dstIp );
179+ }
172180
173- srcMac = portStatus .getAttr ().getLayerConiguration ().getL2Configuration ().getSrc ();
181+ public EthernetPacket sendNeighborSolicitation (
182+ int portIdx , int timeout , String srcMac , String dstIp ) {
183+ long endTs = System .currentTimeMillis () + timeout * 1000 ;
174184
175- Packet icmpv6NSPkt = buildICMPV6NSPkt (multicastMacFromIPv6 (dstIp ).toString (), dstIp , null );
185+ Packet icmpv6NSPkt =
186+ buildICMPV6NSPkt (srcMac , multicastMacFromIPv6 (dstIp ).toString (), dstIp , null );
176187
177188 tRexClient .startStreamsIntermediate (portIdx , Arrays .asList (buildStream (icmpv6NSPkt )));
178189
@@ -221,15 +232,13 @@ public EthernetPacket sendNeighborSolicitation(int portIdx, int timeout, String
221232 }
222233
223234 private Map <String , EthernetPacket > sendNSandIcmpV6Req (
224- int portIdx , int timeDuration , String dstIp ) {
235+ int portIdx , int timeDuration , String srcMac , String dstIp ) {
225236 long endTs = System .currentTimeMillis () + timeDuration * 1000 ;
226237 TRexClientResult <PortStatus > portStatusResult = tRexClient .getPortStatus (portIdx );
227- PortStatus portStatus = portStatusResult .get ();
228-
229- srcMac = portStatus .getAttr ().getLayerConiguration ().getL2Configuration ().getSrc ();
230238
231239 Packet pingPkt = buildICMPV6EchoReq (null , srcMac , null , dstIp );
232- Packet icmpv6NSPkt = buildICMPV6NSPkt (multicastMacFromIPv6 (dstIp ).toString (), dstIp , null );
240+ Packet icmpv6NSPkt =
241+ buildICMPV6NSPkt (srcMac , multicastMacFromIPv6 (dstIp ).toString (), dstIp , null );
233242
234243 List <com .cisco .trex .stateless .model .Stream > stlStreams =
235244 Stream .of (buildStream (pingPkt ), buildStream (icmpv6NSPkt )).collect (Collectors .toList ());
@@ -300,7 +309,7 @@ private com.cisco.trex.stateless.model.Stream buildStream(Packet pkt) {
300309 null );
301310 }
302311
303- private Packet buildICMPV6NSPkt (String dstMac , String dstIp , String srcIp ) {
312+ private Packet buildICMPV6NSPkt (String srcMac , String dstMac , String dstIp , String srcIp ) {
304313 EthernetPacket .Builder ethBuilder = new EthernetPacket .Builder ();
305314 try {
306315
@@ -379,7 +388,7 @@ private static String getLinkLayerAddress(IpV6Packet pkt) {
379388 return ByteArrays .toHexString (linkLayerAddress , ":" );
380389 }
381390
382- private Packet buildICMPV6NAPkt (String dstMac , String dstIp , String srcIP ) {
391+ private Packet buildICMPV6NAPkt (String srcMac , String dstMac , String dstIp , String srcIP ) {
383392 final String specifiedSrcIP = srcIP != null ? srcIP : generateIPv6AddrFromMAC (srcMac );
384393
385394 EthernetPacket .Builder ethBuilder = new EthernetPacket .Builder ();
0 commit comments