summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/stack_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip/stack/stack_test.go')
-rw-r--r--pkg/tcpip/stack/stack_test.go65
1 files changed, 22 insertions, 43 deletions
diff --git a/pkg/tcpip/stack/stack_test.go b/pkg/tcpip/stack/stack_test.go
index 816707d27..279867315 100644
--- a/pkg/tcpip/stack/stack_test.go
+++ b/pkg/tcpip/stack/stack_test.go
@@ -73,7 +73,7 @@ func (f *fakeNetworkEndpoint) ID() *stack.NetworkEndpointID {
return &f.id
}
-func (f *fakeNetworkEndpoint) HandlePacket(r *stack.Route, vv *buffer.VectorisedView) {
+func (f *fakeNetworkEndpoint) HandlePacket(r *stack.Route, vv buffer.VectorisedView) {
// Increment the received packet count in the protocol descriptor.
f.proto.packetCount[int(f.id.LocalAddress[0])%len(f.proto.packetCount)]++
@@ -205,15 +205,12 @@ func TestNetworkReceive(t *testing.T) {
}
fakeNet := s.NetworkProtocolInstance(fakeNetNumber).(*fakeNetworkProtocol)
- var views [1]buffer.View
- // Allocate the buffer containing the packet that will be injected into
- // the stack.
+
buf := buffer.NewView(30)
// Make sure packet with wrong address is not delivered.
buf[0] = 3
- vv := buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 0 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 0)
}
@@ -223,8 +220,7 @@ func TestNetworkReceive(t *testing.T) {
// Make sure packet is delivered to first endpoint.
buf[0] = 1
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -234,8 +230,7 @@ func TestNetworkReceive(t *testing.T) {
// Make sure packet is delivered to second endpoint.
buf[0] = 2
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -244,8 +239,7 @@ func TestNetworkReceive(t *testing.T) {
}
// Make sure packet is not delivered if protocol number is wrong.
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber-1, &vv)
+ linkEP.Inject(fakeNetNumber-1, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -255,8 +249,7 @@ func TestNetworkReceive(t *testing.T) {
// Make sure packet that is too small is dropped.
buf.CapLength(2)
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -460,16 +453,14 @@ func TestAddressRemoval(t *testing.T) {
t.Fatalf("AddAddress failed: %v", err)
}
- var views [1]buffer.View
- buf := buffer.NewView(30)
-
fakeNet := s.NetworkProtocolInstance(fakeNetNumber).(*fakeNetworkProtocol)
+ buf := buffer.NewView(30)
+
// Write a packet, and check that it gets delivered.
fakeNet.packetCount[1] = 0
buf[0] = 1
- vv := buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -480,8 +471,7 @@ func TestAddressRemoval(t *testing.T) {
t.Fatalf("RemoveAddress failed: %v", err)
}
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -510,14 +500,12 @@ func TestDelayedRemovalDueToRoute(t *testing.T) {
fakeNet := s.NetworkProtocolInstance(fakeNetNumber).(*fakeNetworkProtocol)
- var views [1]buffer.View
buf := buffer.NewView(30)
// Write a packet, and check that it gets delivered.
fakeNet.packetCount[1] = 0
buf[0] = 1
- vv := buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -528,8 +516,7 @@ func TestDelayedRemovalDueToRoute(t *testing.T) {
t.Fatalf("FindRoute failed: %v", err)
}
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 2 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 2)
}
@@ -540,8 +527,7 @@ func TestDelayedRemovalDueToRoute(t *testing.T) {
t.Fatalf("RemoveAddress failed: %v", err)
}
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 3 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 3)
}
@@ -553,8 +539,7 @@ func TestDelayedRemovalDueToRoute(t *testing.T) {
// Release the route, then check that packet is not deliverable anymore.
r.Release()
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 3 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 3)
}
@@ -574,15 +559,13 @@ func TestPromiscuousMode(t *testing.T) {
fakeNet := s.NetworkProtocolInstance(fakeNetNumber).(*fakeNetworkProtocol)
- var views [1]buffer.View
buf := buffer.NewView(30)
// Write a packet, and check that it doesn't get delivered as we don't
// have a matching endpoint.
fakeNet.packetCount[1] = 0
buf[0] = 1
- vv := buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 0 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 0)
}
@@ -592,8 +575,7 @@ func TestPromiscuousMode(t *testing.T) {
t.Fatalf("SetPromiscuousMode failed: %v", err)
}
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -610,8 +592,7 @@ func TestPromiscuousMode(t *testing.T) {
t.Fatalf("SetPromiscuousMode failed: %v", err)
}
- vv = buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -675,8 +656,8 @@ func TestSubnetAcceptsMatchingPacket(t *testing.T) {
fakeNet := s.NetworkProtocolInstance(fakeNetNumber).(*fakeNetworkProtocol)
- var views [1]buffer.View
buf := buffer.NewView(30)
+
buf[0] = 1
fakeNet.packetCount[1] = 0
subnet, err := tcpip.NewSubnet(tcpip.Address("\x00"), tcpip.AddressMask("\xF0"))
@@ -687,8 +668,7 @@ func TestSubnetAcceptsMatchingPacket(t *testing.T) {
t.Fatalf("AddSubnet failed: %v", err)
}
- vv := buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 1 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 1)
}
@@ -709,8 +689,8 @@ func TestSubnetRejectsNonmatchingPacket(t *testing.T) {
fakeNet := s.NetworkProtocolInstance(fakeNetNumber).(*fakeNetworkProtocol)
- var views [1]buffer.View
buf := buffer.NewView(30)
+
buf[0] = 1
fakeNet.packetCount[1] = 0
subnet, err := tcpip.NewSubnet(tcpip.Address("\x10"), tcpip.AddressMask("\xF0"))
@@ -720,8 +700,7 @@ func TestSubnetRejectsNonmatchingPacket(t *testing.T) {
if err := s.AddSubnet(1, fakeNetNumber, subnet); err != nil {
t.Fatalf("AddSubnet failed: %v", err)
}
- vv := buf.ToVectorisedView(views)
- linkEP.Inject(fakeNetNumber, &vv)
+ linkEP.Inject(fakeNetNumber, buf.ToVectorisedView())
if fakeNet.packetCount[1] != 0 {
t.Errorf("packetCount[1] = %d, want %d", fakeNet.packetCount[1], 0)
}