MCPcopy Index your code
hub / github.com/google/gvisor / TestAddRoute

Function TestAddRoute

pkg/tcpip/stack/stack_test.go:4409–4442  ·  view source on GitHub ↗

TestAddRoute tests Stack.AddRoute

(t *testing.T)

Source from the content-addressed store, hash-verified

4407
4408// TestAddRoute tests Stack.AddRoute
4409func TestAddRoute(t *testing.T) {
4410 s := stack.New(stack.Options{})
4411
4412 subnet1, err := tcpip.NewSubnet(tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), tcpip.MaskFrom("\x00\x00\x00\x00"))
4413 if err != nil {
4414 t.Fatal(err)
4415 }
4416
4417 subnet2, err := tcpip.NewSubnet(tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), tcpip.MaskFrom("\xff\x00\x00\x00"))
4418 if err != nil {
4419 t.Fatal(err)
4420 }
4421
4422 expected := []tcpip.Route{
4423 {Destination: subnet2, Gateway: tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), NIC: 1},
4424 {Destination: subnet1, Gateway: tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), NIC: 1},
4425 }
4426
4427 // Initialize the route table with one route.
4428 s.SetRouteTable([]tcpip.Route{expected[0]})
4429
4430 // Add another route.
4431 s.AddRoute(expected[1])
4432
4433 rt := s.GetRouteTable()
4434 if got, want := len(rt), len(expected); got != want {
4435 t.Fatalf("Unexpected route table length got = %d, want = %d", got, want)
4436 }
4437 for i, route := range rt {
4438 if got, want := route, expected[i]; !got.Equal(want) {
4439 t.Fatalf("Unexpected route got = %#v, want = %#v", got, want)
4440 }
4441 }
4442}
4443
4444// TestRemoveRoutes tests Stack.RemoveRoutes
4445func TestRemoveRoutes(t *testing.T) {

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
NewSubnetFunction · 0.92
AddrFromSliceFunction · 0.92
MaskFromFunction · 0.92
SetRouteTableMethod · 0.80
AddRouteMethod · 0.80
GetRouteTableMethod · 0.80
FatalfMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…