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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/gbp_contract_cmds.hpp"
17 #include "vom/api_types.hpp"
20 namespace gbp_contract_cmds {
22 create_cmd::create_cmd(HW::item<bool>& item,
26 const gbp_contract::gbp_rules_t& gbp_rules,
27 const gbp_contract::ethertype_set_t& allowed_ethertypes)
29 , m_src_epg_id(src_epg_id)
30 , m_dst_epg_id(dst_epg_id)
32 , m_gbp_rules(gbp_rules)
33 , m_allowed_ethertypes(allowed_ethertypes)
38 create_cmd::operator==(const create_cmd& other) const
40 return ((m_acl == other.m_acl) && (m_src_epg_id == other.m_src_epg_id) &&
41 (m_dst_epg_id == other.m_dst_epg_id) &&
42 (m_gbp_rules == other.m_gbp_rules) &&
43 (m_allowed_ethertypes == other.m_allowed_ethertypes));
47 create_cmd::issue(connection& con)
49 size_t n_rules = m_gbp_rules.size();
50 size_t n_et_rules = 0;
52 msg_t req(con.ctx(), n_rules, n_et_rules, std::ref(*this));
54 auto& payload = req.get_request().get_payload();
56 payload.contract.acl_index = m_acl.value();
57 payload.contract.src_epg = m_src_epg_id;
58 payload.contract.dst_epg = m_dst_epg_id;
61 payload.contract.n_rules = n_rules;
63 for (auto rule : m_gbp_rules) {
64 if (rule.action() == gbp_rule::action_t::REDIRECT)
65 payload.contract.rules[ii].action = GBP_API_RULE_REDIRECT;
66 else if (rule.action() == gbp_rule::action_t::PERMIT)
67 payload.contract.rules[ii].action = GBP_API_RULE_PERMIT;
69 payload.contract.rules[ii].action = GBP_API_RULE_DENY;
71 if (rule.nhs().hash_mode() == gbp_rule::hash_mode_t::SYMMETRIC)
72 payload.contract.rules[ii].nh_set.hash_mode = GBP_API_HASH_MODE_SYMMETRIC;
73 else if (rule.nhs().hash_mode() == gbp_rule::hash_mode_t::SRC_IP)
74 payload.contract.rules[ii].nh_set.hash_mode = GBP_API_HASH_MODE_SRC_IP;
76 payload.contract.rules[ii].nh_set.hash_mode = GBP_API_HASH_MODE_DST_IP;
78 const gbp_rule::next_hops_t& next_hops = rule.nhs().next_hops();
79 uint8_t jj = 0, nh_size = (next_hops.size() > 8) ? 8 : next_hops.size();
81 payload.contract.rules[ii].nh_set.n_nhs = nh_size;
82 for (auto nh : next_hops) {
83 to_api(nh.getIp(), payload.contract.rules[ii].nh_set.nhs[jj].ip);
84 to_api(nh.getMac(), payload.contract.rules[ii].nh_set.nhs[jj].mac);
85 payload.contract.rules[ii].nh_set.nhs[jj].bd_id = nh.getBdId();
86 payload.contract.rules[ii].nh_set.nhs[jj].rd_id = nh.getRdId();
95 data = (((u8*)&payload.contract.n_ether_types) +
96 (sizeof(payload.contract.rules[0]) * payload.contract.n_rules));
97 *data = m_allowed_ethertypes.size();
100 for (auto tt : m_allowed_ethertypes) {
105 VAPI_CALL(req.execute());
111 create_cmd::to_string() const
113 std::ostringstream s;
114 s << "gbp-contract-create: " << m_hw_item.to_string()
115 << " src-epg-id:" << m_src_epg_id << " dst-epg-id:" << m_dst_epg_id
118 for (auto e : m_allowed_ethertypes)
125 delete_cmd::delete_cmd(HW::item<bool>& item,
129 , m_src_epg_id(src_epg_id)
130 , m_dst_epg_id(dst_epg_id)
135 delete_cmd::operator==(const delete_cmd& other) const
137 return ((m_src_epg_id == other.m_src_epg_id) &&
138 (m_dst_epg_id == other.m_dst_epg_id));
142 delete_cmd::issue(connection& con)
144 msg_t req(con.ctx(), 0, 0, std::ref(*this));
146 auto& payload = req.get_request().get_payload();
148 payload.contract.acl_index = ~0;
149 payload.contract.src_epg = m_src_epg_id;
150 payload.contract.dst_epg = m_dst_epg_id;
152 VAPI_CALL(req.execute());
158 delete_cmd::to_string() const
160 std::ostringstream s;
161 s << "gbp-contract-delete: " << m_hw_item.to_string()
162 << " src-epg-id:" << m_src_epg_id << " dst-epg-id:" << m_dst_epg_id;
168 dump_cmd::operator==(const dump_cmd& other) const
174 dump_cmd::issue(connection& con)
176 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
178 VAPI_CALL(m_dump->execute());
186 dump_cmd::to_string() const
188 return ("gbp-contract-dump");
191 }; // namespace gbp_contract_cmds
195 * fd.io coding-style-patch-verification: ON
198 * eval: (c-set-style "mozilla")