sysrepo  5.3.0
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 {
66  SRUDPN_MT_CBOR = 3,
68  SRUDPN_MT_PRIVATE = 16
70 
76 typedef struct {
77  uint8_t version;
78  uint8_t s_flag;
79  uint8_t media_type;
80  uint8_t header_len;
81  uint16_t message_len;
82  uint32_t publisher_id;
83  uint32_t message_id;
84  int segmented;
85  uint16_t segment_num;
87 } srudpn_hdr_t;
88 
102 typedef struct {
103  uint32_t datagrams;
104  uint32_t messages;
105  uint32_t dup_segments;
106  uint32_t malformed;
107  uint32_t unsupported;
108  uint32_t reasm_discarded;
110 
114 typedef struct srudpn_msg_s srudpn_msg_t;
115 
142 typedef struct srudpn_notif_s srudpn_notif_t;
143 
147 typedef struct srudpn_s srudpn_t;
148 
157 int srudpn_open(const char *address, uint16_t port, srudpn_t **udp);
158 
167 int srudpn_get_fd(const srudpn_t *udp);
168 
175 uint16_t srudpn_get_port(const srudpn_t *udp);
176 
184 
191 
203 int srudpn_read_msg(srudpn_t *udp, int32_t timeout_ms, srudpn_msg_t **msg);
204 
212 
223 
233 void srudpn_msg_get_payload(const srudpn_msg_t *msg, const uint8_t **payload, uint32_t *payload_len);
234 
242 void srudpn_msg_get_source(const srudpn_msg_t *msg, char *addr, uint16_t *port);
243 
252 int srudpn_msg_parse(const srudpn_msg_t *msg, const struct ly_ctx *ly_ctx, srudpn_notif_t **notif);
253 
260 
267 const struct lyd_node *srudpn_notif_get_tree(const srudpn_notif_t *notif);
268 
282 const struct lyd_node *srudpn_notif_get_envelope(const srudpn_notif_t *notif);
283 
290 const struct timespec *srudpn_notif_get_event_time(const srudpn_notif_t *notif);
291 
298 const char *srudpn_notif_get_hostname(const srudpn_notif_t *notif);
299 
306 const uint32_t *srudpn_notif_get_sequence_number(const srudpn_notif_t *notif);
307 
314 
328 typedef struct {
330  uint8_t hdr_len;
331  const uint8_t *data;
332  uint16_t data_len;
334 
345 int srudpn_encode_notification(const struct lyd_node *notif, const struct timespec *event_time,
346  srudpn_media_type_t media_type, uint8_t **payload, uint32_t *payload_len);
347 
363 int srudpn_encode_envelope(const struct lyd_node *notif, const struct timespec *event_time, const char *hostname,
364  uint32_t sequence_number, srudpn_media_type_t media_type, uint8_t **payload, uint32_t *payload_len);
365 
381 int srudpn_build_dgrams(srudpn_media_type_t media_type, uint32_t publisher_id, uint32_t message_id,
382  const uint8_t *payload, uint32_t payload_len, uint16_t max_segment_size, srudpn_dgram_t **dgrams);
383 
386 #ifdef __cplusplus
387 }
388 #endif
389 
390 #endif /* SYSREPO_UDP_NOTIF_H_ */
uint32_t unsupported
Definition: udp_notif.h:107
uint32_t reasm_discarded
Definition: udp_notif.h:108
uint32_t messages
Definition: udp_notif.h:104
uint32_t datagrams
Definition: udp_notif.h:103
uint32_t malformed
Definition: udp_notif.h:106
uint32_t dup_segments
Definition: udp_notif.h:105
UDP-Notif collector diagnostic counters.
Definition: udp_notif.h:102
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:142
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:147
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:114
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.
const uint32_t * srudpn_notif_get_sequence_number(const srudpn_notif_t *notif)
Get the sequence number of the message from the YANG-Push envelope of a parsed notification.
const char * srudpn_notif_get_hostname(const srudpn_notif_t *notif)
Get the hostname of the publisher from the YANG-Push envelope of a parsed notification.
uint8_t version
Definition: udp_notif.h:77
int segmented
Definition: udp_notif.h:84
uint8_t header_len
Definition: udp_notif.h:80
int last_segment
Definition: udp_notif.h:86
uint8_t media_type
Definition: udp_notif.h:79
uint32_t publisher_id
Definition: udp_notif.h:82
uint32_t message_id
Definition: udp_notif.h:83
uint16_t segment_num
Definition: udp_notif.h:85
uint16_t message_len
Definition: udp_notif.h:81
uint8_t s_flag
Definition: udp_notif.h:78
Parsed header of one UDP-Notif datagram.
Definition: udp_notif.h:76
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:68
const uint8_t * data
Definition: udp_notif.h:331
uint16_t data_len
Definition: udp_notif.h:332
uint8_t hdr_len
Definition: udp_notif.h:330
One encoded UDP-Notif datagram, header and data to be sent together.
Definition: udp_notif.h:328
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.
int srudpn_encode_envelope(const struct lyd_node *notif, const struct timespec *event_time, const char *hostname, uint32_t sequence_number, srudpn_media_type_t media_type, uint8_t **payload, uint32_t *payload_len)
Encode a notification in the YANG-Push notification envelope (draft-ietf-netconf-notif-envelope).
public API sysrepo header