forked from nlewo/contrail-introspect-cli
/
descriptions.go
339 lines (311 loc) · 12.1 KB
/
descriptions.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
package descriptions
import "fmt"
import "log"
import "github.com/jbowtie/gokogiri/xml"
import "github.com/gosuri/uitable"
import "github.com/tu-pm/contrail-introspect-cli/utils"
import "github.com/tu-pm/contrail-introspect-cli/collection"
func CtrlIfmap() collection.DescCollection {
return collection.DescCollection{
BaseXpath: "IFMapTableShowResp/ifmap_db/list",
DescElt: collection.DescElement{
ShortDetailXpath: "node_name/text()",
LongDetail: collection.LongFormatFn(ifmapNeighbors),
},
PageArgs: []string{"controller-fqdn", "table-name", "search-string"},
PageBuilder: func(args []string) collection.Sourcer {
path := fmt.Sprintf("Snh_IFMapTableShowReq?table_name=%s&search_string=%s", args[1], args[2])
return collection.Webui{Path: path, VrouterUrl: args[0], Port: 8083}
},
PrimaryField: "node_name",
}
}
func ifmapNeighbors(t *uitable.Table, e collection.Element) {
t.AddRow("Node name", "Neighbors")
nodeName, _ := e.Node.Search("node_name/text()")
t.AddRow(fmt.Sprintf("%s", nodeName[0]))
neighbors, _ := e.Node.Search("neighbors/list/element/text()")
for _, n := range neighbors {
t.AddRow("", fmt.Sprintf("%s", n))
}
t.AddRow("", "")
}
func Interface() collection.DescCollection {
return collection.DescCollection{
BaseXpath: "__ItfResp_list/ItfResp/itf_list/list",
DescElt: collection.DescElement{
ShortDetailXpath: "name/text()",
LongDetail: collection.LongFormatXpaths([]string{"uuid", "name", "vrf_name", "vm_uuid", "ip_addr", "mdata_ip_addr"}),
},
PageArgs: []string{"vrouter-fqdn"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Remote{Table: "db.interface.0", VrouterUrl: args[0], Port: 8085}
},
PrimaryField: "name",
}
}
func Peering() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"vrouter-fqdn"},
BaseXpath: "AgentXmppConnectionStatus/peer/list",
PageBuilder: func(args []string) collection.Sourcer {
return collection.Webui{Path: "Snh_AgentXmppConnectionStatusReq", VrouterUrl: args[0], Port: 8085}
},
DescElt: collection.DescElement{
ShortDetailXpath: "controller_ip/text()",
LongDetail: collection.LongFormatXpaths([]string{"controller_ip", "state", "flap_count", "cfg_controller"}),
},
PrimaryField: "name",
}
}
func Si() collection.DescCollection {
return collection.DescCollection{
BaseXpath: "__ServiceInstanceResp_list/ServiceInstanceResp/service_instance_list/list",
DescElt: collection.DescElement{
ShortDetailXpath: "uuid/text()",
// LongDetailHelp: []string{"Service instance uuid", "Type of service instance", "Virtual machine uuid"},
LongDetail: collection.LongFormatXpaths([]string{"uuid", "service_type", "instance_id"}),
},
PageArgs: []string{"vrouter-fqdn"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Remote{Table: "db.service-instance.0", VrouterUrl: args[0], Port: 8085}
},
PrimaryField: "uuid",
}
}
func UcRoute() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"vrouter-fqdn", "vrf-name"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Remote{VrouterUrl: args[0], Table: args[1] + ".uc.route.0,", Port: 8085}
},
BaseXpath: "__Inet4UcRouteResp_list/Inet4UcRouteResp/route_list/list",
DescElt: collection.DescElement{
ShortDetailXpath: "src_ip/text()",
LongDetail: collection.LongFormatFn(ucRouteDetail)},
PrimaryField: "src_ip",
}
}
func L2Route() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"vrouter-fqdn", "vrf-name"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Remote{VrouterUrl: args[0], Table: args[1] + ".l2.route.0,", Port: 8085}
},
BaseXpath: "__BridgeRouteResp_list/BridgeRouteResp/route_list/list",
DescElt: collection.DescElement{
ShortDetailXpath: "mac/text()",
LongDetail: collection.LongFormatFn(l2RouteDetail)},
PrimaryField: "mac",
}
}
func Vrf() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"vrouter-fqdn"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Remote{Table: "db.vrf.0", VrouterUrl: args[0], Port: 8085}
},
BaseXpath: "__VrfListResp_list/VrfListResp/vrf_list/list",
DescElt: collection.DescElement{
ShortDetailXpath: "name/text()",
LongDetail: collection.LongFormatXpaths([]string{"name", "ucindex"}),
},
PrimaryField: "name",
}
}
func Vn() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"vrouter-fqdn"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Remote{Table: "db.vn.0", VrouterUrl: args[0], Port: 8085}
},
BaseXpath: "__VnListResp_list/VnListResp/vn_list/list",
DescElt: collection.DescElement{
ShortDetailXpath: "name/text()",
LongDetail: collection.LongFormatXpaths([]string{"name", "vrf_name"}),
},
PrimaryField: "name",
}
}
func RiSummary() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"controller-fqdn"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Webui{Path: "Snh_ShowRoutingInstanceSummaryReq?search_string=", VrouterUrl: args[0], Port: 8083}
},
BaseXpath: "ShowRoutingInstanceSummaryResp/instances/list",
DescElt: collection.DescElement{
ShortDetailXpath: "name/text()",
LongDetail: collection.LongFormatXpaths([]string{"name", "virtual_network"}),
},
PrimaryField: "name",
}
}
func CtrlRouteSummary() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"controller-fqdn", "search"},
PageBuilder: func(args []string) collection.Sourcer {
path := fmt.Sprintf("Snh_ShowRouteSummaryReq?search_string=%s", args[1])
return collection.Webui{Path: path, VrouterUrl: args[0], Port: 8083}
},
BaseXpath: "ShowRouteSummaryResp/tables/list",
DescElt: collection.DescElement{
ShortDetailXpath: "name/text()",
LongDetail: collection.LongFormatXpaths([]string{"name", "prefixes", "paths", "primary_paths", "secondary_paths", "pending_updates"}),
},
PrimaryField: "name",
}
}
func CtrlRoute() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"controller-fqdn", "routing-instance"},
PageBuilder: func(args []string) collection.Sourcer {
path := fmt.Sprintf("Snh_ShowRouteReq?x=%s.inet.0", args[1])
return collection.Webui{Path: path, VrouterUrl: args[0], Port: 8083}
},
BaseXpath: "ShowRouteResp/tables/list/ShowRouteTable/routes/list",
DescElt: collection.DescElement{
ShortDetailXpath: "prefix/text()",
LongDetail: collection.LongFormatFn(controllerRoutePath),
},
PrimaryField: "prefix",
}
}
func CtrlNeighbor() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"controller-fqdn"},
PageBuilder: func(args []string) collection.Sourcer {
path := "Snh_ShowBgpNeighborSummaryReq"
return collection.Webui{Path: path, VrouterUrl: args[0], Port: 8083}
},
BaseXpath: "ShowBgpNeighborSummaryResp/neighbors/list",
DescElt: collection.DescElement{
ShortDetailXpath: "peer/text()",
LongDetail: collection.LongFormatXpaths([]string{"peer", "peer_address", "peer_id", "peer_asn", "peer_type", "state", "local_address", "local_asn", "primary_path_count"}),
},
PrimaryField: "peer",
}
}
func Mpls() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"vrouter-fqdn"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Remote{Table: "db.mpls.0", VrouterUrl: args[0], Port: 8085}
},
BaseXpath: "__MplsResp_list/MplsResp/mpls_list/list",
DescElt: collection.DescElement{
ShortDetailXpath: "label/text()",
LongDetail: collection.LongFormatFn(mplsDetail),
},
PrimaryField: "label",
}
}
func Vxlan() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"vrouter-fqdn"},
PageBuilder: func(args []string) collection.Sourcer {
return collection.Remote{Table: "db.vxlan.0", VrouterUrl: args[0], Port: 8085}
},
BaseXpath: "__VxLanResp_list/VxLanResp/vxlan_list/list",
DescElt: collection.DescElement{
ShortDetailXpath: "vxlan_id/text()",
LongDetail: collection.LongFormatFn(vxlanDetail),
},
PrimaryField: "vxlan_id",
}
}
func ucRouteDetail(t *uitable.Table, e collection.Element) {
srcIp, _ := e.Node.Search("src_ip/text()")
srcPrefix, _ := e.Node.Search("src_plen/text()")
t.AddRow(fmt.Sprintf("Src %s/%s", srcIp[0], srcPrefix[0]))
paths, _ := e.Node.Search("path_list/list/PathSandeshData")
t.AddRow(" Dst", "Peers", "MPLS label", "Local Pref", "Interface", "Dest VN")
for _, path := range paths {
nhs, _ := path.Search("nh/NhSandeshData//dip/text()")
peers, _ := path.Search("peer/text()")
label, _ := path.Search("label/text()")
pref, _ := path.Search("path_preference_data/PathPreferenceSandeshData/preference/text()")
destvn, _ := path.Search("dest_vn/text()")
itf, _ := path.Search("nh/NhSandeshData/itf/text()")
t.AddRow(" "+utils.Pretty(nhs), utils.Pretty(peers), utils.Pretty(label),
utils.Pretty(pref), utils.Pretty(itf), utils.Pretty(destvn))
}
t.AddRow("")
}
func l2RouteDetail(t *uitable.Table, e collection.Element) {
mac, _ := e.Node.Search("mac/text()")
t.AddRow(fmt.Sprintf("Src %s", mac[0]))
paths, _ := e.Node.Search("path_list/list/PathSandeshData")
t.AddRow(" Dst", "Peers", "MPLS label", "Local Pref", "Interface", "Dest VN")
for _, path := range paths {
nhs, _ := path.Search("nh/NhSandeshData//dip/text()")
peers, _ := path.Search("peer/text()")
label, _ := path.Search("label/text()")
pref, _ := path.Search("path_preference_data/PathPreferenceSandeshData/preference/text()")
destvn, _ := path.Search("dest_vn/text()")
itf, _ := path.Search("nh/NhSandeshData/itf/text()")
t.AddRow(" "+utils.Pretty(nhs), utils.Pretty(peers), utils.Pretty(label),
utils.Pretty(pref), utils.Pretty(itf), utils.Pretty(destvn))
}
t.AddRow("")
}
func mplsDetail(t *uitable.Table, e collection.Element) {
label, err := e.GetField("label")
if err != nil {
log.Fatal(err)
}
t.AddRow(fmt.Sprintf("Label: %s", label))
nexthopDetail(t, e.Node)
t.AddRow("")
}
func vxlanDetail(t *uitable.Table, e collection.Element) {
vxlanID, err := e.GetField("vxlan_id")
if err != nil {
log.Fatal(err)
}
t.AddRow(fmt.Sprintf("VxlanID: %s", vxlanID))
nexthopDetail(t, e.Node)
t.AddRow("")
}
func nexthopDetail(t *uitable.Table, node xml.Node) {
t.AddRow(" Type", "Interface", "Nexthop index")
nhs, _ := node.Search("nh/NhSandeshData/type/text()")
itf, _ := node.Search("nh/NhSandeshData/itf/text()")
nhIdx, _ := node.Search("nh/NhSandeshData/nh_index/text()")
t.AddRow(" "+utils.Pretty(nhs), utils.Pretty(itf), utils.Pretty(nhIdx))
}
func controllerRoutePath(t *uitable.Table, e collection.Element) {
srcIp, _ := e.Node.Search("prefix/text()")
t.AddRow(fmt.Sprintf("Prefix %s", srcIp[0]))
paths, _ := e.Node.Search("paths/list/ShowRoutePath")
t.AddRow(" Protocol", "Nexthop", "Local Pref", "Peers", "MPLS label")
for _, path := range paths {
protocol, _ := path.Search("protocol/text()")
nhs, _ := path.Search("next_hop/text()")
peers, _ := path.Search("source/text()")
label, _ := path.Search("label/text()")
localPref, _ := path.Search("local_preference/text()")
t.AddRow(" "+utils.Pretty(protocol), utils.Pretty(nhs), utils.Pretty(localPref), utils.Pretty(peers), utils.Pretty(label))
}
t.AddRow("")
}
func AgentPing() collection.DescCollection {
return collection.DescCollection{
PageArgs: []string{"vrouter-fqdn", "vrf-name", "source-ip", "source-port", "dest-ip", "dest-port"},
PageBuilder: func(args []string) collection.Sourcer {
sourceIp := args[2]
sourcePort := args[3]
destIp := args[4]
destPort := args[5]
vrfName := args[1]
path := fmt.Sprintf("Snh_PingReq?source_ip=%s&source_port=%s&dest_ip=%s&dest_port=%s&protocol=6&vrf_name=%s&packet_size=&count=1&interval=",
sourceIp, sourcePort, destIp, destPort, vrfName)
return collection.Webui{Path: path, VrouterUrl: args[0], Port: 8085}
},
BaseXpath: "__PingResp_list",
DescElt: collection.DescElement{
ShortDetailXpath: "resp/text()",
LongDetail: collection.LongFormatXpaths([]string{"resp", "rtt"}),
},
}
}