- # receive ICMPv6 echo request on second TG interface
- ether = dst_rxq.recv(2, dst_sent_packets)
- if ether is None:
- raise RuntimeError('ICMPv6 echo reply Rx timeout')
-
- if not ether.haslayer(IPv6):
- raise RuntimeError('Unexpected packet with no IPv6 received {0}'.format(
- ether.__repr__()))
-
- ipv6 = ether['IPv6']
-
- # verify hop limit processing
- if ipv6.hlim != (hop_limit - hop_num):
- raise RuntimeError(
- 'Invalid hop limit {0} should be {1}'.format(ipv6.hlim,
- hop_limit - hop_num))
-
- if not ipv6.haslayer(ICMPv6EchoRequest):
- raise RuntimeError(
- 'Unexpected packet with no IPv6 ICMP received {0}'.format(
- ipv6.__repr__()))
-
- icmpv6 = ipv6['ICMPv6 Echo Request']
-
- # check identifier and sequence number
- if icmpv6.id != echo_id or icmpv6.seq != echo_seq:
- raise RuntimeError(
- 'Invalid ICMPv6 echo reply received ID {0} seq {1} should be ' +
- 'ID {2} seq {3}'.format(icmpv6.id, icmpv6.seq, echo_id, echo_seq))
-
- # verify checksum
- cksum = icmpv6.cksum
- del icmpv6.cksum
- tmp = ICMPv6EchoRequest(str(icmpv6))
- if tmp.cksum != cksum:
- raise RuntimeError(
- 'Invalid checksum {0} should be {1}'.format(cksum, tmp.cksum))
-
- # send ICMPv6 echo reply from second TG interface
- pkt_send = (Ether(src=dst_mac, dst=dst_nh_mac) /
- IPv6(src=dst_ip, dst=src_ip) /
- ICMPv6EchoReply(id=echo_id, seq=echo_seq))
- dst_sent_packets.append(pkt_send)
- dst_txq.send(pkt_send)
+ if is_dst_tg:
+ # receive ICMPv6 echo request on second TG interface
+ while True:
+ ether = dst_rxq.recv(2, dst_sent_packets)
+ if ether is None:
+ raise RuntimeError('ICMPv6 echo reply Rx timeout')
+
+ if ether.haslayer(ICMPv6ND_NS):
+ # read another packet in the queue if the current one is
+ # ICMPv6ND_NS
+ continue
+ else:
+ # otherwise process the current packet
+ break
+
+ if not ether.haslayer(IPv6):
+ raise RuntimeError('Unexpected packet with no IPv6 received: {0}'.
+ format(ether.__repr__()))
+
+ ipv6 = ether[IPv6]
+
+ # verify hop limit processing
+ if ipv6.hlim != (hop_limit - hop_num):
+ raise RuntimeError('Invalid hop limit {0} should be {1}'.
+ format(ipv6.hlim, hop_limit - hop_num))
+
+ if not ipv6.haslayer(ICMPv6EchoRequest):
+ raise RuntimeError('Unexpected packet with no IPv6 ICMP received '
+ '{0}'.format(ipv6.__repr__()))
+
+ icmpv6 = ipv6[ICMPv6EchoRequest]
+
+ # check identifier and sequence number
+ if icmpv6.id != echo_id or icmpv6.seq != echo_seq:
+ raise RuntimeError('Invalid ICMPv6 echo reply received ID {0} '
+ 'seq {1} should be ID {2} seq {3}'.
+ format(icmpv6.id, icmpv6.seq, echo_id, echo_seq))
+
+ # verify checksum
+ cksum = icmpv6.cksum
+ del icmpv6.cksum
+ tmp = ICMPv6EchoRequest(str(icmpv6))
+ if not checksum_equal(tmp.cksum, cksum):
+ raise RuntimeError('Invalid checksum {0} should be {1}'.
+ format(cksum, tmp.cksum))
+
+ # send ICMPv6 echo reply from second TG interface
+ pkt_send = (Ether(src=dst_mac, dst=dst_nh_mac) /
+ IPv6(src=dst_ip, dst=src_ip, hlim=(ipv6.hlim - 1)) /
+ ICMPv6EchoReply(id=echo_id, seq=echo_seq))
+ dst_sent_packets.append(pkt_send)
+ dst_txq.send(pkt_send)