service mode is now by message to RX core 73/5273/1
authorimarom <[email protected]>
Mon, 23 Jan 2017 14:45:01 +0000 (16:45 +0200)
committerimarom <[email protected]>
Mon, 23 Jan 2017 14:45:01 +0000 (16:45 +0200)
Signed-off-by: imarom <[email protected]>
src/stateless/cp/trex_stateless_port.cpp
src/stateless/cp/trex_stateless_port.h
src/stateless/messaging/trex_stateless_messaging.cpp
src/stateless/messaging/trex_stateless_messaging.h
src/stateless/rx/trex_stateless_rx_port_mngr.h

index 9cf048b..bfc7dce 100644 (file)
@@ -162,13 +162,14 @@ private:
  * trex stateless port
  * 
  **************************/
-TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this), m_service_mode(port_id, api) {
+TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this) {
     std::vector<std::pair<uint8_t, uint8_t>> core_pair_list;
 
-    m_port_id            = port_id;
-    m_port_state         = PORT_STATE_IDLE;
-    m_platform_api       = api;
-
+    m_port_id             = port_id;
+    m_port_state          = PORT_STATE_IDLE;
+    m_platform_api        = api;
+    m_is_service_mode_on  = false;
+    
     /* get the platform specific data */
     api->get_interface_info(port_id, m_api_info);
 
@@ -948,6 +949,44 @@ TrexStatelessPort::remove_and_delete_all_streams() {
     }
 }
 
+/**
+ * enable/disable service mode 
+ * sends a query to the RX core 
+ * 
+ */
+void 
+TrexStatelessPort::set_service_mode(bool enabled) {
+    static MsgReply<TrexStatelessRxQuery::query_rc_e> reply;
+    reply.reset();
+    
+    TrexStatelessRxQuery::query_type_e query_type = (enabled ? TrexStatelessRxQuery::SERVICE_MODE_ON : TrexStatelessRxQuery::SERVICE_MODE_OFF);
+    
+    TrexStatelessRxQuery *msg = new TrexStatelessRxQuery(m_port_id, query_type, reply);
+    send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
+    
+    TrexStatelessRxQuery::query_rc_e rc = reply.wait_for_reply();
+    
+    switch (rc) {
+    case TrexStatelessRxQuery::RC_OK:
+        if (enabled) {
+            getPortAttrObj()->set_rx_filter_mode(RX_FILTER_MODE_ALL);
+        } else {
+            getPortAttrObj()->set_rx_filter_mode(RX_FILTER_MODE_HW);
+        }
+        m_is_service_mode_on = enabled;
+        return;
+        
+    case TrexStatelessRxQuery::RC_FAIL_RX_QUEUE_ACTIVE:
+        throw TrexException("unable to disable service mode - please remove RX queue");
+        
+    case TrexStatelessRxQuery::RC_FAIL_CAPTURE_ACTIVE:
+        throw TrexException("unable to disable service mode - an active capture on port " + std::to_string(m_port_id) + " exists");
+        
+    default:
+        assert(0);
+    }
+}
+
 
 void 
 TrexStatelessPort::start_rx_queue(uint64_t size) {
@@ -962,16 +1001,12 @@ TrexStatelessPort::start_rx_queue(uint64_t size) {
        this might cause the user to lose some packets from the queue
      */
     reply.wait_for_reply();
-
-    m_service_mode.set_rx_queue();
 }
 
 void
 TrexStatelessPort::stop_rx_queue() {
     TrexStatelessCpToRxMsgBase *msg = new TrexStatelessRxStopQueue(m_port_id);
     send_message_to_rx(msg);
-
-    m_service_mode.unset_rx_queue();
 }
 
 
index 0ef8ae6..4b8ea3d 100644 (file)
@@ -115,57 +115,6 @@ private:
     static const std::string g_unowned_handler;
 };
 
-/**
- * enforces in/out from service mode
- * 
- * @author imarom (1/4/2017)
- */
-class TrexServiceMode {
-public:
-    TrexServiceMode(uint8_t port_id, const TrexPlatformApi *api) {
-        m_is_enabled   = false;
-        m_has_rx_queue = false;
-        m_port_id      = port_id;
-        m_port_attr    = api->getPortAttrObj(port_id);
-    }
-
-    void enable() {
-        m_port_attr->set_rx_filter_mode(RX_FILTER_MODE_ALL);
-        m_is_enabled = true;
-    }
-
-    void disable() {
-        if (m_has_rx_queue) {
-            throw TrexException("unable to disable service mode - please remove RX queue");
-        }
-
-        if (TrexStatelessCaptureMngr::getInstance().is_active(m_port_id)) {
-            throw TrexException("unable to disable service mode - an active capture on port " + std::to_string(m_port_id) + " exists");
-        }
-        
-        m_port_attr->set_rx_filter_mode(RX_FILTER_MODE_HW);
-        m_is_enabled = false;
-    }
-
-    bool is_enabled() const {
-        return m_is_enabled;
-    }
-
-    void set_rx_queue() {
-        m_has_rx_queue = true;
-    }
-
-    void unset_rx_queue() {
-        m_has_rx_queue = false;
-    }
-
-private:
-    bool            m_is_enabled;
-    bool            m_has_rx_queue;
-    TRexPortAttr   *m_port_attr;
-    uint8_t         m_port_id;
-};
-
 class AsyncStopEvent;
 
 /**
@@ -287,20 +236,20 @@ public:
                      double            duration,
                      bool              is_dual);
 
-    /** 
-     * moves port to / out service mode 
+    
+    /**
+     * sets service mode
+     * 
+     * @author imarom (1/22/2017)
+     * 
+     * @param enabled 
      */
