FD.io VPP  v19.04-6-g6f05f72
Vector Packet Processing
test_stats.cpp
Go to the documentation of this file.
1 #include <vom/om.hpp>
2 #include <vom/hw.hpp>
3 #include <vom/types.hpp>
4 #include <vom/prefix.hpp>
5 #include <vom/tap_interface.hpp>
6 
8 {
9 public:
10  listener() {}
11  ~listener() {}
13  {
14  std::cout << itf.name() << " " << itf.get_stats();
15  }
16 };
17 
18 /**
19  * Run VPP on another terminal before running vom_stats_test
20  */
21 int main()
22 {
23  uint8_t i = 5;
24  listener *listen = new listener();
25 
27  VOM::OM::init();
28 
29  while (VOM::HW::connect() != true)
30  ;
31 
33  VOM::OM::write("__TAP__", itf);
34 
35  std::shared_ptr<VOM::tap_interface> intf = itf.singular();
36 
37 
39  VOM::OM::write("__TAP__", itf1);
40 
41  std::shared_ptr<VOM::tap_interface> intf1 = itf1.singular();
42 
44  VOM::OM::write("__TAP__", itf2);
45 
46  std::shared_ptr<VOM::tap_interface> intf2 = itf2.singular();
47 
48  if (VOM::handle_t::INVALID == intf->handle() || VOM::handle_t::INVALID == intf1->handle()
49  || VOM::handle_t::INVALID == intf2->handle())
50  {
51  std::cout << "Interface index is INVALID" << std::endl;
53 
54  return 0;
55  }
56  else
57  {
58  std::cout << "Interface #1 index is " << intf->handle().value() << std::endl;
59  std::cout << "Interface #2 index is " << intf1->handle().value() << std::endl;
60  std::cout << "Interface #3 index is " << intf2->handle().value() << std::endl;
61  }
62 
63  intf->enable_stats(listen);
64  intf1->enable_stats(listen);
65  intf2->enable_stats(listen);
66 
67  while (i--)
68  {
69  sleep(3);
70  std::cout << "stats # " << std::to_string(i) << std::endl;
72 
73  if (i == 2)
74  intf->disable_stats();
75 
76  }
77 
78  intf1->disable_stats();
79  intf2->disable_stats();
80 
81  intf.reset();
82  intf1.reset();
83  intf2.reset();
84 
85  VOM::OM::remove("__TAP__");
86 
87  delete listen;
88  sleep(2);
90 
91  return 0;
92 }
static void init()
Init.
Definition: om.cpp:30
static void read_stats()
read stats from stat segment
Definition: hw.cpp:272
A tap-interface.
void handle_interface_stat(const VOM::interface &itf)
Virtual function called on the listener when the command has data ready to process.
Definition: test_stats.cpp:12
int i
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
int main()
Run VPP on another terminal before running vom_stats_test.
Definition: test_stats.cpp:21
static bool connect()
Blocking Connect to VPP.
Definition: hw.cpp:230
static void remove(const client_db::key_t &key)
Remove all object in the OM referenced by the key.
Definition: om.cpp:70
A class that listens to interface Stats.
Definition: interface.hpp:460
The pipe to VPP into which we write the commands.
Definition: hw.hpp:187
A representation of an interface in VPP.
Definition: interface.hpp:41
std::shared_ptr< tap_interface > singular() const
Return the matching &#39;singular instance&#39; of the TAP interface.
static void init()
Initialise the HW.
Definition: hw.cpp:205
const std::string & name() const
Return the interface type.
Definition: interface.cpp:264
static void disconnect()
Disconnect to VPP.
Definition: hw.cpp:236
static rc_t write(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
Definition: om.hpp:221
static const admin_state_t UP
Admin UP state.
Definition: interface.hpp:147
const stats_t & get_stats(void) const
Get the interface stats.
Definition: interface.cpp:448
static const prefix_t ZERO
The all Zeros prefix.
Definition: prefix.hpp:166