LCOV - code coverage report
Current view: top level - vnsw/agent/pkt - pkt_flow_info.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 22 22 100.0 %
Date: 2026-08-03 02:19:58 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef __agent_pkt_flow_info_h_
       6             : #define __agent_pkt_flow_info_h_
       7             : 
       8             : class VrfEntry;
       9             : class Interface;
      10             : class VnEntry;
      11             : class VmEntry;
      12             : class FlowTable;
      13             : class FlowEntry;
      14             : class AgentRoute;
      15             : struct PktInfo;
      16             : struct MatchPolicy;
      17             : 
      18             : typedef map<int, int> FlowRouteRefMap;
      19             : 
      20             : struct PktControlInfo {
      21          94 :     PktControlInfo() :
      22          94 :         vrf_(NULL), intf_(NULL), rt_(NULL), vn_(NULL), vm_(NULL),
      23          94 :         vlan_nh_(false), vlan_tag_(0) { }
      24          94 :     virtual ~PktControlInfo() { }
      25             : 
      26             :     const VrfEntry *vrf_;
      27             :     const Interface *intf_;
      28             :     const AgentRoute *rt_;
      29             :     const VnEntry *vn_;
      30             :     const VmEntry *vm_;
      31             :     bool  vlan_nh_;
      32             :     uint16_t vlan_tag_;
      33             :     // The NH-ID field used as key in the flow
      34             :     uint32_t nh_;
      35             : };
      36             : 
      37             : class PktFlowInfo {
      38             : public:
      39             :     static const int kLinkLocalInvalidFd = -1;
      40             :     static const Ip4Address kDefaultIpv4;
      41             :     static const Ip6Address kDefaultIpv6;
      42             :     static const int kBgpRouterServiceInvalidFd = -1;
      43             : 
      44          47 :     PktFlowInfo(Agent *a, boost::shared_ptr<PktInfo> info, FlowTable *ftable) :
      45          47 :         l3_flow(false), family(info->family), pkt(info),
      46          47 :         flow_table(ftable), agent(a),
      47          94 :         flow_source_vrf(-1), flow_dest_vrf(-1), nat_done(false),
      48          47 :         nat_ip_saddr(), nat_ip_daddr(), nat_sport(0), nat_dport(0), nat_vrf(0),
      49          47 :         nat_dest_vrf(0), dest_vrf(0), acl(NULL), ingress(false),
      50          47 :         short_flow(false), local_flow(false), linklocal_flow(false),
      51          47 :         tcp_ack(false), linklocal_bind_local_port(false),
      52          47 :         linklocal_src_port_fd(kLinkLocalInvalidFd),
      53          47 :         ecmp(false), out_component_nh_idx(-1), disable_validation(false),
      54          47 :         fip_snat(false), fip_dnat(false), snat_fip(),
      55          47 :         short_flow_reason(0), peer_vrouter(), tunnel_type(TunnelType::INVALID),
      56          47 :         flow_entry(NULL),
      57          47 :         flood_unknown_unicast(false), bgp_router_service_flow(false),
      58          47 :         alias_ip_flow(false), ttl(0), underlay_flow(false),
      59          47 :         src_policy_vrf(-1), dst_policy_vrf(-1), port_allocated(false),
      60          47 :         overlay_route_not_found(false) {
      61          47 :     }
      62             : 
      63             :     static bool ComputeDirection(const Interface *intf);
      64             :     void CheckLinkLocal(const PktInfo *pkt);
      65             :     void LinkLocalServiceFromVm(const PktInfo *pkt, PktControlInfo *in,
      66             :                                 PktControlInfo *out);
      67             :     void LinkLocalServiceFromHost(const PktInfo *pkt, PktControlInfo *in,
      68             :                                   PktControlInfo *out);
      69             :     void LinkLocalServiceTranslate(const PktInfo *pkt, PktControlInfo *in,
      70             :                                    PktControlInfo *out);
      71             :     void BgpRouterServiceFromVm(const PktInfo *pkt, PktControlInfo *in,
      72             :                                 PktControlInfo *out);
      73             :     void BgpRouterServiceTranslate(const PktInfo *pkt, PktControlInfo *in,
      74             :                                    PktControlInfo *out);
      75             :     void FloatingIpSNat(const PktInfo *pkt, PktControlInfo *in,
      76             :                         PktControlInfo *out);
      77             :     void FloatingIpDNat(const PktInfo *pkt, PktControlInfo *in,
      78             :                         PktControlInfo *out);
      79             :     void IngressProcess(const PktInfo *pkt, PktControlInfo *in,
      80             :                         PktControlInfo *out);
      81             :     void EgressProcess(const PktInfo *pkt, PktControlInfo *in,
      82             :                        PktControlInfo *out);
      83             :     void Add(const PktInfo *pkt, PktControlInfo *in,
      84             :              PktControlInfo *out);
      85             :     bool Process(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out);
      86             :     bool ValidateConfig(const PktInfo *pkt, PktControlInfo *in);
      87             :     static bool GetIngressNwPolicyAclList(const Interface *intf,
      88             :                                           const VnEntry *vn,
      89             :                                           MatchPolicy *m_policy);
      90             :     bool VrfTranslate(const PktInfo *pkt, PktControlInfo *ctrl,
      91             :                       PktControlInfo *rev_flow, const IpAddress &src_ip,
      92             :                       bool nat_flow);
      93             :     void NatVxlanVrfTranslate(const PktInfo *pkt, PktControlInfo *in,
      94             :         PktControlInfo *out);
      95             :     void UpdateFipStatsInfo(FlowEntry *flow, FlowEntry *rflow, const PktInfo *p,
      96             :                             const PktControlInfo *in, const PktControlInfo *o);
      97             :     const NextHop *TunnelToNexthop(const PktInfo *pkt);
      98             :     void ChangeVrf(const PktInfo *pkt, PktControlInfo *info,
      99             :                    const VrfEntry *vrf);
     100             :     bool UnknownUnicastFlow(const PktInfo *p,
     101             :                             const PktControlInfo *in_info,
     102             :                             const PktControlInfo *out_info);
     103             :     void GenerateTrafficSeen(const PktInfo *pkt, const PktControlInfo *in);
     104             :     void ApplyFlowLimits(const PktControlInfo *in, const PktControlInfo *out);
     105             :     void LinkLocalPortBind(const PktInfo *pkt, const PktControlInfo *in,
     106             :                            FlowEntry *flow);
     107             :     bool IngressRouteAllowNatLookup(const AgentRoute *in_rt,
     108             :                                     const AgentRoute *out_rt,
     109             :                                     uint32_t sport,
     110             :                                     uint32_t dport,
     111             :                                     const Interface *intf);
     112             :     bool EgressRouteAllowNatLookup(const AgentRoute *in_rt,
     113             :                                    const AgentRoute *out_rt,
     114             :                                    uint32_t sport,
     115             :                                    uint32_t dport,
     116             :                                    const Interface *intf);
     117             :     void ChangeEncap(const VmInterface *intf, const PktInfo *pkt,
     118             :                      PktControlInfo *in, PktControlInfo *out,
     119             :                      bool nat_flow);
     120             :     void ChangeFloatingIpEncap(const PktInfo *pkt,
     121             :                                PktControlInfo *in,
     122             :                                PktControlInfo *out);
     123             :     void ChangeEncapToOverlay(const VmInterface *intf,
     124             :                               const PktInfo *pkt,
     125             :                               PktControlInfo *in,
     126             :                               PktControlInfo *out);
     127             : public:
     128             :     IpAddress FamilyToAddress(Address::Family family);
     129             :     void UpdateRoute(const AgentRoute **rt, const VrfEntry *vrf,
     130             :                      const IpAddress &addr, const MacAddress &mac,
     131             :                      FlowRouteRefMap &ref_map);
     132             :     uint8_t RouteToPrefixLen(const AgentRoute *route);
     133             :     void CalculatePort(const PktInfo *p, const Interface *intf);
     134             :     void SetPktInfo(boost::shared_ptr<PktInfo> info);
     135             :     bool RouteAllowNatLookupCommon(const AgentRoute *rt,
     136             :                                    uint32_t sport,
     137             :                                    uint32_t dport,
     138             :                                    const Interface *intf);
     139             :     bool IsBgpRouterServiceRoute(const AgentRoute *in_rt,
     140             :                                  const AgentRoute *out_rt,
     141             :                                  const Interface *intf,
     142             :                                  uint32_t sport,
     143             :                                  uint32_t dport);
     144             :     void UpdateEvictedFlowStats(const PktInfo *pkt);
     145             :     bool                l3_flow;
     146             :     Address::Family     family;
     147             :     boost::shared_ptr<PktInfo> pkt;
     148             :     FlowTable           *flow_table;
     149             :     Agent               *agent;
     150             : 
     151             :     uint32_t            flow_source_vrf;
     152             :     uint32_t            flow_dest_vrf;
     153             :     // map for references to the routes which were ignored due to more specific
     154             :     // route this will be used to trigger flow re-compute to use more specific
     155             :     // on route add. key for the map is vrf and data is prefix length
     156             :     FlowRouteRefMap     flow_source_plen_map;
     157             :     FlowRouteRefMap     flow_dest_plen_map;
     158             : 
     159             :     // NAT addresses
     160             :     bool                nat_done;
     161             :     IpAddress           nat_ip_saddr;
     162             :     IpAddress           nat_ip_daddr;
     163             :     uint32_t            nat_sport;
     164             :     uint32_t            nat_dport;
     165             :     // VRF for matching the NAT flow
     166             :     uint32_t            nat_vrf;
     167             :     // Modified VRF for the NAT flow
     168             :     // After flow processing, packet is assigned this VRF
     169             :     uint32_t            nat_dest_vrf;
     170             : 
     171             :     // Modified VRF for the forward flow
     172             :     // After flow processing, packet is assigned this VRF
     173             :     uint32_t            dest_vrf;
     174             : 
     175             :     // Intermediate fields used in creating flows
     176             :     const AclDBEntry    *acl;
     177             : 
     178             :     // Ingress flow or egress flow
     179             :     bool                ingress;
     180             :     bool                short_flow;
     181             :     bool                local_flow;
     182             :     bool                linklocal_flow;
     183             :     bool                tcp_ack;
     184             :     bool                linklocal_bind_local_port;
     185             :     int                 linklocal_src_port_fd;
     186             : 
     187             :     bool                ecmp;
     188             :     uint32_t            out_component_nh_idx;
     189             : 
     190             :     // Ignore validations for specific flows, like BFD health check
     191             :     bool                disable_validation;
     192             : 
     193             :     // Following fields are required for FIP stats accounting
     194             :     bool                fip_snat;
     195             :     bool                fip_dnat;
     196             :     IpAddress           snat_fip;
     197             :     uint16_t            short_flow_reason;
     198             :     std::string         peer_vrouter;
     199             :     TunnelType          tunnel_type;
     200             : 
     201             :     // flow entry obtained from flow IPC, which requires recomputation.
     202             :     FlowEntry           *flow_entry;
     203             :     bool                 flood_unknown_unicast;
     204             : 
     205             :     //BGP router service info
     206             :     bool                 bgp_router_service_flow;
     207             : 
     208             :     // Alias IP flow
     209             :     bool                 alias_ip_flow;
     210             :     //TTL of nat'd flow especially bgp-service flows
     211             :     uint8_t              ttl;
     212             :     //Is it underlay flow
     213             :     bool                 underlay_flow;
     214             :     uint32_t             src_policy_vrf;
     215             :     uint32_t             dst_policy_vrf;
     216             :     const VnListType           *src_vn;
     217             :     const VnListType           *dst_vn;
     218             :     bool                 port_allocated;
     219             :     bool                 overlay_route_not_found;
     220             : };
     221             : 
     222             : #endif // __agent_pkt_flow_info_h_

Generated by: LCOV version 1.14