-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
bgp_peer.go
241 lines (189 loc) · 6.48 KB
/
bgp_peer.go
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Code generated by go-swagger; DO NOT EDIT.
// Copyright Authors of Cilium
// SPDX-License-Identifier: Apache-2.0
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// BgpPeer State of a BGP Peer
//
// +k8s:deepcopy-gen=true
//
// swagger:model BgpPeer
type BgpPeer struct {
// Applied initial value for the BGP HoldTimer (RFC 4271, Section 4.2) in seconds.
// The applied value holds the value that is in effect on the current BGP session.
//
AppliedHoldTimeSeconds int64 `json:"applied-hold-time-seconds,omitempty"`
// Applied initial value for the BGP KeepaliveTimer (RFC 4271, Section 8) in seconds.
// The applied value holds the value that is in effect on the current BGP session.
//
AppliedKeepAliveTimeSeconds int64 `json:"applied-keep-alive-time-seconds,omitempty"`
// Configured initial value for the BGP HoldTimer (RFC 4271, Section 4.2) in seconds.
// The configured value will be used for negotiation with the peer during the BGP session establishment.
//
ConfiguredHoldTimeSeconds int64 `json:"configured-hold-time-seconds,omitempty"`
// Configured initial value for the BGP KeepaliveTimer (RFC 4271, Section 8) in seconds.
// The applied value may be different than the configured value, as it depends on the negotiated hold time interval.
//
ConfiguredKeepAliveTimeSeconds int64 `json:"configured-keep-alive-time-seconds,omitempty"`
// Initial value for the BGP ConnectRetryTimer (RFC 4271, Section 8) in seconds
ConnectRetryTimeSeconds int64 `json:"connect-retry-time-seconds,omitempty"`
// Time To Live (TTL) value used in BGP packets sent to the eBGP neighbor.
// 1 implies that eBGP multi-hop feature is disabled (only a single hop is allowed).
//
EbgpMultihopTTL int64 `json:"ebgp-multihop-ttl,omitempty"`
// BGP peer address family state
Families []*BgpPeerFamilies `json:"families"`
// Graceful restart capability
GracefulRestart *BgpGracefulRestart `json:"graceful-restart,omitempty"`
// Local AS Number
LocalAsn int64 `json:"local-asn,omitempty"`
// IP Address of peer
PeerAddress string `json:"peer-address,omitempty"`
// Peer AS Number
PeerAsn int64 `json:"peer-asn,omitempty"`
// TCP port number of peer
// Maximum: 65535
// Minimum: 1
PeerPort int64 `json:"peer-port,omitempty"`
// BGP peer operational state as described here
// https://www.rfc-editor.org/rfc/rfc4271#section-8.2.2
//
SessionState string `json:"session-state,omitempty"`
// Set when a TCP password is configured for communications with this peer
TCPPasswordEnabled bool `json:"tcp-password-enabled,omitempty"`
// BGP peer connection uptime in nano seconds.
UptimeNanoseconds int64 `json:"uptime-nanoseconds,omitempty"`
}
// Validate validates this bgp peer
func (m *BgpPeer) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateFamilies(formats); err != nil {
res = append(res, err)
}
if err := m.validateGracefulRestart(formats); err != nil {
res = append(res, err)
}
if err := m.validatePeerPort(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *BgpPeer) validateFamilies(formats strfmt.Registry) error {
if swag.IsZero(m.Families) { // not required
return nil
}
for i := 0; i < len(m.Families); i++ {
if swag.IsZero(m.Families[i]) { // not required
continue
}
if m.Families[i] != nil {
if err := m.Families[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("families" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("families" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *BgpPeer) validateGracefulRestart(formats strfmt.Registry) error {
if swag.IsZero(m.GracefulRestart) { // not required
return nil
}
if m.GracefulRestart != nil {
if err := m.GracefulRestart.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("graceful-restart")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("graceful-restart")
}
return err
}
}
return nil
}
func (m *BgpPeer) validatePeerPort(formats strfmt.Registry) error {
if swag.IsZero(m.PeerPort) { // not required
return nil
}
if err := validate.MinimumInt("peer-port", "body", m.PeerPort, 1, false); err != nil {
return err
}
if err := validate.MaximumInt("peer-port", "body", m.PeerPort, 65535, false); err != nil {
return err
}
return nil
}
// ContextValidate validate this bgp peer based on the context it is used
func (m *BgpPeer) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateFamilies(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateGracefulRestart(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *BgpPeer) contextValidateFamilies(ctx context.Context, formats strfmt.Registry) error {
for i := 0; i < len(m.Families); i++ {
if m.Families[i] != nil {
if err := m.Families[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("families" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("families" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *BgpPeer) contextValidateGracefulRestart(ctx context.Context, formats strfmt.Registry) error {
if m.GracefulRestart != nil {
if err := m.GracefulRestart.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("graceful-restart")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("graceful-restart")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *BgpPeer) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *BgpPeer) UnmarshalBinary(b []byte) error {
var res BgpPeer
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}