Skip to content

Commit

Permalink
autotest: add nat46clat basic autotest with TCP
Browse files Browse the repository at this point in the history
  • Loading branch information
Timur Aitov authored and taitov committed Jan 9, 2024
1 parent 34fa8e0 commit b43961d
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions autotest/units/001_one_port/069_nat46clat/autotest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
- ipv4Update: "0.0.0.0/0 -> 200.0.0.1"
- ipv6Update: "::/0 -> fe80::1"
- sendPackets:
- port: kni0
send: 001-send.pcap
expect: 001-expect.pcap
- sendPackets:
- port: kni0
send: 002-send.pcap
expect: 002-expect.pcap
56 changes: 56 additions & 0 deletions autotest/units/001_one_port/069_nat46clat/controlplane.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"modules": {
"lp0.100": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "100",
"macAddress": "00:00:00:11:11:11",
"nextModule": "acl0"
},
"lp0.200": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "200",
"macAddress": "00:00:00:22:22:22",
"nextModule": "acl0"
},
"acl0": {
"type": "acl",
"nextModules": [
"nat0",
"route0"
]
},
"nat0": {
"type": "nat46clat",
"ipv6_source": "2000:abcd:fefe:b0b0:c0c0:fea6::",
"ipv6_destination": "6464:6464:6464:6464:6464:6464::",
"ipv6_prefixes": [
"2000:abcd:fefe:b0b0:c0c0:fea6::/96"
],
"ipv4_prefixes": [
"0.0.0.0/0"
],
"announces" : [
"2000:abcd:fefe:b0b0:c0c0:fea6::/96",
"0.0.0.0/0"
],
"nextModule": "route0"
},
"route0": {
"type": "route",
"interfaces": {
"kni0.100": {
"neighborIPv4Address": "200.0.0.1",
"neighborMacAddress": "00:00:EE:10:44:44",
"nextModule": "lp0.100"
},
"kni0.200": {
"neighborIPv6Address": "fe80::1",
"neighborMacAddress": "00:00:EE:20:66:66",
"nextModule": "lp0.200"
}
}
}
}
}
65 changes: 65 additions & 0 deletions autotest/units/001_one_port/069_nat46clat/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from scapy.all import *


def write_pcap(filename, *packetsList):
if len(packetsList) == 0:
PcapWriter(filename)._write_header(Ether())
return

PcapWriter(filename)

for packets in packetsList:
if type(packets) == list:
for packet in packets:
packet.time = 0
wrpcap(filename, [p for p in packet], append=True)
else:
packets.time = 0
wrpcap(filename, [p for p in packets], append=True)


# lan (ipv4 -> ipv6)
write_pcap("001-send.pcap",
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="4.4.4.4", src="10.0.0.1", ttl=64)/TCP(dport=2048, sport=80),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="4.4.4.4", src="10.0.0.1", ttl=64)/TCP(dport=2048, sport=443),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="4.4.4.4", src="20.0.0.1", ttl=64)/TCP(dport=2048, sport=80),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="4.4.4.4", src="20.0.0.1", ttl=64)/TCP(dport=2048, sport=443),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="88.88.4.4", src="10.0.0.1", ttl=64)/TCP(dport=5548, sport=80),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="88.88.4.4", src="10.0.0.1", ttl=64)/TCP(dport=5548, sport=443),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="88.88.4.4", src="20.0.0.1", ttl=64)/TCP(dport=5548, sport=80),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="88.88.4.4", src="20.0.0.1", ttl=64)/TCP(dport=5548, sport=443))

