mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-19 16:35:10 +03:00
fix darwin tests
This commit is contained in:
parent
686e3943e7
commit
a1eaabc056
5 changed files with 199 additions and 79 deletions
55
ipv4_test.go
55
ipv4_test.go
|
@ -2,11 +2,8 @@ package water
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/songgao/water/waterutil"
|
||||
)
|
||||
|
||||
const BUFFERSIZE = 1522
|
||||
|
@ -24,58 +21,6 @@ func startRead(ch chan<- []byte, ifce *Interface) {
|
|||
}()
|
||||
}
|
||||
|
||||
func TestBroadcast(t *testing.T) {
|
||||
var (
|
||||
self = net.IPv4(10, 0, 42, 1)
|
||||
mask = net.IPv4Mask(255, 255, 255, 0)
|
||||
brd = net.IPv4(10, 0, 42, 255)
|
||||
)
|
||||
|
||||
ifce, err := New(Config{DeviceType: TAP})
|
||||
if err != nil {
|
||||
t.Fatalf("creating TAP error: %v\n", err)
|
||||
}
|
||||
|
||||
setupIfce(t, net.IPNet{IP: self, Mask: mask}, ifce.Name())
|
||||
startBroadcast(t, brd)
|
||||
|
||||
dataCh := make(chan []byte, 8)
|
||||
startRead(dataCh, ifce)
|
||||
|
||||
timeout := time.NewTimer(8 * time.Second).C
|
||||
|
||||
readFrame:
|
||||
for {
|
||||
select {
|
||||
case buffer := <-dataCh:
|
||||
ethertype := waterutil.MACEthertype(buffer)
|
||||
if ethertype != waterutil.IPv4 {
|
||||
continue readFrame
|
||||
}
|
||||
if !waterutil.IsBroadcast(waterutil.MACDestination(buffer)) {
|
||||
continue readFrame
|
||||
}
|
||||
packet := waterutil.MACPayload(buffer)
|
||||
if !waterutil.IsIPv4(packet) {
|
||||
continue readFrame
|
||||
}
|
||||
if !waterutil.IPv4Source(packet).Equal(self) {
|
||||
continue readFrame
|
||||
}
|
||||
if !waterutil.IPv4Destination(packet).Equal(brd) {
|
||||
continue readFrame
|
||||
}
|
||||
if waterutil.IPv4Protocol(packet) != waterutil.ICMP {
|
||||
continue readFrame
|
||||
}
|
||||
t.Logf("received broadcast frame: %#v\n", buffer)
|
||||
break readFrame
|
||||
case <-timeout:
|
||||
t.Fatal("Waiting for broadcast packet timeout")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloseUnblockPendingRead(t *testing.T) {
|
||||
ifce, err := New(Config{DeviceType: TUN})
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue