OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmp_proto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_gmp_proto_h
6 #define vnsw_agent_gmp_proto_h
7 
8 typedef struct gmp_intf_ gmp_intf;
10 class TaskMap;
11 class GmpIntf;
12 class GmpProto;
13 
14 #define GMP_TX_BUFF_LEN 512
15 
16 struct GmpPacket {
17  GmpPacket(uint8_t *pkt, uint32_t pkt_len, IpAddress dst_addr)
18  : pkt_(pkt), pkt_len_(pkt_len), dst_addr_(dst_addr) {}
19 
20  uint8_t *pkt_;
21  uint32_t pkt_len_;
23 };
24 
26 public:
28  source_ = IpAddress();
29  group_ = IpAddress();
30  flags_ = 0;
32  refcount_ = 0;
33  }
35 
36  enum IgmpVersion {
37  IGMP_VERSION_V1 = 1 << 0,
38  IGMP_VERSION_V2 = 1 << 1,
39  IGMP_VERSION_V3 = 1 << 2,
40  };
41 
42  enum GmpMode {
46  };
47 
50  uint8_t flags_;
52  uint32_t refcount_;
53 };
54 
55 class VnGmpIntfState;
56 class VnGmpDBState : public DBState {
57 public:
58  typedef std::set<GmpSourceGroup *> VnGmpIntfSGList;
59  typedef VnGmpIntfSGList::iterator VnGmpSGIntfListIter;
60 
62  public:
63 
66 
69  };
70 
71  typedef std::map<IpAddress, VnGmpIntfState *> VnGmpIntfMap;
72  typedef std::set<GmpSourceGroup *> VnGmpSGList;
73  typedef VnGmpSGList::iterator VnGmpSGListIter;
74 
77 
80 };
81 
82 class VmiGmpDBState : public DBState {
83 public:
86 
87  std::string vrf_name_;
89 };
90 
91 class GmpIntf {
92 public:
93  GmpIntf(const GmpProto *);
94  ~GmpIntf() {};
95 
96  void SetGif(gmp_intf *gif) { gif_ = gif; }
97  gmp_intf *GetGif() { return gif_; }
98  const IpAddress get_ip_address() { return ip_addr_; }
99  bool set_ip_address(const IpAddress &ip_addr);
100  const string &get_vrf_name() { return vrf_name_; }
101  bool set_vrf_name(const std::string &vrf_name);
102  bool set_gmp_querying(bool querying);
103 
104 private:
106  string vrf_name_;
109  bool querying_;
110 };
111 
112 struct GmpType {
113  enum Type {
117  };
118 };
119 
120 class GmpProto {
121 public:
122  static const int kGmpTriggerRestartTimer = 100; /* milli-seconds */
123  typedef boost::function<bool(const VrfEntry *, IpAddress, GmpPacket *)> Callback;
124  struct GmpStats {
125  GmpStats() { Reset(); }
126  void Reset() {
127  gmp_g_add_count_ = 0;
128  gmp_g_del_count_ = 0;
129 
130  gmp_sg_add_count_ = 0;
131  gmp_sg_del_count_ = 0;
132  }
133 
136 
139  };
140 
141  GmpProto(GmpType::Type type, Agent *agent, const std::string &task_name,
142  int instance, boost::asio::io_context &io);
143  ~GmpProto();
144  GmpIntf *CreateIntf();
145  bool DeleteIntf(GmpIntf *gif);
146 
147  void Register(Callback cb) { cb_ = cb; }
148 
149  bool Start();
150  bool Stop();
151 
152  void GmpIntfSGClear(VnGmpDBState *state,
153  VnGmpDBState::VnGmpIntfState *gmp_intf_state);
154 
157 
158  bool GmpProcessPkt(const VmInterface *vm_itf, void *rcv_pkt,
159  uint32_t packet_len, IpAddress ip_saddr,
160  IpAddress ip_daddr);
161  uint8_t *GmpBufferGet();
162  void GmpBufferFree(uint8_t *pkt);
163  bool GmpNotificationHandler();
164  bool GmpNotificationTimer();
165  void GmpNotificationReady();
166  void GroupNotify(GmpIntf *gif, IpAddress source, IpAddress group,
167  int group_action);
168  void ResyncNotify(GmpIntf *gif, IpAddress source, IpAddress group);
169  void UpdateHostInSourceGroup(GmpIntf *gif, bool join, IpAddress host,
170  IpAddress source, IpAddress group);
171  void TriggerMvpnNotification(const VmInterface *vm_intf, bool join,
172  IpAddress source, IpAddress group);
173  void TriggerEvpnNotification(const VmInterface *vm_intf, bool join,
174  IpAddress source, IpAddress group);
175  bool MulticastPolicyCheck(GmpIntf *gif, IpAddress source, IpAddress group);
176  bool SendPacket(GmpIntf *gif, uint8_t *pkt, uint32_t pkt_len,
177  IpAddress dest);
178  const GmpStats &GetStats() const { return stats_; }
179  void ClearStats() { stats_.Reset(); }
180 
181 private:
182  void GmpVnNotify(DBTablePartBase *part, DBEntryBase *entry);
183  void GmpVrfNotify(DBTablePartBase *part, DBEntryBase *entry);
184  void GmpItfNotify(DBTablePartBase *part, DBEntryBase *entry);
185 
188  const std::string &name_;
190  boost::asio::io_context &io_;
191 
194 
200 
203 
204  typedef std::map<IpAddress, boost::uuids::uuid> VmIpInterfaceMap;
206 
207  friend class GmpIntf;
208 };
209 
211 public:
213  const std::string &name, int instance,
214  boost::asio::io_context &io);
215  static bool DeleteGmpProto(GmpProto *gmp_proto);
216 
217  friend class GmpProto;
218 };
219 
220 #endif /* vnsw_agent_gmp_proto_h */
string vrf_name_
Definition: gmp_proto.h:106
uint32_t gmp_g_del_count_
Definition: gmp_proto.h:135
bool GmpNotificationHandler()
Definition: gmp_proto.cc:492
boost::function< bool(const VrfEntry *, IpAddress, GmpPacket *)> Callback
Definition: gmp_proto.h:123
Callback cb_
Definition: gmp_proto.h:199
void TriggerMvpnNotification(const VmInterface *vm_intf, bool join, IpAddress source, IpAddress group)
Definition: gmp_proto.cc:697
uint8_t flags_
Definition: gmp_proto.h:50
std::map< IpAddress, boost::uuids::uuid > VmIpInterfaceMap
Definition: gmp_proto.h:204
static GmpProto * CreateGmpProto(GmpType::Type type, Agent *agent, const std::string &name, int instance, boost::asio::io_context &io)
Definition: gmp_proto.cc:804
bool GmpProcessPkt(const VmInterface *vm_itf, void *rcv_pkt, uint32_t packet_len, IpAddress ip_saddr, IpAddress ip_daddr)
Definition: gmp_proto.cc:443
VnGmpSGList gmp_sg_list_
Definition: gmp_proto.h:79
void GmpItfNotify(DBTablePartBase *part, DBEntryBase *entry)
Definition: gmp_proto.cc:337
TaskTrigger * gmp_notif_trigger_
Definition: gmp_proto.h:197
DBTableBase::ListenerId itf_listener_id_
Definition: gmp_proto.h:193
Agent * agent_
Definition: gmp_proto.h:187
bool Stop()
Definition: gmp_proto.cc:139
static bool DeleteGmpProto(GmpProto *gmp_proto)
Definition: gmp_proto.cc:816
~GmpIntf()
Definition: gmp_proto.h:94
VnGmpIntfMap gmp_intf_map_
Definition: gmp_proto.h:78
GmpProto(GmpType::Type type, Agent *agent, const std::string &task_name, int instance, boost::asio::io_context &io)
Definition: gmp_proto.cc:76
uint32_t gmp_sg_add_count_
Definition: gmp_proto.h:137
VnGmpIntfSGList gmp_intf_sg_list_
Definition: gmp_proto.h:68
const IpAddress get_ip_address()
Definition: gmp_proto.h:98
uint8_t * pkt_
Definition: gmp_proto.h:20
DBTableBase::ListenerId vn_listener_id_
Definition: gmp_proto.h:192
bool querying_
Definition: gmp_proto.h:109
const string & get_vrf_name()
Definition: gmp_proto.h:100
boost::asio::ip::address IpAddress
Definition: address.h:13
int instance_
Definition: gmp_proto.h:189
int ListenerId
Definition: db_table.h:62
GmpType::Type type_
Definition: gmp_proto.h:186
uint8_t * GmpBufferGet()
Definition: gmp_proto.cc:483
std::string vrf_name_
Definition: gmp_proto.h:87
~GmpProto()
Definition: gmp_proto.cc:94
VnGmpSGList::iterator VnGmpSGListIter
Definition: gmp_proto.h:73
bool Start()
Definition: gmp_proto.cc:98
void UpdateHostInSourceGroup(GmpIntf *gif, bool join, IpAddress host, IpAddress source, IpAddress group)
Definition: gmp_proto.cc:655
IpAddress dst_addr_
Definition: gmp_proto.h:22
bool MulticastPolicyCheck(GmpIntf *gif, IpAddress source, IpAddress group)
Definition: gmp_proto.cc:751
gmp_proto
Definition: gmp.h:45
IpAddress vmi_v4_addr_
Definition: gmp_proto.h:88
void ResyncNotify(GmpIntf *gif, IpAddress source, IpAddress group)
Definition: gmp_proto.cc:649
IpAddress ip_addr_
Definition: gmp_proto.h:107
void ClearStats()
Definition: gmp_proto.h:179
uint8_t type
Definition: load_balance.h:109
Definition: agent.h:358
uint32_t refcount_
Definition: gmp_proto.h:52
GmpPacket(uint8_t *pkt, uint32_t pkt_len, IpAddress dst_addr)
Definition: gmp_proto.h:17
bool DeleteIntf(GmpIntf *gif)
Definition: gmp_proto.cc:434
uint32_t gmp_sg_del_count_
Definition: gmp_proto.h:138
uint32_t gmp_g_add_count_
Definition: gmp_proto.h:134
void SetGif(gmp_intf *gif)
Definition: gmp_proto.h:96
static const int kGmpTriggerRestartTimer
Definition: gmp_proto.h:122
void GmpBufferFree(uint8_t *pkt)
Definition: gmp_proto.cc:487
boost::asio::io_context & io_
Definition: gmp_proto.h:190
void Register(Callback cb)
Definition: gmp_proto.h:147
gmp_intf * GetGif()
Definition: gmp_proto.h:97
Timer * gmp_trigger_timer_
Definition: gmp_proto.h:196
IpAddress group_
Definition: gmp_proto.h:49
bool set_ip_address(const IpAddress &ip_addr)
Definition: gmp_proto.cc:40
IpAddress source_
Definition: gmp_proto.h:48
bool SendPacket(GmpIntf *gif, uint8_t *pkt, uint32_t pkt_len, IpAddress dest)
Definition: gmp_proto.cc:786
VnGmpIntfSGList::iterator VnGmpSGIntfListIter
Definition: gmp_proto.h:59
void GmpVrfNotify(DBTablePartBase *part, DBEntryBase *entry)
bool GmpNotificationTimer()
Definition: gmp_proto.cc:511
DBTableBase::ListenerId vn_listener_id()
bool set_vrf_name(const std::string &vrf_name)
Definition: gmp_proto.cc:58
VmIpInterfaceMap vm_ip_to_vmi_
Definition: gmp_proto.h:205
int itf_attach_count_
Definition: gmp_proto.h:202
TaskMap * task_map_
Definition: gmp_proto.h:195
GmpIntf * CreateIntf()
Definition: gmp_proto.cc:420
std::map< IpAddress, VnGmpIntfState * > VnGmpIntfMap
Definition: gmp_proto.h:71
gmp_intf * gif_
Definition: gmp_proto.h:108
std::set< GmpSourceGroup * > VnGmpIntfSGList
Definition: gmp_proto.h:58
void GmpIntfSGClear(VnGmpDBState *state, VnGmpDBState::VnGmpIntfState *gmp_intf_state)
Definition: gmp_proto.cc:168
GmpMode mode_
Definition: gmp_proto.h:51
DBTableBase::ListenerId itf_listener_id()
Definition: timer.h:54
bool set_gmp_querying(bool querying)
Definition: gmp_proto.cc:64
GmpIntf(const GmpProto *)
Definition: gmp_proto.cc:30
const GmpProto * gmp_proto_
Definition: gmp_proto.h:105
GmpStats stats_
Definition: gmp_proto.h:201
void TriggerEvpnNotification(const VmInterface *vm_intf, bool join, IpAddress source, IpAddress group)
Definition: gmp_proto.cc:726
void GmpVnNotify(DBTablePartBase *part, DBEntryBase *entry)
Definition: gmp_proto.cc:210
std::set< GmpSourceGroup * > VnGmpSGList
Definition: gmp_proto.h:72
void GmpNotificationReady()
Definition: gmp_proto.cc:525
uint32_t pkt_len_
Definition: gmp_proto.h:21
void GroupNotify(GmpIntf *gif, IpAddress source, IpAddress group, int group_action)
Definition: gmp_proto.cc:537
const std::string & name_
Definition: gmp_proto.h:188
const GmpStats & GetStats() const
Definition: gmp_proto.h:178
mgm_global_data * gd_
Definition: gmp_proto.h:198