Skip to content

Commit

Permalink
add: S2nLink link up netns if and sw
Browse files Browse the repository at this point in the history
  • Loading branch information
ak1ra24 committed Dec 13, 2019
1 parent 5e76e21 commit e1615cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,18 @@ func N2nLink(nodeName string, inf Interface) []string {
}

// S2nLink Connect links between nodes and switches
func S2nLink(nodeName string, inf Interface) string {
func S2nLink(nodeName string, inf Interface) []string {
var s2nLinkCmds []string

nodeinf := inf.Name
peerBr := inf.Args
s2nLinkCmd := fmt.Sprintf("ip link add %s netns %s type veth peer name %s-%s", nodeinf, nodeName, peerBr, nodeName)
return s2nLinkCmd
peerBr = fmt.Sprintf("%s-%s", peerBr, nodeName)
s2nLinkCmd := fmt.Sprintf("ip link add %s netns %s type veth peer name %s", nodeinf, nodeName, peerBr)
s2nLinkCmds = append(s2nLinkCmds, s2nLinkCmd)
s2nLinkCmds = append(s2nLinkCmds, NetnsLinkUp(nodeName, nodeinf))
s2nLinkCmds = append(s2nLinkCmds, HostLinkUp(peerBr))

return s2nLinkCmds
}

// V2cLink Connect links between veth and container
Expand Down
6 changes: 3 additions & 3 deletions shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func TestS2nLink(t *testing.T) {
tests := []struct {
name string
args args
want string
want []string
}{
{
name: "link connect between switch and container",
Expand All @@ -676,12 +676,12 @@ func TestS2nLink(t *testing.T) {
Args: "SW",
},
},
want: "ip link add net0 netns R1 type veth peer name SW-R1",
want: []string{"ip link add net0 netns R1 type veth peer name SW-R1", "ip netns exec R1 ip link set net0 up", "ip link set SW-R1 up"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := S2nLink(tt.args.nodeName, tt.args.inf); got != tt.want {
if got := S2nLink(tt.args.nodeName, tt.args.inf); !reflect.DeepEqual(got, tt.want) {
t.Errorf("S2nLink() = %v, want %v", got, tt.want)
}
})
Expand Down

0 comments on commit e1615cb

Please sign in to comment.