Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support add veth pairs #10

Merged
merged 8 commits into from
Jun 4, 2018
Merged

support add veth pairs #10

merged 8 commits into from
Jun 4, 2018

Conversation

John-Lin
Copy link
Contributor

@John-Lin John-Lin commented Jun 3, 2018

Fork and modify from containernetworking/plugins support to create veth pairs. Given the container's vethName, host's VethName, mtu and host network namespace.

APIs

  • makeVethPair(name, peer string, mtu int) is equivalent

veth name: veth-ns1
peer name: ovs-1

ip link add name veth-ns1 type veth peer name ovs-1
  • SetupVeth(contVethName, hostVethName string, mtu int, hostNS ns.NetNS) is equivalent

network namespace name: ns1
veth name: veth-ns1
peer name: ovs-1

# given a network namespace ns1
# ip netns add ns1
ip link add name veth-ns1 type veth peer name ovs-1
ip link set veth-ns1 netns ns1

@codecov
Copy link

codecov bot commented Jun 3, 2018

Codecov Report

Merging #10 into master will decrease coverage by 5.6%.
The diff coverage is 65.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #10      +/-   ##
==========================================
- Coverage   80.82%   75.21%   -5.61%     
==========================================
  Files           3        4       +1     
  Lines          73      117      +44     
==========================================
+ Hits           59       88      +29     
- Misses         12       20       +8     
- Partials        2        9       +7
Impacted Files Coverage Δ
link/link.go 65.9% <65.9%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54d8b65...3641530. Read the comment docs.

Copy link
Contributor

@hwchiu hwchiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the testing for

  • makeVethPair
  1. invalid link name
  2. invalid MTU value
  • SetupVeth
  1. Invalid NS Object

  2. invalid


assert.Equal(t, "test-veth-ns1", contVeth.Attrs().Name)
assert.Equal(t, 1500, contVeth.Attrs().MTU)
defer netlink.LinkDel(contVeth)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to line 17, we usually call the defer remove.. after we create that resoruce

contVeth, err := makeVethPair("invalid-test-veth-ns1", "invalid-test-ovs-1", -1800)
// Err: numerical result out of range
assert.Error(t, err)
defer netlink.LinkDel(contVeth)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

})
hostVeth, err := netlink.LinkByName(hostVethName)
assert.NoError(t, err)
defer netlink.LinkDel(hostVeth)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this case should delete link outside the netns.Do since defer will be executed at the end of the enclosing function (func(hostNS ns.NetNS) error)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

@@ -25,7 +25,7 @@ before_install:
- make pb

script:
- sudo -E env PATH=$PATH TEST_OVS=1 gotestcover -coverprofile=coverage.txt -covermode=atomic ./...
- sudo -E env PATH=$PATH TEST_OVS=1 TEST_VETH=1 gotestcover -coverprofile=coverage.txt -covermode=atomic ./...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add the TEST_VETH to Makefile's target test

func SetupVeth(contVethName, hostVethName string, mtu int, hostNS ns.NetNS) (net.Interface, net.Interface, error) {
contVeth, err := makeVethPair(contVethName, hostVethName, mtu)
if err != nil {
return net.Interface{}, net.Interface{}, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about changing the type of returning values to pointer and this line will be return nil, nil, err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@John-Lin John-Lin merged commit 79dd331 into master Jun 4, 2018
@John-Lin John-Lin deleted the johnlin/netlink branch June 5, 2018 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants