1ed76ee24SMohsin Kazmi/*
2ed76ee24SMohsin Kazmi * Copyright (c) 2018 Cisco and/or its affiliates.
3ed76ee24SMohsin Kazmi * Licensed under the Apache License, Version 2.0 (the "License");
4ed76ee24SMohsin Kazmi * you may not use this file except in compliance with the License.
5ed76ee24SMohsin Kazmi * You may obtain a copy of the License at:
6ed76ee24SMohsin Kazmi *
7ed76ee24SMohsin Kazmi *     http://www.apache.org/licenses/LICENSE-2.0
8ed76ee24SMohsin Kazmi *
9ed76ee24SMohsin Kazmi * Unless required by applicable law or agreed to in writing, software
10ed76ee24SMohsin Kazmi * distributed under the License is distributed on an "AS IS" BASIS,
11ed76ee24SMohsin Kazmi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12ed76ee24SMohsin Kazmi * See the License for the specific language governing permissions and
13ed76ee24SMohsin Kazmi * limitations under the License.
14ed76ee24SMohsin Kazmi */
15ed76ee24SMohsin Kazmi
16ed76ee24SMohsin Kazmi#include "vom/bond_interface_cmds.hpp"
17ed76ee24SMohsin Kazmi
18ed76ee24SMohsin KazmiDEFINE_VAPI_MSG_IDS_BOND_API_JSON;
19ed76ee24SMohsin Kazmi
20ed76ee24SMohsin Kazminamespace VOM {
21ed76ee24SMohsin Kazminamespace bond_interface_cmds {
22ed76ee24SMohsin Kazmicreate_cmd::create_cmd(HW::item<handle_t>& item,
23ed76ee24SMohsin Kazmi                       const std::string& name,
24ed76ee24SMohsin Kazmi                       const bond_interface::mode_t& mode,
25ed76ee24SMohsin Kazmi                       const bond_interface::lb_t& lb,
26ed76ee24SMohsin Kazmi                       const l2_address_t& l2_address)
27ed76ee24SMohsin Kazmi  : interface::create_cmd<vapi::Bond_create>(item, name)
28ed76ee24SMohsin Kazmi  , m_mode(mode)
29ed76ee24SMohsin Kazmi  , m_lb(lb)
30ed76ee24SMohsin Kazmi  , m_l2_address(l2_address)
31ed76ee24SMohsin Kazmi{
32ed76ee24SMohsin Kazmi}
33ed76ee24SMohsin Kazmi
34ed76ee24SMohsin Kazmirc_t
35ed76ee24SMohsin Kazmicreate_cmd::issue(connection& con)
36ed76ee24SMohsin Kazmi{
37ed76ee24SMohsin Kazmi  msg_t req(con.ctx(), std::ref(*this));
38ed76ee24SMohsin Kazmi
39ed76ee24SMohsin Kazmi  auto& payload = req.get_request().get_payload();
40ed76ee24SMohsin Kazmi
41ed76ee24SMohsin Kazmi  if (m_l2_address != l2_address_t::ZERO) {
42ed76ee24SMohsin Kazmi    m_l2_address.to_bytes(payload.mac_address, 6);
43ed76ee24SMohsin Kazmi    payload.use_custom_mac = 1;
44ed76ee24SMohsin Kazmi  }
45ed76ee24SMohsin Kazmi
463d1ef873SJakub Grajciar  payload.mode = (vapi_enum_bond_mode)m_mode.value();
47ed76ee24SMohsin Kazmi  if ((m_mode == bond_interface::mode_t::XOR ||
48ed76ee24SMohsin Kazmi       m_mode == bond_interface::mode_t::LACP) &&
49ed76ee24SMohsin Kazmi      m_lb != bond_interface::lb_t::UNSPECIFIED)
503d1ef873SJakub Grajciar    payload.lb = (vapi_enum_bond_lb_algo)m_lb.value();
51ed76ee24SMohsin Kazmi
52ed76ee24SMohsin Kazmi  VAPI_CALL(req.execute());
53ed76ee24SMohsin Kazmi
54208c29aaSNeale Ranns  wait();
55208c29aaSNeale Ranns
56ed76ee24SMohsin Kazmi  if (m_hw_item.rc() == rc_t::OK) {
57ed76ee24SMohsin Kazmi    insert_interface();
58ed76ee24SMohsin Kazmi  }
59ed76ee24SMohsin Kazmi
60ed76ee24SMohsin Kazmi  return rc_t::OK;
61ed76ee24SMohsin Kazmi}
62ed76ee24SMohsin Kazmi
63ed76ee24SMohsin Kazmistd::string
64ed76ee24SMohsin Kazmicreate_cmd::to_string() const
65ed76ee24SMohsin Kazmi{
66ed76ee24SMohsin Kazmi  std::ostringstream s;
67ed76ee24SMohsin Kazmi  s << "bond-intf-create: " << m_hw_item.to_string();
68ed76ee24SMohsin Kazmi
69ed76ee24SMohsin Kazmi  return (s.str());
70ed76ee24SMohsin Kazmi}
71ed76ee24SMohsin Kazmi
72ed76ee24SMohsin Kazmidelete_cmd::delete_cmd(HW::item<handle_t>& item)
73ed76ee24SMohsin Kazmi  : interface::delete_cmd<vapi::Bond_delete>(item)
74ed76ee24SMohsin Kazmi{
75ed76ee24SMohsin Kazmi}
76ed76ee24SMohsin Kazmi
77ed76ee24SMohsin Kazmirc_t
78ed76ee24SMohsin Kazmidelete_cmd::issue(connection& con)
79ed76ee24SMohsin Kazmi{
80ed76ee24SMohsin Kazmi  msg_t req(con.ctx(), std::ref(*this));
81ed76ee24SMohsin Kazmi
82ed76ee24SMohsin Kazmi  auto& payload = req.get_request().get_payload();
83ed76ee24SMohsin Kazmi  payload.sw_if_index = m_hw_item.data().value();
84ed76ee24SMohsin Kazmi
85ed76ee24SMohsin Kazmi  VAPI_CALL(req.execute());
86ed76ee24SMohsin Kazmi
87ed76ee24SMohsin Kazmi  wait();
88ed76ee24SMohsin Kazmi  m_hw_item.set(rc_t::NOOP);
89ed76ee24SMohsin Kazmi  remove_interface();
90ed76ee24SMohsin Kazmi
91ed76ee24SMohsin Kazmi  return rc_t::OK;
92ed76ee24SMohsin Kazmi}
93ed76ee24SMohsin Kazmi
94ed76ee24SMohsin Kazmistd::string
95ed76ee24SMohsin Kazmidelete_cmd::to_string() const
96ed76ee24SMohsin Kazmi{
97ed76ee24SMohsin Kazmi  std::ostringstream s;
98ed76ee24SMohsin Kazmi  s << "bond-itf-delete: " << m_hw_item.to_string();
99ed76ee24SMohsin Kazmi
100ed76ee24SMohsin Kazmi  return (s.str());
101ed76ee24SMohsin Kazmi}
102ed76ee24SMohsin Kazmi
103ed76ee24SMohsin Kazmidump_cmd::dump_cmd()
104ed76ee24SMohsin Kazmi{
105ed76ee24SMohsin Kazmi}
106ed76ee24SMohsin Kazmi
107ed76ee24SMohsin Kazmibool
108ed76ee24SMohsin Kazmidump_cmd::operator==(const dump_cmd& other) const
109ed76ee24SMohsin Kazmi{
110ed76ee24SMohsin Kazmi  return (true);
111ed76ee24SMohsin Kazmi}
112ed76ee24SMohsin Kazmi
113ed76ee24SMohsin Kazmirc_t
114ed76ee24SMohsin Kazmidump_cmd::issue(connection& con)
115ed76ee24SMohsin Kazmi{
116ed76ee24SMohsin Kazmi  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
117ed76ee24SMohsin Kazmi
118ed76ee24SMohsin Kazmi  VAPI_CALL(m_dump->execute());
119ed76ee24SMohsin Kazmi
120ed76ee24SMohsin Kazmi  wait();
121ed76ee24SMohsin Kazmi
122ed76ee24SMohsin Kazmi  return rc_t::OK;
123ed76ee24SMohsin Kazmi}
124ed76ee24SMohsin Kazmi
125ed76ee24SMohsin Kazmistd::string
126ed76ee24SMohsin Kazmidump_cmd::to_string() const
127ed76ee24SMohsin Kazmi{
128ed76ee24SMohsin Kazmi  return ("bond-itf-dump");
129ed76ee24SMohsin Kazmi}
130ed76ee24SMohsin Kazmi} // namespace bond_interface_cmds
131ed76ee24SMohsin Kazmi} // namespace VOM
132ed76ee24SMohsin Kazmi
133ed76ee24SMohsin Kazmi/*
134ed76ee24SMohsin Kazmi * fd.io coding-style-patch-verification: ON
135ed76ee24SMohsin Kazmi *
136ed76ee24SMohsin Kazmi * Local Variables:
137ed76ee24SMohsin Kazmi * eval: (c-set-style "mozilla")
138ed76ee24SMohsin Kazmi * End:
139ed76ee24SMohsin Kazmi */
140