vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / qos_map_cmds.cpp
1 /*
2  * Copyright (c) 2019 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/qos_map_cmds.hpp"
17 #include "vom/qos_types_api.hpp"
18
19 namespace VOM {
20 namespace QoS {
21 namespace map_cmds {
22
23 static void
24 to_api(const map::outputs_t& o, vapi_type_qos_egress_map_row rows[4])
25 {
26   for (uint32_t ii = 0; ii < 4; ii++) {
27     std::copy(o[ii].begin(), o[ii].end(), std::begin(rows[ii].outputs));
28   }
29 }
30
31 create_cmd::create_cmd(HW::item<bool>& item,
32                        uint32_t id,
33                        const map::outputs_t& o)
34   : rpc_cmd(item)
35   , m_id(id)
36   , m_outputs(o)
37 {
38 }
39
40 bool
41 create_cmd::operator==(const create_cmd& other) const
42 {
43   return (m_id == other.m_id && m_outputs == other.m_outputs);
44 }
45
46 rc_t
47 create_cmd::issue(connection& con)
48 {
49   msg_t req(con.ctx(), std::ref(*this));
50
51   auto& payload = req.get_request().get_payload();
52
53   payload.map.id = m_id;
54   to_api(m_outputs, payload.map.rows);
55
56   VAPI_CALL(req.execute());
57
58   return (wait());
59 }
60
61 std::string
62 create_cmd::to_string() const
63 {
64   std::ostringstream s;
65   s << "qos-map-create: " << m_hw_item.to_string() << " map:" << m_id;
66
67   return (s.str());
68 }
69
70 delete_cmd::delete_cmd(HW::item<bool>& item, uint32_t id)
71   : rpc_cmd(item)
72   , m_id(id)
73 {
74 }
75
76 bool
77 delete_cmd::operator==(const delete_cmd& other) const
78 {
79   return (m_hw_item == other.m_hw_item && m_id == other.m_id);
80 }
81
82 rc_t
83 delete_cmd::issue(connection& con)
84 {
85   msg_t req(con.ctx(), std::ref(*this));
86
87   auto& payload = req.get_request().get_payload();
88   payload.map.id = m_id;
89
90   VAPI_CALL(req.execute());
91
92   return (wait());
93 }
94
95 std::string
96 delete_cmd::to_string() const
97 {
98   std::ostringstream s;
99   s << "qos-map-delete: " << m_hw_item.to_string() << " map:" << m_id;
100
101   return (s.str());
102 }
103
104 dump_cmd::dump_cmd()
105 {
106 }
107
108 bool
109 dump_cmd::operator==(const dump_cmd& other) const
110 {
111   return (true);
112 }
113
114 rc_t
115 dump_cmd::issue(connection& con)
116 {
117   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
118
119   VAPI_CALL(m_dump->execute());
120
121   wait();
122
123   return rc_t::OK;
124 }
125
126 std::string
127 dump_cmd::to_string() const
128 {
129   return ("qos-map-dump");
130 }
131
132 }; // namespace map_cmds
133 }; // namespace QoS
134 }; // namespace VOM
135
136 /*
137  * fd.io coding-style-patch-verification: ON
138  *
139  * Local Variables:
140  * eval: (c-set-style "mozilla")
141  * End:
142  */