VOM: support for pipes
[vpp.git] / extras / vom / vom / pipe_cmds.cpp
1 /*
2  * Copyright (c) 2018 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/pipe_cmds.hpp"
17
18 DEFINE_VAPI_MSG_IDS_PIPE_API_JSON;
19
20 namespace VOM {
21 namespace pipe_cmds {
22
23 create_cmd::create_cmd(HW::item<handle_t>& item,
24                        const std::string& name,
25                        uint32_t instance,
26                        HW::item<pipe::handle_pair_t>& ends)
27   : interface::create_cmd<vapi::Pipe_create>(item, name)
28   , m_hdl_pair(ends)
29   , m_instance(instance)
30 {
31 }
32
33 bool
34 create_cmd::operator==(const create_cmd& other) const
35 {
36   return (m_name == other.m_name);
37 }
38
39 vapi_error_e
40 create_cmd::operator()(vapi::Pipe_create& reply)
41 {
42   auto& payload = reply.get_response().get_payload();
43
44   VOM_LOG(log_level_t::DEBUG) << to_string() << " " << payload.retval;
45
46   const rc_t& rc = rc_t::from_vpp_retval(payload.retval);
47
48   m_hdl_pair = { pipe::handle_pair_t(payload.pipe_sw_if_index[0],
49                                      payload.pipe_sw_if_index[1]),
50                  rc };
51
52   fulfill(HW::item<handle_t>(payload.sw_if_index, rc));
53
54   return (VAPI_OK);
55 }
56 rc_t
57 create_cmd::issue(connection& con)
58 {
59   msg_t req(con.ctx(), std::ref(*this));
60
61   auto& payload = req.get_request().get_payload();
62
63   payload.is_specified = 1;
64   payload.user_instance = m_instance;
65
66   VAPI_CALL(req.execute());
67
68   if (rc_t::OK == wait()) {
69     insert_interface();
70   }
71
72   return rc_t::OK;
73 }
74
75 std::string
76 create_cmd::to_string() const
77 {
78   std::ostringstream s;
79
80   s << "pipe-create: " << m_name << " instance:" << m_instance;
81
82   return (s.str());
83 }
84
85 delete_cmd::delete_cmd(HW::item<handle_t>& item,
86                        HW::item<pipe::handle_pair_t>& end_pair)
87   : interface::delete_cmd<vapi::Pipe_delete>(item)
88   , m_hdl_pair(end_pair)
89 {
90 }
91
92 bool
93 delete_cmd::operator==(const delete_cmd& other) const
94 {
95   return (m_hw_item == other.m_hw_item);
96 }
97
98 rc_t
99 delete_cmd::issue(connection& con)
100 {
101   msg_t req(con.ctx(), std::ref(*this));
102
103   VAPI_CALL(req.execute());
104
105   wait();
106   m_hw_item.set(rc_t::NOOP);
107   m_hdl_pair.set(rc_t::NOOP);
108
109   remove_interface();
110
111   return (rc_t::OK);
112 }
113
114 std::string
115 delete_cmd::to_string() const
116 {
117   return ("pipe-delete");
118 }
119
120 bool
121 dump_cmd::operator==(const dump_cmd& other) const
122 {
123   return (true);
124 }
125
126 rc_t
127 dump_cmd::issue(connection& con)
128 {
129   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
130
131   VAPI_CALL(m_dump->execute());
132
133   wait();
134
135   return rc_t::OK;
136 }
137
138 std::string
139 dump_cmd::to_string() const
140 {
141   return ("pipe-dump");
142 }
143
144 } // namespace pipe_cmds
145 } // namespace VOM
146
147 /*
148  * fd.io coding-style-patch-verification: ON
149  *
150  * Local Variables:
151  * eval: (c-set-style "mozilla")
152  * End:
153  */