github.com/cilium/cilium@v1.16.2/api/v1/models/bgp_route.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  )
    19  
    20  // BgpRoute Single BGP route retrieved from the RIB of underlying router
    21  //
    22  // swagger:model BgpRoute
    23  type BgpRoute struct {
    24  
    25  	// IP address specifying a BGP neighbor if the source table type is adj-rib-in or adj-rib-out
    26  	Neighbor string `json:"neighbor,omitempty"`
    27  
    28  	// List of routing paths leading towards the prefix
    29  	Paths []*BgpPath `json:"paths"`
    30  
    31  	// IP prefix of the route
    32  	Prefix string `json:"prefix,omitempty"`
    33  
    34  	// Autonomous System Number (ASN) identifying a BGP virtual router instance
    35  	RouterAsn int64 `json:"router-asn,omitempty"`
    36  }
    37  
    38  // Validate validates this bgp route
    39  func (m *BgpRoute) Validate(formats strfmt.Registry) error {
    40  	var res []error
    41  
    42  	if err := m.validatePaths(formats); err != nil {
    43  		res = append(res, err)
    44  	}
    45  
    46  	if len(res) > 0 {
    47  		return errors.CompositeValidationError(res...)
    48  	}
    49  	return nil
    50  }
    51  
    52  func (m *BgpRoute) validatePaths(formats strfmt.Registry) error {
    53  	if swag.IsZero(m.Paths) { // not required
    54  		return nil
    55  	}
    56  
    57  	for i := 0; i < len(m.Paths); i++ {
    58  		if swag.IsZero(m.Paths[i]) { // not required
    59  			continue
    60  		}
    61  
    62  		if m.Paths[i] != nil {
    63  			if err := m.Paths[i].Validate(formats); err != nil {
    64  				if ve, ok := err.(*errors.Validation); ok {
    65  					return ve.ValidateName("paths" + "." + strconv.Itoa(i))
    66  				} else if ce, ok := err.(*errors.CompositeError); ok {
    67  					return ce.ValidateName("paths" + "." + strconv.Itoa(i))
    68  				}
    69  				return err
    70  			}
    71  		}
    72  
    73  	}
    74  
    75  	return nil
    76  }
    77  
    78  // ContextValidate validate this bgp route based on the context it is used
    79  func (m *BgpRoute) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    80  	var res []error
    81  
    82  	if err := m.contextValidatePaths(ctx, formats); err != nil {
    83  		res = append(res, err)
    84  	}
    85  
    86  	if len(res) > 0 {
    87  		return errors.CompositeValidationError(res...)
    88  	}
    89  	return nil
    90  }
    91  
    92  func (m *BgpRoute) contextValidatePaths(ctx context.Context, formats strfmt.Registry) error {
    93  
    94  	for i := 0; i < len(m.Paths); i++ {
    95  
    96  		if m.Paths[i] != nil {
    97  
    98  			if swag.IsZero(m.Paths[i]) { // not required
    99  				return nil
   100  			}
   101  
   102  			if err := m.Paths[i].ContextValidate(ctx, formats); err != nil {
   103  				if ve, ok := err.(*errors.Validation); ok {
   104  					return ve.ValidateName("paths" + "." + strconv.Itoa(i))
   105  				} else if ce, ok := err.(*errors.CompositeError); ok {
   106  					return ce.ValidateName("paths" + "." + strconv.Itoa(i))
   107  				}
   108  				return err
   109  			}
   110  		}
   111  
   112  	}
   113  
   114  	return nil
   115  }
   116  
   117  // MarshalBinary interface implementation
   118  func (m *BgpRoute) MarshalBinary() ([]byte, error) {
   119  	if m == nil {
   120  		return nil, nil
   121  	}
   122  	return swag.WriteJSON(m)
   123  }
   124  
   125  // UnmarshalBinary interface implementation
   126  func (m *BgpRoute) UnmarshalBinary(b []byte) error {
   127  	var res BgpRoute
   128  	if err := swag.ReadJSON(b, &res); err != nil {
   129  		return err
   130  	}
   131  	*m = res
   132  	return nil
   133  }