1
0

operstate.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _IPYML_OPERSTATE_H
  2. #define _IPYML_OPERSTATE_H
  3. #include "yaml.h"
  4. #include <libmnl/libmnl.h>
  5. #include <linux/if.h>
  6. #include <linux/netlink.h>
  7. class OperState : public YamlObject {
  8. // RFC 2863 operational status
  9. /* linux/if.h:
  10. enum {
  11. IF_OPER_UNKNOWN,
  12. IF_OPER_NOTPRESENT,
  13. IF_OPER_DOWN,
  14. IF_OPER_LOWERLAYERDOWN,
  15. IF_OPER_TESTING,
  16. IF_OPER_DORMANT,
  17. IF_OPER_UP,
  18. };
  19. */
  20. unsigned char state;
  21. public:
  22. OperState &operator=(const nlattr *attr) {
  23. assert(mnl_attr_validate(attr, MNL_TYPE_U8) == 0);
  24. this->state = mnl_attr_get_u8(attr);
  25. return *this;
  26. }
  27. void write_yaml(std::ostream &stream,
  28. const yaml_indent_level_t indent_level = 0) const {
  29. const char *label = NULL;
  30. switch (state) {
  31. case IF_OPER_UNKNOWN:
  32. label = "unknown";
  33. break;
  34. case IF_OPER_NOTPRESENT:
  35. label = "not present";
  36. break;
  37. case IF_OPER_DOWN:
  38. label = "down";
  39. break;
  40. case IF_OPER_LOWERLAYERDOWN:
  41. label = "lower layer down";
  42. break;
  43. case IF_OPER_TESTING:
  44. label = "testing";
  45. break;
  46. case IF_OPER_DORMANT:
  47. label = "dormant";
  48. break;
  49. case IF_OPER_UP:
  50. label = "up";
  51. break;
  52. }
  53. assert(label);
  54. stream << label << "\n";
  55. }
  56. };
  57. #endif