forked from v222008/PonControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_lib.php
More file actions
315 lines (199 loc) · 6.67 KB
/
function_lib.php
File metadata and controls
315 lines (199 loc) · 6.67 KB
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
<?php
// ---------- Correct function ip2long for work on 32bit systems
function ip2longfixed($ip) {
$sql_ip = sprintf('%u', ip2long($ip));
return $sql_ip;
}
// END ----------
// ---------- Get FDB By SNMP
function GetFdb ($ip, $ro, $iface) {
$session = new SNMP(SNMP::VERSION_1, $ip, $ro);
$session->oid_increasing_check = FALSE;
$session->oid_output_format = SNMP_OID_OUTPUT_NUMERIC;
$fdb = $session->walk("1.3.6.1.4.1.3320.152.1.1.3.$iface");
$session->close();
return $fdb;
}
// END ----------
// ----------Get PVID on port ----------
function GetPVID($ip, $ro, $iface, $port) {
$pvid = snmp2_get($ip, $ro, "1.3.6.1.4.1.3320.101.12.1.1.3.$iface.$port");
$pvid = end(explode('INTEGER: ', $pvid));
return $pvid;
}
// ----------Get num ports on ONU ----------
function GetNumPorts($ip, $ro, $iface) {
$Array_num_ports = snmprealwalk($ip, $ro, "1.3.6.1.4.1.3320.101.12.1.1.8.$iface");
if(count($Array_num_ports)>0)
foreach($Array_num_ports as $oid => $result)
{
$num_ports = $oid;
}
$num_ports = end(explode("12.1.1.8.$iface.", $num_ports));
return $num_ports;
}
// END ----------
// ----------Get copper port state on ONU ----------
function OnuCopperPortState($ip, $ro, $iface, $port) {
$port_state = snmp2_get($ip, $ro, "1.3.6.1.4.1.3320.101.12.1.1.7.$iface.$port");
$port_state = end(explode('INTEGER: ', $port_state));
// 1 - Enabled, 2 - Disabled
return $port_state;
}
// END ----------
//----------Set Copper port state on ONU DOWN-------
function OnuCopperPortStateDown($ip, $rw, $iface, $port) {
$port_state_down = snmp2_set($ip, $rw, "1.3.6.1.4.1.3320.101.12.1.1.7.$iface.$port", i, "2");
//$port_state_down = end(explode('INTEGER: ', $port_state));
// 1 - Enabled, 2 - Disabled
return $port_state;
}
// END ----------
//----------Set Copper port state on ONU UP---------testestest
function OnuCopperPortStateUp($ip, $rw, $iface, $port) {
$port_state_up = snmp2_set($ip, $rw, "1.3.6.1.4.1.3320.101.12.1.1.7.$iface.$port", i, "1");
//$port_state_up = end(explode('INTEGER: ', $port_state));
// 1 - Enabled, 2 - Disabled
return $port_state;
}
// END ----------
// ----------Get copper link state on ONU ----------
function OnuCopperLinkState($ip, $ro, $iface, $port) {
$link_state = snmp2_get($ip, $ro, "1.3.6.1.4.1.3320.101.12.1.1.8.$iface.$port");
$link_state = end(explode('INTEGER: ', $link_state));
// 1 - Link down, 2 - Link up
return $link_state;
}
// END ----------
// ---------- Get iface number on OLT by MAC ONU ----------
function IfaceByMac($ip, $ro, $mac) {
$mac_spaced = str_replace(':',' ',$mac);
$mac_spaced = str_replace('a','A',$mac_spaced);
$mac_spaced = str_replace('b','B',$mac_spaced);
$mac_spaced = str_replace('c','C',$mac_spaced);
$mac_spaced = str_replace('d','D',$mac_spaced);
$mac_spaced = str_replace('e','E',$mac_spaced);
$mac_spaced = str_replace('f','F',$mac_spaced);
$Array_descr = snmprealwalk($ip, $ro, ".1.3.6.1.4.1.3320.101.10.1.1.3");
if(count($Array_descr)>0)
{
foreach($Array_descr as $key => $type)
{
$key = end(explode('10.1.1.3.', $key));
$real_mac_spaced = trim(end(explode('STRING: ', $type)));
if ($real_mac_spaced == $mac_spaced) {
$iface = $key;
}
}
}
return $iface;
}
// END ----------
// ----------Get distance to ONU by Iface----------
function DistById($ip, $ro, $iface) {
$dist = snmp2_get($ip, $ro, ".1.3.6.1.4.1.3320.101.10.1.1.27.$iface");
$dist = end(explode('INTEGER: ', $dist));
return $dist;
}
// END ----------
// ----------Get RX level by Interface ID----------
function RxById($ip, $ro, $iface) {
// Get RX level with "INTEGER: "
$rx = snmp2_get($ip, $ro, ".1.3.6.1.4.1.3320.101.10.5.1.5.$iface");
// Get CLEAN RX level
$rx = end(explode('INTEGER: ', $rx));
$rx = end(explode('OID', $rx));
if ($rx == 0 OR !$rx OR $rx == NULL OR $rx == -65536) {
$rx = "Offline";
} else {
$rx=($rx/10);
$rx=sprintf("%.1f", $rx);
}
return $rx;
}
// END ----------Get RX level by Interface ID----------
// ----------Get PON interface name by Interface ID----------
function NameById($ip, $ro, $iface) {
$iface_name = snmp2_get($ip, $ro, "1.3.6.1.2.1.2.2.1.2.$iface");
//Get CLEAN name
$iface_name = end(explode(' ', $iface_name));
$iface_name = str_replace("\"", "", $iface_name);
return $iface_name;
}
// END ----------Get PON interface name by Interface ID----------
// ----------Get MAC ADDRESS of ONU by nterface ID----------
function MacById($ip, $ro, $iface) {
$mac = snmp2_get($ip, $ro, "1.3.6.1.4.1.3320.101.10.1.1.3.$iface");
$mac = trim(end(explode(':', $mac)));
$mac = str_replace (" ", ":", $mac);
return $mac;
}
// END ----------
// ----------Get TEMPERATURE of ONU by nterface ID----------
function TempById($ip, $ro, $iface) {
$temp = snmp2_get($ip, $ro, "1.3.6.1.4.1.3320.101.10.5.1.2.$iface");
$temp = end(explode(' ', $temp));
$temp = $temp/256;
return $temp;
}
// END ----------
// ---------- Delete zero from interface name for correct sorting ----------
function NameIntDelZero($nameint) {
$nameint = str_replace (":0", ":", $nameint);
return $nameint;
}
// END ----------
// ---------- Add zero to interface name for correct sorting ----------
function NameIntAddZero($nameint) {
$end = end(explode(':', $nameint));
$count = strlen($end);
if ($count == 1){
$nameint = str_replace (":1", ":01", $nameint);
$nameint = str_replace (":2", ":02", $nameint);
$nameint = str_replace (":3", ":03", $nameint);
$nameint = str_replace (":4", ":04", $nameint);
$nameint = str_replace (":5", ":05", $nameint);
$nameint = str_replace (":6", ":06", $nameint);
$nameint = str_replace (":7", ":07", $nameint);
$nameint = str_replace (":8", ":08", $nameint);
$nameint = str_replace (":9", ":09", $nameint);
}
return $nameint;
}
// END ----------
// ---------- MYSQL update last activity of OLT ----------
function UpdateOltLastAct($conn, $sql_ip, $date) {
$sql = "UPDATE olts SET last_act='$date' WHERE ip='$sql_ip'";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
}
// END ----------
// ---------- MYSQL Update/Add ONU ----------
function UpdateOnu($conn, $sql_ip, $date, $nameint, $mac, $rx) {
$sql = "INSERT INTO onus (olt,name,mac,pwr) VALUES ('$sql_ip','$nameint','$mac','$rx') ON DUPLICATE KEY UPDATE name=VALUES(name), olt=VALUES(olt),pwr=VALUES(pwr)";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
}
if ($rx == "Offline") {
$rx = 0;
} else {
$sql = "UPDATE onus SET olt='$sql_ip',last_pwr='$rx',last_activity='$date' WHERE mac='$mac'";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
}
$sql = "INSERT INTO onus_s (olt,mac,pwr,datetime) VALUES ('$sql_ip','$mac','$rx','$date')";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
}
// END ----------
?>