sysrepo  5.2.34
YANG-based system repository for all-around configuration management.
udp_notif.h
Go to the documentation of this file.
1 
17 #ifndef SYSREPO_UDP_NOTIF_H_
18 #define SYSREPO_UDP_NOTIF_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <net/if.h>
25 #include <netinet/in.h>
26 #include <stdint.h>
27 #include <time.h>
28 
29 #include "sysrepo.h"
30 
46 #define SRUDPN_VERSION 1
47 
49 #define SRUDPN_HDR_SIZE 12
50 
52 #define SRUDPN_OPT_SEGMENTATION 1
53 
55 #define SRUDPN_OPT_SEGMENTATION_SIZE 4
56 
58 #define SRUDPN_ADDR_STRLEN (INET6_ADDRSTRLEN + IF_NAMESIZE)
59 
63 typedef enum {
67  SRUDPN_MT_PRIVATE = 16
69 
75 typedef struct {
76  uint8_t version;
77  uint8_t s_flag;
78  uint8_t media_type;
79  uint8_t header_len;
80  uint16_t message_len;
81  uint32_t publisher_id;
82  uint32_t message_id;
83  int segmented;
84  uint16_t segment_num;
86 } srudpn_hdr_t;
87 
101 typedef struct {
102  uint32_t datagrams;
103  uint32_t messages;
104  uint32_t dup_segments;
105  uint32_t malformed;
106  uint32_t unsupported;
107  uint32_t reasm_discarded;
109 
113 typedef struct srudpn_msg_s srudpn_msg_t;
114 
128 typedef struct srudpn_notif_s srudpn_notif_t;
129 
133 typedef struct srudpn_s srudpn_t;
134 
143 int srudpn_open(const char *address, uint16_t port, srudpn_t **udp);
144 
153 int srudpn_get_fd(const srudpn_t *udp);
154 
161 uint16_t srudpn_get_port(const srudpn_t *udp);
162 
170 
177 
189 int srudpn_read_msg(srudpn_t *udp, int32_t timeout_ms, srudpn_msg_t **msg);
190 
198 
209 
219 void srudpn_msg_get_payload(const srudpn_msg_t *msg, const uint8_t **payload, uint32_t *payload_len);
220 
228 void srudpn_msg_get_source(const srudpn_msg_t *msg, char *addr, uint16_t *port);
229 
238 int srudpn_msg_parse(const srudpn_msg_t *msg, const struct ly_ctx *ly_ctx, srudpn_notif_t **notif);
239 
246 
253 const struct lyd_node *srudpn_notif_get_tree(const srudpn_notif_t *notif);
254 
266 const struct lyd_node *srudpn_notif_get_envelope(const srudpn_notif_t *notif);
267 
274 const struct timespec *srudpn_notif_get_event_time(const srudpn_notif_t *notif);
275 
282 
296 typedef struct {
298  uint8_t hdr_len;
299  const uint8_t *data;
300  uint16_t data_len;
302 
313 int srudpn_encode_notification(const struct lyd_node *notif, const struct timespec *event_time,
314  srudpn_media_type_t media_type, uint8_t **payload, uint32_t *payload_len);
315 
331 int srudpn_build_dgrams(srudpn_media_type_t media_type, uint32_t publisher_id, uint32_t message_id,
332  const uint8_t *payload, uint32_t payload_len, uint16_t max_segment_size, srudpn_dgram_t **dgrams);
333 
336 #ifdef __cplusplus
337 }
338 #endif
339 
340 #endif /* SYSREPO_UDP_NOTIF_H_ */
uint32_t unsupported
Definition: udp_notif.h:106
uint32_t reasm_discarded
Definition: udp_notif.h:107
uint32_t messages
Definition: udp_notif.h:103
uint32_t datagrams
Definition: udp_notif.h:102
uint32_t malformed
Definition: udp_notif.h:105
uint32_t dup_segments
Definition: udp_notif.h:104
UDP-Notif collector diagnostic counters.
Definition: udp_notif.h:101
void srudpn_notif_free(srudpn_notif_t *notif)
Free a parsed notification.
int srudpn_get_fd(const srudpn_t *udp)
Get the socket of a collector for polling.
srudpn_stats_t srudpn_get_stats(const srudpn_t *udp)
Get the diagnostic counters of a collector.
const srudpn_hdr_t * srudpn_msg_get_hdr(const srudpn_msg_t *msg)
Get the header of a message.
struct srudpn_notif_s srudpn_notif_t
Parsed notification of a UDP-Notif message.
Definition: udp_notif.h:128
const struct lyd_node * srudpn_notif_get_tree(const srudpn_notif_t *notif)
Get the notification data tree of a parsed notification.
uint16_t srudpn_get_port(const srudpn_t *udp)
Get the port a collector is bound to.
void srudpn_msg_free(srudpn_msg_t *msg)
Free a message.
void srudpn_msg_get_source(const srudpn_msg_t *msg, char *addr, uint16_t *port)
Get the source address and port of a message.
int srudpn_read_msg(srudpn_t *udp, int32_t timeout_ms, srudpn_msg_t **msg)
Read one complete UDP-Notif message.
srudpn_media_type_t srudpn_msg_get_media_type(const srudpn_msg_t *msg)
Get the media type of a message.
const struct timespec * srudpn_notif_get_event_time(const srudpn_notif_t *notif)
Get the event time of a parsed notification.
struct srudpn_s srudpn_t
UDP-Notif collector receiving and reassembling notifications over UDP.
Definition: udp_notif.h:133
const struct lyd_node * srudpn_notif_get_envelope(const srudpn_notif_t *notif)
Get the envelope of a parsed notification.
void srudpn_close(srudpn_t *udp)
Close a collector, any incomplete messages are dropped.
int srudpn_msg_parse(const srudpn_msg_t *msg, const struct ly_ctx *ly_ctx, srudpn_notif_t **notif)
Parse the notification of a message.
struct srudpn_msg_s srudpn_msg_t
Complete (reassembled) UDP-Notif message.
Definition: udp_notif.h:113
int srudpn_open(const char *address, uint16_t port, srudpn_t **udp)
Open a UDP-Notif collector bound to a local address.
void srudpn_msg_get_payload(const srudpn_msg_t *msg, const uint8_t **payload, uint32_t *payload_len)
Get the payload of a message.
uint8_t version
Definition: udp_notif.h:76
int segmented
Definition: udp_notif.h:83
uint8_t header_len
Definition: udp_notif.h:79
int last_segment
Definition: udp_notif.h:85
uint8_t media_type
Definition: udp_notif.h:78
uint32_t publisher_id
Definition: udp_notif.h:81
uint32_t message_id
Definition: udp_notif.h:82
uint16_t segment_num
Definition: udp_notif.h:84
uint16_t message_len
Definition: udp_notif.h:80
uint8_t s_flag
Definition: udp_notif.h:77
Parsed header of one UDP-Notif datagram.
Definition: udp_notif.h:75
srudpn_media_type_t
UDP-Notif media types (MT values with the S-flag unset).
Definition: udp_notif.h:63
#define SRUDPN_OPT_SEGMENTATION_SIZE
Definition: udp_notif.h:55
#define SRUDPN_HDR_SIZE
Definition: udp_notif.h:49
@ SRUDPN_MT_XML
Definition: udp_notif.h:65
@ SRUDPN_MT_JSON
Definition: udp_notif.h:64
@ SRUDPN_MT_CBOR
Definition: udp_notif.h:66
@ SRUDPN_MT_PRIVATE
Definition: udp_notif.h:67
const uint8_t * data
Definition: udp_notif.h:299
uint16_t data_len
Definition: udp_notif.h:300
uint8_t hdr_len
Definition: udp_notif.h:298
One encoded UDP-Notif datagram, header and data to be sent together.
Definition: udp_notif.h:296
int srudpn_build_dgrams(srudpn_media_type_t media_type, uint32_t publisher_id, uint32_t message_id, const uint8_t *payload, uint32_t payload_len, uint16_t max_segment_size, srudpn_dgram_t **dgrams)
Encode a payload into UDP-Notif datagrams.
int srudpn_encode_notification(const struct lyd_node *notif, const struct timespec *event_time, srudpn_media_type_t media_type, uint8_t **payload, uint32_t *payload_len)
Encode a notification in the RFC 5277 envelope.
public API sysrepo header