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 "vom/sub_interface_cmds.hpp"
17#include "vom/cmd.hpp"
18
19#include <vapi/vpe.api.vapi.hpp>
20
21namespace VOM {
22namespace sub_interface_cmds {
23
24create_cmd::create_cmd(HW::item<handle_t>& item,
25                       const std::string& name,
26                       const handle_t& parent,
27                       uint16_t vlan)
28  : interface::create_cmd<vapi::Create_vlan_subif>(item, name)
29  , m_parent(parent)
30  , m_vlan(vlan)
31{
32}
33
34bool
35create_cmd::operator==(const create_cmd& other) const
36{
37  return ((m_name == other.m_name) && (m_parent == other.m_parent) &&
38          (m_vlan == other.m_vlan));
39}
40
41rc_t
42create_cmd::issue(connection& con)
43{
44  msg_t req(con.ctx(), std::ref(*this));
45
46  auto& payload = req.get_request().get_payload();
47  payload.sw_if_index = m_parent.value();
48  payload.vlan_id = m_vlan;
49
50  VAPI_CALL(req.execute());
51
52  wait();
53
54  if (m_hw_item.rc() == rc_t::OK) {
55    insert_interface();
56  }
57
58  return rc_t::OK;
59}
60
61std::string
62create_cmd::to_string() const
63{
64  std::ostringstream s;
65  s << "sub-itf-create: " << m_hw_item.to_string() << " parent:" << m_parent
66    << " vlan:" << m_vlan;
67  return (s.str());
68}
69
70delete_cmd::delete_cmd(HW::item<handle_t>& item)
71  : interface::delete_cmd<vapi::Delete_subif>(item)
72{
73}
74
75bool
76delete_cmd::operator==(const delete_cmd& other) const
77{
78  return (m_hw_item == other.m_hw_item);
79}
80
81rc_t
82delete_cmd::issue(connection& con)
83{
84  msg_t req(con.ctx(), std::ref(*this));
85
86  auto& payload = req.get_request().get_payload();
87  payload.sw_if_index = m_hw_item.data().value();
88
89  VAPI_CALL(req.execute());
90
91  wait();
92  m_hw_item.set(rc_t::NOOP);
93
94  remove_interface();
95  return (rc_t::OK);
96}
97
98std::string
99delete_cmd::to_string() const
100{
101  std::ostringstream s;
102
103  s << "sub-itf-delete: " << m_hw_item.to_string();
104
105  return (s.str());
106}
107} // namespace sub_interface_cmds
108} // namespace VOM
109  /*
110   * fd.io coding-style-patch-verification: ON
111   *
112   * Local Variables:
113   * eval: (c-set-style "mozilla")
114   * End:
115   */
116