Skip to content

Commit

Permalink
adding support for prngseed
Browse files Browse the repository at this point in the history
  • Loading branch information
Caesurus authored and florianl committed Jul 24, 2024
1 parent 8755020 commit ed14d73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions q_netem.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
tcaNetemJitter64
tcaNetemSlot
tcaNetemSlotDist
tcaNetemPrngSeed
)

// Netem contains attributes of the netem discipline
Expand All @@ -38,6 +39,7 @@ type Netem struct {
Latency64 *int64
Jitter64 *int64
Slot *NetemSlot
PrngSeed *uint64
}

// NetemQopt from include/uapi/linux/pkt_sched.h
Expand Down Expand Up @@ -153,6 +155,9 @@ func unmarshalNetem(data []byte, info *Netem) error {
info.Slot = tmp
case tcaNetemPad:
// padding does not contain data, we just skip it
case tcaNetemPrngSeed:
tmp := ad.Uint64()
info.PrngSeed = &tmp
default:
return fmt.Errorf("unmarshalNetem()\t%d\n\t%v", ad.Type(), ad.Bytes())
}
Expand Down Expand Up @@ -211,6 +216,9 @@ func marshalNetem(info *Netem) ([]byte, error) {
multiError = concatError(multiError, err)
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaNetemSlot, Data: data})
}
if info.PrngSeed !=nil {
options = append(options, tcOption{Interpretation: vtUint64, Type: tcaNetemPrngSeed, Data: *info.PrngSeed})
}

data, err := marshalAttributes(options)
multiError = concatError(multiError, err)
Expand Down
7 changes: 4 additions & 3 deletions q_netem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func TestNetem(t *testing.T) {
Jitter: core.Time2Tick(3),
},
DelayDist: &delayDist}},
"simple": {val: Netem{Ecn: uint32Ptr(123), Latency64: int64Ptr(-4242), Jitter64: int64Ptr(-1337)}},
"qopt": {val: Netem{Qopt: NetemQopt{Latency: 42}, Rate64: uint64Ptr(1337)}},
"random": {val: Netem{Corr: &NetemCorr{Delay: 2}, Reorder: &NetemReorder{Correlation: 13}, Corrupt: &NetemCorrupt{Correlation: 11}, Rate: &NetemRate{PacketOverhead: 1337}, Slot: &NetemSlot{MinDelay: 2, MaxDelay: 4}}},
"simple": {val: Netem{Ecn: uint32Ptr(123), Latency64: int64Ptr(-4242), Jitter64: int64Ptr(-1337)}},
"qopt": {val: Netem{Qopt: NetemQopt{Latency: 42}, Rate64: uint64Ptr(1337)}},
"random": {val: Netem{Corr: &NetemCorr{Delay: 2}, Reorder: &NetemReorder{Correlation: 13}, Corrupt: &NetemCorrupt{Correlation: 11}, Rate: &NetemRate{PacketOverhead: 1337}, Slot: &NetemSlot{MinDelay: 2, MaxDelay: 4}}},
"prngseed": {val: Netem{Qopt: NetemQopt{Latency: 42}, Rate64: uint64Ptr(1337), PrngSeed: uint64Ptr(31337)}},
}

for name, testcase := range tests {
Expand Down

0 comments on commit ed14d73

Please sign in to comment.