VOM fixes and logger improvements 70/9470/2
authorNeale Ranns <neale.ranns@cisco.com>
Fri, 17 Nov 2017 13:08:55 +0000 (05:08 -0800)
committerNeale Ranns <nranns@cisco.com>
Fri, 17 Nov 2017 14:39:53 +0000 (14:39 +0000)
Change-Id: I5e3fa5e098a8ea26dbc3d3a1dc064e3507e33d8e
Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
src/vpp-api/vom/hw.cpp
src/vpp-api/vom/hw.hpp
src/vpp-api/vom/interface.cpp
src/vpp-api/vom/l3_binding.cpp
src/vpp-api/vom/l3_binding.hpp
src/vpp-api/vom/logger.cpp
src/vpp-api/vom/logger.hpp

index fee0e86..4150d5f 100644 (file)
@@ -127,9 +127,9 @@ HW::cmd_q::write()
   rc_t rc = rc_t::OK;
 
   /*
- * The queue is enabled, Execute each command in the queue.
- * If one execution fails, abort the rest
- */
  * The queue is enabled, Execute each command in the queue.
  * If one execution fails, abort the rest
  */
   auto it = m_queue.begin();
 
   while (it != m_queue.end()) {
@@ -139,41 +139,43 @@ HW::cmd_q::write()
 
     if (m_enabled) {
       /*
- * before we issue the command we must move it to the pending
- * store
- * ince a async event can be recieved before the command
- * completes
- */
      * before we issue the command we must move it to the pending
      * store
      * ince a async event can be recieved before the command
      * completes
      */
       m_pending[c.get()] = c;
 
       rc = c->issue(m_conn);
 
       if (rc_t::INPROGRESS == rc) {
         /*
- * this command completes asynchronously
- * leave the command in the pending store
- */
        * this command completes asynchronously
        * leave the command in the pending store
        */
       } else {
         /*
- * the command completed, remove from the pending store
- */
        * the command completed, remove from the pending store
        */
         m_pending.erase(c.get());
 
         if (rc_t::OK == rc) {
           /*
- * move to the next
- */
          * move to the next
          */
         } else {
           /*
- * barf out without issuing the rest
- */
+           * barf out without issuing the rest
+           */
+          VOM_LOG(log_level_t::ERROR) << "Failed to execute: "
+                                      << c->to_string();
           break;
         }
       }
     } else {
       /*
- * The HW is disabled, so set each command as succeeded
- */
      * The HW is disabled, so set each command as succeeded
      */
       c->succeeded();
     }
 
@@ -181,8 +183,8 @@ HW::cmd_q::write()
   }
 
   /*
- * erase all objects in the queue
- */
  * erase all objects in the queue
  */
   m_queue.erase(m_queue.begin(), m_queue.end());
 
   return (rc);
index eaa7cf0..77ae5c3 100644 (file)
@@ -76,6 +76,11 @@ public:
     {
     }
 
+    /**
+     * Destructor
+     */
+    ~item() = default;
+
     /**
      * Comparison operator
      */
index 1c90a31..8f1023d 100644 (file)
@@ -54,10 +54,10 @@ interface::interface(const handle_t& handle,
                      const std::string& name,
                      interface::type_t type,
                      interface::admin_state_t state)
-  : m_hdl(handle)
+  : m_hdl(handle, rc_t::OK)
   , m_name(name)
   , m_type(type)
-  , m_state(state)
+  , m_state(state, rc_t::OK)
   , m_table_id(route::DEFAULT_TABLE)
   , m_l2_address(l2_address)
   , m_oper(oper_state_t::DOWN)
@@ -278,8 +278,18 @@ interface::update(const interface& desired)
   if (rc_t::OK != m_hdl.rc()) {
     std::queue<cmd*> cmds;
     HW::enqueue(mk_create_cmd(cmds));
+    /*
+     * interface create now, so we can barf early if it fails
+     */
+    HW::write();
   }
 
+  /*
+   * If the interface is not created do other commands should be issued
+   */
+  if (rc_t::OK != m_hdl.rc())
+    return;
+
   /*
    * change the interface state to that which is deisred
    */
index 8f90d45..065504c 100644 (file)
@@ -27,14 +27,14 @@ l3_binding::event_handler l3_binding::m_evh;
 l3_binding::l3_binding(const interface& itf, const route::prefix_t& pfx)
   : m_itf(itf.singular())
   , m_pfx(pfx)
-  , m_binding(true)
+  , m_binding(true, rc_t::NOOP)
 {
 }
 
 l3_binding::l3_binding(const l3_binding& o)
   : m_itf(o.m_itf)
   , m_pfx(o.m_pfx)
-  , m_binding(true)
+  , m_binding(o.m_binding)
 {
 }
 
index 4403760..a147058 100644 (file)
@@ -167,7 +167,7 @@ private:
   /**
    * The prefix for this L3 configuration
    */
-  const route::prefix_t& m_pfx;
+  const route::prefix_t m_pfx;
 
   /**
    * HW configuration for the binding. The bool representing the
index 1ae55b9..07e2749 100644 (file)
@@ -61,7 +61,7 @@ log_t::set(const std::string& ofile)
 }
 
 std::ostream&
-log_t::stream(const char* file, int line)
+log_t::stream(const char* file, int line, const log_level_t& level)
 {
   auto end = std::chrono::system_clock::now();
   auto end_time = std::chrono::system_clock::to_time_t(end);
@@ -77,7 +77,7 @@ log_t::stream(const char* file, int line)
   boost::split(dirs, file, boost::is_any_of("/"));
 
   *m_o_stream << std::endl
-              << display << "]"
+              << display << " [" << level.to_string() << "]"
               << " " << dirs.back() << ":" << line << ": ";
 
   return (*m_o_stream);
index 0adc677..941623e 100644 (file)
@@ -52,7 +52,7 @@ public:
   /**
    * Return the stream
    */
-  std::ostream& stream(const char* file, int line);
+  std::ostream& stream(const char* file, int line, const log_level_t& level);
 
   /**
    * The configured level
@@ -93,7 +93,7 @@ log_t& logger();
 
 #define VOM_LOG(lvl)                                                           \
   if (lvl >= logger().level())                                                 \
-  logger().stream(__FILE__, __LINE__)
+  logger().stream(__FILE__, __LINE__, lvl)
 };
 
 /*