-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from srl-wim/tools-offload
added disable-tx-offload cmd
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters