mirror of
https://github.com/soypat/lneto.git
synced 2026-09-10 00:29:34 +00:00
fix tests not passing for RingTx
This commit is contained in:
+17
-9
@@ -1,11 +1,13 @@
|
||||
package lneto
|
||||
package lneto_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/soypat/lneto"
|
||||
"github.com/soypat/lneto/internal/ltesto"
|
||||
"github.com/soypat/lneto/tcp"
|
||||
)
|
||||
|
||||
func TestTCPMarshalUnmarshal(t *testing.T) {
|
||||
@@ -16,7 +18,13 @@ func TestTCPMarshalUnmarshal(t *testing.T) {
|
||||
src := make([]byte, maxSize)
|
||||
dst := make([]byte, maxSize)
|
||||
for i := 0; i < 512; i++ {
|
||||
src = gen.AppendRandomIPv4TCPPacket(src[:0], rng)
|
||||
src = gen.AppendRandomIPv4TCPPacket(src[:0], rng, tcp.Segment{
|
||||
SEQ: tcp.Value(rng.Int()),
|
||||
ACK: tcp.Value(rng.Int()),
|
||||
DATALEN: tcp.Size(rng.Intn(256)),
|
||||
WND: tcp.Size(rng.Intn(1024)),
|
||||
Flags: tcp.FlagACK,
|
||||
})
|
||||
dst = dst[:len(src)]
|
||||
testMoveTCPPacket(t, src, dst)
|
||||
if !bytes.Equal(src, dst) {
|
||||
@@ -29,31 +37,31 @@ func testMoveTCPPacket(t *testing.T, src, dst []byte) {
|
||||
if len(src) != len(dst) {
|
||||
panic("expect src and dst same length")
|
||||
}
|
||||
efrm, err := NewEthFrame(src)
|
||||
efrm, err := lneto.NewEthFrame(src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
epl := efrm.Payload()
|
||||
ifrm, err := NewIPv4Frame(epl)
|
||||
ifrm, err := lneto.NewIPv4Frame(epl)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ipl := ifrm.Payload()
|
||||
tfrm, err := NewTCPFrame(ipl)
|
||||
tfrm, err := lneto.NewTCPFrame(ipl)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
efrm2, _ := NewEthFrame(dst)
|
||||
efrm2, _ := lneto.NewEthFrame(dst)
|
||||
*efrm2.DestinationHardwareAddr() = *efrm.DestinationHardwareAddr()
|
||||
*efrm2.SourceHardwareAddr() = *efrm.SourceHardwareAddr()
|
||||
efrm2.SetEtherType(efrm.EtherTypeOrSize())
|
||||
if efrm.EtherTypeOrSize() == EtherTypeVLAN {
|
||||
if efrm.EtherTypeOrSize() == lneto.EtherTypeVLAN {
|
||||
efrm2.SetVLANTag(efrm.VLANTag())
|
||||
efrm2.SetVLANEtherType(efrm.VLANEtherType())
|
||||
}
|
||||
|
||||
ifrm2, _ := NewIPv4Frame(efrm2.Payload())
|
||||
ifrm2, _ := lneto.NewIPv4Frame(efrm2.Payload())
|
||||
ifrm2.SetVersionAndIHL(ifrm.VersionAndIHL())
|
||||
ifrm2.SetToS(ifrm.ToS())
|
||||
ifrm2.SetFlags(ifrm.Flags())
|
||||
@@ -65,7 +73,7 @@ func testMoveTCPPacket(t *testing.T, src, dst []byte) {
|
||||
*ifrm2.SourceAddr() = *ifrm.SourceAddr()
|
||||
*ifrm2.DestinationAddr() = *ifrm.DestinationAddr()
|
||||
|
||||
tfrm2, _ := NewTCPFrame(ifrm2.Payload())
|
||||
tfrm2, _ := lneto.NewTCPFrame(ifrm2.Payload())
|
||||
tfrm2.SetSourcePort(tfrm.SourcePort())
|
||||
tfrm2.SetDestinationPort(tfrm.DestinationPort())
|
||||
tfrm2.SetSeq(tfrm.Seq())
|
||||
|
||||
Reference in New Issue
Block a user