github.com/cilium/cilium@v1.16.2/api/v1/models/bgp_peer.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright Authors of Cilium
     4  // SPDX-License-Identifier: Apache-2.0
     5  
     6  package models
     7  
     8  // This file was generated by the swagger tool.
     9  // Editing this file might prove futile when you re-run the swagger generate command
    10  
    11  import (
    12  	"context"
    13  	"strconv"
    14  
    15  	"github.com/go-openapi/errors"
    16  	"github.com/go-openapi/strfmt"
    17  	"github.com/go-openapi/swag"
    18  	"github.com/go-openapi/validate"
    19  )
    20  
    21  // BgpPeer State of a BGP Peer
    22  //
    23  // +k8s:deepcopy-gen=true
    24  //
    25  // swagger:model BgpPeer
    26  type BgpPeer struct {
    27  
    28  	// Applied initial value for the BGP HoldTimer (RFC 4271, Section 4.2) in seconds.
    29  	// The applied value holds the value that is in effect on the current BGP session.
    30  	//
    31  	AppliedHoldTimeSeconds int64 `json:"applied-hold-time-seconds,omitempty"`
    32  
    33  	// Applied initial value for the BGP KeepaliveTimer (RFC 4271, Section 8) in seconds.
    34  	// The applied value holds the value that is in effect on the current BGP session.
    35  	//
    36  	AppliedKeepAliveTimeSeconds int64 `json:"applied-keep-alive-time-seconds,omitempty"`
    37  
    38  	// Configured initial value for the BGP HoldTimer (RFC 4271, Section 4.2) in seconds.
    39  	// The configured value will be used for negotiation with the peer during the BGP session establishment.
    40  	//
    41  	ConfiguredHoldTimeSeconds int64 `json:"configured-hold-time-seconds,omitempty"`
    42  
    43  	// Configured initial value for the BGP KeepaliveTimer (RFC 4271, Section 8) in seconds.
    44  	// The applied value may be different than the configured value, as it depends on the negotiated hold time interval.
    45  	//
    46  	ConfiguredKeepAliveTimeSeconds int64 `json:"configured-keep-alive-time-seconds,omitempty"`
    47  
    48  	// Initial value for the BGP ConnectRetryTimer (RFC 4271, Section 8) in seconds
    49  	ConnectRetryTimeSeconds int64 `json:"connect-retry-time-seconds,omitempty"`
    50  
    51  	// Time To Live (TTL) value used in BGP packets sent to the eBGP neighbor.
    52  	// 1 implies that eBGP multi-hop feature is disabled (only a single hop is allowed).
    53  	//
    54  	EbgpMultihopTTL int64 `json:"ebgp-multihop-ttl,omitempty"`
    55  
    56  	// BGP peer address family state
    57  	Families []*BgpPeerFamilies `json:"families"`
    58  
    59  	// Graceful restart capability
    60  	GracefulRestart *BgpGracefulRestart `json:"graceful-restart,omitempty"`
    61  
    62  	// Local AS Number
    63  	LocalAsn int64 `json:"local-asn,omitempty"`
    64  
    65  	// IP Address of peer
    66  	PeerAddress string `json:"peer-address,omitempty"`
    67  
    68  	// Peer AS Number
    69  	PeerAsn int64 `json:"peer-asn,omitempty"`
    70  
    71  	// TCP port number of peer
    72  	// Maximum: 65535
    73  	// Minimum: 1
    74  	PeerPort int64 `json:"peer-port,omitempty"`
    75  
    76  	// BGP peer operational state as described here
    77  	// https://www.rfc-editor.org/rfc/rfc4271#section-8.2.2
    78  	//
    79  	SessionState string `json:"session-state,omitempty"`
    80  
    81  	// Set when a TCP password is configured for communications with this peer
    82  	TCPPasswordEnabled bool `json:"tcp-password-enabled,omitempty"`
    83  
    84  	// BGP peer connection uptime in nano seconds.
    85  	UptimeNanoseconds int64 `json:"uptime-nanoseconds,omitempty"`
    86  }
    87  
    88  // Validate validates this bgp peer
    89  func (m *BgpPeer) Validate(formats strfmt.Registry) error {
    90  	var res []error
    91  
    92  	if err := m.validateFamilies(formats); err != nil {
    93  		res = append(res, err)
    94  	}
    95  
    96  	if err := m.validateGracefulRestart(formats); err != nil {
    97  		res = append(res, err)
    98  	}
    99  
   100  	if err := m.validatePeerPort(formats); err != nil {
   101  		res = append(res, err)
   102  	}
   103  
   104  	if len(res) > 0 {
   105  		return errors.CompositeValidationError(res...)
   106  	}
   107  	return nil
   108  }
   109  
   110  func (m *BgpPeer) validateFamilies(formats strfmt.Registry) error {
   111  	if swag.IsZero(m.Families) { // not required
   112  		return nil
   113  	}
   114  
   115  	for i := 0; i < len(m.Families); i++ {
   116  		if swag.IsZero(m.Families[i]) { // not required
   117  			continue
   118  		}
   119  
   120  		if m.Families[i] != nil {
   121  			if err := m.Families[i].Validate(formats); err != nil {
   122  				if ve, ok := err.(*errors.Validation); ok {
   123  					return ve.ValidateName("families" + "." + strconv.Itoa(i))
   124  				} else if ce, ok := err.(*errors.CompositeError); ok {
   125  					return ce.ValidateName("families" + "." + strconv.Itoa(i))
   126  				}
   127  				return err
   128  			}
   129  		}
   130  
   131  	}
   132  
   133  	return nil
   134  }
   135  
   136  func (m *BgpPeer) validateGracefulRestart(formats strfmt.Registry) error {
   137  	if swag.IsZero(m.GracefulRestart) { // not required
   138  		return nil
   139  	}
   140  
   141  	if m.GracefulRestart != nil {
   142  		if err := m.GracefulRestart.Validate(formats); err != nil {
   143  			if ve, ok := err.(*errors.Validation); ok {
   144  				return ve.ValidateName("graceful-restart")
   145  			} else if ce, ok := err.(*errors.CompositeError); ok {
   146  				return ce.ValidateName("graceful-restart")
   147  			}
   148  			return err
   149  		}
   150  	}
   151  
   152  	return nil
   153  }
   154  
   155  func (m *BgpPeer) validatePeerPort(formats strfmt.Registry) error {
   156  	if swag.IsZero(m.PeerPort) { // not required
   157  		return nil
   158  	}
   159  
   160  	if err := validate.MinimumInt("peer-port", "body", m.PeerPort, 1, false); err != nil {
   161  		return err
   162  	}
   163  
   164  	if err := validate.MaximumInt("peer-port", "body", m.PeerPort, 65535, false); err != nil {
   165  		return err
   166  	}
   167  
   168  	return nil
   169  }
   170  
   171  // ContextValidate validate this bgp peer based on the context it is used
   172  func (m *BgpPeer) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   173  	var res []error
   174  
   175  	if err := m.contextValidateFamilies(ctx, formats); err != nil {
   176  		res = append(res, err)
   177  	}
   178  
   179  	if err := m.contextValidateGracefulRestart(ctx, formats); err != nil {
   180  		res = append(res, err)
   181  	}
   182  
   183  	if len(res) > 0 {
   184  		return errors.CompositeValidationError(res...)
   185  	}
   186  	return nil
   187  }
   188  
   189  func (m *BgpPeer) contextValidateFamilies(ctx context.Context, formats strfmt.Registry) error {
   190  
   191  	for i := 0; i < len(m.Families); i++ {
   192  
   193  		if m.Families[i] != nil {
   194  
   195  			if swag.IsZero(m.Families[i]) { // not required
   196  				return nil
   197  			}
   198  
   199  			if err := m.Families[i].ContextValidate(ctx, formats); err != nil {
   200  				if ve, ok := err.(*errors.Validation); ok {
   201  					return ve.ValidateName("families" + "." + strconv.Itoa(i))
   202  				} else if ce, ok := err.(*errors.CompositeError); ok {
   203  					return ce.ValidateName("families" + "." + strconv.Itoa(i))
   204  				}
   205  				return err
   206  			}
   207  		}
   208  
   209  	}
   210  
   211  	return nil
   212  }
   213  
   214  func (m *BgpPeer) contextValidateGracefulRestart(ctx context.Context, formats strfmt.Registry) error {
   215  
   216  	if m.GracefulRestart != nil {
   217  
   218  		if swag.IsZero(m.GracefulRestart) { // not required
   219  			return nil
   220  		}
   221  
   222  		if err := m.GracefulRestart.ContextValidate(ctx, formats); err != nil {
   223  			if ve, ok := err.(*errors.Validation); ok {
   224  				return ve.ValidateName("graceful-restart")
   225  			} else if ce, ok := err.(*errors.CompositeError); ok {
   226  				return ce.ValidateName("graceful-restart")
   227  			}
   228  			return err
   229  		}
   230  	}
   231  
   232  	return nil
   233  }
   234  
   235  // MarshalBinary interface implementation
   236  func (m *BgpPeer) MarshalBinary() ([]byte, error) {
   237  	if m == nil {
   238  		return nil, nil
   239  	}
   240  	return swag.WriteJSON(m)
   241  }
   242  
   243  // UnmarshalBinary interface implementation
   244  func (m *BgpPeer) UnmarshalBinary(b []byte) error {
   245  	var res BgpPeer
   246  	if err := swag.ReadJSON(b, &res); err != nil {
   247  		return err
   248  	}
   249  	*m = res
   250  	return nil
   251  }