Skip to content

Commit

Permalink
Merge pull request #251 from srl-wim/tools-offload
Browse files Browse the repository at this point in the history
added disable-tx-offload cmd
  • Loading branch information
hellt authored Jan 29, 2021
2 parents a0c9417 + fae3e36 commit 1cce522
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
62 changes: 62 additions & 0 deletions cmd/disableTxOffload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cmd

import (
"context"
"strconv"

"github.com/containernetworking/plugins/pkg/ns"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-wim/container-lab/clab"
)

var cntName string

// upgradeCmd represents the version command
var disableTxOffloadCmd = &cobra.Command{
Use: "disable-tx-offload",
Short: "disables tx checksum offload on eth0 interface of a container",

RunE: func(cmd *cobra.Command, args []string) error {
opts := []clab.ClabOption{
clab.WithDebug(debug),
clab.WithTimeout(timeout),
clab.WithEnvDockerClient(),
}
c := clab.NewContainerLab(opts...)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cnt, err := c.DockerClient.ContainerInspect(ctx, cntName)
if err != nil {
return err
}

log.Infof("getting container '%s' information", cntName)
NSPath := "/proc/" + strconv.Itoa(cnt.State.Pid) + "/ns/net"
nodeNS, err := ns.GetNS(NSPath)
if err != nil {
return err
}
err = nodeNS.Do(func(_ ns.NetNS) error {
// disabling offload on lo0 interface
err = clab.EthtoolTXOff("eth0")
if err != nil {
log.Infof("Failed to disable TX checksum offload for 'eth0' interface for '%s' container", cntName)
}
return nil
})
if err != nil {
return err
}
log.Infof("Tx checksum offload disabled for eth0 interface of %s container", cntName)
return nil
},
}

func init() {
toolsCmd.AddCommand(disableTxOffloadCmd)
disableTxOffloadCmd.Flags().StringVarP(&cntName, "container", "c", "", "container name to disable offload in")
disableTxOffloadCmd.MarkFlagRequired("container")
}
16 changes: 16 additions & 0 deletions cmd/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cmd

import (
"github.com/spf13/cobra"
)

// toolsCmd represents the tools command
var toolsCmd = &cobra.Command{
Use: "tools",
Short: "various tools your lab might need",
Long: "tools command groups various tools you might need for your lab\nreference: https://containerlab.srlinux.dev/cmd/tools/",
}

func init() {
rootCmd.AddCommand(toolsCmd)
}
25 changes: 25 additions & 0 deletions docs/cmd/tools/disable-tx-offload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# disable-tx-offload command

### Description

The `disable-tx-offload` command under the `tools` command disables tx checksum offload for `eth0` interface of a container referenced by its name.

The need for `disable-tx-offload` might arise when you launch a container outside of containerlab or restart a container. Some nodes, like SR Linux, will require to have correct checksums in TCP packets, thus its needed to disable checksum offload on those containers for them to do checksum calculations instead of offloading it.

### Usage

`containerlab tools disable-tx-offload [local-flags]`

### Flags

#### container
With the local mandatory `--container | -c` flag a user specifies which container to remove tx offload in.

### Examples

```bash
# disable tx checksum on gnmic container
❯ clab tools disable-checksum -c clab-st-gnmic
INFO[0000] getting container 'clab-st-gnmic' information
INFO[0000] Tx checksum offload disabled for eth0 interface of clab-st-gnmic container
```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ nav:
- save: cmd/save.md
- generate: cmd/generate.md
- graph: cmd/graph.md
- tools:
- disable-tx-offload: cmd/tools/disable-tx-offload.md
- Lab examples:
- About: lab-examples/lab-examples.md
- Single SR Linux node: lab-examples/single-srl.md
Expand Down

0 comments on commit 1cce522

Please sign in to comment.