-
Notifications
You must be signed in to change notification settings - Fork 7
/
bgp_attributes_community.go
434 lines (385 loc) · 12.9 KB
/
bgp_attributes_community.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
package gosnappi
import (
"fmt"
"strings"
"github.com/ghodss/yaml"
otg "github.com/open-traffic-generator/snappi/gosnappi/otg"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
// ***** BgpAttributesCommunity *****
type bgpAttributesCommunity struct {
validation
obj *otg.BgpAttributesCommunity
marshaller marshalBgpAttributesCommunity
unMarshaller unMarshalBgpAttributesCommunity
customCommunityHolder BgpAttributesCustomCommunity
}
func NewBgpAttributesCommunity() BgpAttributesCommunity {
obj := bgpAttributesCommunity{obj: &otg.BgpAttributesCommunity{}}
obj.setDefault()
return &obj
}
func (obj *bgpAttributesCommunity) msg() *otg.BgpAttributesCommunity {
return obj.obj
}
func (obj *bgpAttributesCommunity) setMsg(msg *otg.BgpAttributesCommunity) BgpAttributesCommunity {
obj.setNil()
proto.Merge(obj.obj, msg)
return obj
}
type marshalbgpAttributesCommunity struct {
obj *bgpAttributesCommunity
}
type marshalBgpAttributesCommunity interface {
// ToProto marshals BgpAttributesCommunity to protobuf object *otg.BgpAttributesCommunity
ToProto() (*otg.BgpAttributesCommunity, error)
// ToPbText marshals BgpAttributesCommunity to protobuf text
ToPbText() (string, error)
// ToYaml marshals BgpAttributesCommunity to YAML text
ToYaml() (string, error)
// ToJson marshals BgpAttributesCommunity to JSON text
ToJson() (string, error)
}
type unMarshalbgpAttributesCommunity struct {
obj *bgpAttributesCommunity
}
type unMarshalBgpAttributesCommunity interface {
// FromProto unmarshals BgpAttributesCommunity from protobuf object *otg.BgpAttributesCommunity
FromProto(msg *otg.BgpAttributesCommunity) (BgpAttributesCommunity, error)
// FromPbText unmarshals BgpAttributesCommunity from protobuf text
FromPbText(value string) error
// FromYaml unmarshals BgpAttributesCommunity from YAML text
FromYaml(value string) error
// FromJson unmarshals BgpAttributesCommunity from JSON text
FromJson(value string) error
}
func (obj *bgpAttributesCommunity) Marshal() marshalBgpAttributesCommunity {
if obj.marshaller == nil {
obj.marshaller = &marshalbgpAttributesCommunity{obj: obj}
}
return obj.marshaller
}
func (obj *bgpAttributesCommunity) Unmarshal() unMarshalBgpAttributesCommunity {
if obj.unMarshaller == nil {
obj.unMarshaller = &unMarshalbgpAttributesCommunity{obj: obj}
}
return obj.unMarshaller
}
func (m *marshalbgpAttributesCommunity) ToProto() (*otg.BgpAttributesCommunity, error) {
err := m.obj.validateToAndFrom()
if err != nil {
return nil, err
}
return m.obj.msg(), nil
}
func (m *unMarshalbgpAttributesCommunity) FromProto(msg *otg.BgpAttributesCommunity) (BgpAttributesCommunity, error) {
newObj := m.obj.setMsg(msg)
err := newObj.validateToAndFrom()
if err != nil {
return nil, err
}
return newObj, nil
}
func (m *marshalbgpAttributesCommunity) ToPbText() (string, error) {
vErr := m.obj.validateToAndFrom()
if vErr != nil {
return "", vErr
}
protoMarshal, err := proto.Marshal(m.obj.msg())
if err != nil {
return "", err
}
return string(protoMarshal), nil
}
func (m *unMarshalbgpAttributesCommunity) FromPbText(value string) error {
retObj := proto.Unmarshal([]byte(value), m.obj.msg())
if retObj != nil {
return retObj
}
m.obj.setNil()
vErr := m.obj.validateToAndFrom()
if vErr != nil {
return vErr
}
return retObj
}
func (m *marshalbgpAttributesCommunity) ToYaml() (string, error) {
vErr := m.obj.validateToAndFrom()
if vErr != nil {
return "", vErr
}
opts := protojson.MarshalOptions{
UseProtoNames: true,
AllowPartial: true,
EmitUnpopulated: false,
}
data, err := opts.Marshal(m.obj.msg())
if err != nil {
return "", err
}
data, err = yaml.JSONToYAML(data)
if err != nil {
return "", err
}
return string(data), nil
}
func (m *unMarshalbgpAttributesCommunity) FromYaml(value string) error {
if value == "" {
value = "{}"
}
data, err := yaml.YAMLToJSON([]byte(value))
if err != nil {
return err
}
opts := protojson.UnmarshalOptions{
AllowPartial: true,
DiscardUnknown: false,
}
uError := opts.Unmarshal([]byte(data), m.obj.msg())
if uError != nil {
return fmt.Errorf("unmarshal error %s", strings.Replace(
uError.Error(), "\u00a0", " ", -1)[7:])
}
m.obj.setNil()
vErr := m.obj.validateToAndFrom()
if vErr != nil {
return vErr
}
return nil
}
func (m *marshalbgpAttributesCommunity) ToJson() (string, error) {
vErr := m.obj.validateToAndFrom()
if vErr != nil {
return "", vErr
}
opts := protojson.MarshalOptions{
UseProtoNames: true,
AllowPartial: true,
EmitUnpopulated: false,
Indent: " ",
}
data, err := opts.Marshal(m.obj.msg())
if err != nil {
return "", err
}
return string(data), nil
}
func (m *unMarshalbgpAttributesCommunity) FromJson(value string) error {
opts := protojson.UnmarshalOptions{
AllowPartial: true,
DiscardUnknown: false,
}
if value == "" {
value = "{}"
}
uError := opts.Unmarshal([]byte(value), m.obj.msg())
if uError != nil {
return fmt.Errorf("unmarshal error %s", strings.Replace(
uError.Error(), "\u00a0", " ", -1)[7:])
}
m.obj.setNil()
err := m.obj.validateToAndFrom()
if err != nil {
return err
}
return nil
}
func (obj *bgpAttributesCommunity) validateToAndFrom() error {
// emptyVars()
obj.validateObj(&obj.validation, true)
return obj.validationResult()
}
func (obj *bgpAttributesCommunity) validate() error {
// emptyVars()
obj.validateObj(&obj.validation, false)
return obj.validationResult()
}
func (obj *bgpAttributesCommunity) String() string {
str, err := obj.Marshal().ToYaml()
if err != nil {
return err.Error()
}
return str
}
func (obj *bgpAttributesCommunity) Clone() (BgpAttributesCommunity, error) {
vErr := obj.validate()
if vErr != nil {
return nil, vErr
}
newObj := NewBgpAttributesCommunity()
data, err := proto.Marshal(obj.msg())
if err != nil {
return nil, err
}
pbErr := proto.Unmarshal(data, newObj.msg())
if pbErr != nil {
return nil, pbErr
}
return newObj, nil
}
func (obj *bgpAttributesCommunity) setNil() {
obj.customCommunityHolder = nil
obj.validationErrors = nil
obj.warnings = nil
obj.constraints = make(map[string]map[string]Constraints)
}
// BgpAttributesCommunity is the COMMUNITY attribute provide additional capability for tagging routes and for modifying BGP routing policy on
// upstream and downstream routers. BGP community is a 32-bit number which is broken into 16-bit AS number and a
// 16-bit custom value or it contains some pre-defined well known values.
type BgpAttributesCommunity interface {
Validation
// msg marshals BgpAttributesCommunity to protobuf object *otg.BgpAttributesCommunity
// and doesn't set defaults
msg() *otg.BgpAttributesCommunity
// setMsg unmarshals BgpAttributesCommunity from protobuf object *otg.BgpAttributesCommunity
// and doesn't set defaults
setMsg(*otg.BgpAttributesCommunity) BgpAttributesCommunity
// provides marshal interface
Marshal() marshalBgpAttributesCommunity
// provides unmarshal interface
Unmarshal() unMarshalBgpAttributesCommunity
// validate validates BgpAttributesCommunity
validate() error
// A stringer function
String() string
// Clones the object
Clone() (BgpAttributesCommunity, error)
validateToAndFrom() error
validateObj(vObj *validation, set_default bool)
setDefault()
// Choice returns BgpAttributesCommunityChoiceEnum, set in BgpAttributesCommunity
Choice() BgpAttributesCommunityChoiceEnum
// setChoice assigns BgpAttributesCommunityChoiceEnum provided by user to BgpAttributesCommunity
setChoice(value BgpAttributesCommunityChoiceEnum) BgpAttributesCommunity
// getter for LlgrStale to set choice.
LlgrStale()
// getter for NoAdvertised to set choice.
NoAdvertised()
// getter for NoLlgr to set choice.
NoLlgr()
// getter for NoExport to set choice.
NoExport()
// getter for NoExportSubconfed to set choice.
NoExportSubconfed()
// CustomCommunity returns BgpAttributesCustomCommunity, set in BgpAttributesCommunity.
// BgpAttributesCustomCommunity is user defined COMMUNITY attribute containing 2 byte AS and custom 2 byte value defined by the administrator of the domain.
CustomCommunity() BgpAttributesCustomCommunity
// SetCustomCommunity assigns BgpAttributesCustomCommunity provided by user to BgpAttributesCommunity.
// BgpAttributesCustomCommunity is user defined COMMUNITY attribute containing 2 byte AS and custom 2 byte value defined by the administrator of the domain.
SetCustomCommunity(value BgpAttributesCustomCommunity) BgpAttributesCommunity
// HasCustomCommunity checks if CustomCommunity has been set in BgpAttributesCommunity
HasCustomCommunity() bool
setNil()
}
type BgpAttributesCommunityChoiceEnum string
// Enum of Choice on BgpAttributesCommunity
var BgpAttributesCommunityChoice = struct {
CUSTOM_COMMUNITY BgpAttributesCommunityChoiceEnum
NO_EXPORT BgpAttributesCommunityChoiceEnum
NO_ADVERTISED BgpAttributesCommunityChoiceEnum
NO_EXPORT_SUBCONFED BgpAttributesCommunityChoiceEnum
LLGR_STALE BgpAttributesCommunityChoiceEnum
NO_LLGR BgpAttributesCommunityChoiceEnum
}{
CUSTOM_COMMUNITY: BgpAttributesCommunityChoiceEnum("custom_community"),
NO_EXPORT: BgpAttributesCommunityChoiceEnum("no_export"),
NO_ADVERTISED: BgpAttributesCommunityChoiceEnum("no_advertised"),
NO_EXPORT_SUBCONFED: BgpAttributesCommunityChoiceEnum("no_export_subconfed"),
LLGR_STALE: BgpAttributesCommunityChoiceEnum("llgr_stale"),
NO_LLGR: BgpAttributesCommunityChoiceEnum("no_llgr"),
}
func (obj *bgpAttributesCommunity) Choice() BgpAttributesCommunityChoiceEnum {
return BgpAttributesCommunityChoiceEnum(obj.obj.Choice.Enum().String())
}
// getter for LlgrStale to set choice
func (obj *bgpAttributesCommunity) LlgrStale() {
obj.setChoice(BgpAttributesCommunityChoice.LLGR_STALE)
}
// getter for NoAdvertised to set choice
func (obj *bgpAttributesCommunity) NoAdvertised() {
obj.setChoice(BgpAttributesCommunityChoice.NO_ADVERTISED)
}
// getter for NoLlgr to set choice
func (obj *bgpAttributesCommunity) NoLlgr() {
obj.setChoice(BgpAttributesCommunityChoice.NO_LLGR)
}
// getter for NoExport to set choice
func (obj *bgpAttributesCommunity) NoExport() {
obj.setChoice(BgpAttributesCommunityChoice.NO_EXPORT)
}
// getter for NoExportSubconfed to set choice
func (obj *bgpAttributesCommunity) NoExportSubconfed() {
obj.setChoice(BgpAttributesCommunityChoice.NO_EXPORT_SUBCONFED)
}
func (obj *bgpAttributesCommunity) setChoice(value BgpAttributesCommunityChoiceEnum) BgpAttributesCommunity {
intValue, ok := otg.BgpAttributesCommunity_Choice_Enum_value[string(value)]
if !ok {
obj.validationErrors = append(obj.validationErrors, fmt.Sprintf(
"%s is not a valid choice on BgpAttributesCommunityChoiceEnum", string(value)))
return obj
}
enumValue := otg.BgpAttributesCommunity_Choice_Enum(intValue)
obj.obj.Choice = &enumValue
obj.obj.CustomCommunity = nil
obj.customCommunityHolder = nil
if value == BgpAttributesCommunityChoice.CUSTOM_COMMUNITY {
obj.obj.CustomCommunity = NewBgpAttributesCustomCommunity().msg()
}
return obj
}
// description is TBD
// CustomCommunity returns a BgpAttributesCustomCommunity
func (obj *bgpAttributesCommunity) CustomCommunity() BgpAttributesCustomCommunity {
if obj.obj.CustomCommunity == nil {
obj.setChoice(BgpAttributesCommunityChoice.CUSTOM_COMMUNITY)
}
if obj.customCommunityHolder == nil {
obj.customCommunityHolder = &bgpAttributesCustomCommunity{obj: obj.obj.CustomCommunity}
}
return obj.customCommunityHolder
}
// description is TBD
// CustomCommunity returns a BgpAttributesCustomCommunity
func (obj *bgpAttributesCommunity) HasCustomCommunity() bool {
return obj.obj.CustomCommunity != nil
}
// description is TBD
// SetCustomCommunity sets the BgpAttributesCustomCommunity value in the BgpAttributesCommunity object
func (obj *bgpAttributesCommunity) SetCustomCommunity(value BgpAttributesCustomCommunity) BgpAttributesCommunity {
obj.setChoice(BgpAttributesCommunityChoice.CUSTOM_COMMUNITY)
obj.customCommunityHolder = nil
obj.obj.CustomCommunity = value.msg()
return obj
}
func (obj *bgpAttributesCommunity) validateObj(vObj *validation, set_default bool) {
if set_default {
obj.setDefault()
}
// Choice is required
if obj.obj.Choice == nil {
vObj.validationErrors = append(vObj.validationErrors, "Choice is required field on interface BgpAttributesCommunity")
}
if obj.obj.CustomCommunity != nil {
obj.CustomCommunity().validateObj(vObj, set_default)
}
}
func (obj *bgpAttributesCommunity) setDefault() {
var choices_set int = 0
var choice BgpAttributesCommunityChoiceEnum
if obj.obj.CustomCommunity != nil {
choices_set += 1
choice = BgpAttributesCommunityChoice.CUSTOM_COMMUNITY
}
if choices_set == 1 && choice != "" {
if obj.obj.Choice != nil {
if obj.Choice() != choice {
obj.validationErrors = append(obj.validationErrors, "choice not matching with property in BgpAttributesCommunity")
}
} else {
intVal := otg.BgpAttributesCommunity_Choice_Enum_value[string(choice)]
enumValue := otg.BgpAttributesCommunity_Choice_Enum(intVal)
obj.obj.Choice = &enumValue
}
}
}