16 #include <boost/algorithm/string.hpp> 29 l3_proto_t::l3_proto_t(
int v,
const std::string& s)
30 : enum_base<l3_proto_t>(v, s)
37 return (*
this == IPV6);
43 return (*
this == IPV4);
61 else if (*
this == IPV6)
63 else if (*
this == MPLS)
84 nh_proto_t::nh_proto_t(
int v,
const std::string& s)
118 : m_addr(boost::asio::ip::
address::from_string(s))
163 if (m_len == o.m_len) {
164 return (m_addr < o.m_addr);
166 return (m_len < o.m_len);
173 return (m_len == o.m_len && m_addr == o.m_addr);
179 return (!(*
this == o));
185 std::ostringstream s;
187 s << m_addr.to_string() <<
"/" << std::to_string(m_len);
198 std::array<uint8_t, 16>
a;
199 std::copy(bytes, bytes + 16, std::begin(a));
200 boost::asio::ip::address_v6 v6(a);
203 std::array<uint8_t, 4>
a;
204 std::copy(bytes, bytes + 4, std::begin(a));
205 boost::asio::ip::address_v4 v4(a);
220 memcpy(array, addr.to_bytes().data(), 16);
226 memcpy(array, addr.to_bytes().data(), 4);
260 if (m_addr.is_v6()) {
277 boost::asio::ip::address_v4
279 const boost::asio::ip::address_v4& addr2)
282 a = addr1.to_ulong() | addr2.to_ulong();
283 boost::asio::ip::address_v4
addr(a);
287 boost::asio::ip::address_v4
operator&(
const boost::asio::ip::address_v4& addr1,
288 const boost::asio::ip::address_v4& addr2)
291 a = addr1.to_ulong() & addr2.to_ulong();
292 boost::asio::ip::address_v4
addr(a);
296 boost::asio::ip::address_v4
operator~(
const boost::asio::ip::address_v4& addr1)
299 a = ~addr1.to_ulong();
300 boost::asio::ip::address_v4
addr(a);
304 boost::asio::ip::address_v6
306 const boost::asio::ip::address_v6& addr2)
308 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
309 boost::asio::ip::address_v6::bytes_type b2 = addr2.to_bytes();
311 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
312 ii < b1.max_size(); ii++) {
316 boost::asio::ip::address_v6
addr(b1);
320 boost::asio::ip::address_v6
operator&(
const boost::asio::ip::address_v6& addr1,
321 const boost::asio::ip::address_v6& addr2)
323 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
324 boost::asio::ip::address_v6::bytes_type b2 = addr2.to_bytes();
326 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
327 ii < b1.max_size(); ii++) {
331 boost::asio::ip::address_v6
addr(b1);
335 boost::asio::ip::address_v6
operator~(
const boost::asio::ip::address_v6& addr1)
337 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
339 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
340 ii < b1.max_size(); ii++) {
344 boost::asio::ip::address_v6
addr(b1);
352 return (addr1.to_v6() | addr2.to_v6());
354 return (addr1.to_v4() | addr2.to_v4());
361 return (addr1.to_v6() & addr2.to_v6());
363 return (addr1.to_v4() & addr2.to_v4());
369 return ~(addr1.to_v6());
371 return ~(addr1.to_v4());
377 if (m_addr.is_v6()) {
378 boost::asio::ip::address_v6::bytes_type b =
383 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
384 ii < b.max_size(); ii++) {
385 for (int8_t bit = 7; bit >= 0 && n_bits; bit--) {
393 return (boost::asio::ip::address_v6(b));
399 return (boost::asio::ip::address_v4(a));
408 pfx.m_addr = pfx.m_addr & pfx.
mask();
418 pfx.m_addr = pfx.m_addr | ~pfx.
mask();
519 if (m_len == o.m_len) {
520 if (m_saddr == o.m_saddr)
521 return (m_gaddr < o.m_gaddr);
523 return (m_saddr < o.m_saddr);
525 return (m_len < o.m_len);
532 return (m_len == o.m_len && m_gaddr == o.m_gaddr && m_saddr == o.m_saddr);
538 return (!(*
this == o));
544 std::ostringstream s;
546 s <<
"(" << m_saddr.to_string() <<
"," << m_gaddr.to_string() <<
"/" 547 << std::to_string(m_len) <<
")";
const nh_proto_t & to_nh_proto() const
bool operator<(const prefix_t &o) const
Less than operator.
l3_proto_t l3_proto() const
Get the L3 protocol.
static const nh_proto_t IPV6
static const nh_proto_t IPV4
bool operator==(const mprefix_t &o) const
equals operator
static const prefix_t ZEROv6
The all Zeros v6 prefix.
uint8_t mask_width() const
Get the network mask width.
boost::asio::ip::address mask() const
Return a address representation of the mask, e.g.
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route...
static const nh_proto_t & from_address(const boost::asio::ip::address &addr)
mprefix_t()
Default Constructor - creates ::/0.
bool operator!=(const prefix_t &o) const
not equal opartor
static const l3_proto_t MPLS
prefix_t low() const
get the lowest address in the prefix
std::ostream & operator<<(std::ostream &os, const ip_route::key_t &key)
Types belonging to Routing.
static const l3_proto_t IPV4
const boost::asio::ip::address & grp_address() const
Get the address.
static const l3_proto_t IPV6
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
std::string to_string() const
convert to string format for debug purposes
boost::asio::ip::address_v4 operator|(const boost::asio::ip::address_v4 &addr1, const boost::asio::ip::address_v4 &addr2)
prefix_t high() const
Get the highest address in the prefix.
void to_vpp(uint8_t *is_ip6, uint8_t *saddr, uint8_t *gaddr, uint16_t *len) const
bool operator<(const mprefix_t &o) const
Less than operator.
static const mprefix_t ZERO
The all Zeros prefix.
boost::asio::ip::address_v4 operator~(const boost::asio::ip::address_v4 &addr1)
prefix_t()
Default Constructor - creates ::/0.
static const mprefix_t ZEROv6
The all Zeros v6 prefix.
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
bool operator!=(const mprefix_t &o) const
not equal opartor
boost::asio::ip::address_v4 operator&(const boost::asio::ip::address_v4 &addr1, const boost::asio::ip::address_v4 &addr2)
std::string to_string() const
convert to string format for debug purposes
prefix_t & operator=(const prefix_t &)
Assignement.
const boost::asio::ip::address & src_address() const
boost::asio::ip::address from_bytes(uint8_t is_ip6, const uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
bool operator==(const prefix_t &o) const
equals operator
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
static const l3_proto_t & from_address(const boost::asio::ip::address &addr)
static const nh_proto_t MPLS
The VPP Object Model (VOM) library.
static const prefix_t ZERO
The all Zeros prefix.
uint8_t mask_width() const
Get the network mask width.
const std::string & to_string() const
convert to string format for debug purposes
const boost::asio::ip::address & address() const
Get the address.
mprefix_t & operator=(const mprefix_t &)
Assignement.
static const nh_proto_t ETHERNET