FD.io VPP  v21.01.1
Vector Packet Processing
srpc_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_SRPC_CMD_H__
17 #define __VOM_SRPC_CMD_H__
18 
19 #include "vom/hw.hpp"
20 #include "vom/rpc_cmd.hpp"
21 
22 namespace VOM {
23 template <typename MSG>
24 class srpc_cmd : public rpc_cmd<HW::item<handle_t>, MSG>
25 {
26 public:
27  /**
28  * convenient typedef
29  */
30  typedef MSG msg_t;
31 
32  /**
33  * Constructor taking the HW item that will be updated by the command
34  */
36  : rpc_cmd<HW::item<handle_t>, MSG>(item)
37  {
38  }
39 
40  /**
41  * Desructor
42  */
43  virtual ~srpc_cmd() {}
44 
45  virtual vapi_error_e operator()(MSG& reply)
46  {
47  int stats_index = reply.get_response().get_payload().stats_index;
48  int retval = reply.get_response().get_payload().retval;
49 
50  VOM_LOG(log_level_t::DEBUG) << this->to_string() << " " << retval;
51 
52  rc_t rc = rc_t::from_vpp_retval(retval);
53  handle_t handle = handle_t::INVALID;
54 
55  if (rc_t::OK == rc) {
56  handle = stats_index;
57  }
58 
59  this->fulfill(HW::item<handle_t>(handle, rc));
60 
61  return (VAPI_OK);
62  }
63 };
64 };
65 
66 /*
67  * fd.io coding-style-patch-verification: OFF
68  *
69  * Local Variables:
70  * eval: (c-set-style "mozilla")
71  * End:
72  */
73 
74 #endif
virtual std::string to_string() const =0
convert to string format for debug purposes
static const rc_t & from_vpp_retval(int32_t rv)
Get the rc_t from the VPP API value.
Definition: types.cpp:33
MSG msg_t
convenient typedef
Definition: srpc_cmd.hpp:30
#define VOM_LOG(lvl)
Definition: logger.hpp:181
Definition: hw.hpp:34
virtual ~srpc_cmd()
Desructor.
Definition: srpc_cmd.hpp:43
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
static const log_level_t DEBUG
Definition: logger.hpp:32
srpc_cmd(HW::item< handle_t > &item)
Constructor taking the HW item that will be updated by the command.
Definition: srpc_cmd.hpp:35
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
virtual vapi_error_e operator()(MSG &reply)
call operator used as a callback by VAPI when the reply is available
Definition: srpc_cmd.hpp:45
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
void fulfill(const HW::item< handle_t > &d)
Fulfill the commands promise.
Definition: rpc_cmd.hpp:76
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
u32 stats_index
Definition: ip.api:143
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
success
Definition: vapi_common.h:27
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi_error_e
Definition: vapi_common.h:25