vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / bridge_domain_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/bridge_domain_cmds.hpp"
17
18 DEFINE_VAPI_MSG_IDS_L2_API_JSON;
19
20 namespace VOM {
21 namespace bridge_domain_cmds {
22 create_cmd::create_cmd(HW::item<uint32_t>& item,
23                        const bridge_domain::learning_mode_t& lmode,
24                        const bridge_domain::arp_term_mode_t& amode,
25                        const bridge_domain::arp_ufwd_mode_t& aumode,
26                        const bridge_domain::flood_mode_t& fmode,
27                        const bridge_domain::uu_flood_mode_t& uufmode,
28                        const bridge_domain::mac_age_mode_t& mmode)
29   : rpc_cmd(item)
30   , m_learning_mode(lmode)
31   , m_arp_term_mode(amode)
32   , m_arp_ufwd_mode(aumode)
33   , m_flood_mode(fmode)
34   , m_uu_flood_mode(uufmode)
35   , m_mac_age_mode(mmode)
36 {
37 }
38
39 bool
40 create_cmd::operator==(const create_cmd& other) const
41 {
42   return (m_hw_item.data() == other.m_hw_item.data());
43 }
44
45 rc_t
46 create_cmd::issue(connection& con)
47 {
48   msg_t req(con.ctx(), std::ref(*this));
49
50   auto& payload = req.get_request().get_payload();
51   payload.bd_id = m_hw_item.data();
52   payload.flood = m_flood_mode.value();
53   payload.uu_flood = m_uu_flood_mode.value();
54   payload.forward = 1;
55   payload.learn = m_learning_mode.value();
56   payload.arp_term = m_arp_term_mode.value();
57   payload.arp_ufwd = m_arp_ufwd_mode.value();
58   payload.mac_age = m_mac_age_mode.value();
59   payload.is_add = 1;
60
61   VAPI_CALL(req.execute());
62
63   return (wait());
64 }
65
66 std::string
67 create_cmd::to_string() const
68 {
69   std::ostringstream s;
70   s << "bridge-domain-create: " << m_hw_item.to_string();
71
72   return (s.str());
73 }
74
75 delete_cmd::delete_cmd(HW::item<uint32_t>& item)
76   : rpc_cmd(item)
77 {
78 }
79
80 bool
81 delete_cmd::operator==(const delete_cmd& other) const
82 {
83   return (m_hw_item == other.m_hw_item);
84 }
85
86 rc_t
87 delete_cmd::issue(connection& con)
88 {
89   msg_t req(con.ctx(), std::ref(*this));
90
91   auto& payload = req.get_request().get_payload();
92   payload.bd_id = m_hw_item.data();
93   payload.is_add = 0;
94
95   VAPI_CALL(req.execute());
96
97   wait();
98   m_hw_item.set(rc_t::NOOP);
99
100   return (rc_t::OK);
101 }
102
103 std::string
104 delete_cmd::to_string() const
105 {
106   std::ostringstream s;
107   s << "bridge-domain-delete: " << m_hw_item.to_string();
108
109   return (s.str());
110 }
111
112 dump_cmd::dump_cmd()
113 {
114 }
115
116 bool
117 dump_cmd::operator==(const dump_cmd& other) const
118 {
119   return (true);
120 }
121
122 rc_t
123 dump_cmd::issue(connection& con)
124 {
125   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
126
127   auto& payload = m_dump->get_request().get_payload();
128   payload.bd_id = ~0;
129
130   VAPI_CALL(m_dump->execute());
131
132   wait();
133
134   return rc_t::OK;
135 }
136
137 std::string
138 dump_cmd::to_string() const
139 {
140   return ("bridge-domain-dump");
141 }
142 }
143 }
144
145 /*
146  * fd.io coding-style-patch-verification: ON
147  *
148  * Local Variables:
149  * eval: (c-set-style "mozilla")
150  * End:
151  */