Skip to content

Commit

Permalink
- add renew/rebind
Browse files Browse the repository at this point in the history
- add gi-addr
  • Loading branch information
hujun-open committed Oct 14, 2024
1 parent 0ac7c0a commit ffad016
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 74 deletions.
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ dhcplt is a DHCPv4/DHCPv6 load tester for Linux with following features:

- DHCPv4

- Support DORA and Release
- Support DORA, Release, Renew and Rebind
- Following DHCPv4 options could be included in request:
- Client Id
- Vendor Class
- Option82 Circuit-Id
- Option82 Remote-Id
- Gi Addr
- Custom option
- DHCPv6:

- Support DORA and Release
- Support DORA Release, Renew and Rebind
- Request for IA_NA and/or IA_PD prefix
- Send request in relay-forward message to simulate a relayed message, and handle the relay-reply message
- following DHCPv6 options could be included in request:
Expand All @@ -28,7 +29,12 @@ dhcplt is a DHCPv4/DHCPv6 load tester for Linux with following features:
- performant: test shows that it could do 4k DORA per sec on a single core VM

## Usage Example
**Note: using dhcplt requires root privilege**
Notes:

- **using dhcplt requires root privilege**
- action release, renew and rebind require a previous saved lease file



1. 10000 DHCPv4 clients doing DORA on interface eth1, no VLAN, starting MAC address is the eth1 interface mac, increase by 1 for each client
```
Expand Down Expand Up @@ -95,6 +101,11 @@ dhcplt -i eth1 -action release
dhcplt -i eth1 -action release -v6
```

16. using saved lease file to send renew msg, only send renew for all dhcpv4 leases in the lease file
```
dhcplt -i eth1 -action renew
```

