Skip to content

Commit

Permalink
cmd/tcpconn: build disruptor and queue according to refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nadiamoe committed Nov 1, 2023
1 parent 384541a commit bf7e939
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions cmd/agent/commands/tcpdrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

// BuildTCPDropCmd returns a cobra command with the specification of the tcp-drop command.
func BuildTCPDropCmd(env runtime.Environment, config *agent.Config) *cobra.Command {
disruption := tcpconn.Disruption{}
var duration time.Duration
filter := tcpconn.Filter{}
dropRate := 0.0

cmd := &cobra.Command{
Use: "tcp-drop",
Expand All @@ -22,7 +23,7 @@ func BuildTCPDropCmd(env runtime.Environment, config *agent.Config) *cobra.Comma
" When running as a transparent proxy requires NET_ADMIM capabilities for setting" +
" iptable rules.",
RunE: func(cmd *cobra.Command, _ []string) error {
if disruption.Port == 0 {
if filter.Port == 0 {
return fmt.Errorf("target port for fault injection is required")
}

Expand All @@ -33,27 +34,23 @@ func BuildTCPDropCmd(env runtime.Environment, config *agent.Config) *cobra.Comma

defer agent.Stop()

nfqConfig := tcpconn.RandomNFQConfig()

queue := tcpconn.NFQueue{
NFQConfig: nfqConfig,
Disruption: disruption,
Executor: env.Executor(),
dropper := tcpconn.TCPConnectionDropper{
DropRate: dropRate,
}

disruptor := tcpconn.Disruptor{
NFQConfig: nfqConfig,
Disruption: disruption,
Queue: queue,
Executor: env.Executor(),
Filter: filter,
Dropper: dropper,
}

return agent.ApplyDisruption(cmd.Context(), disruptor, duration)
},
}

cmd.Flags().DurationVarP(&duration, "duration", "d", 0, "duration of the disruptions")
cmd.Flags().UintVarP(&disruption.Port, "port", "p", 8000, "target port of the connections to be disrupted")
cmd.Flags().Float64VarP(&disruption.DropRate, "rate", "r", 0, "fraction of connections to drop")
cmd.Flags().UintVarP(&filter.Port, "port", "p", 8000, "target port of the connections to be disrupted")
cmd.Flags().Float64VarP(&dropRate, "rate", "r", 0, "fraction of connections to drop")

return cmd
}

0 comments on commit bf7e939

Please sign in to comment.