dhcp6_test: add new DHCPv6 infra packet capture

This commit is contained in:
Michael Stapelberg 2019-12-02 10:43:39 +01:00
parent 70edcab16b
commit 3b5cf99b29
2 changed files with 71 additions and 45 deletions

View File

@ -27,11 +27,35 @@ import (
)
func TestDHCP6(t *testing.T) {
for _, tt := range []struct {
CaptureFile string
SolicitTID dhcpv6.TransactionID
RequestTID dhcpv6.TransactionID
Prefix net.IPNet
Expiry time.Duration
}{
{
CaptureFile: "fiber7.pcap",
SolicitTID: dhcpv6.TransactionID{0x48, 0xe5, 0x9e},
RequestTID: dhcpv6.TransactionID{0x73, 0x8c, 0x3b},
Prefix: mustParseCIDR("2a02:168:4a00::/48"),
Expiry: 20 * time.Minute,
},
{
CaptureFile: "fiber7-2019-12-02.pcap",
SolicitTID: dhcpv6.TransactionID{0x49, 0xb4, 0x8c},
RequestTID: dhcpv6.TransactionID{0x49, 0xb4, 0x8c},
Prefix: mustParseCIDR("2a02:168:4bf3::/48"),
Expiry: 1000 * time.Second,
},
} {
t.Run(tt.CaptureFile, func(t *testing.T) {
pcappath := os.Getenv("ROUTER7_PCAP_DIR")
if pcappath != "" {
pcappath = filepath.Join(pcappath, "dhcp6.pcap")
}
conn, err := pcapreplayer.NewPacketConn("testdata/fiber7.pcap", pcappath)
conn, err := pcapreplayer.NewPacketConn("testdata/"+tt.CaptureFile, pcappath)
if err != nil {
t.Fatal(err)
}
@ -48,8 +72,8 @@ func TestDHCP6(t *testing.T) {
LocalAddr: laddr,
Conn: conn,
TransactionIDs: []dhcpv6.TransactionID{
{0x48, 0xe5, 0x9e}, // SOLICIT
{0x73, 0x8c, 0x3b}, // REQUEST
tt.SolicitTID,
tt.RequestTID,
},
HardwareAddr: []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
})
@ -64,9 +88,9 @@ func TestDHCP6(t *testing.T) {
}
got := c.Config()
want := Config{
RenewAfter: now.Add(20 * time.Minute),
RenewAfter: now.Add(tt.Expiry),
Prefixes: []net.IPNet{
mustParseCIDR("2a02:168:4a00::/48"),
tt.Prefix,
},
DNS: []string{
"2001:1620:2777:1::10",
@ -76,6 +100,8 @@ func TestDHCP6(t *testing.T) {
if diff := cmp.Diff(want, got); diff != "" {
t.Fatalf("unexpected config: diff (-want +got):\n%s", diff)
}
})
}
}
func mustParseCIDR(s string) net.IPNet {

Binary file not shown.