deprecate tapcli
[vpp.git] / extras / vom / vom / gbp_vxlan_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 "vom/gbp_vxlan_cmds.hpp"
17
18 namespace VOM {
19 namespace gbp_vxlan_cmds {
20 create_cmd::create_cmd(HW::item<handle_t>& item,
21                        const std::string& name,
22                        uint32_t vni,
23                        bool is_l2,
24                        uint32_t bd_rd)
25   : interface::create_cmd<vapi::Gbp_vxlan_tunnel_add>(item, name)
26   , m_vni(vni)
27   , m_is_l2(is_l2)
28   , m_bd_rd(bd_rd)
29 {
30 }
31
32 rc_t
33 create_cmd::issue(connection& con)
34 {
35   msg_t req(con.ctx(), std::ref(*this));
36
37   auto& payload = req.get_request().get_payload();
38
39   payload.tunnel.vni = m_vni;
40   payload.tunnel.bd_rd_id = m_bd_rd;
41   if (m_is_l2)
42     payload.tunnel.mode = GBP_VXLAN_TUNNEL_MODE_L2;
43   else
44     payload.tunnel.mode = GBP_VXLAN_TUNNEL_MODE_L3;
45
46   VAPI_CALL(req.execute());
47
48   wait();
49   if (m_hw_item.rc() == rc_t::OK) {
50     insert_interface();
51   }
52
53   return (m_hw_item.rc());
54 }
55
56 std::string
57 create_cmd::to_string() const
58 {
59   std::ostringstream s;
60   s << "gbp-vxlan-create: " << m_hw_item.to_string() << " vni:" << m_vni
61     << " bd/rd:" << m_bd_rd;
62
63   return (s.str());
64 }
65
66 delete_cmd::delete_cmd(HW::item<handle_t>& item, uint32_t vni)
67   : interface::delete_cmd<vapi::Gbp_vxlan_tunnel_del>(item)
68   , m_vni(vni)
69 {
70 }
71
72 rc_t
73 delete_cmd::issue(connection& con)
74 {
75   msg_t req(con.ctx(), std::ref(*this));
76
77   auto& payload = req.get_request().get_payload();
78   payload.vni = m_vni;
79
80   VAPI_CALL(req.execute());
81
82   wait();
83   m_hw_item.set(rc_t::NOOP);
84
85   remove_interface();
86   return rc_t::OK;
87 }
88
89 std::string
90 delete_cmd::to_string() const
91 {
92   std::ostringstream s;
93   s << "gbp-vxlan-delete: " << m_hw_item.to_string() << " vni:" << m_vni;
94
95   return (s.str());
96 }
97
98 dump_cmd::dump_cmd()
99 {
100 }
101
102 bool
103 dump_cmd::operator==(const dump_cmd& other) const
104 {
105   return (true);
106 }
107
108 rc_t
109 dump_cmd::issue(connection& con)
110 {
111   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
112
113   VAPI_CALL(m_dump->execute());
114
115   wait();
116
117   return rc_t::OK;
118 }
119
120 std::string
121 dump_cmd::to_string() const
122 {
123   return ("gbp-vxlan-dump");
124 }
125
126 } // namespace gbp_vxlan_cmds
127 } // namespace VOM
128
129 /*
130  * fd.io coding-style-patch-verification: ON
131  *
132  * Local Variables:
133  * eval: (c-set-style "mozilla")
134  * End:
135  */