blob: cf751b3b89af757f5cce216b5b9bde57e4b50c8c [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001/*
2 * Copyright (c) 2011-2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef __included_bfd_protocol_h__
16#define __included_bfd_protocol_h__
17/**
18 * @file
19 * @brief BFD protocol declarations
20 */
21
22#include <vppinfra/types.h>
23#include <vppinfra/clib.h>
24
25/* *INDENT-OFF* */
26typedef CLIB_PACKED (struct {
27 /*
28 An optional Authentication Section MAY be present:
29
30 0 1 2 3
31 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
32 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 | Auth Type | Auth Len | Authentication Data... |
34 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 */
36 u8 type;
37 u8 len;
38 u8 data[0];
39}) bfd_auth_t;
40/* *INDENT-ON* */
41
42/* *INDENT-OFF* */
43typedef CLIB_PACKED (struct {
44 /*
45 The Mandatory Section of a BFD Control packet has the following
46 format:
47
48 0 1 2 3
49 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
50 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 |Vers | Diag |Sta|P|F|C|A|D|M| Detect Mult | Length |
52 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 | My Discriminator |
54 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 | Your Discriminator |
56 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 | Desired Min TX Interval |
58 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 | Required Min RX Interval |
60 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 | Required Min Echo RX Interval |
62 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63 */
64 struct
65 {
66 u8 vers_diag;
67 u8 sta_flags;
68 u8 detect_mult;
69 u8 length;
70 } head;
71 u32 my_disc;
72 u32 your_disc;
73 u32 des_min_tx;
74 u32 req_min_rx;
75 u32 req_min_echo_rx;
76}) bfd_pkt_t;
77/* *INDENT-ON* */
78
79/* *INDENT-OFF* */
80typedef CLIB_PACKED (struct {
81 bfd_pkt_t pkt;
82 bfd_auth_t auth;
83}) bfd_pkt_with_auth_t;
84/* *INDENT-ON* */
85
86u8 bfd_pkt_get_version (const bfd_pkt_t * pkt);
87void bfd_pkt_set_version (bfd_pkt_t * pkt, int version);
88u8 bfd_pkt_get_diag_code (const bfd_pkt_t * pkt);
89void bfd_pkt_set_diag_code (bfd_pkt_t * pkt, int value);
90u8 bfd_pkt_get_state (const bfd_pkt_t * pkt);
91void bfd_pkt_set_state (bfd_pkt_t * pkt, int value);
92u8 bfd_pkt_get_poll (const bfd_pkt_t * pkt);
93void bfd_pkt_set_final (bfd_pkt_t * pkt);
94u8 bfd_pkt_get_final (const bfd_pkt_t * pkt);
95void bfd_pkt_set_poll (bfd_pkt_t * pkt);
96u8 bfd_pkt_get_control_plane_independent (const bfd_pkt_t * pkt);
97void bfd_pkt_set_control_plane_independent (bfd_pkt_t * pkt);
98u8 bfd_pkt_get_auth_present (const bfd_pkt_t * pkt);
99void bfd_pkt_set_auth_present (bfd_pkt_t * pkt);
100u8 bfd_pkt_get_demand (const bfd_pkt_t * pkt);
101void bfd_pkt_set_demand (bfd_pkt_t * pkt);
102u8 bfd_pkt_get_multipoint (const bfd_pkt_t * pkt);
103void bfd_pkt_set_multipoint (bfd_pkt_t * pkt);
104
105/* BFD diagnostic codes */
106#define foreach_bfd_diag_code(F) \
107 F (0, no_diag, "No Diagnostic") \
108 F (1, det_time_exp, "Control Detection Time Expired") \
109 F (2, echo_failed, "Echo Function Failed") \
110 F (3, neighbor_sig_down, "Neighbor Signaled Session Down") \
111 F (4, fwd_plain_reset, "Forwarding Plane Reset") \
112 F (5, path_down, "Path Down") \
113 F (6, concat_path_down, "Concatenated Path Down") \
114 F (7, admin_down, "Administratively Down") \
115 F (8, reverse_concat_path_down, "Reverse Concatenated Path Down")
116
117#define BFD_DIAG_CODE_NAME(t) BFD_DIAG_CODE_##t
118
119typedef enum
120{
121#define F(n, t, s) BFD_DIAG_CODE_NAME (t) = n,
122 foreach_bfd_diag_code (F)
123#undef F
124} bfd_diag_code_e;
125
126const char *bfd_diag_code_string (bfd_diag_code_e diag);
127
128/* BFD state values */
129#define foreach_bfd_state(F) \
130 F (0, admin_down, "AdminDown") \
131 F (1, down, "Down") \
132 F (2, init, "Init") \
133 F (3, up, "Up")
134
135#define BFD_STATE_NAME(t) BFD_STATE_##t
136
137typedef enum
138{
139#define F(n, t, s) BFD_STATE_NAME (t) = n,
140 foreach_bfd_state (F)
141#undef F
142} bfd_state_e;
143
144const char *bfd_state_string (bfd_state_e state);
145
146#endif /* __included_bfd_protocol_h__ */
147
148/*
149 * fd.io coding-style-patch-verification: ON
150 *
151 * Local Variables:
152 * eval: (c-set-style "gnu")
153 * End:
154 */