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)
149 : m_addr(boost::asio::
ip::
address::from_string(s))
194 if (m_len == o.m_len) {
195 return (m_addr < o.m_addr);
197 return (m_len < o.m_len);
204 return (m_len == o.m_len && m_addr == o.m_addr);
210 return (!(*
this == o));
216 std::ostringstream s;
218 s << m_addr.to_string() <<
"/" << std::to_string(m_len);
229 std::array<uint8_t, 16>
a;
230 std::copy(bytes, bytes + 16, std::begin(a));
231 boost::asio::ip::address_v6 v6(a);
234 std::array<uint8_t, 4>
a;
235 std::copy(bytes, bytes + 4, std::begin(a));
236 boost::asio::ip::address_v4 v4(a);
251 memcpy(array, addr.to_bytes().data(), 16);
257 memcpy(array, addr.to_bytes().data(), 4);
291 if (m_addr.is_v6()) {
308 boost::asio::ip::address_v4
310 const boost::asio::ip::address_v4& addr2)
313 a = addr1.to_ulong() | addr2.to_ulong();
314 boost::asio::ip::address_v4
addr(a);
318 boost::asio::ip::address_v4
operator&(
const boost::asio::ip::address_v4& addr1,
319 const boost::asio::ip::address_v4& addr2)
322 a = addr1.to_ulong() & addr2.to_ulong();
323 boost::asio::ip::address_v4
addr(a);
327 boost::asio::ip::address_v4
operator~(
const boost::asio::ip::address_v4& addr1)
330 a = ~addr1.to_ulong();
331 boost::asio::ip::address_v4
addr(a);
335 boost::asio::ip::address_v6
337 const boost::asio::ip::address_v6& addr2)
339 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
340 boost::asio::ip::address_v6::bytes_type b2 = addr2.to_bytes();
342 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
343 ii < b1.max_size(); ii++) {
347 boost::asio::ip::address_v6
addr(b1);
351 boost::asio::ip::address_v6
operator&(
const boost::asio::ip::address_v6& addr1,
352 const boost::asio::ip::address_v6& addr2)
354 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
355 boost::asio::ip::address_v6::bytes_type b2 = addr2.to_bytes();
357 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
358 ii < b1.max_size(); ii++) {
362 boost::asio::ip::address_v6
addr(b1);
366 boost::asio::ip::address_v6
operator~(
const boost::asio::ip::address_v6& addr1)
368 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
370 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
371 ii < b1.max_size(); ii++) {
375 boost::asio::ip::address_v6
addr(b1);
383 return (addr1.to_v6() | addr2.to_v6());
385 return (addr1.to_v4() | addr2.to_v4());
392 return (addr1.to_v6() & addr2.to_v6());
394 return (addr1.to_v4() & addr2.to_v4());
400 return ~(addr1.to_v6());
402 return ~(addr1.to_v4());
408 if (m_addr.is_v6()) {
409 boost::asio::ip::address_v6::bytes_type b =
414 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
415 ii < b.max_size(); ii++) {
416 for (int8_t bit = 7; bit >= 0 && n_bits; bit--) {
424 return (boost::asio::ip::address_v6(b));
430 return (boost::asio::ip::address_v4(a));
439 pfx.m_addr = pfx.m_addr & pfx.
mask();
449 pfx.m_addr = pfx.m_addr | ~pfx.
mask();
529 if (m_gaddr.is_v6()) {
551 if (m_len == o.m_len) {
552 if (m_saddr == o.m_saddr)
553 return (m_gaddr < o.m_gaddr);
555 return (m_saddr < o.m_saddr);
557 return (m_len < o.m_len);
564 return (m_len == o.m_len && m_gaddr == o.m_gaddr && m_saddr == o.m_saddr);
570 return (!(*
this == o));
576 std::ostringstream s;
578 s <<
"(" << m_saddr.to_string() <<
"," << m_gaddr.to_string() <<
"/" 579 << std::to_string(m_len) <<
")";
static const ip_dscp_t DSCP_AF21
static const ip_dscp_t DSCP_CS4
boost::asio::ip::address mask() const
Return a address representation of the mask, e.g.
static const ip_dscp_t DSCP_AF11
const boost::asio::ip::address & address() const
Get the address.
std::string to_string() const
convert to string format for debug purposes
static const nh_proto_t IPV6
bool operator==(const prefix_t &o) const
equals operator
static const nh_proto_t IPV4
const boost::asio::ip::address & grp_address() const
Get the address.
static const ip_dscp_t DSCP_AF33
static const prefix_t ZEROv6
The all Zeros v6 prefix.
prefix_t high() const
Get the highest address in the prefix.
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route...
static const ip_dscp_t DSCP_AF12
static const nh_proto_t & from_address(const boost::asio::ip::address &addr)
boost::asio::ip::address_v4 operator &(const boost::asio::ip::address_v4 &addr1, const boost::asio::ip::address_v4 &addr2)
mprefix_t()
Default Constructor - creates ::/0.
uint8_t mask_width() const
Get the network mask width.
static const l3_proto_t MPLS
static const ip_dscp_t DSCP_AF13
static const ip_dscp_t DSCP_CS2
uint8_t mask_width() const
Get the network mask width.
std::ostream & operator<<(std::ostream &os, const ip_route::key_t &key)
static const ip_dscp_t DSCP_AF32
Types belonging to Routing.
static const l3_proto_t IPV4
l3_proto_t l3_proto() const
Get the L3 protocol.
ip_dscp_t(int v)
Constructor allows the creation of any DSCP value.
static const ip_dscp_t DSCP_CS5
static const l3_proto_t IPV6
const boost::asio::ip::address & src_address() const
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
const nh_proto_t & to_nh_proto() const
boost::asio::ip::address_v4 operator|(const boost::asio::ip::address_v4 &addr1, const boost::asio::ip::address_v4 &addr2)
static const ip_dscp_t DSCP_CS7
prefix_t low() const
get the lowest address in the prefix
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 ip_dscp_t DSCP_CS6
bool operator<(const mprefix_t &o) const
Less than operator.
bool operator<(const prefix_t &o) const
Less than operator.
static const mprefix_t ZEROv6
The all Zeros v6 prefix.
static const ip_dscp_t DSCP_AF41
vl_api_ip4_address_t gaddr
std::string to_string() const
convert to string format for debug purposes
static const ip_dscp_t DSCP_AF43
bool operator==(const mprefix_t &o) const
equals operator
static const ip_dscp_t DSCP_CS1
static const ip_dscp_t DSCP_AF22
prefix_t & operator=(const prefix_t &)
Assignement.
const std::string & to_string() const
convert to string format for debug purposes
static const ip_dscp_t DSCP_AF23
bool operator!=(const prefix_t &o) const
not equal opartor
static const ip_dscp_t DSCP_EF
manual_print typedef address
static const ip_dscp_t DSCP_AF42
boost::asio::ip::address from_bytes(uint8_t is_ip6, const uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
static const ip_dscp_t DSCP_AF31
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 ip_dscp_t DSCP_CS0
static const prefix_t ZERO
The all Zeros prefix.
static const ip_dscp_t DSCP_CS3
mprefix_t & operator=(const mprefix_t &)
Assignement.
l3_proto_t l3_proto() const
Get the L3 protocol.
std::string to_string() const
convert to string format for debug purposes
static const nh_proto_t ETHERNET
bool operator!=(const mprefix_t &o) const
not equal opartor