write_pcap("001-expect.pcap",
Ether(dst="00:00:EE:20:66:66", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="6464:6464:6464:6464:6464:6464:0404:0404", src="2000:abcd:fefe:b0b0:c0c0:fea6:10.0.0.1", hlim=63)/TCP(dport=2048, sport=80),
Ether(dst="00:00:EE:20:66:66", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="6464:6464:6464:6464:6464:6464:0404:0404", src="2000:abcd:fefe:b0b0:c0c0:fea6:10.0.0.1", hlim=63)/TCP(dport=2048, sport=443),
Ether(dst="00:00:EE:20:66:66", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="6464:6464:6464:6464:6464:6464:0404:0404", src="2000:abcd:fefe:b0b0:c0c0:fea6:20.0.0.1", hlim=63)/TCP(dport=2048, sport=80),
Ether(dst="00:00:EE:20:66:66", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="6464:6464:6464:6464:6464:6464:0404:0404", src="2000:abcd:fefe:b0b0:c0c0:fea6:20.0.0.1", hlim=63)/TCP(dport=2048, sport=443),
Ether(dst="00:00:EE:20:66:66", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="6464:6464:6464:6464:6464:6464:5858:0404", src="2000:abcd:fefe:b0b0:c0c0:fea6:10.0.0.1", hlim=63)/TCP(dport=5548, sport=80),
Ether(dst="00:00:EE:20:66:66", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="6464:6464:6464:6464:6464:6464:5858:0404", src="2000:abcd:fefe:b0b0:c0c0:fea6:10.0.0.1", hlim=63)/TCP(dport=5548, sport=443),
Ether(dst="00:00:EE:20:66:66", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="6464:6464:6464:6464:6464:6464:5858:0404", src="2000:abcd:fefe:b0b0:c0c0:fea6:20.0.0.1", hlim=63)/TCP(dport=5548, sport=80),
Ether(dst="00:00:EE:20:66:66", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="6464:6464:6464:6464:6464:6464:5858:0404", src="2000:abcd:fefe:b0b0:c0c0:fea6:20.0.0.1", hlim=63)/TCP(dport=5548, sport=443))


# wan (ipv6 -> ipv4)
write_pcap("002-send.pcap",
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:abcd:fefe:b0b0:c0c0:fea6:10.0.0.1", src="6464:6464:6464:6464:6464:6464:0404:0404", hlim=64)/TCP(dport=80, sport=2048),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:abcd:fefe:b0b0:c0c0:fea6:10.0.0.1", src="6464:6464:6464:6464:6464:6464:0404:0404", hlim=64)/TCP(dport=443, sport=2048),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:abcd:fefe:b0b0:c0c0:fea6:20.0.0.1", src="6464:6464:6464:6464:6464:6464:0404:0404", hlim=64)/TCP(dport=80, sport=2048),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:abcd:fefe:b0b0:c0c0:fea6:20.0.0.1", src="6464:6464:6464:6464:6464:6464:0404:0404", hlim=64)/TCP(dport=443, sport=2048),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:abcd:fefe:b0b0:c0c0:fea6:10.0.0.1", src="6464:6464:6464:6464:6464:6464:5858:0404", hlim=64)/TCP(dport=80, sport=5548),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:abcd:fefe:b0b0:c0c0:fea6:10.0.0.1", src="6464:6464:6464:6464:6464:6464:5858:0404", hlim=64)/TCP(dport=443, sport=5548),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:abcd:fefe:b0b0:c0c0:fea6:20.0.0.1", src="6464:6464:6464:6464:6464:6464:5858:0404", hlim=64)/TCP(dport=80, sport=5548),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:abcd:fefe:b0b0:c0c0:fea6:20.0.0.1", src="6464:6464:6464:6464:6464:6464:5858:0404", hlim=64)/TCP(dport=443, sport=5548))

write_pcap("002-expect.pcap",
Ether(dst="00:00:EE:10:44:44", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="10.0.0.1", src="4.4.4.4", ttl=63, id=0)/TCP(dport=80, sport=2048),
Ether(dst="00:00:EE:10:44:44", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="10.0.0.1", src="4.4.4.4", ttl=63, id=0)/TCP(dport=443, sport=2048),
Ether(dst="00:00:EE:10:44:44", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="20.0.0.1", src="4.4.4.4", ttl=63, id=0)/TCP(dport=80, sport=2048),
Ether(dst="00:00:EE:10:44:44", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="20.0.0.1", src="4.4.4.4", ttl=63, id=0)/TCP(dport=443, sport=2048),
Ether(dst="00:00:EE:10:44:44", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="10.0.0.1", src="88.88.4.4", ttl=63, id=0)/TCP(dport=80, sport=5548),
Ether(dst="00:00:EE:10:44:44", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="10.0.0.1", src="88.88.4.4", ttl=63, id=0)/TCP(dport=443, sport=5548),
Ether(dst="00:00:EE:10:44:44", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="20.0.0.1", src="88.88.4.4", ttl=63, id=0)/TCP(dport=80, sport=5548),
Ether(dst="00:00:EE:10:44:44", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="20.0.0.1", src="88.88.4.4", ttl=63, id=0)/TCP(dport=443, sport=5548))

0 comments on commit b43961d

Please sign in to comment.