FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
l3_binding_cmds.cpp
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 #include "vom/l3_binding_cmds.hpp"
17 
19 
20 namespace VOM {
21 namespace l3_binding_cmds {
23  const handle_t& itf,
24  const route::prefix_t& pfx)
25  : rpc_cmd(item)
26  , m_itf(itf)
27  , m_pfx(pfx)
28 {
29 }
30 
31 bool
32 bind_cmd::operator==(const bind_cmd& other) const
33 {
34  return ((m_itf == other.m_itf) && (m_pfx == other.m_pfx));
35 }
36 
37 rc_t
39 {
40  msg_t req(con.ctx(), std::ref(*this));
41 
42  auto& payload = req.get_request().get_payload();
43  payload.sw_if_index = m_itf.value();
44  payload.is_add = 1;
45  payload.del_all = 0;
46 
47  m_pfx.to_vpp((uint8_t*)&payload.prefix.address.af,
48  (uint8_t*)&payload.prefix.address,
49  (uint8_t*)&payload.prefix.len);
50 
51  VAPI_CALL(req.execute());
52 
53  return (wait());
54 }
55 
58 {
59  std::ostringstream s;
60  s << "L3-bind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
61  << " pfx:" << m_pfx.to_string();
62 
63  return (s.str());
64 }
65 
67  const handle_t& itf,
68  const route::prefix_t& pfx)
69  : rpc_cmd(item)
70  , m_itf(itf)
71  , m_pfx(pfx)
72 {
73 }
74 
75 bool
77 {
78  return ((m_itf == other.m_itf) && (m_pfx == other.m_pfx));
79 }
80 
81 rc_t
83 {
84  msg_t req(con.ctx(), std::ref(*this));
85 
86  auto& payload = req.get_request().get_payload();
87  payload.sw_if_index = m_itf.value();
88  payload.is_add = 0;
89  payload.del_all = 0;
90 
91  m_pfx.to_vpp((uint8_t*)&payload.prefix.address.af,
92  (uint8_t*)&payload.prefix.address,
93  (uint8_t*)&payload.prefix.len);
94 
95  VAPI_CALL(req.execute());
96 
97  wait();
99 
100  return rc_t::OK;
101 }
102 
105 {
106  std::ostringstream s;
107  s << "L3-unbind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
108  << " pfx:" << m_pfx.to_string();
109 
110  return (s.str());
111 }
112 
114  : m_itf(hdl)
115 {
116 }
117 
119  : m_itf(d.m_itf)
120 {
121 }
122 
123 bool
125 {
126  return (true);
127 }
128 
129 rc_t
131 {
132  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
133 
134  auto& payload = m_dump->get_request().get_payload();
135  payload.sw_if_index = m_itf.value();
136  payload.is_ipv6 = 0;
137 
138  VAPI_CALL(m_dump->execute());
139 
140  wait();
141 
142  return rc_t::OK;
143 }
144 
147 {
148  return ("L3-binding-dump");
149 }
150 
151 }; // namespace l3_binding_cmds
152 }; // namespace VOM
153 
154 /*
155  * fd.io coding-style-patch-verification: OFF
156  *
157  * Local Variables:
158  * eval: (c-set-style "mozilla")
159  * End:
160  */
VOM::route::prefix_t
A prefix defintion.
Definition: prefix.hpp:131
VOM::HW::item< bool >
VOM::dump_cmd< vapi::Ip_address_dump >::msg_t
vapi::Ip_address_dump msg_t
Definition: dump_cmd.hpp:46
VOM::l3_binding_cmds::bind_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: l3_binding_cmds.cpp:38
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_add_del_address >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
Definition: hw.hpp:125
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::l3_binding_cmds::dump_v4_cmd::operator==
bool operator==(const dump_v4_cmd &i) const
Comparison operator - only used for UT.
Definition: l3_binding_cmds.cpp:124
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::l3_binding_cmds::unbind_cmd::unbind_cmd
unbind_cmd(HW::item< bool > &item, const handle_t &itf, const route::prefix_t &pfx)
Constructor.
Definition: l3_binding_cmds.cpp:66
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::l3_binding_cmds::dump_v4_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: l3_binding_cmds.cpp:130
VOM::l3_binding_cmds::bind_cmd
A functor class that binds the L3 config to the interface.
Definition: l3_binding_cmds.hpp:32
VOM::l3_binding_cmds::dump_v4_cmd
A cmd class that Dumps all the IPv4 L3 configs.
Definition: l3_binding_cmds.hpp:112
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_add_del_address >::m_hw_item
HW::item< bool > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::dump_cmd< vapi::Ip_address_dump >::m_dump
std::unique_ptr< vapi::Ip_address_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::route::prefix_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:214
VOM::l3_binding_cmds::unbind_cmd::operator==
bool operator==(const unbind_cmd &i) const
Comparison operator - only used for UT.
Definition: l3_binding_cmds.cpp:76
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::l3_binding_cmds::bind_cmd::operator==
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
Definition: l3_binding_cmds.cpp:32
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::dump_cmd< vapi::Ip_address_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
l3_binding_cmds.hpp
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
VOM::l3_binding_cmds::dump_v4_cmd::dump_v4_cmd
dump_v4_cmd(const handle_t &itf)
Constructor.
Definition: l3_binding_cmds.cpp:113
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::l3_binding_cmds::dump_v4_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: l3_binding_cmds.cpp:146
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_add_del_address >::msg_t
vapi::Sw_interface_add_del_address msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::l3_binding_cmds::bind_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: l3_binding_cmds.cpp:57
VOM::l3_binding_cmds::unbind_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: l3_binding_cmds.cpp:82
VOM::handle_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
VOM::route::prefix_t::to_vpp
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
Definition: prefix.cpp:282
DEFINE_VAPI_MSG_IDS_IP_API_JSON
DEFINE_VAPI_MSG_IDS_IP_API_JSON
Definition: l3_binding_cmds.cpp:18
VOM::l3_binding_cmds::unbind_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: l3_binding_cmds.cpp:104
item
cJSON * item
Definition: cJSON.h:222
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::l3_binding_cmds::bind_cmd::bind_cmd
bind_cmd(HW::item< bool > &item, const handle_t &itf, const route::prefix_t &pfx)
Constructor.
Definition: l3_binding_cmds.cpp:22
VOM::l3_binding_cmds::unbind_cmd
A cmd class that Unbinds L3 Config from an interface.
Definition: l3_binding_cmds.hpp:72
string
const char *const string
Definition: cJSON.h:172