1/*
2 * Copyright (c) 2018 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/bond_interface_cmds.hpp"
17
18DEFINE_VAPI_MSG_IDS_BOND_API_JSON;
19
20namespace VOM {
21namespace bond_interface_cmds {
22create_cmd::create_cmd(HW::item<handle_t>& item,
23                       const std::string& name,
24                       const bond_interface::mode_t& mode,
25                       const bond_interface::lb_t& lb,
26                       const l2_address_t& l2_address)
27  : interface::create_cmd<vapi::Bond_create>(item, name)
28  , m_mode(mode)
29  , m_lb(lb)
30  , m_l2_address(l2_address)
31{
32}
33
34rc_t
35create_cmd::issue(connection& con)
36{
37  msg_t req(con.ctx(), std::ref(*this));
38
39  auto& payload = req.get_request().get_payload();
40
41  if (m_l2_address != l2_address_t::ZERO) {
42    m_l2_address.to_bytes(payload.mac_address, 6);
43    payload.use_custom_mac = 1;
44  }
45
46  payload.mode = (vapi_enum_bond_mode)m_mode.value();
47  if ((m_mode == bond_interface::mode_t::XOR ||
48       m_mode == bond_interface::mode_t::LACP) &&
49      m_lb != bond_interface::lb_t::UNSPECIFIED)
50    payload.lb = (vapi_enum_bond_lb_algo)m_lb.value();
51
52  VAPI_CALL(req.execute());
53
54  wait();
55
56  if (m_hw_item.rc() == rc_t::OK) {
57    insert_interface();
58  }
59
60  return rc_t::OK;
61}
62
63std::string
64create_cmd::to_string() const
65{
66  std::ostringstream s;
67  s << "bond-intf-create: " << m_hw_item.to_string();
68
69  return (s.str());
70}
71
72delete_cmd::delete_cmd(HW::item<handle_t>& item)
73  : interface::delete_cmd<vapi::Bond_delete>(item)
74{
75}
76
77rc_t
78delete_cmd::issue(connection& con)
79{
80  msg_t req(con.ctx(), std::ref(*this));
81
82  auto& payload = req.get_request().get_payload();
83  payload.sw_if_index = m_hw_item.data().value();
84
85  VAPI_CALL(req.execute());
86
87  wait();
88  m_hw_item.set(rc_t::NOOP);
89  remove_interface();
90
91  return rc_t::OK;
92}
93
94std::string
95delete_cmd::to_string() const
96{
97  std::ostringstream s;
98  s << "bond-itf-delete: " << m_hw_item.to_string();
99
100  return (s.str());
101}
102
103dump_cmd::dump_cmd()
104{
105}
106
107bool
108dump_cmd::operator==(const dump_cmd& other) const
109{
110  return (true);
111}
112
113rc_t
114dump_cmd::issue(connection& con)
115{
116  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
117
118  VAPI_CALL(m_dump->execute());
119
120  wait();
121
122  return rc_t::OK;
123}
124
125std::string
126dump_cmd::to_string() const
127{
128  return ("bond-itf-dump");
129}
130} // namespace bond_interface_cmds
131} // namespace VOM
132
133/*
134 * fd.io coding-style-patch-verification: ON
135 *
136 * Local Variables:
137 * eval: (c-set-style "mozilla")
138 * End:
139 */
140