## DORA Result Summary
With action DORA, dhcplt will display a summary of results after it s done like following:
```
Expand All @@ -121,8 +132,8 @@ Avg dial success time:135.940204ms
## Command Line Parameters

```
a DHCP load tester
- action: dora | release
a DHCP load tester, v0.7.0
- action: dora | release | renew | rebind
default:dora
- applylease: apply assigned address on the interface if true
default:false
Expand All @@ -143,10 +154,12 @@ a DHCP load tester
default:0
- flapstaydowndur: duriation of stay down
default:10s
- giaddr: Gi address for DHCPv4
default:0.0.0.0
- i: interface name
- interval: interval between setup of sessions
default:1s
- leasefile:
- leasefile:
default:dhcplt.lease
- mac: starting MAC address
- macstep: amount of increase between two consecutive MAC address
Expand Down Expand Up @@ -185,8 +198,7 @@ a DHCP load tester
-cfgfromfile: load configuration from the specified file
default:dhcplt.conf
```
- interval: this is wait interval between launch client DORA
- all duration type could use syntax that can be parsed by GOlang flag.Duration, like "1s", "1ms"
Expand Down
2 changes: 1 addition & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func MyLog(format string, a ...interface{}) {
}
msg := fmt.Sprintf(format, a...)
_, fname, linenum, _ := runtime.Caller(1)
Logger.Print(fmt.Sprintf("%v:%v:%v", filepath.Base(fname), linenum, msg))
Logger.Printf("%v:%v:%v", filepath.Base(fname), linenum, msg)
}
14 changes: 13 additions & 1 deletion conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"net"
"net/netip"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -39,6 +40,7 @@ type testSetup struct {
ApplyLease bool `usage:"apply assigned address on the interface if true"`
Retry uint `usage:"number of setup retry"`
Timeout time.Duration `usage:"setup timout"`
GiAddr netip.Addr `usage:"Gi address for DHCPv4"`
//following are template str, $ID will be replaced by client id
RID string `usage:"BBF remote-id"`
CID string `usage:"BBF circuit-id"`
Expand All @@ -57,7 +59,7 @@ type testSetup struct {
SendRSFirst bool `usage:"send Router Solict first if true"`
Profiling bool `usage:"enable profiling, dev use only"`
LeaseFile string
Action actionType `usage:"dora | release"`
Action actionType `usage:"dora | release | renew | rebind"`
saveV4Chan chan *v4LeaseWithID
saveV6Chan chan *v6LeaseWithID
}
Expand All @@ -71,6 +73,7 @@ func newDefaultConf() *testSetup {
VLANEType: etherconn.DefaultVLANEtype,
VLANStep: 1,
Interval: time.Second,
GiAddr: netip.MustParseAddr("0.0.0.0"),
Retry: 1,
Timeout: 5 * time.Second,
EnableV4: true,
Expand Down Expand Up @@ -123,6 +126,15 @@ func (setup *testSetup) init() error {
for _, v := range setup.StartVLANs {
v.EtherType = uint16(setup.VLANEType)
}
if setup.GiAddr.IsValid() {
if !setup.GiAddr.IsUnspecified() {
if !setup.GiAddr.Is4() || !setup.GiAddr.IsGlobalUnicast() {
return fmt.Errorf("gi address must be an IPv4 unicast addr")
}
}
} else {
setup.GiAddr = netip.MustParseAddr("0.0.0.0")
}
setup.ExcludedVLANs = []uint16{}
for _, n := range setup.ExcludedVLANs {
if n > 4096 {
Expand Down
8 changes: 6 additions & 2 deletions dhcplt.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type resultSummary struct {
Success int
Failed int
Released int
Renewed int
Rebinded int
LessThanSecond int
Shortest time.Duration
Longest time.Duration
Expand All @@ -78,6 +80,8 @@ func (rs resultSummary) String() string {
r += fmt.Sprintf("total trans: %d\n", rs.Total)
r += fmt.Sprintf("Success dial:%d\n", rs.Success)
r += fmt.Sprintf("Success release:%d\n", rs.Released)
r += fmt.Sprintf("Success renew:%d\n", rs.Renewed)
r += fmt.Sprintf("Success rebind:%d\n", rs.Rebinded)
r += fmt.Sprintf("Failed trans:%d\n", rs.Failed)
r += fmt.Sprintf("Duration:%v\n", rs.TotalTime)
r += fmt.Sprintf("Interval:%v\n", rs.setup.Interval)
Expand Down Expand Up @@ -132,7 +136,7 @@ const (
ENG_XDP = etherconn.RelayTypeXDP
)

var VERSION string
var VERSION string = "unversioned"

func handleCtrlC(c chan os.Signal, cf context.CancelFunc) {
<-c
Expand All @@ -145,7 +149,7 @@ func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
cnf, err := shouchan.NewSConf(newDefaultConf(), "dhcplt",
"a DHCP load tester", shouchan.WithDefaultConfigFilePath[*testSetup]("dhcplt.conf"))
fmt.Sprintf("a DHCP load tester, %v", VERSION), shouchan.WithDefaultConfigFilePath[*testSetup]("dhcplt.conf"))
if err != nil {
panic(err)
}
Expand Down
24 changes: 9 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,30 @@ go 1.20
require (
github.com/RobinUS2/golang-moving-average v1.0.0
github.com/google/gopacket v1.1.19
github.com/hujun-open/cmprule v0.3.0
github.com/hujun-open/etherconn v0.7.0
github.com/hujun-open/myaddr v0.1.1
github.com/hujun-open/shouchan v0.3.4
github.com/insomniacslk/dhcp v0.0.0-20230516061539-49801966e6cb
github.com/vishvananda/netlink v1.1.0
github.com/hujun-open/cmprule v0.3.1
github.com/hujun-open/etherconn v0.9.0
github.com/hujun-open/myaddr v0.1.3
github.com/hujun-open/shouchan v0.3.5
github.com/insomniacslk/dhcp v0.0.0-20240829085014-a3a4c1f04475
github.com/vishvananda/netlink v1.3.0
)

// replace github.com/hujun-open/etherconn => ../etherconn

// replace github.com/hujun-open/myflags => ../myflags

require (
github.com/asavie/xdp v0.3.4-0.20211113171712-711132ccc429 // indirect
github.com/cilium/ebpf v0.8.1 // indirect
github.com/cilium/ebpf v0.4.0 // indirect
github.com/hujun-open/extyaml v0.4.0 // indirect
github.com/hujun-open/myflags v0.3.2 // indirect
github.com/josharian/native v1.1.0 // indirect
github.com/mdlayher/packet v1.1.2 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/pierrec/lz4/v4 v4.1.14 // indirect
github.com/safchain/ethtool v0.1.0 // indirect
github.com/stretchr/testify v1.8.3 // indirect
github.com/safchain/ethtool v0.0.0-20201023143004-874930cb3ce0 // indirect
github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 // indirect
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/hujun-open/shouchan => ../shouchan/
// replace github.com/insomniacslk/dhcp => ../dhcp
4 changes: 2 additions & 2 deletions lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ func (lease *v6Lease) addrStr() (r []string) {
return
}

func (lease *v6Lease) Genv6Release() (*dhcpv6.Message, error) {
func (lease *v6Lease) Genv6Release(mt dhcpv6.MessageType) (*dhcpv6.Message, error) {
msg, err := dhcpv6.NewMessage()
if err != nil {
return nil, err
}
msg.MessageType = dhcpv6.MessageTypeRelease
msg.MessageType = mt
msg.AddOption(lease.ReplyOptions.GetOne(dhcpv6.OptionClientID))
msg.AddOption(lease.ReplyOptions.GetOne(dhcpv6.OptionServerID))
msg.AddOption(dhcpv6.OptElapsedTime(0))
Expand Down
Loading

0 comments on commit ffad016

Please sign in to comment.