aboutsummaryrefslogtreecommitdiffstats
path: root/extras/deprecated/vom/vom/test_stats.cpp
blob: 6235dd44e3f5d37d01aa9fcf8cae7b6f48aa63eb (plain)
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
#include <vom/om.hpp>
#include <vom/hw.hpp>
#include <vom/types.hpp>
#include <vom/prefix.hpp>
#include <vom/tap_interface.hpp>

class listener : public VOM::interface::stat_listener
{
public:
  listener() {}
  ~listener() {}
  void handle_interface_stat(const VOM::interface& itf)
  {
    std::cout << itf.name() << " " << itf.get_stats();
  }
};

/**
 * Run VPP on another terminal before running vom_stats_test
 */
int main()
{
  uint8_t i = 5;
  listener *listen = new listener();

  VOM::HW::init(new VOM::HW::cmd_q());
  VOM::OM::init();

  while (VOM::HW::connect() != true)
    ;

  VOM::tap_interface itf("tap0", VOM::interface::admin_state_t::UP, VOM::route::prefix_t::ZERO);
  VOM::OM::write("__TAP__", itf);

  std::shared_ptr<VOM::tap_interface> intf = itf.singular();


  VOM::tap_interface itf1("tap1", VOM::interface::admin_state_t::UP, VOM::route::prefix_t::ZERO);
  VOM::OM::write("__TAP__", itf1);

  std::shared_ptr<VOM::tap_interface> intf1 = itf1.singular();

  VOM::tap_interface itf2("tap2", VOM::interface::admin_state_t::UP, VOM::route::prefix_t::ZERO);
  VOM::OM::write("__TAP__", itf2);

  std::shared_ptr<VOM::tap_interface> intf2 = itf2.singular();

  if (VOM::handle_t::INVALID == intf->handle() || VOM::handle_t::INVALID == intf1->handle()
      || VOM::handle_t::INVALID == intf2->handle())
    {
      std::cout << "Interface index is INVALID" << std::endl;
      VOM::HW::disconnect();

      return 0;
    }
  else
    {
      std::cout << "Interface #1 index is " << intf->handle().value() << std::endl;
      std::cout << "Interface #2 index is " << intf1->handle().value() << std::endl;
      std::cout << "Interface #3 index is " << intf2->handle().value() << std::endl;
    }

  intf->enable_stats(listen);
  intf1->enable_stats(listen);
  intf2->enable_stats(listen);

  while (i--)
    {
      sleep(3);
      std::cout << "stats # " << std::to_string(i) << std::endl;
      VOM::HW::read_stats();

      if (i == 2)
        intf->disable_stats();

    }

  intf1->disable_stats();
  intf2->disable_stats();

  intf.reset();
  intf1.reset();
  intf2.reset();

  VOM::OM::remove("__TAP__");

  delete listen;
  sleep(2);
  VOM::HW::disconnect();

  return 0;
}