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

Generated by: LCOV version 1.14