VOM: Additions to allow uses to UT applications that use VOM
[vpp.git] / src / vpp-api / vom / types.cpp
index c362a60..c5325d2 100644 (file)
@@ -18,6 +18,8 @@
 #include <iostream>
 #include <sstream>
 
+#include <boost/algorithm/string.hpp>
+
 #include "vom/types.hpp"
 
 namespace VOM {
@@ -101,16 +103,6 @@ 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));
@@ -121,6 +113,19 @@ mac_address_t::mac_address_t(std::initializer_list<uint8_t> i)
   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 });
@@ -133,23 +138,6 @@ mac_address_t::to_bytes(uint8_t* array, uint8_t len) const
   }
 }
 
-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
 {
@@ -158,7 +146,6 @@ mac_address_t::to_string() const
 
   s.fill('0');
   s << std::hex;
-  s << "mac:[";
   for (auto byte : bytes) {
     if (first)
       first = false;
@@ -166,7 +153,6 @@ mac_address_t::to_string() const
       s << ":";
     s << std::setw(2) << static_cast<unsigned int>(byte);
   }
-  s << "]";
 
   return (s.str());
 }