-    void set_service_mode(bool enabled) {
-        if (enabled) {
-            m_service_mode.enable();
-        } else {
-            m_service_mode.disable();
-        }
-    }
+    void set_service_mode(bool enabled);
+    
     bool is_service_mode_on() const {
-        return m_service_mode.is_enabled();
+        return m_is_service_mode_on;
     }
-    
+     
     /**
      * get the port state
      *
@@ -578,8 +527,8 @@ private:
 
     int m_pending_async_stop_event;
     
-    TrexServiceMode m_service_mode;
-
+    bool  m_is_service_mode_on;
+    
     static const uint32_t MAX_STREAMS = 20000;
 
 };
index 2452487..21fe7a1 100644 (file)
@@ -381,3 +381,40 @@ TrexStatelessRxSetL3Mode::handle(CRxCoreStateless *rx_core) {
     return true;
 }
 
+bool
+TrexStatelessRxQuery::handle(CRxCoreStateless *rx_core) {
+
+    query_rc_e rc = RC_OK;
+    
+    switch (m_query_type) {
+   
+    case SERVICE_MODE_ON:
+        /* for service mode on - always allow this */
+        rc = RC_OK;
+        break;
+        
+    case SERVICE_MODE_OFF:
+        /* cannot leave service mode when RX queue is active */
+        if (rx_core->get_rx_port_mngr(m_port_id).is_feature_set(RXPortManager::QUEUE)) {
+            rc = RC_FAIL_RX_QUEUE_ACTIVE;
+            break;
+        }
+        
+        /* cannot leave service mode if PCAP capturing is active */
+        if (TrexStatelessCaptureMngr::getInstance().is_active(m_port_id)) {
+            rc = RC_FAIL_CAPTURE_ACTIVE;
+            break;
+        }
+        
+        break;
+    
+    default:
+        assert(0);
+        break;
+        
+    }
+    
+    m_reply.set_reply(rc);
+    
+    return true;
+}
index 3535ad4..ed14b10 100644 (file)
@@ -677,4 +677,42 @@ private:
     MsgReply<Json::Value>   &m_reply;
 };
 
+
+class TrexStatelessRxQuery : public TrexStatelessCpToRxMsgBase {
+public:
+
+    /**
+     * query type to request
+     */
+    enum query_type_e {
+        SERVICE_MODE_ON,
+        SERVICE_MODE_OFF,
+    };
+    
+    /**
+     * RC types for queries
+     */
+    enum query_rc_e {
+        RC_OK,
+        RC_FAIL_RX_QUEUE_ACTIVE,
+        RC_FAIL_CAPTURE_ACTIVE,
+    };
+    
+    TrexStatelessRxQuery(uint8_t port_id, query_type_e query_type, MsgReply<query_rc_e> &reply) : m_reply(reply) {
+        m_port_id    = port_id;
+        m_query_type = query_type;
+    }
+     
+    /**
+     * virtual function to handle a message
+     *
+     */
+    virtual bool handle(CRxCoreStateless *rx_core);
+    
+private:
+    uint8_t                m_port_id;
+    query_type_e           m_query_type;
+    MsgReply<query_rc_e>  &m_reply;
+};
+
 #endif /* __TREX_STATELESS_MESSAGING_H__ */
index 0cc6071..b318d97 100644 (file)
@@ -305,11 +305,14 @@ public:
         return (m_features != NO_FEATURES);
     }
 
-
     bool no_features_set() {
         return (!has_features_set());
     }
 
+    bool is_feature_set(feature_t feature) const {
+        return ( (m_features & feature) == feature );
+    }
+
     /**
      * returns ignored set of stats
      * (grat ARP, PING response and etc.)
@@ -334,11 +337,7 @@ private:
     void unset_feature(feature_t feature) {
         m_features &= (~feature);
     }
-
-    bool is_feature_set(feature_t feature) const {
-        return ( (m_features & feature) == feature );
-    }
-
+  
     uint32_t                     m_features;
     uint8_t                      m_port_id;
     RXLatency                    m_latency;