1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func (ti
*testInterface
) setBroadcast(suffix
int) error
{
14 ti
.name
= fmt
.Sprintf("gotest%d", suffix
)
15 xname
, err
:= exec
.LookPath("ip")
19 ti
.setupCmds
= append(ti
.setupCmds
, &exec
.Cmd
{
21 Args
: []string{"ip", "link", "add", ti
.name
, "type", "dummy"},
23 ti
.setupCmds
= append(ti
.setupCmds
, &exec
.Cmd
{
25 Args
: []string{"ip", "address", "add", ti
.local
, "peer", ti
.remote
, "dev", ti
.name
},
27 ti
.teardownCmds
= append(ti
.teardownCmds
, &exec
.Cmd
{
29 Args
: []string{"ip", "address", "del", ti
.local
, "peer", ti
.remote
, "dev", ti
.name
},
31 ti
.teardownCmds
= append(ti
.teardownCmds
, &exec
.Cmd
{
33 Args
: []string{"ip", "link", "delete", ti
.name
, "type", "dummy"},
38 func (ti
*testInterface
) setLinkLocal(suffix
int) error
{
39 ti
.name
= fmt
.Sprintf("gotest%d", suffix
)
40 xname
, err
:= exec
.LookPath("ip")
44 ti
.setupCmds
= append(ti
.setupCmds
, &exec
.Cmd
{
46 Args
: []string{"ip", "link", "add", ti
.name
, "type", "dummy"},
48 ti
.setupCmds
= append(ti
.setupCmds
, &exec
.Cmd
{
50 Args
: []string{"ip", "address", "add", ti
.local
, "dev", ti
.name
},
52 ti
.teardownCmds
= append(ti
.teardownCmds
, &exec
.Cmd
{
54 Args
: []string{"ip", "address", "del", ti
.local
, "dev", ti
.name
},
56 ti
.teardownCmds
= append(ti
.teardownCmds
, &exec
.Cmd
{
58 Args
: []string{"ip", "link", "delete", ti
.name
, "type", "dummy"},
63 func (ti
*testInterface
) setPointToPoint(suffix
int) error
{
64 ti
.name
= fmt
.Sprintf("gotest%d", suffix
)
65 xname
, err
:= exec
.LookPath("ip")
69 ti
.setupCmds
= append(ti
.setupCmds
, &exec
.Cmd
{
71 Args
: []string{"ip", "tunnel", "add", ti
.name
, "mode", "gre", "local", ti
.local
, "remote", ti
.remote
},
73 ti
.setupCmds
= append(ti
.setupCmds
, &exec
.Cmd
{
75 Args
: []string{"ip", "address", "add", ti
.local
, "peer", ti
.remote
, "dev", ti
.name
},
77 ti
.teardownCmds
= append(ti
.teardownCmds
, &exec
.Cmd
{
79 Args
: []string{"ip", "address", "del", ti
.local
, "peer", ti
.remote
, "dev", ti
.name
},
81 ti
.teardownCmds
= append(ti
.teardownCmds
, &exec
.Cmd
{
83 Args
: []string{"ip", "tunnel", "del", ti
.name
, "mode", "gre", "local", ti
.local
, "remote", ti
.remote
},
89 numOfTestIPv4MCAddrs
= 14
90 numOfTestIPv6MCAddrs
= 18
94 igmpInterfaceTable
= []Interface
{
96 {Name
: "eth0"}, {Name
: "eth1"}, {Name
: "eth2"},
97 {Name
: "eth0.100"}, {Name
: "eth0.101"}, {Name
: "eth0.102"}, {Name
: "eth0.103"},
98 {Name
: "device1tap2"},
100 igmp6InterfaceTable
= []Interface
{
102 {Name
: "eth0"}, {Name
: "eth1"}, {Name
: "eth2"},
103 {Name
: "eth0.100"}, {Name
: "eth0.101"}, {Name
: "eth0.102"}, {Name
: "eth0.103"},
104 {Name
: "device1tap2"},
109 func TestParseProcNet(t
*testing
.T
) {
111 if p
:= recover(); p
!= nil {
112 t
.Fatalf("panicked: %v", p
)
117 for _
, ifi
:= range igmpInterfaceTable
{
118 ifmat
:= parseProcNetIGMP("testdata/igmp", &ifi
)
119 ifmat4
= append(ifmat4
, ifmat
...)
121 if len(ifmat4
) != numOfTestIPv4MCAddrs
{
122 t
.Fatalf("got %d; want %d", len(ifmat4
), numOfTestIPv4MCAddrs
)
126 for _
, ifi
:= range igmp6InterfaceTable
{
127 ifmat
:= parseProcNetIGMP6("testdata/igmp6", &ifi
)
128 ifmat6
= append(ifmat6
, ifmat
...)
130 if len(ifmat6
) != numOfTestIPv6MCAddrs
{
131 t
.Fatalf("got %d; want %d", len(ifmat6
), numOfTestIPv6MCAddrs
)