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