/
entry.go
175 lines (150 loc) · 4.33 KB
/
entry.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
package group
import (
"encoding/xml"
"github.com/PaloAltoNetworks/pango/util"
"github.com/PaloAltoNetworks/pango/version"
)
// Entry is a normalized, version independent representation of a BGP
// peer group.
type Entry struct {
Name string
Enable bool
AggregatedConfedAsPath bool
SoftResetWithStoredInfo bool
Type string
ExportNextHop string
ImportNextHop string
RemovePrivateAs bool
raw map[string]string
}
// Copy copies the information from source Entry `s` to this object. As the
// Name field relates to the XPATH of this object, this field is not copied.
func (o *Entry) Copy(s Entry) {
o.Enable = s.Enable
o.AggregatedConfedAsPath = s.AggregatedConfedAsPath
o.SoftResetWithStoredInfo = s.SoftResetWithStoredInfo
o.Type = s.Type
o.ExportNextHop = s.ExportNextHop
o.ImportNextHop = s.ImportNextHop
o.RemovePrivateAs = s.RemovePrivateAs
}
/** Structs / functions for this namespace. **/
func (o Entry) Specify(v version.Number) (string, interface{}) {
_, fn := versioning(v)
return o.Name, fn(o)
}
type normalizer interface {
Normalize() []Entry
Names() []string
}
type container_v1 struct {
Answer []entry_v1 `xml:"entry"`
}
func (o *container_v1) Normalize() []Entry {
ans := make([]Entry, 0, len(o.Answer))
for i := range o.Answer {
ans = append(ans, o.Answer[i].normalize())
}
return ans
}
func (o *container_v1) Names() []string {
ans := make([]string, 0, len(o.Answer))
for i := range o.Answer {
ans = append(ans, o.Answer[i].Name)
}
return ans
}
func (o *entry_v1) normalize() Entry {
ans := Entry{
Name: o.Name,
Enable: util.AsBool(o.Enable),
AggregatedConfedAsPath: util.AsBool(o.AggregatedConfedAsPath),
SoftResetWithStoredInfo: util.AsBool(o.SoftResetWithStoredInfo),
}
if o.Type == nil {
ans.Type = TypeEbgp
} else if o.Type.Ebgp != nil {
ans.Type = TypeEbgp
ans.ExportNextHop = o.Type.Ebgp.ExportNextHop
ans.ImportNextHop = o.Type.Ebgp.ImportNextHop
ans.RemovePrivateAs = util.AsBool(o.Type.Ebgp.RemovePrivateAs)
} else if o.Type.EbgpConfed != nil {
ans.Type = TypeEbgpConfed
ans.ExportNextHop = o.Type.EbgpConfed.ExportNextHop
} else if o.Type.Ibgp != nil {
ans.Type = TypeIbgp
ans.ExportNextHop = o.Type.Ibgp.ExportNextHop
} else if o.Type.IbgpConfed != nil {
ans.Type = TypeIbgpConfed
ans.ExportNextHop = o.Type.IbgpConfed.ExportNextHop
}
if o.Peer != nil {
ans.raw = map[string]string{
"peer": util.CleanRawXml(o.Peer.Text),
}
}
return ans
}
type entry_v1 struct {
XMLName xml.Name `xml:"entry"`
Name string `xml:"name,attr"`
Enable string `xml:"enable"`
AggregatedConfedAsPath string `xml:"aggregated-confed-as-path"`
SoftResetWithStoredInfo string `xml:"soft-reset-with-stored-info"`
Type *gType `xml:"type"`
Peer *util.RawXml `xml:"peer"`
}
type gType struct {
Ebgp *ebgpOptions `xml:"ebgp"`
EbgpConfed *basicOptions `xml:"ebgp-confed"`
Ibgp *basicOptions `xml:"ibgp"`
IbgpConfed *basicOptions `xml:"ibgp-confed"`
}
type ebgpOptions struct {
ExportNextHop string `xml:"export-nexthop,omitempty"`
ImportNextHop string `xml:"import-nexthop,omitempty"`
RemovePrivateAs string `xml:"remove-private-as"`
}
type basicOptions struct {
ExportNextHop string `xml:"export-nexthop,omitempty"`
}
func specify_v1(e Entry) interface{} {
ans := entry_v1{
Name: e.Name,
Enable: util.YesNo(e.Enable),
AggregatedConfedAsPath: util.YesNo(e.AggregatedConfedAsPath),
SoftResetWithStoredInfo: util.YesNo(e.SoftResetWithStoredInfo),
}
switch e.Type {
case TypeEbgp:
ans.Type = &gType{
Ebgp: &ebgpOptions{
ExportNextHop: e.ExportNextHop,
ImportNextHop: e.ImportNextHop,
RemovePrivateAs: util.YesNo(e.RemovePrivateAs),
},
}
case TypeEbgpConfed:
ans.Type = &gType{
EbgpConfed: &basicOptions{
ExportNextHop: e.ExportNextHop,
},
}
case TypeIbgp:
ans.Type = &gType{
Ibgp: &basicOptions{
ExportNextHop: e.ExportNextHop,
},
}
case TypeIbgpConfed:
ans.Type = &gType{
IbgpConfed: &basicOptions{
ExportNextHop: e.ExportNextHop,
},
}
}
if text, present := e.raw["peer"]; present {
ans.Peer = &util.RawXml{text}
}
return ans
}