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)
28 , m_src_epg_id(src_epg_id)
29 , m_dst_epg_id(dst_epg_id)
31 , m_gbp_rules(gbp_rules)
36 create_cmd::operator==(const create_cmd& other) const
38 return ((m_acl == other.m_acl) && (m_src_epg_id == other.m_src_epg_id) &&
39 (m_dst_epg_id == other.m_dst_epg_id) &&
40 (m_gbp_rules == other.m_gbp_rules));
44 create_cmd::issue(connection& con)
46 u8 size = m_gbp_rules.empty() ? 1 : m_gbp_rules.size();
47 msg_t req(con.ctx(), size, std::ref(*this));
49 auto& payload = req.get_request().get_payload();
51 payload.contract.acl_index = m_acl.value();
52 payload.contract.src_epg = m_src_epg_id;
53 payload.contract.dst_epg = m_dst_epg_id;
56 auto it = m_gbp_rules.cbegin();
57 payload.contract.n_rules = m_gbp_rules.size();
58 while (it != m_gbp_rules.cend()) {
59 if (it->action() == gbp_rule::action_t::REDIRECT)
60 payload.contract.rules[ii].action = GBP_API_RULE_REDIRECT;
61 else if (it->action() == gbp_rule::action_t::PERMIT)
62 payload.contract.rules[ii].action = GBP_API_RULE_PERMIT;
64 payload.contract.rules[ii].action = GBP_API_RULE_DENY;
66 if (it->nhs().getHashMode() == gbp_rule::hash_mode_t::SYMMETRIC)
67 payload.contract.rules[ii].nh_set.hash_mode =
68 GBP_API_HASH_MODE_SYMMETRIC;
69 else if (it->nhs().getHashMode() == gbp_rule::hash_mode_t::SRC_IP)
70 payload.contract.rules[ii].nh_set.hash_mode = GBP_API_HASH_MODE_SRC_IP;
72 payload.contract.rules[ii].nh_set.hash_mode = GBP_API_HASH_MODE_DST_IP;
74 const gbp_rule::next_hops_t& next_hops = it->nhs().getNextHops();
75 u8 jj = 0, nh_size = (next_hops.size() > 8) ? 8 : next_hops.size();
76 auto nh_it = next_hops.cbegin();
78 payload.contract.rules[ii].nh_set.n_nhs = nh_size;
79 while (jj < nh_size) {
80 to_api(nh_it->getIp(), payload.contract.rules[ii].nh_set.nhs[jj].ip);
81 payload.contract.rules[ii].nh_set.nhs[jj].mac = to_api(nh_it->getMac());
82 payload.contract.rules[ii].nh_set.nhs[jj].bd_id = nh_it->getBdId();
83 payload.contract.rules[ii].nh_set.nhs[jj].rd_id = nh_it->getRdId();
92 VAPI_CALL(req.execute());
98 create_cmd::to_string() const
100 std::ostringstream s;
101 s << "gbp-contract-create: " << m_hw_item.to_string()
102 << " src-epg-id:" << m_src_epg_id << " dst-epg-id:" << m_dst_epg_id
108 delete_cmd::delete_cmd(HW::item<bool>& item,
112 , m_src_epg_id(src_epg_id)
113 , m_dst_epg_id(dst_epg_id)
118 delete_cmd::operator==(const delete_cmd& other) const
120 return ((m_src_epg_id == other.m_src_epg_id) &&
121 (m_dst_epg_id == other.m_dst_epg_id));
125 delete_cmd::issue(connection& con)
127 msg_t req(con.ctx(), 1, std::ref(*this));
129 auto& payload = req.get_request().get_payload();
131 payload.contract.acl_index = ~0;
132 payload.contract.src_epg = m_src_epg_id;
133 payload.contract.dst_epg = m_dst_epg_id;
135 VAPI_CALL(req.execute());
141 delete_cmd::to_string() const
143 std::ostringstream s;
144 s << "gbp-contract-delete: " << m_hw_item.to_string()
145 << " src-epg-id:" << m_src_epg_id << " dst-epg-id:" << m_dst_epg_id;
151 dump_cmd::operator==(const dump_cmd& other) const
157 dump_cmd::issue(connection& con)
159 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
161 VAPI_CALL(m_dump->execute());
169 dump_cmd::to_string() const
171 return ("gbp-contract-dump");
174 }; // namespace gbp_contract_cmds
178 * fd.io coding-style-patch-verification: ON
181 * eval: (c-set-style "mozilla")