FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
dump_cmd.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __VOM_DUMP_CMD_H__
17 #define __VOM_DUMP_CMD_H__
18 
19 #include <future>
20 
21 #include "vom/cmd.hpp"
22 #include "vom/hw.hpp"
23 
24 #include <vapi/vapi.hpp>
25 
26 namespace VOM {
27 /**
28  * A function type def for calculating a message's size
29  */
30 typedef unsigned int (*get_msg_size_t)(void*);
31 
32 /**
33  * A base class for VPP dump commands.
34  * Dump commands are one of the sub-set of command types to VPP. Here the
35  * client
36  * makes a read request on the resource and VPP responds with all the
37  * records.
38  * This command is executed synchronously. Once complete the client can
39  * 'pop'
40  * the records from the command object
41  */
42 template <typename MSG>
43 class dump_cmd : public cmd
44 {
45 public:
46  typedef MSG msg_t;
47  typedef typename MSG::resp_type record_t;
48 
51 
52  /**
53  * Default Constructor
54  */
56  : cmd()
57  {
58  }
59 
60  /**
61  * Destructor
62  */
63  virtual ~dump_cmd() {}
64 
65  dump_cmd(const dump_cmd& d) = default;
66 
67  /**
68  * Constant iterator to the start of the records retunred during the dump
69  */
71  {
72  /*
73  * m_dump is NULL during client UT when the commands are not issued.
74  */
75  if (!m_dump)
76  return const_iterator();
77  return (m_dump->get_result_set().begin());
78  }
79 
80  /**
81  * Constant iterator to the end of the records retunred during the dump
82  */
84  {
85  if (!m_dump)
86  return const_iterator();
87  return (m_dump->get_result_set().end());
88  }
89 
90  /**
91  * Wait for the issue of the command to complete
92  */
94  {
95  std::future_status status;
96  std::future<rc_t> result;
97 
98  result = m_promise.get_future();
99  status = result.wait_for(std::chrono::seconds(5));
100 
101  if (status != std::future_status::ready) {
102  return (rc_t::TIMEOUT);
103  }
104 
105  return (result.get());
106  }
107 
108  /**
109  * Call operator called when the dump is complete
110  */
112  {
113  m_promise.set_value(rc_t::OK);
114 
115  return (VAPI_OK);
116  }
117 
118  /**
119  * Retire/cancel a long running command
120  */
121  virtual void retire(connection& con) {}
122 
123 protected:
124  /**
125  * The underlying promise that implements the synchornous nature
126  * of the command issue
127  */
128  std::promise<rc_t> m_promise;
129 
130  /**
131  * Dump commands should not be issued whilst the HW is disabled
132  */
133  void succeeded() {}
134 
135  /**
136  * The HW::cmd_q is a friend so it can call suceedded.
137  */
138  friend class HW::cmd_q;
139 
140  /**
141  * The VAPI event registration
142  */
143  std::unique_ptr<MSG> m_dump;
144 };
145 };
146 
147 /*
148  * fd.io coding-style-patch-verification: ON
149  *
150  * Local Variables:
151  * eval: (c-set-style "mozilla")
152  * End:
153  */
154 
155 #endif
virtual ~dump_cmd()
Destructor.
Definition: dump_cmd.hpp:63
MSG::resp_type record_t
Definition: dump_cmd.hpp:47
vapi_error_e operator()(MSG &d)
Call operator called when the dump is complete.
Definition: dump_cmd.hpp:111
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
C++ VPP API.
virtual void retire(connection &con)
Retire/cancel a long running command.
Definition: dump_cmd.hpp:121
const_iterator begin()
Constant iterator to the start of the records retunred during the dump.
Definition: dump_cmd.hpp:70
A representation of the connection to VPP.
Definition: connection.hpp:33
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
void succeeded()
Dump commands should not be issued whilst the HW is disabled.
Definition: dump_cmd.hpp:133
The pipe to VPP into which we write the commands.
Definition: hw.hpp:187
const_iterator end()
Constant iterator to the end of the records retunred during the dump.
Definition: dump_cmd.hpp:83
unsigned int(* get_msg_size_t)(void *)
A function type def for calculating a message&#39;s size.
Definition: dump_cmd.hpp:30
typename std::vector< Msg< M >, typename Msg< M >::Msg_allocator >::const_iterator const_iterator
Definition: vapi.hpp:723
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
success
Definition: vapi_common.h:27
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
std::promise< rc_t > m_promise
The underlying promise that implements the synchornous nature of the command issue.
Definition: dump_cmd.hpp:128
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
std::unique_ptr< MSG > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
vapi::Result_set< typename MSG::resp_type >::const_iterator const_iterator
Definition: dump_cmd.hpp:50
A base class for VPP dump commands.
Definition: dump_cmd.hpp:43
static const rc_t TIMEOUT
HW write timedout - VPP did not respond within a timely manner.
Definition: types.hpp:119
vapi_error_e
Definition: vapi_common.h:25