2 * Copyright (c) 2018 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.
18 #include "vom/gbp_rule.hpp"
21 gbp_rule::next_hop_t::next_hop_t(const boost::asio::ip::address& ip,
22 const mac_address_t& mac,
33 gbp_rule::next_hop_t::to_string() const
38 << "ip:" << m_ip << " mac:" << m_mac.to_string() << " bd:" << m_bd_id
39 << " rd:" << m_rd_id << "]";
45 gbp_rule::next_hop_t::operator<(const gbp_rule::next_hop_t& nh) const
47 return (nh.m_ip < m_ip);
51 gbp_rule::next_hop_t::operator==(const gbp_rule::next_hop_t& nh) const
53 return ((m_ip == nh.m_ip) && (m_mac == nh.m_mac) && (m_bd_id == nh.m_bd_id) &&
54 (m_rd_id == nh.m_rd_id));
57 const boost::asio::ip::address&
58 gbp_rule::next_hop_t::getIp() const
64 gbp_rule::next_hop_t::getMac() const
70 gbp_rule::next_hop_t::getBdId() const
76 gbp_rule::next_hop_t::getRdId() const
81 const gbp_rule::hash_mode_t gbp_rule::hash_mode_t::SRC_IP(1, "src-ip");
82 const gbp_rule::hash_mode_t gbp_rule::hash_mode_t::DST_IP(0, "dst-ip");
83 const gbp_rule::hash_mode_t gbp_rule::hash_mode_t::SYMMETRIC(2, "symmetric");
85 gbp_rule::hash_mode_t::hash_mode_t(int v, const std::string s)
90 const gbp_rule::hash_mode_t&
91 gbp_rule::hash_mode_t::from_int(vapi_enum_gbp_hash_mode i)
93 if (i == GBP_API_HASH_MODE_SYMMETRIC)
94 return gbp_rule::hash_mode_t::SYMMETRIC;
95 else if (i == GBP_API_HASH_MODE_SRC_IP)
96 return gbp_rule::hash_mode_t::SRC_IP;
98 return gbp_rule::hash_mode_t::DST_IP;
101 gbp_rule::next_hop_set_t::next_hop_set_t(const gbp_rule::hash_mode_t& hm,
102 gbp_rule::next_hops_t& nhs)
108 gbp_rule::next_hop_set_t::next_hop_set_t(const hash_mode_t& hm)
115 gbp_rule::next_hop_set_t::to_string() const
117 std::ostringstream s;
119 s << "hash-mode:" << m_hm.to_string() << " next-hops:[";
120 auto it = m_nhs.cbegin();
121 while (it != m_nhs.cend()) {
122 s << " " << it->to_string();
125 s << " ] next-hop-size:" << m_nhs.size();
131 gbp_rule::next_hop_set_t::operator==(const next_hop_set_t& nhs) const
133 return ((m_hm == nhs.m_hm) && (m_nhs == nhs.m_nhs));
136 const gbp_rule::hash_mode_t&
137 gbp_rule::next_hop_set_t::hash_mode() const
142 const gbp_rule::next_hops_t&
143 gbp_rule::next_hop_set_t::next_hops() const
148 const gbp_rule::action_t gbp_rule::action_t::REDIRECT(2, "redirect");
149 const gbp_rule::action_t gbp_rule::action_t::PERMIT(1, "permit");
150 const gbp_rule::action_t gbp_rule::action_t::DENY(0, "deny");
152 gbp_rule::action_t::action_t(int v, const std::string s)
157 const gbp_rule::action_t&
158 gbp_rule::action_t::from_int(vapi_enum_gbp_rule_action i)
160 if (i == GBP_API_RULE_REDIRECT)
161 return gbp_rule::action_t::REDIRECT;
162 else if (i == GBP_API_RULE_PERMIT)
163 return gbp_rule::action_t::PERMIT;
165 return gbp_rule::action_t::DENY;
168 gbp_rule::gbp_rule(uint32_t priority,
169 const gbp_rule::next_hop_set_t& nhs,
170 const gbp_rule::action_t& a)
171 : m_priority(priority)
177 gbp_rule::gbp_rule(uint32_t priority, const gbp_rule::action_t& a)
178 : m_priority(priority)
185 gbp_rule::operator<(const gbp_rule& other) const
187 return (other.m_priority < m_priority);
191 gbp_rule::operator==(const gbp_rule& rule) const
193 return ((m_action == rule.m_action) && (m_nhs == rule.m_nhs) &&
194 (m_priority == rule.m_priority));
198 gbp_rule::to_string() const
200 std::ostringstream s;
203 << "priority:" << m_priority << " action:" << m_action.to_string()
204 << " next-hop-set:[" << m_nhs.to_string() << "]]";
209 const gbp_rule::action_t&
210 gbp_rule::action() const
215 const gbp_rule::next_hop_set_t&
216 gbp_rule::nhs() const
223 * fd.io coding-style-patch-verification: ON
226 * eval: (c-set-style "mozilla")