class.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package netlink
  2. import (
  3. "fmt"
  4. )
  5. type Class interface {
  6. Attrs() *ClassAttrs
  7. Type() string
  8. }
  9. // ClassAttrs represents a netlink class. A filter is associated with a link,
  10. // has a handle and a parent. The root filter of a device should have a
  11. // parent == HANDLE_ROOT.
  12. type ClassAttrs struct {
  13. LinkIndex int
  14. Handle uint32
  15. Parent uint32
  16. Leaf uint32
  17. }
  18. func (q ClassAttrs) String() string {
  19. return fmt.Sprintf("{LinkIndex: %d, Handle: %s, Parent: %s, Leaf: %d}", q.LinkIndex, HandleStr(q.Handle), HandleStr(q.Parent), q.Leaf)
  20. }
  21. type HtbClassAttrs struct {
  22. // TODO handle all attributes
  23. Rate uint64
  24. Ceil uint64
  25. Buffer uint32
  26. Cbuffer uint32
  27. Quantum uint32
  28. Level uint32
  29. Prio uint32
  30. }
  31. func (q HtbClassAttrs) String() string {
  32. return fmt.Sprintf("{Rate: %d, Ceil: %d, Buffer: %d, Cbuffer: %d}", q.Rate, q.Ceil, q.Buffer, q.Cbuffer)
  33. }
  34. // HtbClass represents an Htb class
  35. type HtbClass struct {
  36. ClassAttrs
  37. Rate uint64
  38. Ceil uint64
  39. Buffer uint32
  40. Cbuffer uint32
  41. Quantum uint32
  42. Level uint32
  43. Prio uint32
  44. }
  45. func (q HtbClass) String() string {
  46. return fmt.Sprintf("{Rate: %d, Ceil: %d, Buffer: %d, Cbuffer: %d}", q.Rate, q.Ceil, q.Buffer, q.Cbuffer)
  47. }
  48. func (q *HtbClass) Attrs() *ClassAttrs {
  49. return &q.ClassAttrs
  50. }
  51. func (q *HtbClass) Type() string {
  52. return "htb"
  53. }
  54. // GenericClass classes represent types that are not currently understood
  55. // by this netlink library.
  56. type GenericClass struct {
  57. ClassAttrs
  58. ClassType string
  59. }
  60. func (class *GenericClass) Attrs() *ClassAttrs {
  61. return &class.ClassAttrs
  62. }
  63. func (class *GenericClass) Type() string {
  64. return class.ClassType
  65. }