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