forked from EricssonResearch/dnt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.h
More file actions
126 lines (97 loc) · 3.81 KB
/
Copy pathinterface.h
File metadata and controls
126 lines (97 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2023-2025, Ericsson AB and Ericsson Telecommunication Hungary
// All rights reserved.
#ifndef DNT_INTERFACE_H
#define DNT_INTERFACE_H
#include "pipeline.h"
#include "protocol.h"
#include "time_utils.h"
#include "value.h"
#include <stdio.h>
#include <stdbool.h>
struct Interface;
struct HeaderDescriptor;
struct ParseTree;
enum IfaceType {
IF_ETH = 1,
IF_INTERNAL,
IF_IP,
IF_OAM,
IF_OAM_ETH,
IF_OAM_CMD,
IF_UDP_IN,
IF_UDP_OUT,
};
enum IfaceState {
IFSTATE_INIT = 1, // created but not yet opened
IFSTATE_OPEN, // opened and ready to send/recv
IFSTATE_SHUTDOWN, // closing, can still send but not recv
};
// sends the packet on the interface
// @returns false if the packet sending failed
typedef bool iface_send_fun(struct Interface *iface, struct Packet *p);
// opens the interface
// @returns false on error
typedef bool iface_open_fun(struct Interface *iface);
// closes the interface, called by @close_interface
// @close_interface frees @name and @ifname so this callback doesn't have to
// @returns false on error
typedef bool iface_close_fun(struct Interface *iface);
// @return a function that can read @property of the interface
// @type is the type the consumer wants, it is checked against the property
// the bitoffset and bitlength in @target is checked against the property
// @returns NULL on error
typedef value_producer *iface_get_property_reader(const struct Interface *iface, const char *property,
enum ProtocolFieldType target_type, const struct Value *target);
struct Interface {
enum IfaceType type;
int reference_count;
int sender_count;
enum IfaceState state;
int recvfd; // receives packets on this file descriptor
char *name;
char *ifname;
void *iface_private;
bool delay_offload;
int dropstat_cntr;
int dropstat_last_warn;
unsigned long long recv_packets;
unsigned long long recv_octets;
unsigned long long send_packets;
unsigned long long send_octets;
unsigned long long checksum_errors;
struct timespec last_alert;
struct ParseTree *parsetree_; // private
struct Thread *recv_th_; // private
// all of these methods are mandatory
iface_send_fun *send;
iface_open_fun *open;
iface_close_fun *close_;
// this method is optional
iface_get_property_reader *get_property_reader;
// this method is optional
void (*print_private_info)(const struct Interface *iface, FILE *cmd_w);
};
// no global constructor, each interface type has its own, they all return Interface*
// add a reference to the interface, this is an ownership relation
// typically there is only one owner (hashmap countainer) that holds reference
void iface_ref(struct Interface *iface);
// remove a reference from the interface
// the interface disappears when reference_count=0 and sender_count=0
void iface_unref(struct Interface *iface);
// count the streams that are sending packets on @iface
// interface with @reference_count=0 can not disappear while it is still used for sending traffic
void iface_add_sender(struct Interface *iface);
// count the streams that are sending packets on @iface
// interface with @reference_count=0 can not disappear while it is still used for sending traffic
void iface_del_sender(struct Interface *iface);
// add a stream that this interface will receive
// adds a reference to @pipe, makes a copy of @headers
// @returns true on success
bool iface_add_stream(struct Interface *iface, struct HeaderDescriptor *headers, struct Pipeline *pipe);
// @returns the name of this interface @type
const char *iface_type_str(enum IfaceType type);
// prints information about @iface to @cmd_w
// for the 'iface' telnet command
// prints more info if @stream_info is true
void iface_print_info(const struct Interface *iface, FILE *cmd_w, bool stream_info);
#endif // DNT_INTERFACE_H