github.com/cilium/cilium@v1.16.2/api/v1/models/bgp_path.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  // BgpPath Single BGP routing Path containing BGP Network Layer Reachability Information (NLRI) and path attributes
    21  //
    22  // swagger:model BgpPath
    23  type BgpPath struct {
    24  
    25  	// Age of the path (time since its creation) in nanoseconds
    26  	AgeNanoseconds int64 `json:"age-nanoseconds,omitempty"`
    27  
    28  	// True value flags the best path towards the destination prefix
    29  	Best bool `json:"best,omitempty"`
    30  
    31  	// Address Family Indicator (AFI) and Subsequent Address Family Indicator (SAFI) of the path
    32  	Family *BgpFamily `json:"family,omitempty"`
    33  
    34  	// Network Layer Reachability Information of the path
    35  	Nlri *BgpNlri `json:"nlri,omitempty"`
    36  
    37  	// List of BGP path attributes specific for the path
    38  	PathAttributes []*BgpPathAttribute `json:"path-attributes"`
    39  
    40  	// True value marks the path as stale
    41  	Stale bool `json:"stale,omitempty"`
    42  }
    43  
    44  // Validate validates this bgp path
    45  func (m *BgpPath) Validate(formats strfmt.Registry) error {
    46  	var res []error
    47  
    48  	if err := m.validateFamily(formats); err != nil {
    49  		res = append(res, err)
    50  	}
    51  
    52  	if err := m.validateNlri(formats); err != nil {
    53  		res = append(res, err)
    54  	}
    55  
    56  	if err := m.validatePathAttributes(formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	if len(res) > 0 {
    61  		return errors.CompositeValidationError(res...)
    62  	}
    63  	return nil
    64  }
    65  
    66  func (m *BgpPath) validateFamily(formats strfmt.Registry) error {
    67  	if swag.IsZero(m.Family) { // not required
    68  		return nil
    69  	}
    70  
    71  	if m.Family != nil {
    72  		if err := m.Family.Validate(formats); err != nil {
    73  			if ve, ok := err.(*errors.Validation); ok {
    74  				return ve.ValidateName("family")
    75  			} else if ce, ok := err.(*errors.CompositeError); ok {
    76  				return ce.ValidateName("family")
    77  			}
    78  			return err
    79  		}
    80  	}
    81  
    82  	return nil
    83  }
    84  
    85  func (m *BgpPath) validateNlri(formats strfmt.Registry) error {
    86  	if swag.IsZero(m.Nlri) { // not required
    87  		return nil
    88  	}
    89  
    90  	if m.Nlri != nil {
    91  		if err := m.Nlri.Validate(formats); err != nil {
    92  			if ve, ok := err.(*errors.Validation); ok {
    93  				return ve.ValidateName("nlri")
    94  			} else if ce, ok := err.(*errors.CompositeError); ok {
    95  				return ce.ValidateName("nlri")
    96  			}
    97  			return err
    98  		}
    99  	}
   100  
   101  	return nil
   102  }
   103  
   104  func (m *BgpPath) validatePathAttributes(formats strfmt.Registry) error {
   105  	if swag.IsZero(m.PathAttributes) { // not required
   106  		return nil
   107  	}
   108  
   109  	for i := 0; i < len(m.PathAttributes); i++ {
   110  		if swag.IsZero(m.PathAttributes[i]) { // not required
   111  			continue
   112  		}
   113  
   114  		if m.PathAttributes[i] != nil {
   115  			if err := m.PathAttributes[i].Validate(formats); err != nil {
   116  				if ve, ok := err.(*errors.Validation); ok {
   117  					return ve.ValidateName("path-attributes" + "." + strconv.Itoa(i))
   118  				} else if ce, ok := err.(*errors.CompositeError); ok {
   119  					return ce.ValidateName("path-attributes" + "." + strconv.Itoa(i))
   120  				}
   121  				return err
   122  			}
   123  		}
   124  
   125  	}
   126  
   127  	return nil
   128  }
   129  
   130  // ContextValidate validate this bgp path based on the context it is used
   131  func (m *BgpPath) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   132  	var res []error
   133  
   134  	if err := m.contextValidateFamily(ctx, formats); err != nil {
   135  		res = append(res, err)
   136  	}
   137  
   138  	if err := m.contextValidateNlri(ctx, formats); err != nil {
   139  		res = append(res, err)
   140  	}
   141  
   142  	if err := m.contextValidatePathAttributes(ctx, formats); err != nil {
   143  		res = append(res, err)
   144  	}
   145  
   146  	if len(res) > 0 {
   147  		return errors.CompositeValidationError(res...)
   148  	}
   149  	return nil
   150  }
   151  
   152  func (m *BgpPath) contextValidateFamily(ctx context.Context, formats strfmt.Registry) error {
   153  
   154  	if m.Family != nil {
   155  
   156  		if swag.IsZero(m.Family) { // not required
   157  			return nil
   158  		}
   159  
   160  		if err := m.Family.ContextValidate(ctx, formats); err != nil {
   161  			if ve, ok := err.(*errors.Validation); ok {
   162  				return ve.ValidateName("family")
   163  			} else if ce, ok := err.(*errors.CompositeError); ok {
   164  				return ce.ValidateName("family")
   165  			}
   166  			return err
   167  		}
   168  	}
   169  
   170  	return nil
   171  }
   172  
   173  func (m *BgpPath) contextValidateNlri(ctx context.Context, formats strfmt.Registry) error {
   174  
   175  	if m.Nlri != nil {
   176  
   177  		if swag.IsZero(m.Nlri) { // not required
   178  			return nil
   179  		}
   180  
   181  		if err := m.Nlri.ContextValidate(ctx, formats); err != nil {
   182  			if ve, ok := err.(*errors.Validation); ok {
   183  				return ve.ValidateName("nlri")
   184  			} else if ce, ok := err.(*errors.CompositeError); ok {
   185  				return ce.ValidateName("nlri")
   186  			}
   187  			return err
   188  		}
   189  	}
   190  
   191  	return nil
   192  }
   193  
   194  func (m *BgpPath) contextValidatePathAttributes(ctx context.Context, formats strfmt.Registry) error {
   195  
   196  	for i := 0; i < len(m.PathAttributes); i++ {
   197  
   198  		if m.PathAttributes[i] != nil {
   199  
   200  			if swag.IsZero(m.PathAttributes[i]) { // not required
   201  				return nil
   202  			}
   203  
   204  			if err := m.PathAttributes[i].ContextValidate(ctx, formats); err != nil {
   205  				if ve, ok := err.(*errors.Validation); ok {
   206  					return ve.ValidateName("path-attributes" + "." + strconv.Itoa(i))
   207  				} else if ce, ok := err.(*errors.CompositeError); ok {
   208  					return ce.ValidateName("path-attributes" + "." + strconv.Itoa(i))
   209  				}
   210  				return err
   211  			}
   212  		}
   213  
   214  	}
   215  
   216  	return nil
   217  }
   218  
   219  // MarshalBinary interface implementation
   220  func (m *BgpPath) MarshalBinary() ([]byte, error) {
   221  	if m == nil {
   222  		return nil, nil
   223  	}
   224  	return swag.WriteJSON(m)
   225  }
   226  
   227  // UnmarshalBinary interface implementation
   228  func (m *BgpPath) UnmarshalBinary(b []byte) error {
   229  	var res BgpPath
   230  	if err := swag.ReadJSON(b, &res); err != nil {
   231  		return err
   232  	}
   233  	*m = res
   234  	return nil
   235  }