forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
105 lines (84 loc) · 3.11 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package tgconsumer
//go:generate go run ../../mk/enumgen/ -guard=NDNDPDK_TGCONSUMER_ENUM_H -out=../../csrc/tgconsumer/enum.h .
import (
"errors"
"fmt"
"time"
"github.com/usnistgov/ndn-dpdk/core/nnduration"
"github.com/usnistgov/ndn-dpdk/iface"
"github.com/usnistgov/ndn-dpdk/ndni"
)
const (
// MaxPatterns is maximum number of traffic patterns.
MaxPatterns = 128
// MaxSumWeight is maximum sum of weights among traffic patterns.
MaxSumWeight = 8192
// DigestLowWatermark is the number of remaining Data packets in the crypto device before enqueuing a new burst.
DigestLowWatermark = 16
// DigestBurstSize is the number of Data packets to enqueue into crypto device.
DigestBurstSize = 64
_ = "enumgen::Tgc"
)
const defaultInterval = 1 * time.Millisecond
// Config describes consumer configuration.
type Config struct {
RxQueue iface.PktQueueConfig `json:"rxQueue,omitempty"`
// Interval defines average Interest interval.
// TX thread transmits Interests in bursts, so the specified interval will be converted to
// a burst interval with equivalent traffic amount.
// Default is 1ms.
Interval nnduration.Nanoseconds `json:"interval"`
// Patterns defines traffic patterns.
// It must contain between 1 and MaxPatterns entries.
Patterns []Pattern `json:"patterns"`
nWeights, nDigestPatterns int
}
// Validate applies defaults and validates the configuration.
func (cfg *Config) Validate() error {
cfg.RxQueue.DisableCoDel = true
if len(cfg.Patterns) == 0 {
return errors.New("no pattern specified")
}
if len(cfg.Patterns) > MaxPatterns {
return fmt.Errorf("cannot add more than %d patterns", MaxPatterns)
}
patterns := []Pattern{}
nWeights, nDigestPatterns := 0, 0
for i, pattern := range cfg.Patterns {
pattern.applyDefaults()
patterns = append(patterns, pattern)
nWeights += pattern.Weight
if pattern.Digest != nil {
nDigestPatterns++
}
if pattern.SeqNumOffset != 0 {
if pattern.Digest != nil {
return errors.New("pattern cannot have both Digest and SeqNumOffset")
}
if i == 0 {
return errors.New("first pattern cannot have SeqNumOffset")
}
}
}
if nWeights > MaxSumWeight {
return fmt.Errorf("sum of weight cannot exceed %d", MaxSumWeight)
}
cfg.Patterns, cfg.nWeights, cfg.nDigestPatterns = patterns, nWeights, nDigestPatterns
return nil
}
// Pattern configures how the consumer generates a sequence of Interests.
type Pattern struct {
// Weight of random choice, minimum/default is 1.
Weight int `json:"weight,omitempty"`
ndni.InterestTemplateConfig
// If specified, append implicit digest to Interest name.
// For Data to satisfy Interests, the producer pattern must reply with the same DataGenConfig.
Digest *ndni.DataGenConfig `json:"digest,omitempty"`
// If non-zero, request cached Data. This must appear after a pattern without SeqNumOffset.
// The consumer derives sequence number by subtracting SeqNumOffset from the previous pattern's
// sequence number. Sufficient CS capacity is necessary for Data to actually come from CS.
SeqNumOffset int `json:"seqNumOffset,omitempty"`
}
func (pattern *Pattern) applyDefaults() {
pattern.Weight = max(1, pattern.Weight)
}