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