OpenSDN source code
pkt_flow_info.h
Go to the documentation of this file.
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 
23  vrf_(NULL), intf_(NULL), rt_(NULL), vn_(NULL), vm_(NULL),
24  vlan_nh_(false), vlan_tag_(0) { }
25  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  PktFlowInfo(Agent *a, boost::shared_ptr<PktInfo> info, FlowTable *ftable) :
46  l3_flow(false), family(info->family), pkt(info),
47  flow_table(ftable), agent(a),
48  flow_source_vrf(-1), flow_dest_vrf(-1), nat_done(false),
50  nat_dest_vrf(0), dest_vrf(0), acl(NULL), ingress(false),
51  short_flow(false), local_flow(false), linklocal_flow(false),
52  tcp_ack(false), linklocal_bind_local_port(false),
54  ecmp(false), out_component_nh_idx(-1), disable_validation(false),
55  fip_snat(false), fip_dnat(false), snat_fip(),
57  flow_entry(NULL),
59  alias_ip_flow(false), ttl(0), underlay_flow(false),
62  }
63 
64  static bool ComputeDirection(const Interface *intf);
65  void CheckLinkLocal(const PktInfo *pkt);
67  PktControlInfo *out);
69  PktControlInfo *out);
71  PktControlInfo *out);
73  PktControlInfo *out);
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);
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:
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;
148  boost::shared_ptr<PktInfo> pkt;
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
159 
160  // NAT addresses
161  bool nat_done;
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;
184  bool tcp_ack;
187 
188  bool ecmp;
190 
191  // Ignore validations for specific flows, like BFD health check
193 
194  // Following fields are required for FIP stats accounting
195  bool fip_snat;
196  bool fip_dnat;
199  std::string peer_vrouter;
201 
202  // flow entry obtained from flow IPC, which requires recomputation.
205 
206  //BGP router service info
208 
209  // Alias IP flow
211  //TTL of nat'd flow especially bgp-service flows
212  uint8_t ttl;
213  //Is it underlay flow
215  uint32_t src_policy_vrf;
216  uint32_t dst_policy_vrf;
221 };
222 
223 #endif // __agent_pkt_flow_info_h_
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
std::set< std::string > VnListType
Definition: agent.h:213
Definition: acl.h:92
Family
Definition: address.h:25
Base class for all Route entries in agent.
Definition: agent_route.h:225
Definition: agent.h:361
void Add(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
bool ValidateConfig(const PktInfo *pkt, PktControlInfo *in)
bool Process(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
void CheckLinkLocal(const PktInfo *pkt)
void LinkLocalPortBind(const PktInfo *pkt, const PktControlInfo *in, FlowEntry *flow)
void ChangeVrf(const PktInfo *pkt, PktControlInfo *info, const VrfEntry *vrf)
void LinkLocalServiceFromHost(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
IpAddress nat_ip_saddr
FlowRouteRefMap flow_dest_plen_map
uint32_t src_policy_vrf
boost::shared_ptr< PktInfo > pkt
static bool GetIngressNwPolicyAclList(const Interface *intf, const VnEntry *vn, MatchPolicy *m_policy)
bool EgressRouteAllowNatLookup(const AgentRoute *in_rt, const AgentRoute *out_rt, uint32_t sport, uint32_t dport, const Interface *intf)
void ChangeEncap(const VmInterface *intf, const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out, bool nat_flow)
bool linklocal_bind_local_port
IpAddress FamilyToAddress(Address::Family family)
bool port_allocated
void ChangeFloatingIpEncap(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
void GenerateTrafficSeen(const PktInfo *pkt, const PktControlInfo *in)
static const int kLinkLocalInvalidFd
Definition: pkt_flow_info.h:40
uint8_t RouteToPrefixLen(const AgentRoute *route)
const NextHop * TunnelToNexthop(const PktInfo *pkt)
bool IngressRouteAllowNatLookup(const AgentRoute *in_rt, const AgentRoute *out_rt, uint32_t sport, uint32_t dport, const Interface *intf)
FlowEntry * flow_entry
PktFlowInfo(Agent *a, boost::shared_ptr< PktInfo > info, FlowTable *ftable)
Definition: pkt_flow_info.h:45
bool bgp_router_service_flow
IpAddress snat_fip
void IngressProcess(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
bool alias_ip_flow
void UpdateFipStatsInfo(FlowEntry *flow, FlowEntry *rflow, const PktInfo *p, const PktControlInfo *in, const PktControlInfo *o)
uint32_t out_component_nh_idx
static const Ip6Address kDefaultIpv6
Definition: pkt_flow_info.h:42
void CalculatePort(const PktInfo *p, const Interface *intf)
Address::Family family
void FloatingIpDNat(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
bool disable_validation
void SetPktInfo(boost::shared_ptr< PktInfo > info)
uint32_t dst_policy_vrf
uint32_t nat_vrf
void LinkLocalServiceTranslate(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
uint32_t nat_dest_vrf
bool overlay_route_not_found
static const int kBgpRouterServiceInvalidFd
Definition: pkt_flow_info.h:43
bool flood_unknown_unicast
uint32_t flow_source_vrf
bool underlay_flow
void NatVxlanVrfTranslate(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
bool VrfTranslate(const PktInfo *pkt, PktControlInfo *ctrl, PktControlInfo *rev_flow, const IpAddress &src_ip, bool nat_flow)
uint16_t short_flow_reason
void EgressProcess(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
const VnListType * dst_vn
int linklocal_src_port_fd
uint32_t nat_sport
void BgpRouterServiceTranslate(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
static const Ip4Address kDefaultIpv4
Definition: pkt_flow_info.h:41
bool IsBgpRouterServiceRoute(const AgentRoute *in_rt, const AgentRoute *out_rt, const Interface *intf, uint32_t sport, uint32_t dport)
void UpdateRoute(const AgentRoute **rt, const VrfEntry *vrf, const IpAddress &addr, const MacAddress &mac, FlowRouteRefMap &ref_map)
bool UnknownUnicastFlow(const PktInfo *p, const PktControlInfo *in_info, const PktControlInfo *out_info)
IpAddress nat_ip_daddr
std::string peer_vrouter
bool linklocal_flow
Agent * agent
TunnelType tunnel_type
const AclDBEntry * acl
void FloatingIpSNat(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
bool RouteAllowNatLookupCommon(const AgentRoute *rt, uint32_t sport, uint32_t dport, const Interface *intf)
FlowRouteRefMap flow_source_plen_map
const VnListType * src_vn
void UpdateEvictedFlowStats(const PktInfo *pkt)
void LinkLocalServiceFromVm(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
void ApplyFlowLimits(const PktControlInfo *in, const PktControlInfo *out)
uint32_t dest_vrf
void BgpRouterServiceFromVm(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
uint32_t nat_dport
static bool ComputeDirection(const Interface *intf)
void ChangeEncapToOverlay(const VmInterface *intf, const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
FlowTable * flow_table
uint32_t flow_dest_vrf
Definition: vm.h:35
Definition: vn.h:152
Definition: vrf.h:90
@ INVALID
Definition: globals.h:150
map< int, int > FlowRouteRefMap
Definition: pkt_flow_info.h:17
const VnEntry * vn_
Definition: pkt_flow_info.h:30
const AgentRoute * rt_
Definition: pkt_flow_info.h:29
virtual ~PktControlInfo()
Definition: pkt_flow_info.h:25
const Interface * intf_
Definition: pkt_flow_info.h:28
const VrfEntry * vrf_
Definition: pkt_flow_info.h:27
uint16_t vlan_tag_
Definition: pkt_flow_info.h:33
const VmEntry * vm_
Definition: pkt_flow_info.h:31