summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/npt66/npt66_node.c4
-rw-r--r--test/test_npt66.py45
2 files changed, 28 insertions, 21 deletions
diff --git a/src/plugins/npt66/npt66_node.c b/src/plugins/npt66/npt66_node.c
index 95fe8594dbb..21dddee3951 100644
--- a/src/plugins/npt66/npt66_node.c
+++ b/src/plugins/npt66/npt66_node.c
@@ -121,7 +121,6 @@ static int
npt66_translate (ip6_header_t *ip, npt66_binding_t *binding, int dir)
{
int rv = 0;
- clib_warning ("npt66_translate: before: %U", format_ip6_header, ip, 40);
if (dir == VLIB_TX)
{
if (!ip6_prefix_cmp (ip->src_address, binding->internal,
@@ -147,9 +146,8 @@ npt66_translate (ip6_header_t *ip, npt66_binding_t *binding, int dir)
ip->dst_address = ip6_prefix_copy (ip->dst_address, binding->internal,
binding->internal_plen);
rv = npt66_adjust_checksum (binding->internal_plen, true, binding->delta,
- &ip->src_address);
+ &ip->dst_address);
}
- clib_warning ("npt66_translate: after: %U", format_ip6_header, ip, 40);
done:
return rv;
}
diff --git a/test/test_npt66.py b/test/test_npt66.py
index 5173c62d44f..6565c38aae0 100644
--- a/test/test_npt66.py
+++ b/test/test_npt66.py
@@ -29,35 +29,43 @@ class TestNPT66(VppTestCase):
i.admin_down()
super(TestNPT66, self).tearDown()
- def send_and_verify(self, in2out, internal, external):
- if in2out:
- sendif = self.pg0
- recvif = self.pg1
- local_mac = self.pg0.local_mac
- remote_mac = self.pg0.remote_mac
- src = ipaddress.ip_interface(internal).ip + 1
- dst = self.pg1.remote_ip6
- else:
- sendif = self.pg1
- recvif = self.pg0
- local_mac = self.pg1.local_mac
- remote_mac = self.pg1.remote_mac
- src = self.pg1.remote_ip6
- dst = ipaddress.ip_interface(external).ip + 1
+ def send_and_verify(self, internal):
+ sendif = self.pg0
+ recvif = self.pg1
+ local_mac = self.pg0.local_mac
+ remote_mac = self.pg0.remote_mac
+ src = ipaddress.ip_interface(internal).ip + 1
+ dst = self.pg1.remote_ip6
p = (
Ether(dst=local_mac, src=remote_mac)
/ IPv6(src=src, dst=dst)
/ ICMPv6EchoRequest()
+ / Raw(b"Request")
)
rxs = self.send_and_expect(sendif, p, recvif)
for rx in rxs:
- rx.show2()
original_cksum = rx[ICMPv6EchoRequest].cksum
del rx[ICMPv6EchoRequest].cksum
rx = rx.__class__(bytes(rx))
self.assertEqual(original_cksum, rx[ICMPv6EchoRequest].cksum)
+ # Generate a replies
+ reply = (
+ Ether(dst=rx[Ether].src, src=local_mac)
+ / IPv6(src=rx[IPv6].dst, dst=rx[IPv6].src)
+ / ICMPv6EchoRequest()
+ / Raw(b"Reply")
+ )
+
+ replies = self.send_and_expect(recvif, reply, sendif)
+ for r in replies:
+ self.assertEqual(str(p[IPv6].src), r[IPv6].dst)
+ original_cksum = r[ICMPv6EchoRequest].cksum
+ del r[ICMPv6EchoRequest].cksum
+ r = r.__class__(bytes(r))
+ self.assertEqual(original_cksum, r[ICMPv6EchoRequest].cksum)
+
def do_test(self, internal, external):
self.vapi.npt66_binding_add_del(
sw_if_index=self.pg1.sw_if_index,
@@ -65,10 +73,10 @@ class TestNPT66(VppTestCase):
external=external,
is_add=True,
)
+ ## TODO use route api
self.vapi.cli(f"ip route add {internal} via {self.pg0.remote_ip6}")
- self.send_and_verify(True, internal, external)
- self.send_and_verify(False, internal, external)
+ self.send_and_verify(internal)
self.vapi.npt66_binding_add_del(
sw_if_index=self.pg1.sw_if_index,
@@ -80,6 +88,7 @@ class TestNPT66(VppTestCase):
def test_npt66_simple(self):
"""Send and receive a packet through NPT66"""
+ self.do_test("fd00:0000:0000::/48", "2001:4650:c3ed::/48")
self.do_test("fc00:1::/48", "2001:db8:1::/48")
self.do_test("fc00:1234::/32", "2001:db8:1::/32")
self.do_test("fc00:1234::/63", "2001:db8:1::/56")