LCOV - code coverage report
Current view: top level - bgp/routing-policy - routing_policy_action.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 38 41 92.7 %
Date: 2026-11-09 02:10:49 Functions: 34 39 87.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef SRC_BGP_ROUTING_POLICY_ROUTING_POLICY_ACTION_H_
       7             : #define SRC_BGP_ROUTING_POLICY_ROUTING_POLICY_ACTION_H_
       8             : 
       9             : #include <stdint.h>
      10             : #include <string>
      11             : #include <typeinfo>
      12             : #include <vector>
      13             : #include "bgp/community.h"
      14             : #include "net/community_type.h"
      15             : 
      16             : class BgpAttr;
      17             : 
      18             : class RoutingPolicyAction {
      19             : public:
      20        1017 :     virtual ~RoutingPolicyAction() {}
      21             :     // Whether the action is terminal (Accept/Reject)
      22             :     virtual bool terminal()  const = 0;
      23             :     virtual bool accept()  const = 0;
      24             :     virtual std::string ToString() const = 0;
      25         431 :     virtual bool operator==(const RoutingPolicyAction &action) const {
      26         431 :         if (typeid(*this) == typeid(action))
      27         430 :             return IsEqual(action);
      28           1 :         return false;
      29             :     }
      30         431 :     virtual bool operator!=(const RoutingPolicyAction &action) const {
      31         431 :         return !operator==(action);
      32             :     }
      33             :     virtual bool IsEqual(const RoutingPolicyAction &action) const = 0;
      34             : };
      35             : 
      36             : class RoutingPolicyUpdateAction : public RoutingPolicyAction {
      37             : public:
      38         540 :     virtual ~RoutingPolicyUpdateAction() {}
      39           0 :     bool terminal()  const { return false; }
      40           0 :     bool accept() const { return true; }
      41             :     virtual void operator()(BgpAttr *out_attr) const = 0;
      42             : };
      43             : 
      44             : class RoutingPolicyAcceptAction : public RoutingPolicyAction {
      45             : public:
      46         482 :     virtual ~RoutingPolicyAcceptAction() {}
      47         840 :     bool terminal()  const { return true; }
      48         260 :     bool accept() const { return true; }
      49          10 :     std::string ToString() const {
      50          10 :         return "accept";
      51             :     }
      52         132 :     virtual bool IsEqual(const RoutingPolicyAction &action) const {
      53         132 :         return true;
      54             :     }
      55             : };
      56             : 
      57             : class RoutingPolicyRejectAction : public RoutingPolicyAction {
      58             : public:
      59         268 :     virtual ~RoutingPolicyRejectAction() {}
      60         297 :     bool terminal()  const { return true; }
      61          28 :     bool accept() const { return false; }
      62           9 :     std::string ToString() const {
      63           9 :         return "reject";
      64             :     }
      65          74 :     virtual bool IsEqual(const RoutingPolicyAction &action) const {
      66          74 :         return true;
      67             :     }
      68             : };
      69             : 
      70             : class RoutingPolicyNexTermAction : public RoutingPolicyAction {
      71             : public:
      72         204 :     virtual ~RoutingPolicyNexTermAction() {}
      73         107 :     bool terminal()  const { return false; }
      74           0 :     bool accept() const { return false; }
      75           4 :     std::string ToString() const {
      76           4 :         return "next-term";
      77             :     }
      78          51 :     virtual bool IsEqual(const RoutingPolicyAction &action) const {
      79          51 :         return true;
      80             :     }
      81             : };
      82             : 
      83             : class UpdateAsPath : public RoutingPolicyUpdateAction {
      84             : public:
      85             :     UpdateAsPath(const std::vector<uint32_t> &asn_list);
      86          23 :     virtual ~UpdateAsPath() {}
      87             : 
      88             :     virtual void operator()(BgpAttr *out_attr) const;
      89             :     std::string ToString() const;
      90             :     virtual bool IsEqual(const RoutingPolicyAction &as_path) const;
      91           5 :     const std::vector<uint32_t> &asn_list() const { return asn_list_; }
      92             : 
      93             : private:
      94             :     std::vector<uint32_t> asn_list_;
      95             : };
      96             : 
      97             : class UpdateCommunity : public RoutingPolicyUpdateAction {
      98             : public:
      99             :     typedef std::vector<uint32_t> CommunityList;
     100             :     enum CommunityUpdateOp {
     101             :         ADD,
     102             :         REMOVE,
     103             :         SET
     104             :     };
     105             :     UpdateCommunity(const std::vector<std::string> communities, std::string op);
     106         311 :     virtual ~UpdateCommunity() {}
     107             :     virtual void operator()(BgpAttr *out_attr) const;
     108             :     std::string ToString() const;
     109             :     virtual bool IsEqual(const RoutingPolicyAction &community) const;
     110         134 :     const CommunityList &communities() const {
     111         134 :         return communities_;
     112             :     }
     113             : 
     114             : private:
     115             :     CommunityList communities_;
     116             :     CommunityUpdateOp op_;
     117             : };
     118             : 
     119             : class UpdateExtCommunity : public RoutingPolicyUpdateAction {
     120             : public:
     121             :     enum CommunityUpdateOp {
     122             :         ADD,
     123             :         REMOVE,
     124             :         SET
     125             :     };
     126             :     UpdateExtCommunity(const std::vector<std::string> &communities,
     127             :                        std::string op);
     128          77 :     virtual ~UpdateExtCommunity() {}
     129             :     virtual void operator()(BgpAttr *out_attr) const;
     130             :     std::string ToString() const;
     131             :     virtual bool IsEqual(const RoutingPolicyAction &community) const;
     132          37 :     const ExtCommunity::ExtCommunityList &communities() const {
     133          37 :         return communities_;
     134             :     }
     135             : 
     136             : private:
     137             :     ExtCommunity::ExtCommunityList communities_;
     138             :     CommunityUpdateOp op_;
     139             : };
     140             : 
     141             : class UpdateLocalPref : public RoutingPolicyUpdateAction {
     142             : public:
     143             :     explicit UpdateLocalPref(uint32_t local_pref);
     144         456 :     virtual ~UpdateLocalPref() {}
     145             :     virtual void operator()(BgpAttr *out_attr) const;
     146             :     std::string ToString() const;
     147             :     virtual bool IsEqual(const RoutingPolicyAction &local_pref) const;
     148             : 
     149             : private:
     150             :     uint32_t local_pref_;
     151             : };
     152             : 
     153             : class UpdateMed : public RoutingPolicyUpdateAction {
     154             : public:
     155             :     explicit UpdateMed(uint32_t med);
     156           5 :     virtual ~UpdateMed() {}
     157             :     virtual void operator()(BgpAttr *out_attr) const;
     158             :     std::string ToString() const;
     159             :     virtual bool IsEqual(const RoutingPolicyAction &med) const;
     160             : 
     161             : private:
     162             :     uint32_t med_;
     163             : };
     164             : 
     165             : #endif  // SRC_BGP_ROUTING_POLICY_ROUTING_POLICY_ACTION_H_

Generated by: LCOV version 1.14