mirror of
https://github.com/vishvananda/netlink.git
synced 2025-10-05 15:56:54 +08:00
Cleanup from golint and go vet
This commit is contained in:
2
Makefile
2
Makefile
@@ -11,7 +11,7 @@ goroot = $(addprefix ../../../,$(1))
|
|||||||
unroot = $(subst ../../../,,$(1))
|
unroot = $(subst ../../../,,$(1))
|
||||||
fmt = $(addprefix fmt-,$(1))
|
fmt = $(addprefix fmt-,$(1))
|
||||||
|
|
||||||
all: fmt test
|
all: test
|
||||||
|
|
||||||
$(call goroot,$(DEPS)):
|
$(call goroot,$(DEPS)):
|
||||||
go get $(call unroot,$@)
|
go get $(call unroot,$@)
|
||||||
|
@@ -12,7 +12,7 @@ func TestAddr(t *testing.T) {
|
|||||||
t.Skipf("Fails in travis with: addr_test.go:68: Address flags not set properly, got=0, expected=128")
|
t.Skipf("Fails in travis with: addr_test.go:68: Address flags not set properly, got=0, expected=128")
|
||||||
}
|
}
|
||||||
// TODO: IFA_F_PERMANENT does not seem to be set by default on older kernels?
|
// TODO: IFA_F_PERMANENT does not seem to be set by default on older kernels?
|
||||||
var address = &net.IPNet{net.IPv4(127, 0, 0, 2), net.CIDRMask(24, 32)}
|
var address = &net.IPNet{IP: net.IPv4(127, 0, 0, 2), Mask: net.CIDRMask(24, 32)}
|
||||||
var addrTests = []struct {
|
var addrTests = []struct {
|
||||||
addr *Addr
|
addr *Addr
|
||||||
expected *Addr
|
expected *Addr
|
||||||
|
12
class.go
12
class.go
@@ -9,7 +9,7 @@ type Class interface {
|
|||||||
Type() string
|
Type() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class represents a netlink class. A filter is associated with a link,
|
// ClassAttrs represents a netlink class. A filter is associated with a link,
|
||||||
// has a handle and a parent. The root filter of a device should have a
|
// has a handle and a parent. The root filter of a device should have a
|
||||||
// parent == HANDLE_ROOT.
|
// parent == HANDLE_ROOT.
|
||||||
type ClassAttrs struct {
|
type ClassAttrs struct {
|
||||||
@@ -20,7 +20,7 @@ type ClassAttrs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q ClassAttrs) String() string {
|
func (q ClassAttrs) String() string {
|
||||||
return fmt.Sprintf("{LinkIndex: %d, Handle: %s, Parent: %s, Leaf: %s}", q.LinkIndex, HandleStr(q.Handle), HandleStr(q.Parent), q.Leaf)
|
return fmt.Sprintf("{LinkIndex: %d, Handle: %s, Parent: %s, Leaf: %d}", q.LinkIndex, HandleStr(q.Handle), HandleStr(q.Parent), q.Leaf)
|
||||||
}
|
}
|
||||||
|
|
||||||
type HtbClassAttrs struct {
|
type HtbClassAttrs struct {
|
||||||
@@ -38,7 +38,7 @@ func (q HtbClassAttrs) String() string {
|
|||||||
return fmt.Sprintf("{Rate: %d, Ceil: %d, Buffer: %d, Cbuffer: %d}", q.Rate, q.Ceil, q.Buffer, q.Cbuffer)
|
return fmt.Sprintf("{Rate: %d, Ceil: %d, Buffer: %d, Cbuffer: %d}", q.Rate, q.Ceil, q.Buffer, q.Cbuffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Htb class
|
// HtbClass represents an Htb class
|
||||||
type HtbClass struct {
|
type HtbClass struct {
|
||||||
ClassAttrs
|
ClassAttrs
|
||||||
Rate uint64
|
Rate uint64
|
||||||
@@ -87,11 +87,11 @@ func (q HtbClass) String() string {
|
|||||||
return fmt.Sprintf("{Rate: %d, Ceil: %d, Buffer: %d, Cbuffer: %d}", q.Rate, q.Ceil, q.Buffer, q.Cbuffer)
|
return fmt.Sprintf("{Rate: %d, Ceil: %d, Buffer: %d, Cbuffer: %d}", q.Rate, q.Ceil, q.Buffer, q.Cbuffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (class *HtbClass) Attrs() *ClassAttrs {
|
func (q *HtbClass) Attrs() *ClassAttrs {
|
||||||
return &class.ClassAttrs
|
return &q.ClassAttrs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (class *HtbClass) Type() string {
|
func (q *HtbClass) Type() string {
|
||||||
return "htb"
|
return "htb"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -73,20 +73,20 @@ func classPayload(req *nl.NetlinkRequest, class Class) error {
|
|||||||
opt.Prio = htb.Prio
|
opt.Prio = htb.Prio
|
||||||
// TODO: Handle Debug properly. For now default to 0
|
// TODO: Handle Debug properly. For now default to 0
|
||||||
/* Calculate {R,C}Tab and set Rate and Ceil */
|
/* Calculate {R,C}Tab and set Rate and Ceil */
|
||||||
cell_log := -1
|
cellLog := -1
|
||||||
ccell_log := -1
|
ccellLog := -1
|
||||||
linklayer := nl.LINKLAYER_ETHERNET
|
linklayer := nl.LINKLAYER_ETHERNET
|
||||||
mtu := 1600
|
mtu := 1600
|
||||||
var rtab [256]uint32
|
var rtab [256]uint32
|
||||||
var ctab [256]uint32
|
var ctab [256]uint32
|
||||||
tcrate := nl.TcRateSpec{Rate: uint32(htb.Rate)}
|
tcrate := nl.TcRateSpec{Rate: uint32(htb.Rate)}
|
||||||
if CalcRtable(&tcrate, rtab, cell_log, uint32(mtu), linklayer) < 0 {
|
if CalcRtable(&tcrate, rtab, cellLog, uint32(mtu), linklayer) < 0 {
|
||||||
return errors.New("HTB: failed to calculate rate table.")
|
return errors.New("HTB: failed to calculate rate table")
|
||||||
}
|
}
|
||||||
opt.Rate = tcrate
|
opt.Rate = tcrate
|
||||||
tcceil := nl.TcRateSpec{Rate: uint32(htb.Ceil)}
|
tcceil := nl.TcRateSpec{Rate: uint32(htb.Ceil)}
|
||||||
if CalcRtable(&tcceil, ctab, ccell_log, uint32(mtu), linklayer) < 0 {
|
if CalcRtable(&tcceil, ctab, ccellLog, uint32(mtu), linklayer) < 0 {
|
||||||
return errors.New("HTB: failed to calculate ceil rate table.")
|
return errors.New("HTB: failed to calculate ceil rate table")
|
||||||
}
|
}
|
||||||
opt.Ceil = tcceil
|
opt.Ceil = tcceil
|
||||||
nl.NewRtAttrChild(options, nl.TCA_HTB_PARMS, opt.Serialize())
|
nl.NewRtAttrChild(options, nl.TCA_HTB_PARMS, opt.Serialize())
|
||||||
|
@@ -269,14 +269,14 @@ func TestHtbClassAddHtbClassChangeDel(t *testing.T) {
|
|||||||
// For change to work, the handle and parent cannot be changed.
|
// For change to work, the handle and parent cannot be changed.
|
||||||
|
|
||||||
// First, test it fails if we change the Handle.
|
// First, test it fails if we change the Handle.
|
||||||
old_handle := classattrs.Handle
|
oldHandle := classattrs.Handle
|
||||||
classattrs.Handle = MakeHandle(0xffff, 3)
|
classattrs.Handle = MakeHandle(0xffff, 3)
|
||||||
class = NewHtbClass(classattrs, htbclassattrs)
|
class = NewHtbClass(classattrs, htbclassattrs)
|
||||||
if err := ClassChange(class); err == nil {
|
if err := ClassChange(class); err == nil {
|
||||||
t.Fatal("ClassChange should not work when using a different handle.")
|
t.Fatal("ClassChange should not work when using a different handle.")
|
||||||
}
|
}
|
||||||
// It should work with the same handle
|
// It should work with the same handle
|
||||||
classattrs.Handle = old_handle
|
classattrs.Handle = oldHandle
|
||||||
htbclassattrs.Rate = 4321000
|
htbclassattrs.Rate = 4321000
|
||||||
class = NewHtbClass(classattrs, htbclassattrs)
|
class = NewHtbClass(classattrs, htbclassattrs)
|
||||||
if err := ClassChange(class); err != nil {
|
if err := ClassChange(class); err != nil {
|
||||||
|
16
filter.go
16
filter.go
@@ -11,7 +11,7 @@ type Filter interface {
|
|||||||
Type() string
|
Type() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter represents a netlink filter. A filter is associated with a link,
|
// FilterAttrs represents a netlink filter. A filter is associated with a link,
|
||||||
// has a handle and a parent. The root filter of a device should have a
|
// has a handle and a parent. The root filter of a device should have a
|
||||||
// parent == HANDLE_ROOT.
|
// parent == HANDLE_ROOT.
|
||||||
type FilterAttrs struct {
|
type FilterAttrs struct {
|
||||||
@@ -91,7 +91,7 @@ type FilterFwAttrs struct {
|
|||||||
LinkLayer int
|
LinkLayer int
|
||||||
}
|
}
|
||||||
|
|
||||||
// FwFilter filters on firewall marks
|
// Fw filter filters on firewall marks
|
||||||
type Fw struct {
|
type Fw struct {
|
||||||
FilterAttrs
|
FilterAttrs
|
||||||
ClassId uint32
|
ClassId uint32
|
||||||
@@ -107,8 +107,8 @@ type Fw struct {
|
|||||||
func NewFw(attrs FilterAttrs, fattrs FilterFwAttrs) (*Fw, error) {
|
func NewFw(attrs FilterAttrs, fattrs FilterFwAttrs) (*Fw, error) {
|
||||||
var rtab [256]uint32
|
var rtab [256]uint32
|
||||||
var ptab [256]uint32
|
var ptab [256]uint32
|
||||||
rcell_log := -1
|
rcellLog := -1
|
||||||
pcell_log := -1
|
pcellLog := -1
|
||||||
avrate := fattrs.AvRate / 8
|
avrate := fattrs.AvRate / 8
|
||||||
police := nl.TcPolice{}
|
police := nl.TcPolice{}
|
||||||
police.Rate.Rate = fattrs.Rate / 8
|
police.Rate.Rate = fattrs.Rate / 8
|
||||||
@@ -124,8 +124,8 @@ func NewFw(attrs FilterAttrs, fattrs FilterFwAttrs) (*Fw, error) {
|
|||||||
if police.Rate.Rate != 0 {
|
if police.Rate.Rate != 0 {
|
||||||
police.Rate.Mpu = fattrs.Mpu
|
police.Rate.Mpu = fattrs.Mpu
|
||||||
police.Rate.Overhead = fattrs.Overhead
|
police.Rate.Overhead = fattrs.Overhead
|
||||||
if CalcRtable(&police.Rate, rtab, rcell_log, fattrs.Mtu, linklayer) < 0 {
|
if CalcRtable(&police.Rate, rtab, rcellLog, fattrs.Mtu, linklayer) < 0 {
|
||||||
return nil, errors.New("TBF: failed to calculate rate table.")
|
return nil, errors.New("TBF: failed to calculate rate table")
|
||||||
}
|
}
|
||||||
police.Burst = uint32(Xmittime(uint64(police.Rate.Rate), uint32(buffer)))
|
police.Burst = uint32(Xmittime(uint64(police.Rate.Rate), uint32(buffer)))
|
||||||
}
|
}
|
||||||
@@ -133,8 +133,8 @@ func NewFw(attrs FilterAttrs, fattrs FilterFwAttrs) (*Fw, error) {
|
|||||||
if police.PeakRate.Rate != 0 {
|
if police.PeakRate.Rate != 0 {
|
||||||
police.PeakRate.Mpu = fattrs.Mpu
|
police.PeakRate.Mpu = fattrs.Mpu
|
||||||
police.PeakRate.Overhead = fattrs.Overhead
|
police.PeakRate.Overhead = fattrs.Overhead
|
||||||
if CalcRtable(&police.PeakRate, ptab, pcell_log, fattrs.Mtu, linklayer) < 0 {
|
if CalcRtable(&police.PeakRate, ptab, pcellLog, fattrs.Mtu, linklayer) < 0 {
|
||||||
return nil, errors.New("POLICE: failed to calculate peak rate table.")
|
return nil, errors.New("POLICE: failed to calculate peak rate table")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -91,7 +91,7 @@ func FilterAdd(filter Filter) error {
|
|||||||
nl.NewRtAttrChild(options, nl.TCA_FW_CLASSID, b)
|
nl.NewRtAttrChild(options, nl.TCA_FW_CLASSID, b)
|
||||||
}
|
}
|
||||||
} else if bpf, ok := filter.(*BpfFilter); ok {
|
} else if bpf, ok := filter.(*BpfFilter); ok {
|
||||||
var bpf_flags uint32
|
var bpfFlags uint32
|
||||||
if bpf.ClassId != 0 {
|
if bpf.ClassId != 0 {
|
||||||
nl.NewRtAttrChild(options, nl.TCA_BPF_CLASSID, nl.Uint32Attr(bpf.ClassId))
|
nl.NewRtAttrChild(options, nl.TCA_BPF_CLASSID, nl.Uint32Attr(bpf.ClassId))
|
||||||
}
|
}
|
||||||
@@ -102,9 +102,9 @@ func FilterAdd(filter Filter) error {
|
|||||||
nl.NewRtAttrChild(options, nl.TCA_BPF_NAME, nl.ZeroTerminated(bpf.Name))
|
nl.NewRtAttrChild(options, nl.TCA_BPF_NAME, nl.ZeroTerminated(bpf.Name))
|
||||||
}
|
}
|
||||||
if bpf.DirectAction {
|
if bpf.DirectAction {
|
||||||
bpf_flags |= nl.TCA_BPF_FLAG_ACT_DIRECT
|
bpfFlags |= nl.TCA_BPF_FLAG_ACT_DIRECT
|
||||||
}
|
}
|
||||||
nl.NewRtAttrChild(options, nl.TCA_BPF_FLAGS, nl.Uint32Attr(bpf_flags))
|
nl.NewRtAttrChild(options, nl.TCA_BPF_FLAGS, nl.Uint32Attr(bpfFlags))
|
||||||
}
|
}
|
||||||
|
|
||||||
req.AddData(options)
|
req.AddData(options)
|
||||||
@@ -385,27 +385,27 @@ func AdjustSize(sz uint, mpu uint, linklayer int) uint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CalcRtable(rate *nl.TcRateSpec, rtab [256]uint32, cell_log int, mtu uint32, linklayer int) int {
|
func CalcRtable(rate *nl.TcRateSpec, rtab [256]uint32, cellLog int, mtu uint32, linklayer int) int {
|
||||||
bps := rate.Rate
|
bps := rate.Rate
|
||||||
mpu := rate.Mpu
|
mpu := rate.Mpu
|
||||||
var sz uint
|
var sz uint
|
||||||
if mtu == 0 {
|
if mtu == 0 {
|
||||||
mtu = 2047
|
mtu = 2047
|
||||||
}
|
}
|
||||||
if cell_log < 0 {
|
if cellLog < 0 {
|
||||||
cell_log = 0
|
cellLog = 0
|
||||||
for (mtu >> uint(cell_log)) > 255 {
|
for (mtu >> uint(cellLog)) > 255 {
|
||||||
cell_log++
|
cellLog++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := 0; i < 256; i++ {
|
for i := 0; i < 256; i++ {
|
||||||
sz = AdjustSize(uint((i+1)<<uint32(cell_log)), uint(mpu), linklayer)
|
sz = AdjustSize(uint((i+1)<<uint32(cellLog)), uint(mpu), linklayer)
|
||||||
rtab[i] = uint32(Xmittime(uint64(bps), uint32(sz)))
|
rtab[i] = uint32(Xmittime(uint64(bps), uint32(sz)))
|
||||||
}
|
}
|
||||||
rate.CellAlign = -1
|
rate.CellAlign = -1
|
||||||
rate.CellLog = uint8(cell_log)
|
rate.CellLog = uint8(cellLog)
|
||||||
rate.Linklayer = uint8(linklayer & nl.TC_LINKLAYER_MASK)
|
rate.Linklayer = uint8(linklayer & nl.TC_LINKLAYER_MASK)
|
||||||
return cell_log
|
return cellLog
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeserializeRtab(b []byte) [256]uint32 {
|
func DeserializeRtab(b []byte) [256]uint32 {
|
||||||
|
4
link.go
4
link.go
@@ -425,7 +425,7 @@ const (
|
|||||||
BOND_AD_SELECT_COUNT
|
BOND_AD_SELECT_COUNT
|
||||||
)
|
)
|
||||||
|
|
||||||
// BondAdInfo
|
// BondAdInfo represents ad info for bond
|
||||||
type BondAdInfo struct {
|
type BondAdInfo struct {
|
||||||
AggregatorId int
|
AggregatorId int
|
||||||
NumPorts int
|
NumPorts int
|
||||||
@@ -526,7 +526,7 @@ func (bond *Bond) Type() string {
|
|||||||
return "bond"
|
return "bond"
|
||||||
}
|
}
|
||||||
|
|
||||||
// GreTap devices must specify LocalIP and RemoteIP on create
|
// Gretap devices must specify LocalIP and RemoteIP on create
|
||||||
type Gretap struct {
|
type Gretap struct {
|
||||||
LinkAttrs
|
LinkAttrs
|
||||||
IKey uint32
|
IKey uint32
|
||||||
|
@@ -72,7 +72,7 @@ func testLinkAddDel(t *testing.T, link Link) {
|
|||||||
} else {
|
} else {
|
||||||
// recent kernels set the parent index for veths in the response
|
// recent kernels set the parent index for veths in the response
|
||||||
if rBase.ParentIndex == 0 && base.ParentIndex != 0 {
|
if rBase.ParentIndex == 0 && base.ParentIndex != 0 {
|
||||||
t.Fatal("Created link doesn't have parent %d but it should", base.ParentIndex)
|
t.Fatalf("Created link doesn't have parent %d but it should", base.ParentIndex)
|
||||||
} else if rBase.ParentIndex != 0 && base.ParentIndex == 0 {
|
} else if rBase.ParentIndex != 0 && base.ParentIndex == 0 {
|
||||||
t.Fatalf("Created link has parent %d but it shouldn't", rBase.ParentIndex)
|
t.Fatalf("Created link has parent %d but it shouldn't", rBase.ParentIndex)
|
||||||
} else if rBase.ParentIndex != 0 && base.ParentIndex != 0 {
|
} else if rBase.ParentIndex != 0 && base.ParentIndex != 0 {
|
||||||
|
@@ -14,8 +14,8 @@ import (
|
|||||||
"github.com/vishvananda/netlink/nl"
|
"github.com/vishvananda/netlink/nl"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Family type definitions
|
||||||
const (
|
const (
|
||||||
// Family type definitions
|
|
||||||
FAMILY_ALL = nl.FAMILY_ALL
|
FAMILY_ALL = nl.FAMILY_ALL
|
||||||
FAMILY_V4 = nl.FAMILY_V4
|
FAMILY_V4 = nl.FAMILY_V4
|
||||||
FAMILY_V6 = nl.FAMILY_V6
|
FAMILY_V6 = nl.FAMILY_V6
|
||||||
|
42
qdisc.go
42
qdisc.go
@@ -22,7 +22,7 @@ type Qdisc interface {
|
|||||||
Type() string
|
Type() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Qdisc represents a netlink qdisc. A qdisc is associated with a link,
|
// QdiscAttrs represents a netlink qdisc. A qdisc is associated with a link,
|
||||||
// has a handle, a parent and a refcnt. The root qdisc of a device should
|
// has a handle, a parent and a refcnt. The root qdisc of a device should
|
||||||
// have parent == HANDLE_ROOT.
|
// have parent == HANDLE_ROOT.
|
||||||
type QdiscAttrs struct {
|
type QdiscAttrs struct {
|
||||||
@@ -33,7 +33,7 @@ type QdiscAttrs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q QdiscAttrs) String() string {
|
func (q QdiscAttrs) String() string {
|
||||||
return fmt.Sprintf("{LinkIndex: %d, Handle: %s, Parent: %s, Refcnt: %s}", q.LinkIndex, HandleStr(q.Handle), HandleStr(q.Parent), q.Refcnt)
|
return fmt.Sprintf("{LinkIndex: %d, Handle: %s, Parent: %s, Refcnt: %d}", q.LinkIndex, HandleStr(q.Handle), HandleStr(q.Parent), q.Refcnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeHandle(major, minor uint16) uint32 {
|
func MakeHandle(major, minor uint16) uint32 {
|
||||||
@@ -154,7 +154,7 @@ type NetemQdiscAttrs struct {
|
|||||||
|
|
||||||
func (q NetemQdiscAttrs) String() string {
|
func (q NetemQdiscAttrs) String() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"{Latency: %d, Limit: %d, Loss: %d, Gap: %d, Duplicate: %d, Jitter: %d}",
|
"{Latency: %d, Limit: %d, Loss: %f, Gap: %d, Duplicate: %f, Jitter: %d}",
|
||||||
q.Latency, q.Limit, q.Loss, q.Gap, q.Duplicate, q.Jitter,
|
q.Latency, q.Limit, q.Loss, q.Gap, q.Duplicate, q.Jitter,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -178,9 +178,9 @@ type Netem struct {
|
|||||||
|
|
||||||
func NewNetem(attrs QdiscAttrs, nattrs NetemQdiscAttrs) *Netem {
|
func NewNetem(attrs QdiscAttrs, nattrs NetemQdiscAttrs) *Netem {
|
||||||
var limit uint32 = 1000
|
var limit uint32 = 1000
|
||||||
var loss_corr, delay_corr, duplicate_corr uint32
|
var lossCorr, delayCorr, duplicateCorr uint32
|
||||||
var reorder_prob, reorder_corr uint32
|
var reorderProb, reorderCorr uint32
|
||||||
var corrupt_prob, corrupt_corr uint32
|
var corruptProb, corruptCorr uint32
|
||||||
|
|
||||||
latency := nattrs.Latency
|
latency := nattrs.Latency
|
||||||
loss := Percentage2u32(nattrs.Loss)
|
loss := Percentage2u32(nattrs.Loss)
|
||||||
@@ -190,13 +190,13 @@ func NewNetem(attrs QdiscAttrs, nattrs NetemQdiscAttrs) *Netem {
|
|||||||
|
|
||||||
// Correlation
|
// Correlation
|
||||||
if latency > 0 && jitter > 0 {
|
if latency > 0 && jitter > 0 {
|
||||||
delay_corr = Percentage2u32(nattrs.DelayCorr)
|
delayCorr = Percentage2u32(nattrs.DelayCorr)
|
||||||
}
|
}
|
||||||
if loss > 0 {
|
if loss > 0 {
|
||||||
loss_corr = Percentage2u32(nattrs.LossCorr)
|
lossCorr = Percentage2u32(nattrs.LossCorr)
|
||||||
}
|
}
|
||||||
if duplicate > 0 {
|
if duplicate > 0 {
|
||||||
duplicate_corr = Percentage2u32(nattrs.DuplicateCorr)
|
duplicateCorr = Percentage2u32(nattrs.DuplicateCorr)
|
||||||
}
|
}
|
||||||
// FIXME should validate values(like loss/duplicate are percentages...)
|
// FIXME should validate values(like loss/duplicate are percentages...)
|
||||||
latency = time2Tick(latency)
|
latency = time2Tick(latency)
|
||||||
@@ -209,34 +209,34 @@ func NewNetem(attrs QdiscAttrs, nattrs NetemQdiscAttrs) *Netem {
|
|||||||
jitter = time2Tick(jitter)
|
jitter = time2Tick(jitter)
|
||||||
}
|
}
|
||||||
|
|
||||||
reorder_prob = Percentage2u32(nattrs.ReorderProb)
|
reorderProb = Percentage2u32(nattrs.ReorderProb)
|
||||||
reorder_corr = Percentage2u32(nattrs.ReorderCorr)
|
reorderCorr = Percentage2u32(nattrs.ReorderCorr)
|
||||||
|
|
||||||
if reorder_prob > 0 {
|
if reorderProb > 0 {
|
||||||
// ERROR if lantency == 0
|
// ERROR if lantency == 0
|
||||||
if gap == 0 {
|
if gap == 0 {
|
||||||
gap = 1
|
gap = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
corrupt_prob = Percentage2u32(nattrs.CorruptProb)
|
corruptProb = Percentage2u32(nattrs.CorruptProb)
|
||||||
corrupt_corr = Percentage2u32(nattrs.CorruptCorr)
|
corruptCorr = Percentage2u32(nattrs.CorruptCorr)
|
||||||
|
|
||||||
return &Netem{
|
return &Netem{
|
||||||
QdiscAttrs: attrs,
|
QdiscAttrs: attrs,
|
||||||
Latency: latency,
|
Latency: latency,
|
||||||
DelayCorr: delay_corr,
|
DelayCorr: delayCorr,
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
Loss: loss,
|
Loss: loss,
|
||||||
LossCorr: loss_corr,
|
LossCorr: lossCorr,
|
||||||
Gap: gap,
|
Gap: gap,
|
||||||
Duplicate: duplicate,
|
Duplicate: duplicate,
|
||||||
DuplicateCorr: duplicate_corr,
|
DuplicateCorr: duplicateCorr,
|
||||||
Jitter: jitter,
|
Jitter: jitter,
|
||||||
ReorderProb: reorder_prob,
|
ReorderProb: reorderProb,
|
||||||
ReorderCorr: reorder_corr,
|
ReorderCorr: reorderCorr,
|
||||||
CorruptProb: corrupt_prob,
|
CorruptProb: corruptProb,
|
||||||
CorruptCorr: corrupt_corr,
|
CorruptCorr: corruptCorr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -334,9 +334,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tickInUsec float64 = 0.0
|
tickInUsec float64
|
||||||
clockFactor float64 = 0.0
|
clockFactor float64
|
||||||
hz float64 = 0.0
|
hz float64
|
||||||
)
|
)
|
||||||
|
|
||||||
func initClock() {
|
func initClock() {
|
||||||
|
@@ -10,7 +10,7 @@ func TestRuleAddDel(t *testing.T) {
|
|||||||
srcNet := &net.IPNet{IP: net.IPv4(172, 16, 0, 1), Mask: net.CIDRMask(16, 32)}
|
srcNet := &net.IPNet{IP: net.IPv4(172, 16, 0, 1), Mask: net.CIDRMask(16, 32)}
|
||||||
dstNet := &net.IPNet{IP: net.IPv4(172, 16, 1, 1), Mask: net.CIDRMask(24, 32)}
|
dstNet := &net.IPNet{IP: net.IPv4(172, 16, 1, 1), Mask: net.CIDRMask(24, 32)}
|
||||||
|
|
||||||
rules_begin, err := RuleList(syscall.AF_INET)
|
rulesBegin, err := RuleList(syscall.AF_INET)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ func TestRuleAddDel(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(rules) != len(rules_begin)+1 {
|
if len(rules) != len(rulesBegin)+1 {
|
||||||
t.Fatal("Rule not added properly")
|
t.Fatal("Rule not added properly")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,12 +55,12 @@ func TestRuleAddDel(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rules_end, err := RuleList(syscall.AF_INET)
|
rulesEnd, err := RuleList(syscall.AF_INET)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(rules_end) != len(rules_begin) {
|
if len(rulesEnd) != len(rulesBegin) {
|
||||||
t.Fatal("Rule not removed properly")
|
t.Fatal("Rule not removed properly")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ func (e EncapType) String() string {
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
// XfrmEncap represents the encapsulation to use for the ipsec encryption.
|
// XfrmStateEncap represents the encapsulation to use for the ipsec encryption.
|
||||||
type XfrmStateEncap struct {
|
type XfrmStateEncap struct {
|
||||||
Type EncapType
|
Type EncapType
|
||||||
SrcPort int
|
SrcPort int
|
||||||
|
Reference in New Issue
Block a user