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