-
Notifications
You must be signed in to change notification settings - Fork 44
/
bgpFormatters.js
200 lines (189 loc) · 7.55 KB
/
bgpFormatters.js
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
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
define(['underscore'], function(_){
var bgpFormatters = function() {
var self = this;
/*
* @displayNameFormatter
*/
self.displayNameFormatter = function(r, c, v, cd, dc) {
var displayName = getValueByJsonPath(dc, "display_name", "");
if(!displayName){
displayName = getValueByJsonPath(dc, "name", "-");
}
return displayName;
};
/*
* @routerTypeFormatter
*/
self.routerTypeFormatter = function(r, c, v, cd, dc) {
var routerTypeDisplayName;
var routerType = getValueByJsonPath(dc, "bgp_router_parameters;router_type", "");
switch(routerType) {
case "control-node" :
routerTypeDisplayName = "Control Node";
break;
case "external-control-node" :
routerTypeDisplayName = "External Control Node";
break;
case "router" :
routerTypeDisplayName = "BGP Router";
break;
case "bgpaas-server" :
routerTypeDisplayName = "BGP as a service Server";
break;
case "bgpaas-client" :
routerTypeDisplayName = "BGP as a service Client";
break;
default :
routerTypeDisplayName = "-";
break;
}
return routerTypeDisplayName;
};
/*
* @ipAdressFormatter
*/
self.ipAdressFormatter = function(r, c, v, cd, dc) {
var ipAdress = getValueByJsonPath(dc,
'bgp_router_parameters;address', '-');
return ipAdress;
};
/*
* @vendorFormatter
*/
self.vendorFormatter = function(r, c, v, cd, dc) {
var vendor = getValueByJsonPath(dc,
'bgp_router_parameters;vendor', '-');
return vendor;
};
/*
* @peersFormatter
*/
self.peersFormatter = function(r, c, v, cd, dc) {
var peerString = "";
var bgpRefs = getValueByJsonPath(dc,"bgp_router_refs", []);
if(bgpRefs.length > 0){
peerString =
"<table style='width:1000px !important;'><thead><tr><th style='width:200px;'>Peer Name</th>\
<th style='width:150px;'>Admin State</th>\
<th style='width:120px;'>Passive</th>\
<th style='width:280px;'>Hold Time (seconds)</th>\
<th style='width:170px;'>Loop Count</th>\
<th style='width:200px;'>Auth Mode</th>\
<th style='width:900px;'>Family Attributes</th></tr></thead>";
bgpRefs.forEach(function(bgp){
var attr = getValueByJsonPath(bgp,
"attr;session;0;attributes;0", {});
var adminState;
peerString += "<tr style='vertical-align:top'><td>";
peerString += bgp.to[4] + "</td><td>";
var adminDown = getValueByJsonPath(attr, "admin_down", "-");
if(adminDown != "-") {
adminState = adminDown ? "False" : "True";
} else {
adminState = "-";
}
peerString += adminState + "</td><td>";
var passive = getValueByJsonPath(attr, "passive", "-");
if(passive != "-") {
passive = passive ? "True" : "False";
}
peerString += passive + "</td><td>";
peerString += getValueByJsonPath(attr, "hold_time", "-") + "</td><td>";
peerString += getValueByJsonPath(attr, "loop_count", "-") + "</td><td>";
peerString += getValueByJsonPath(attr, 'auth_data;key_type', '-')
peerString += "</td><td>";
var familyAttrs = getValueByJsonPath(attr, "family_attributes", []);
if(familyAttrs.length > 0) {
for(var i = 0 ; i < familyAttrs.length; i++) {
var familyAttr = familyAttrs[i];
peerString += "<span class='sec_label'>Address Family :</span> " + getValueByJsonPath(familyAttr, "address_family", "-");
peerString += ", <span class='sec_label'>Loop Count :</span> " + getValueByJsonPath(familyAttr, "loop_count", "-");
peerString += ", <span class='sec_label'>Prefix Limit :</span> " + getValueByJsonPath(familyAttr, "prefix_limit;maximum", "-");
if(i === familyAttrs.length - 1) {
peerString +="</br></br>";
} else {
peerString +="</br>";
}
}
} else {
peerString += "-";
}
});
peerString += "</td></tr>";
peerString += "</table>";
} else {
peerString = "-";
}
return peerString;
}
/*
* @availablePeers
*/
self.availablePeers = function(data, currentBGP) {
var peers = [];
for(var i = 0; i < data.length; i++) {
var row = data[i]["bgp-router"];
if(currentBGP && currentBGP === row.name) {
continue;
}
peers.push(row);
}
return peers;
}
/*
* @physicalRouterFormatter
*/
self.physicalRouterFormatter = function(r, c, v, cd, dc) {
var physicalRouters = [];
var pRouterBackRefs = getValueByJsonPath(dc,
'physical_router_back_refs', []);
if(pRouterBackRefs.length > 0) {
pRouterBackRefs.forEach(function(pRouter){
physicalRouters.push(pRouter.to[1]);
});
} else {
physicalRouters = '-';
}
return physicalRouters;
}
/*
* @authKeyFormatter
*/
self.authKeyFormatter = function(r, c, v, cd, dc) {
var authKey = '-';
var authData = dc['bgp_router_parameters']['auth_data'];
if(authData != null) {
authKey =
authData.key_type != null ? authData.key_type : '-';
}
return authKey;
};
/*
* @holdTimeFormatter
*/
self.holdTimeFormatter = function(r, c, v, cd, dc) {
var holdTime = getValueByJsonPath(dc,
'bgp_router_parameters;hold_time', '-');
if(holdTime != '-') {
holdTime = holdTime.toString() + ' (seconds)';
}
return holdTime;
};
/*
* @stateFormatter
*/
self.stateFormatter = function(r, c, v, cd, dc) {
var adminState;
var adminDown = getValueByJsonPath(dc,
"bgp_router_parameters;admin_down", "-");
if(adminDown != "-") {
adminState = adminDown ? "False" : "True";
}
return adminState;
};
};
return bgpFormatters;
});