FD.io VPP  v21.06-3-gbb25fbf28
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 }
VOM::interface::get_stats
const stats_t & get_stats(void) const
Get the interface stats.
Definition: interface.cpp:455
VOM::OM::write
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
VOM::route::prefix_t::ZERO
const static prefix_t ZERO
The all Zeros prefix.
Definition: prefix.hpp:205
om.hpp
listener::listener
listener()
Definition: test_stats.cpp:10
types.hpp
VOM::OM::init
static void init()
Init.
Definition: om.cpp:30
tap_interface.hpp
listener
Definition: test_stats.cpp:7
VOM::interface::name
const std::string & name() const
Return the interface type.
Definition: interface.cpp:271
main
int main()
Run VPP on another terminal before running vom_stats_test.
Definition: test_stats.cpp:21
VOM::HW::init
static void init()
Initialise the HW.
Definition: hw.cpp:205
VOM::HW::cmd_q
The pipe to VPP into which we write the commands.
Definition: hw.hpp:187
VOM::HW::disconnect
static void disconnect()
Disconnect to VPP.
Definition: hw.cpp:236
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
hw.hpp
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
VOM::OM::remove
static void remove(const client_db::key_t &key)
Remove all object in the OM referenced by the key.
Definition: om.cpp:70
VOM::interface::stat_listener
A class that listens to interface Stats.
Definition: interface.hpp:465
prefix.hpp
VOM::HW::read_stats
static void read_stats()
read stats from stat segment
Definition: hw.cpp:272
listener::handle_interface_stat
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
VOM::HW::connect
static bool connect()
Blocking Connect to VPP.
Definition: hw.cpp:230
VOM::tap_interface
A tap-interface.
Definition: tap_interface.hpp:25
VOM::handle_t::INVALID
const static handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
listener::~listener
~listener()
Definition: test_stats.cpp:11
VOM::tap_interface::singular
std::shared_ptr< tap_interface > singular() const
Return the matching 'singular instance' of the TAP interface.
Definition: tap_interface.cpp:77
VOM::interface::admin_state_t::UP
const static admin_state_t UP
Admin UP state.
Definition: interface.hpp:147