LCOV - code coverage report
Current view: top level - vnsw/agent/pkt/flow_mgmt - flow_mgmt_request.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 50 82 61.0 %
Date: 2026-08-03 02:19:58 Functions: 18 29 62.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : #ifndef __AGENT_FLOW_MGMT_REQUEST_H__
       5             : #define __AGENT_FLOW_MGMT_REQUEST_H__
       6             : 
       7             : #include "pkt/flow_table.h"
       8             : #include "pkt/flow_event.h"
       9             : 
      10             : ////////////////////////////////////////////////////////////////////////////
      11             : // Request to the Flow Management module
      12             : ////////////////////////////////////////////////////////////////////////////
      13             : class FlowMgmtRequest {
      14             : public:
      15             :     enum Event {
      16             :         INVALID,
      17             :         ADD_FLOW,
      18             :         DELETE_FLOW,
      19             :         UPDATE_FLOW,
      20             :         ADD_DBENTRY,
      21             :         CHANGE_DBENTRY,
      22             :         DELETE_DBENTRY,
      23             :         RETRY_DELETE_VRF,
      24             :         DELETE_BGP_AAS_FLOWS,
      25             :         UPDATE_FLOW_STATS,
      26             :         IMPLICIT_ROUTE_DELETE,
      27             :         DELETE_LAYER2_FLOW,
      28             :         DUMMY
      29             : 
      30             :     };
      31             : 
      32         244 :     FlowMgmtRequest(Event event, FlowEntry *flow) :
      33         488 :         event_(event), flow_(flow), db_entry_(NULL), vrf_id_(0), gen_id_(),
      34         244 :         bytes_(), packets_(), oflow_bytes_(), params_() {
      35         244 :             if (event == RETRY_DELETE_VRF)
      36           0 :                 assert(vrf_id_);
      37         244 :     }
      38             : 
      39          44 :     FlowMgmtRequest(Event event, FlowEntry *flow,
      40          44 :                     const RevFlowDepParams &params) :
      41          88 :         event_(event), flow_(flow), db_entry_(NULL), vrf_id_(0), gen_id_(),
      42          44 :         bytes_(), packets_(), oflow_bytes_(), params_(params) {
      43          44 :     }
      44             : 
      45           0 :     FlowMgmtRequest(Event event, FlowEntry *flow, uint32_t bytes,
      46             :                     uint32_t packets, uint32_t oflow_bytes,
      47           0 :                     const boost::uuids::uuid &u) :
      48           0 :         event_(event), flow_(flow), db_entry_(NULL), vrf_id_(0), gen_id_(),
      49           0 :         bytes_(bytes), packets_(packets), oflow_bytes_(oflow_bytes), params_(),
      50           0 :         flow_uuid_(u) {
      51           0 :             if (event == RETRY_DELETE_VRF)
      52           0 :                 assert(vrf_id_);
      53           0 :     }
      54             : 
      55         901 :     FlowMgmtRequest(Event event, const DBEntry *db_entry, uint32_t gen_id) :
      56        1802 :         event_(event), flow_(NULL), db_entry_(db_entry), vrf_id_(0),
      57         901 :         gen_id_(gen_id), bytes_(), packets_(), oflow_bytes_(), params_() {
      58         901 :             if (event == RETRY_DELETE_VRF) {
      59          36 :                 const VrfEntry *vrf = dynamic_cast<const VrfEntry *>(db_entry);
      60          36 :                 assert(vrf);
      61          36 :                 vrf_id_ = vrf->vrf_id();
      62             :             }
      63         901 :     }
      64             : 
      65           0 :     FlowMgmtRequest(Event event) :
      66           0 :         event_(event), flow_(NULL), db_entry_(NULL), vrf_id_(),
      67           0 :         gen_id_(), bytes_(), packets_(), oflow_bytes_(), params_() {
      68           0 :     }
      69             : 
      70        2374 :     virtual ~FlowMgmtRequest() { }
      71             : 
      72             :     // At the end of Flow Management Request, we may enqueue a response message
      73             :     // back to FlowTable module. Compute the message type to be enqueued in
      74             :     // response. Returns INVALID if no message to be enqueued
      75         861 :     FlowEvent::Event GetResponseEvent() const {
      76         861 :         FlowEvent::Event resp_event = FlowEvent::INVALID;
      77         861 :         if (event_ == DELETE_BGP_AAS_FLOWS)
      78           0 :             return FlowEvent::DELETE_FLOW;
      79             : 
      80         861 :         if (event_ == IMPLICIT_ROUTE_DELETE) {
      81           0 :             resp_event = FlowEvent::RECOMPUTE_FLOW;
      82             :         }
      83             : 
      84         861 :         if (db_entry_ == NULL)
      85           0 :             return resp_event;
      86             : 
      87         861 :         if (dynamic_cast<const VrfEntry *>(db_entry_)) {
      88          30 :             return resp_event;
      89             :         }
      90             : 
      91         831 :         if (event_ == ADD_DBENTRY || event_ == CHANGE_DBENTRY) {
      92         499 :             resp_event = FlowEvent::REVALUATE_DBENTRY;
      93         332 :         } else if (event_ == DELETE_DBENTRY) {
      94         332 :             resp_event = FlowEvent::DELETE_DBENTRY;
      95             :         }
      96             : 
      97             :         // Add/Change in route needs complete recomputation of flows
      98             :         // 1. Bridge route change can be result of MAC-Move. This will need
      99             :         //    recomputing rpf-nh also.
     100             :         // 2. Add/Delete of inet-uc route can result in change of route used
     101             :         //    used for flow
     102         831 :         const AgentRoute *rt =
     103         831 :             dynamic_cast<const AgentRoute *>(db_entry_);
     104         831 :         if (rt) {
     105         417 :             resp_event = FlowEvent::RECOMPUTE_FLOW;
     106             :         }
     107             : 
     108         831 :         return resp_event;
     109             :     }
     110             : 
     111        2400 :     Event event() const { return event_; }
     112         673 :     FlowEntryPtr &flow() { return flow_; }
     113             :     void set_flow(FlowEntry *flow) { flow_.reset(flow); }
     114        2286 :     const DBEntry *db_entry() const { return db_entry_; }
     115             :     void set_db_entry(const DBEntry *db_entry) { db_entry_ = db_entry; }
     116          36 :     uint32_t vrf_id() const { return vrf_id_; }
     117         350 :     uint32_t gen_id() const { return gen_id_; }
     118           0 :     uint32_t bytes() const { return bytes_;}
     119           0 :     uint32_t packets() const { return packets_;}
     120           0 :     uint32_t oflow_bytes() const { return oflow_bytes_;}
     121         132 :     const RevFlowDepParams& params() const { return params_; }
     122          94 :     void set_params(const RevFlowDepParams &params) {
     123          94 :         params_ = params;
     124          94 :     }
     125           0 :     boost::uuids::uuid flow_uuid() const { return flow_uuid_; }
     126             : 
     127             : private:
     128             :     Event event_;
     129             :     // FlowEntry pointer to hold flow reference till message is processed
     130             :     FlowEntryPtr flow_;
     131             :     // DBEntry pointer. The DBState from FlowTable module ensures DBEntry is
     132             :     // not deleted while message holds pointer
     133             :     const DBEntry *db_entry_;
     134             :     uint32_t vrf_id_;
     135             :     uint32_t gen_id_;
     136             :     uint32_t bytes_;
     137             :     uint32_t packets_;
     138             :     uint32_t oflow_bytes_;
     139             :     RevFlowDepParams params_;
     140             :     boost::uuids::uuid flow_uuid_;
     141             : 
     142             :     DISALLOW_COPY_AND_ASSIGN(FlowMgmtRequest);
     143             : };
     144             : 
     145             : class BgpAsAServiceFlowMgmtRequest : public FlowMgmtRequest {
     146             : public:
     147             :     enum Type {
     148             :         VMI,
     149             :         CONTROLLER,
     150             :         HEALTH_CHECK_ADD,
     151             :         HEALTH_CHECK_DEL
     152             :     };
     153             : 
     154           4 :     BgpAsAServiceFlowMgmtRequest(uint8_t index) :
     155             :         FlowMgmtRequest(FlowMgmtRequest::DELETE_BGP_AAS_FLOWS, NULL, 0),
     156           4 :         type_(BgpAsAServiceFlowMgmtRequest::CONTROLLER), vm_uuid_(),
     157           4 :         source_port_(), index_(index), health_check_uuid_() { }
     158           0 :     BgpAsAServiceFlowMgmtRequest(const boost::uuids::uuid &vm_uuid,
     159           0 :                                  uint32_t source_port) :
     160             :         FlowMgmtRequest(FlowMgmtRequest::DELETE_BGP_AAS_FLOWS, NULL, 0),
     161           0 :         type_(BgpAsAServiceFlowMgmtRequest::VMI), vm_uuid_(vm_uuid),
     162           0 :         source_port_(source_port), index_(), health_check_uuid_() { }
     163           0 :     BgpAsAServiceFlowMgmtRequest(const boost::uuids::uuid &vm_uuid,
     164             :                                  uint32_t source_port,
     165             :                                  const boost::uuids::uuid &hc_uuid,
     166           0 :                                  Type type) :
     167             :         FlowMgmtRequest(FlowMgmtRequest::DELETE_BGP_AAS_FLOWS, NULL, 0),
     168           0 :         type_(type), vm_uuid_(vm_uuid), source_port_(source_port), index_(),
     169           0 :         health_check_uuid_(hc_uuid) { }
     170           8 :     virtual ~BgpAsAServiceFlowMgmtRequest() { }
     171           8 :     BgpAsAServiceFlowMgmtRequest::Type type() const { return type_; }
     172           0 :     const boost::uuids::uuid &vm_uuid() const { return vm_uuid_; }
     173           0 :     uint32_t source_port() const { return source_port_; }
     174           4 :     uint8_t index() const { return index_; }
     175           0 :     const boost::uuids::uuid &health_check_uuid() const {
     176           0 :         return health_check_uuid_;
     177             :     }
     178             : 
     179             : private:
     180             :     BgpAsAServiceFlowMgmtRequest::Type type_;
     181             :     boost::uuids::uuid vm_uuid_;
     182             :     uint32_t source_port_;
     183             :     uint8_t index_;
     184             :     boost::uuids::uuid health_check_uuid_;
     185             :     DISALLOW_COPY_AND_ASSIGN(BgpAsAServiceFlowMgmtRequest);
     186             : };
     187             : #endif //  __AGENT_FLOW_MGMT_REQUEST_H__

Generated by: LCOV version 1.14