#include <iostream>
#include <sstream>
+#include <boost/algorithm/string.hpp>
+
#include "vom/types.hpp"
namespace VOM {
: enum_base<rc_t>(v, s)
{
}
-rc_t::~rc_t()
-{
-}
const rc_t&
rc_t::from_vpp_retval(int32_t rv)
return (rc_t::OK);
}
if (-68 == rv) {
- // interface laready exists
+ // sub interface already exists
+ return (rc_t::OK);
+ }
+ if (-79 == rv) {
+ // interface already exists
return (rc_t::OK);
}
const rc_t rc_t::UNSET(0, "un-set");
const rc_t rc_t::NOOP(1, "no-op");
const rc_t rc_t::OK(2, "ok");
-const rc_t rc_t::INPROGRESS(3, "in-progess");
-const rc_t rc_t::INVALID(4, "invalid");
-const rc_t rc_t::TIMEOUT(5, "timeout");
+const rc_t rc_t::INVALID(3, "invalid");
+const rc_t rc_t::TIMEOUT(4, "timeout");
const handle_t handle_t::INVALID(~0);
return (m_value);
}
+void
+handle_t::reset()
+{
+ m_value = ~0;
+}
+
std::ostream&
operator<<(std::ostream& os, const handle_t& h)
{
return (os);
}
-mac_address_t::mac_address_t(uint64_t address)
-{
- uint8_t mac[6];
-
- std::memcpy(mac, &address, 6);
- for (int i = 0; i < 6; i++) {
- bytes[i] = mac[5 - i];
- }
-}
-
mac_address_t::mac_address_t(uint8_t b[6])
{
std::copy(b, b + 6, std::begin(bytes));
std::copy(i.begin(), i.end(), std::begin(bytes));
}
+mac_address_t::mac_address_t(const std::string& str)
+{
+ std::vector<std::string> parts;
+
+ boost::split(parts, str, boost::is_any_of(":"));
+
+ size_t n_bytes = std::min(bytes.size(), parts.size());
+
+ for (uint32_t ii = 0; ii < n_bytes; ii++) {
+ bytes[ii] = std::stoul(parts[ii], nullptr, 16);
+ }
+}
+
const mac_address_t mac_address_t::ONE({ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff });
const mac_address_t mac_address_t::ZERO({ 0x0 });
}
}
-uint64_t
-mac_address_t::to_u64() const
-{
- uint64_t mac6 = 0;
- uint8_t* b = reinterpret_cast<uint8_t*>(&mac6);
-
- // whack hack. the vapi will byte swap.
- b[2] = bytes[5];
- b[3] = bytes[4];
- b[4] = bytes[3];
- b[5] = bytes[2];
- b[6] = bytes[1];
- b[7] = bytes[0];
-
- return (mac6);
-}
-
std::string
mac_address_t::to_string() const
{
s.fill('0');
s << std::hex;
- s << "mac:[";
for (auto byte : bytes) {
if (first)
first = false;
s << ":";
s << std::setw(2) << static_cast<unsigned int>(byte);
}
- s << "]";
return (s.str());
}
: enum_base(v, s)
{
}
+std::ostream&
+operator<<(std::ostream& os, const direction_t& dir)
+{
+ os << dir.to_string();
+ return os;
+}
+
+const ethertype_t ethertype_t::ARP(0x0806, "arp");
+const ethertype_t ethertype_t::FCOE(0x8906, "fcoe");
+const ethertype_t ethertype_t::IPV4(0x0800, "ipv4");
+const ethertype_t ethertype_t::IPV6(0x86DD, "ipv6");
+const ethertype_t ethertype_t::MAC_SECURITY(0x88E5, "mac-security");
+const ethertype_t ethertype_t::MPLS_UNICAST(0x8847, "mpls-unicast");
+const ethertype_t ethertype_t::TRILL(0x22F3, "trill");
+const ethertype_t ethertype_t::UNSPECIFIED(0x0, "unspecified");
+
+ethertype_t::ethertype_t(int v, const std::string s)
+ : enum_base(v, s)
+{
+}
+
+std::ostream&
+operator<<(std::ostream& os, const ethertype_t& ether)
+{
+ os << ether.to_string();
+ return os;
+}
+
+const ethertype_t&
+ethertype_t::from_numeric_val(uint16_t numeric)
+{
+ if (0x0806 == numeric) {
+ return (ethertype_t::ARP);
+ }
+ if (0x8906 == numeric) {
+ return (ethertype_t::FCOE);
+ }
+ if (0x0800 == numeric) {
+ return (ethertype_t::IPV4);
+ }
+ if (0x86DD == numeric) {
+ return (ethertype_t::IPV6);
+ }
+ if (0x88E5 == numeric) {
+ return (ethertype_t::MAC_SECURITY);
+ }
+ if (0x8847 == numeric) {
+ return (ethertype_t::MPLS_UNICAST);
+ }
+ if (0x22F3 == numeric) {
+ return (ethertype_t::TRILL);
+ }
+
+ return (ethertype_t::UNSPECIFIED);
}
+}; // namespace VOM
+
/*
* fd.io coding-style-patch-verification: ON
*