OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pkt_flow_info.h
Go to the documentation of this file.
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 
22  vrf_(NULL), intf_(NULL), rt_(NULL), vn_(NULL), vm_(NULL),
23  vlan_nh_(false), vlan_tag_(0) { }
24  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  PktFlowInfo(Agent *a, boost::shared_ptr<PktInfo> info, FlowTable *ftable) :
45  l3_flow(false), family(info->family), pkt(info),
46  flow_table(ftable), agent(a),
47  flow_source_vrf(-1), flow_dest_vrf(-1), nat_done(false),
49  nat_dest_vrf(0), dest_vrf(0), acl(NULL), ingress(false),
50  short_flow(false), local_flow(false), linklocal_flow(false),
51  tcp_ack(false), linklocal_bind_local_port(false),
53  ecmp(false), out_component_nh_idx(-1), disable_validation(false),
54  fip_snat(false), fip_dnat(false), snat_fip(),
56  flow_entry(NULL),
58  alias_ip_flow(false), ttl(0), underlay_flow(false),
61  }
62 
63  static bool ComputeDirection(const Interface *intf);
64  void CheckLinkLocal(const PktInfo *pkt);
66  PktControlInfo *out);
68  PktControlInfo *out);
70  PktControlInfo *out);
72  PktControlInfo *out);
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);
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:
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;
147  boost::shared_ptr<PktInfo> pkt;
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
158 
159  // NAT addresses
160  bool nat_done;
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;
183  bool tcp_ack;
186 
187  bool ecmp;
189 
190  // Ignore validations for specific flows, like BFD health check
192 
193  // Following fields are required for FIP stats accounting
194  bool fip_snat;
195  bool fip_dnat;
198  std::string peer_vrouter;
200 
201  // flow entry obtained from flow IPC, which requires recomputation.
204 
205  //BGP router service info
207 
208  // Alias IP flow
210  //TTL of nat'd flow especially bgp-service flows
211  uint8_t ttl;
212  //Is it underlay flow
214  uint32_t src_policy_vrf;
215  uint32_t dst_policy_vrf;
220 };
221 
222 #endif // __agent_pkt_flow_info_h_
std::string peer_vrouter
void SetPktInfo(boost::shared_ptr< PktInfo > info)
bool linklocal_bind_local_port
static const Ip6Address kDefaultIpv6
Definition: pkt_flow_info.h:41
bool bgp_router_service_flow
bool flood_unknown_unicast
bool UnknownUnicastFlow(const PktInfo *p, const PktControlInfo *in_info, const PktControlInfo *out_info)
Definition: vrf.h:86
static bool GetIngressNwPolicyAclList(const Interface *intf, const VnEntry *vn, MatchPolicy *m_policy)
bool IngressRouteAllowNatLookup(const AgentRoute *in_rt, const AgentRoute *out_rt, uint32_t sport, uint32_t dport, const Interface *intf)
const VnListType * src_vn
Family
Definition: address.h:24
uint32_t nat_sport
boost::asio::ip::address IpAddress
Definition: address.h:13
Definition: vm.h:32
bool port_allocated
uint32_t nat_vrf
FlowTable * flow_table
uint32_t out_component_nh_idx
Agent * agent
const NextHop * TunnelToNexthop(const PktInfo *pkt)
void BgpRouterServiceFromVm(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
bool EgressRouteAllowNatLookup(const AgentRoute *in_rt, const AgentRoute *out_rt, uint32_t sport, uint32_t dport, const Interface *intf)
static const int kBgpRouterServiceInvalidFd
Definition: pkt_flow_info.h:42
const VrfEntry * vrf_
Definition: pkt_flow_info.h:26
FlowRouteRefMap flow_source_plen_map
uint32_t nat_dest_vrf
IpAddress snat_fip
bool linklocal_flow
bool RouteAllowNatLookupCommon(const AgentRoute *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)
void UpdateEvictedFlowStats(const PktInfo *pkt)
Base class for all Route entries in agent.
Definition: agent_route.h:224
void LinkLocalPortBind(const PktInfo *pkt, const PktControlInfo *in, FlowEntry *flow)
void ChangeFloatingIpEncap(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
boost::shared_ptr< PktInfo > pkt
void UpdateRoute(const AgentRoute **rt, const VrfEntry *vrf, const IpAddress &addr, const MacAddress &mac, FlowRouteRefMap &ref_map)
const VnListType * dst_vn
bool ValidateConfig(const PktInfo *pkt, PktControlInfo *in)
void IngressProcess(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
IpAddress FamilyToAddress(Address::Family family)
IpAddress nat_ip_daddr
void FloatingIpSNat(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
void GenerateTrafficSeen(const PktInfo *pkt, const PktControlInfo *in)
Definition: agent.h:358
bool disable_validation
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
bool VrfTranslate(const PktInfo *pkt, PktControlInfo *ctrl, PktControlInfo *rev_flow, const IpAddress &src_ip, bool nat_flow)
map< int, int > FlowRouteRefMap
Definition: pkt_flow_info.h:16
bool IsBgpRouterServiceRoute(const AgentRoute *in_rt, const AgentRoute *out_rt, const Interface *intf, uint32_t sport, uint32_t dport)
bool Process(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
static bool ComputeDirection(const Interface *intf)
const AclDBEntry * acl
int linklocal_src_port_fd
static const int kLinkLocalInvalidFd
Definition: pkt_flow_info.h:39
void Add(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
uint32_t nat_dport
uint32_t src_policy_vrf
std::set< std::string > VnListType
Definition: agent.h:212
bool alias_ip_flow
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
Definition: vn.h:151
static const Ip4Address kDefaultIpv4
Definition: pkt_flow_info.h:40
FlowEntry * flow_entry
const Interface * intf_
Definition: pkt_flow_info.h:27
uint8_t RouteToPrefixLen(const AgentRoute *route)
void CalculatePort(const PktInfo *p, const Interface *intf)
IpAddress nat_ip_saddr
bool underlay_flow
uint16_t short_flow_reason
Address::Family family
uint16_t vlan_tag_
Definition: pkt_flow_info.h:32
void BgpRouterServiceTranslate(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
void LinkLocalServiceFromVm(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
const AgentRoute * rt_
Definition: pkt_flow_info.h:28
void ChangeVrf(const PktInfo *pkt, PktControlInfo *info, const VrfEntry *vrf)
uint32_t flow_source_vrf
uint32_t dst_policy_vrf
const VnEntry * vn_
Definition: pkt_flow_info.h:29
const VmEntry * vm_
Definition: pkt_flow_info.h:30
virtual ~PktControlInfo()
Definition: pkt_flow_info.h:24
bool overlay_route_not_found
uint32_t dest_vrf
void CheckLinkLocal(const PktInfo *pkt)
void NatVxlanVrfTranslate(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
FlowRouteRefMap flow_dest_plen_map
void ApplyFlowLimits(const PktControlInfo *in, const PktControlInfo *out)
void ChangeEncapToOverlay(const VmInterface *intf, const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
void EgressProcess(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
uint32_t flow_dest_vrf
void LinkLocalServiceTranslate(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
void LinkLocalServiceFromHost(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
Definition: acl.h:92
void UpdateFipStatsInfo(FlowEntry *flow, FlowEntry *rflow, const PktInfo *p, const PktControlInfo *in, const PktControlInfo *o)
TunnelType tunnel_type
void FloatingIpDNat(const PktInfo *pkt, PktControlInfo *in, PktControlInfo *out)
PktFlowInfo(Agent *a, boost::shared_ptr< PktInfo > info, FlowTable *ftable)
Definition: pkt_flow_info.h:44