-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoam.h
More file actions
165 lines (147 loc) · 4.08 KB
/
oam.h
File metadata and controls
165 lines (147 loc) · 4.08 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef OAM_H
#define OAM_H
#include "oamdefs.h"
#include <stdlib.h>
#include <stdint.h>
#include <sys/queue.h>
#include <linux/if_ether.h>
typedef struct tlv_t {
uint8_t type;
uint8_t len;
uint8_t data[0];
} tlv_t;
typedef struct tlv_elem_t {
STAILQ_ENTRY(tlv_elem_t) entry;
tlv_t tlv;
} tlv_elem_t;
typedef struct ethhdr ethhdr_t;
/*
-------------------------------------------
[6] [5] | Remote Discovery status |
[4] [3] | Local Discovery status |
-------------------------------------------|
0 0 | Unsatisfied, can’t complete |
0 1 | Discovery in process |
1 0 | Satisfied, Discovery complete |
1 1 | Reserved |
-------------------------------------------
*/
typedef struct {
uint16_t link_fault:1;
uint16_t dying_gasp:1;
uint16_t critical:1;
uint16_t local_evaluating:1; //3
uint16_t local_stable:1; //4
uint16_t remove_evaluating:1; //5
uint16_t remote_stable:1; //6
uint16_t _reserved:9;
} __attribute__((packed)) oam_flags_t;
typedef struct {
uint8_t subtype;
oam_flags_t flags;
uint8_t opcode;
} __attribute__((packed)) oam_msg_t;
typedef struct {
oam_msg_t hdr;
uint8_t payload[0];
} __attribute__((packed)) oam_pdu_t;
typedef struct {
uint8_t tlv_version;
uint16_t tlv_revision;
struct {
uint8_t parser_action:2;
uint8_t muxiplexer_action:1;
uint8_t reserved:5;
} __attribute__((packed)) dte_status;
struct {
uint8_t oam_mode:1;
uint8_t uni_dir_support:1;
uint8_t loopback_support:1;
uint8_t link_event_support:1;
uint8_t var_retrieval:1;
uint8_t _reserved:3;
} __attribute__((packed)) oam_conf;
uint16_t max_oampdu_size;
struct {
uint8_t high;
uint16_t low;
}oui;
} __attribute__((packed)) oam_pdu_info_t;
typedef struct {
uint16_t sequence;
STAILQ_HEAD(, tlv_elem_t) tlvs;
} oam_pdu_event_t;
typedef struct leaf_t {
uint8_t branch;
union {
uint16_t leaf;
uint16_t type;
}v;
uint8_t width;
uint8_t value[0];
} __attribute__((packed)) leaf_t;
typedef struct leaf_item_t {
STAILQ_ENTRY(leaf_item_t) entry;
size_t leaflen;
leaf_t leaf;
}leaf_item_t;
typedef struct {
uint16_t fw_ver;
struct {
uint8_t high;
uint16_t low;
} __attribute((packed)) oui;
uint16_t product_id;
uint16_t version;
uint8_t extended_id[64];
uint8_t base_mac[6];
uint8_t max_links;
uint8_t num_ports;
uint8_t num_assignable_upstream_queues;
uint8_t max_queue_per_link_upstream;
uint8_t queue_increment_upstream;
uint8_t num_assignable_downstream_queues;
uint8_t max_queue_per_link_downstream;
uint8_t queue_increment_downstream;
uint16_t upstream_buffer_available;
uint16_t downstream_buffer_available;
uint16_t jedec_manufacturer_id;
uint16_t chip_id;
uint32_t chip_ver;
} __attribute__((packed)) oam_pdu_teknovus_info_t;
typedef struct {
uint32_t oui:24;
uint32_t ext_opcode:8;
union {
STAILQ_HEAD(,leaf_item_t) greq;
STAILQ_HEAD(,leaf_item_t) gresp;
STAILQ_HEAD(,leaf_item_t) sreq;
STAILQ_HEAD(,leaf_item_t) sresp;
oam_pdu_teknovus_info_t info;
}v;
} oam_pdu_org_t;
typedef struct {
/**
* 0x00 : reserved
* 0x01 : enable loopback
* 0x02 : disable loopback
* 0x03-0xFF : reserved
*/
uint8_t cmd;
} oam_pdu_loopback_ctl_t;
typedef struct {
ethhdr_t ethhdr;
oam_pdu_t pdu;
union {
STAILQ_HEAD(,tlv_elem_t) info;
oam_pdu_event_t event;
oam_pdu_org_t org;
STAILQ_HEAD(,leaf_item_t) req;
STAILQ_HEAD(,leaf_item_t) resp;
oam_pdu_loopback_ctl_t loopback;
}payload;
} __attribute__((packed)) oam_frame_t;
extern oam_frame_t* oampdu_parse(oam_frame_t** frame, uint8_t* pkt, size_t len);
extern void oampdu_free_frame(oam_frame_t** frame);
extern void oampdu_dump(const oam_frame_t* frame, uint8_t* buf, size_t buflen);
#endif // OAM_H