vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / route_cmds.cpp
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 <sstream>
17
18 #include <vom/api_types.hpp>
19 #include <vom/route_api_types.hpp>
20 #include <vom/route_cmds.hpp>
21
22 namespace VOM {
23 namespace route {
24 namespace ip_route_cmds {
25
26 update_cmd::update_cmd(HW::item<handle_t>& item,
27                        table_id_t id,
28                        const prefix_t& prefix,
29                        const path_list_t& pl)
30   : srpc_cmd(item)
31   , m_id(id)
32   , m_prefix(prefix)
33   , m_pl(pl)
34 {
35 }
36
37 bool
38 update_cmd::operator==(const update_cmd& other) const
39 {
40   return ((m_prefix == other.m_prefix) && (m_id == other.m_id) &&
41           (m_pl == other.m_pl));
42 }
43
44 rc_t
45 update_cmd::issue(connection& con)
46 {
47   msg_t req(con.ctx(), m_pl.size(), std::ref(*this));
48
49   auto& payload = req.get_request().get_payload();
50
51   payload.route.table_id = m_id;
52   payload.is_add = 1;
53   payload.is_multipath = 1;
54
55   payload.route.table_id = m_id;
56   payload.route.prefix = to_api(m_prefix);
57
58   uint32_t ii = 0;
59   for (auto& p : m_pl)
60     to_api(p, payload.route.paths[ii++]);
61
62   VAPI_CALL(req.execute());
63
64   return (wait());
65 }
66
67 std::string
68 update_cmd::to_string() const
69 {
70   std::ostringstream s;
71   s << "ip-route-create: " << m_hw_item.to_string() << " table-id:" << m_id
72     << " prefix:" << m_prefix.to_string() << " paths:";
73   for (auto p : m_pl)
74     s << p.to_string() << " ";
75
76   return (s.str());
77 }
78
79 delete_cmd::delete_cmd(HW::item<handle_t>& item,
80                        table_id_t id,
81                        const prefix_t& prefix)
82   : rpc_cmd(item)
83   , m_id(id)
84   , m_prefix(prefix)
85 {
86 }
87
88 bool
89 delete_cmd::operator==(const delete_cmd& other) const
90 {
91   return ((m_prefix == other.m_prefix) && (m_id == other.m_id));
92 }
93
94 rc_t
95 delete_cmd::issue(connection& con)
96 {
97   msg_t req(con.ctx(), 0, std::ref(*this));
98
99   auto& payload = req.get_request().get_payload();
100   payload.is_add = 0;
101   payload.is_multipath = 0;
102
103   payload.route.table_id = m_id;
104   payload.route.n_paths = 0;
105   payload.route.table_id = m_id;
106   payload.route.prefix = to_api(m_prefix);
107
108   VAPI_CALL(req.execute());
109
110   wait();
111   m_hw_item.set(rc_t::NOOP);
112
113   return rc_t::OK;
114 }
115
116 std::string
117 delete_cmd::to_string() const
118 {
119   std::ostringstream s;
120   s << "ip-route-delete: " << m_hw_item.to_string() << " id:" << m_id
121     << " prefix:" << m_prefix.to_string();
122
123   return (s.str());
124 }
125
126 dump_cmd::dump_cmd(route::table_id_t id, const l3_proto_t& proto)
127   : m_id(id)
128   , m_proto(proto)
129 {
130 }
131
132 bool
133 dump_cmd::operator==(const dump_cmd& other) const
134 {
135   return (true);
136 }
137
138 rc_t
139 dump_cmd::issue(connection& con)
140 {
141   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
142
143   auto& payload = m_dump->get_request().get_payload();
144
145   payload.table.table_id = m_id;
146   payload.table.is_ip6 = m_proto.is_ipv6();
147
148   VAPI_CALL(m_dump->execute());
149
150   wait();
151
152   return rc_t::OK;
153 }
154
155 std::string
156 dump_cmd::to_string() const
157 {
158   return ("ip-route-v4-dump");
159 }
160
161 } // namespace ip_route_cmds
162 } // namespace route
163 } // namespace vom
164
165 /*
166  * fd.io coding-style-patch-verification: ON
167  *
168  * Local Variables:
169  * eval: (c-set-style "mozilla")
170  * End:
171  */