aboutsummaryrefslogtreecommitdiffstats
path: root/vpp/vnet/vnet/bfd/bfd_protocol.h
blob: cf751b3b89af757f5cce216b5b9bde57e4b50c8c (plain)
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
/*
 * Copyright (c) 2011-2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef __included_bfd_protocol_h__
#define __included_bfd_protocol_h__
/**
 * @file
 * @brief BFD protocol declarations
 */

#include <vppinfra/types.h>
#include <vppinfra/clib.h>

/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
  /*
   An optional Authentication Section MAY be present:

    0                   1                   2                   3
    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
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |   Auth Type   |   Auth Len    |    Authentication Data...     |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
  u8 type;
  u8 len;
  u8 data[0];
}) bfd_auth_t;
/* *INDENT-ON* */

/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
  /*
     The Mandatory Section of a BFD Control packet has the following
     format:

      0                   1                   2                   3
      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
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |Vers |  Diag   |Sta|P|F|C|A|D|M|  Detect Mult  |    Length     |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                       My Discriminator                        |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                      Your Discriminator                       |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                    Desired Min TX Interval                    |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                   Required Min RX Interval                    |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                 Required Min Echo RX Interval                 |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
  struct
  {
    u8 vers_diag;
    u8 sta_flags;
    u8 detect_mult;
    u8 length;
  } head;
  u32 my_disc;
  u32 your_disc;
  u32 des_min_tx;
  u32 req_min_rx;
  u32 req_min_echo_rx;
}) bfd_pkt_t;
/* *INDENT-ON* */

/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
  bfd_pkt_t pkt;
  bfd_auth_t auth;
}) bfd_pkt_with_auth_t;
/* *INDENT-ON* */

u8 bfd_pkt_get_version (const bfd_pkt_t * pkt);
void bfd_pkt_set_version (bfd_pkt_t * pkt, int version);
u8 bfd_pkt_get_diag_code (const bfd_pkt_t * pkt);
void bfd_pkt_set_diag_code (bfd_pkt_t * pkt, int value);
u8 bfd_pkt_get_state (const bfd_pkt_t * pkt);
void bfd_pkt_set_state (bfd_pkt_t * pkt, int value);
u8 bfd_pkt_get_poll (const bfd_pkt_t * pkt);
void bfd_pkt_set_final (bfd_pkt_t * pkt);
u8 bfd_pkt_get_final (const bfd_pkt_t * pkt);
void bfd_pkt_set_poll (bfd_pkt_t * pkt);
u8 bfd_pkt_get_control_plane_independent (const bfd_pkt_t * pkt);
void bfd_pkt_set_control_plane_independent (bfd_pkt_t * pkt);
u8 bfd_pkt_get_auth_present (const bfd_pkt_t * pkt);
void bfd_pkt_set_auth_present (bfd_pkt_t * pkt);
u8 bfd_pkt_get_demand (const bfd_pkt_t * pkt);
void bfd_pkt_set_demand (bfd_pkt_t * pkt);
u8 bfd_pkt_get_multipoint (const bfd_pkt_t * pkt);
void bfd_pkt_set_multipoint (bfd_pkt_t * pkt);

/* BFD diagnostic codes */
#define foreach_bfd_diag_code(F)                             \
  F (0, no_diag, "No Diagnostic")                            \
  F (1, det_time_exp, "Control Detection Time Expired")      \
  F (2, echo_failed, "Echo Function Failed")                 \
  F (3, neighbor_sig_down, "Neighbor Signaled Session Down") \
  F (4, fwd_plain_reset, "Forwarding Plane Reset")           \
  F (5, path_down, "Path Down")                              \
  F (6, concat_path_down, "Concatenated Path Down")          \
  F (7, admin_down, "Administratively Down")                 \
  F (8, reverse_concat_path_down, "Reverse Concatenated Path Down")

#define BFD_DIAG_CODE_NAME(t) BFD_DIAG_CODE_##t

typedef enum
{
#define F(n, t, s) BFD_DIAG_CODE_NAME (t) = n,
  foreach_bfd_diag_code (F)
#undef F
} bfd_diag_code_e;

const char *bfd_diag_code_string (bfd_diag_code_e diag);

/* BFD state values */
#define foreach_bfd_state(F)     \
  F (0, admin_down, "AdminDown") \
  F (1, down, "Down")            \
  F (2, init, "Init")            \
  F (3, up, "Up")

#define BFD_STATE_NAME(t) BFD_STATE_##t

typedef enum
{
#define F(n, t, s) BFD_STATE_NAME (t) = n,
  foreach_bfd_state (F)
#undef F
} bfd_state_e;

const char *bfd_state_string (bfd_state_e state);

#endif /* __included_bfd_protocol_h__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */