fib: fib api updates
[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.route.table_id = m_id;
101   payload.is_add = 0;
102   payload.is_multipath = 0;
103
104   payload.route.table_id = m_id;
105   payload.route.prefix = to_api(m_prefix);
106
107   VAPI_CALL(req.execute());
108
109   wait();
110   m_hw_item.set(rc_t::NOOP);
111
112   return rc_t::OK;
113 }
114
115 std::string
116 delete_cmd::to_string() const
117 {
118   std::ostringstream s;
119   s << "ip-route-delete: " << m_hw_item.to_string() << " id:" << m_id
120     << " prefix:" << m_prefix.to_string();
121
122   return (s.str());
123 }
124
125 dump_cmd::dump_cmd(route::table_id_t id, const l3_proto_t& proto)
126   : m_id(id)
127   , m_proto(proto)
128 {
129 }
130
131 bool
132 dump_cmd::operator==(const dump_cmd& other) const
133 {
134   return (true);
135 }
136
137 rc_t
138 dump_cmd::issue(connection& con)
139 {
140   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
141
142   auto& payload = m_dump->get_request().get_payload();
143
144   payload.table.table_id = m_id;
145   payload.table.is_ip6 = m_proto.is_ipv6();
146
147   VAPI_CALL(m_dump->execute());
148
149   wait();
150
151   return rc_t::OK;
152 }
153
154 std::string
155 dump_cmd::to_string() const
156 {
157   return ("ip-route-v4-dump");
158 }
159
160 } // namespace ip_route_cmds
161 } // namespace route
162 } // namespace vom
163
164 /*
165  * fd.io coding-style-patch-verification: ON
166  *
167  * Local Variables:
168  * eval: (c-set-style "mozilla")
169  * End:
170  */