1
/**************************************************************
2
* Copyright (C) 2001 Tali Rozin, Optical Access
6
* Permission to use, copy, modify and distribute this software and its
7
* documentation for any purpose and without fee is hereby granted,
8
* provided that the above copyright notice appear in all copies and that
9
* both that copyright notice and this permission notice appear in
10
* supporting documentation.
12
* TALI ROZIN DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
13
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
14
* ALEX ROZIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
15
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
17
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19
******************************************************************/
21
#include <net-snmp/net-snmp-config.h>
26
#if TIME_WITH_SYS_TIME
28
# include <sys/timeb.h>
30
# include <sys/time.h>
35
# include <sys/time.h>
44
#include <net-snmp/net-snmp-includes.h>
45
#include <net-snmp/agent/net-snmp-agent-includes.h>
46
#include "util_funcs.h"
47
#include "statistics.h"
49
* Implementation headers
51
#include "agutil_api.h"
54
* File scope definitions section
57
* from MIB compilation
59
#define MIB_DESCR "EthStat"
60
#define etherStatsEntryFirstIndexBegin 11
61
#define IDetherStatsDroppedFrames 1
62
#define IDetherStatsCreateTime 2
63
#define IDetherStatsIndex 3
64
#define IDetherStatsDataSource 4
65
#define IDetherStatsDropEvents 5
66
#define IDetherStatsOctets 6
67
#define IDetherStatsPkts 7
68
#define IDetherStatsBroadcastPkts 8
69
#define IDetherStatsMulticastPkts 9
70
#define IDetherStatsCRCAlignErrors 10
71
#define IDetherStatsUndersizePkts 11
72
#define IDetherStatsOversizePkts 12
73
#define IDetherStatsFragments 13
74
#define IDetherStatsJabbers 14
75
#define IDetherStatsCollisions 15
76
#define IDetherStatsPkts64Octets 16
77
#define IDetherStatsPkts65to127Octets 17
78
#define IDetherStatsPkts128to255Octets 18
79
#define IDetherStatsPkts256to511Octets 19
80
#define IDetherStatsPkts512to1023Octets 20
81
#define IDetherStatsPkts1024to1518Octets 21
82
#define IDetherStatsOwner 22
83
#define IDetherStatsStatus 23
84
#define Leaf_etherStatsDataSource 2
85
#define Leaf_etherStatsOwner 20
86
#define Leaf_etherStatsStatus 21
87
#define MIN_etherStatsIndex 1
88
#define MAX_etherStatsIndex 65535
102
static TABLE_DEFINTION_T
104
static TABLE_DEFINTION_T *
109
* Control Table RowApi Callbacks
113
stat_Create(RMON_ENTRY_T * eptr)
114
{ /* create the body: alloc it and set defaults */
116
static VAR_OID_T data_src_if_index_1 =
117
{ 11, {1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 1} };
119
eptr->body = AGMALLOC(sizeof(CRTL_ENTRY_T));
122
body = (CRTL_ENTRY_T *) eptr->body;
127
memcpy(&body->data_source, &data_src_if_index_1, sizeof(VAR_OID_T));
128
body->data_source.objid[body->data_source.length - 1] =
130
eptr->owner = AGSTRDUP("Startup Mgmt");
131
memset(&body->eth, 0, sizeof(ETH_STATS_T));
137
stat_Validate(RMON_ENTRY_T * eptr)
140
* T.B.D. (system dependent) check valid inteface in body->data_source;
147
stat_Activate(RMON_ENTRY_T * eptr)
149
CRTL_ENTRY_T *body = (CRTL_ENTRY_T *) eptr->body;
151
body->etherStatsCreateTime = AGUTIL_sys_up_time();
157
stat_Copy(RMON_ENTRY_T * eptr)
159
CRTL_ENTRY_T *body = (CRTL_ENTRY_T *) eptr->body;
160
CRTL_ENTRY_T *clone = (CRTL_ENTRY_T *) eptr->tmp;
163
(clone->data_source.objid, clone->data_source.length,
164
body->data_source.objid, body->data_source.length)) {
165
memcpy(&body->data_source, &clone->data_source, sizeof(VAR_OID_T));
172
stat_Deactivate(RMON_ENTRY_T * eptr)
174
CRTL_ENTRY_T *body = (CRTL_ENTRY_T *) eptr->body;
175
memset(&body->eth, 0, sizeof(ETH_STATS_T));
180
/***************************************************
181
* Function:var_etherStats2Entry
182
* Purpose: Handles the request for etherStats2Entry variable instances
183
***************************************************/
185
var_etherStats2Entry(struct variable * vp, oid * name, size_t * length,
186
int exact, size_t * var_len,
187
WriteMethod ** write_method)
189
static long long_return;
190
static CRTL_ENTRY_T theEntry;
193
*write_method = NULL;
195
hdr = ROWAPI_header_ControlEntry(vp, name, length, exact, var_len,
197
&theEntry, sizeof(CRTL_ENTRY_T));
201
*var_len = sizeof(long); /* default */
204
case IDetherStatsDroppedFrames:
206
return (u_char *) & long_return;
207
case IDetherStatsCreateTime:
208
long_return = theEntry.etherStatsCreateTime;
209
return (u_char *) & long_return;
211
ag_trace("%s: unknown vp->magic=%d", table_ptr->name,
214
}; /* of switch by 'vp->magic' */
220
/***************************************************
221
* Function:write_etherStatsEntry
222
***************************************************/
224
write_etherStatsEntry(int action, u_char * var_val, u_char var_val_type,
225
size_t var_val_len, u_char * statP,
226
oid * name, size_t name_len)
229
int leaf_id, snmp_status;
230
static int prev_action = COMMIT;
232
CRTL_ENTRY_T *cloned_body;
243
ROWAPI_do_another_action(name, etherStatsEntryFirstIndexBegin,
244
action, &prev_action, table_ptr,
245
sizeof(CRTL_ENTRY_T));
246
if (SNMP_ERR_NOERROR != snmp_status) {
247
ag_trace("failed action %d with %d", action, snmp_status);
253
* get values from PDU, check them and save them in the cloned entry
255
long_temp = name[etherStatsEntryFirstIndexBegin];
256
leaf_id = (int) name[etherStatsEntryFirstIndexBegin - 1];
257
hdr = ROWAPI_find(table_ptr, long_temp); /* it MUST be OK */
258
cloned_body = (CRTL_ENTRY_T *) hdr->tmp;
259
body = (CRTL_ENTRY_T *) hdr->body;
261
case Leaf_etherStatsDataSource:
262
snmp_status = AGUTIL_get_oid_value(var_val, var_val_type,
264
&cloned_body->data_source);
265
if (SNMP_ERR_NOERROR != snmp_status) {
268
if (RMON1_ENTRY_UNDER_CREATION != hdr->status &&
269
snmp_oid_compare(cloned_body->data_source.objid,
270
cloned_body->data_source.length,
271
body->data_source.objid,
272
body->data_source.length))
273
return SNMP_ERR_BADVALUE;
277
case Leaf_etherStatsOwner:
279
AGFREE(hdr->new_owner);
280
hdr->new_owner = AGMALLOC(MAX_OWNERSTRING);;
282
return SNMP_ERR_TOOBIG;
283
snmp_status = AGUTIL_get_string_value(var_val, var_val_type,
286
1, NULL, hdr->new_owner);
287
if (SNMP_ERR_NOERROR != snmp_status) {
291
case Leaf_etherStatsStatus:
292
snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
297
if (SNMP_ERR_NOERROR != snmp_status) {
298
ag_trace("cannot browse etherStatsStatus");
301
hdr->new_status = long_temp;
305
ag_trace("%s:unknown leaf_id=%d\n", table_ptr->name,
307
return SNMP_ERR_NOSUCHNAME;
308
} /* of switch by 'leaf_id' */
310
} /* of switch by 'action' */
312
prev_action = action;
313
return SNMP_ERR_NOERROR;
316
/***************************************************
317
* Function:var_etherStatsEntry
318
* Purpose: Handles the request for etherStatsEntry variable instances
319
***************************************************/
321
var_etherStatsEntry(struct variable * vp, oid * name, size_t * length,
322
int exact, size_t * var_len,
323
WriteMethod ** write_method)
325
static long long_return;
326
static CRTL_ENTRY_T theEntry;
329
*write_method = write_etherStatsEntry;
330
hdr = ROWAPI_header_ControlEntry(vp, name, length, exact, var_len,
332
&theEntry, sizeof(CRTL_ENTRY_T));
336
if (RMON1_ENTRY_VALID == hdr->status)
337
SYSTEM_get_eth_statistics(&theEntry.data_source, &theEntry.eth);
339
*var_len = sizeof(long);
342
case IDetherStatsIndex:
343
long_return = hdr->ctrl_index;
344
return (u_char *) & long_return;
345
case IDetherStatsDataSource:
346
*var_len = sizeof(oid) * theEntry.data_source.length;
347
return (unsigned char *) theEntry.data_source.objid;
348
case IDetherStatsDropEvents:
349
long_return = 0; /* theEntry.eth.etherStatsDropEvents; */
350
return (u_char *) & long_return;
351
case IDetherStatsOctets:
352
long_return = theEntry.eth.octets;
353
return (u_char *) & long_return;
354
case IDetherStatsPkts:
355
long_return = theEntry.eth.packets;
356
return (u_char *) & long_return;
357
case IDetherStatsBroadcastPkts:
358
long_return = theEntry.eth.bcast_pkts;
359
return (u_char *) & long_return;
360
case IDetherStatsMulticastPkts:
361
long_return = theEntry.eth.mcast_pkts;
362
return (u_char *) & long_return;
363
case IDetherStatsCRCAlignErrors:
364
long_return = theEntry.eth.crc_align;
365
return (u_char *) & long_return;
366
case IDetherStatsUndersizePkts:
367
long_return = theEntry.eth.undersize;
368
return (u_char *) & long_return;
369
case IDetherStatsOversizePkts:
370
long_return = theEntry.eth.oversize;
371
return (u_char *) & long_return;
372
case IDetherStatsFragments:
373
long_return = theEntry.eth.fragments;
374
return (u_char *) & long_return;
375
case IDetherStatsJabbers:
376
long_return = theEntry.eth.jabbers;
377
return (u_char *) & long_return;
378
case IDetherStatsCollisions:
379
long_return = theEntry.eth.collisions;
380
return (u_char *) & long_return;
381
case IDetherStatsPkts64Octets:
382
long_return = theEntry.eth.pkts_64;
383
return (u_char *) & long_return;
384
case IDetherStatsPkts65to127Octets:
385
long_return = theEntry.eth.pkts_65_127;
386
return (u_char *) & long_return;
387
case IDetherStatsPkts128to255Octets:
388
long_return = theEntry.eth.pkts_128_255;
389
return (u_char *) & long_return;
390
case IDetherStatsPkts256to511Octets:
391
long_return = theEntry.eth.pkts_256_511;
392
return (u_char *) & long_return;
393
case IDetherStatsPkts512to1023Octets:
394
long_return = theEntry.eth.pkts_512_1023;
395
return (u_char *) & long_return;
396
case IDetherStatsPkts1024to1518Octets:
397
long_return = theEntry.eth.pkts_1024_1518;
398
return (u_char *) & long_return;
399
case IDetherStatsOwner:
401
*var_len = strlen(hdr->owner);
402
return (unsigned char *) hdr->owner;
405
return (unsigned char *) "";
407
case IDetherStatsStatus:
408
long_return = hdr->status;
409
return (u_char *) & long_return;
412
}; /* of switch by 'vp->magic' */
417
#if 1 /* debug, but may be used for init. TBD: may be token snmpd.conf ? */
419
add_statistics_entry(int ctrl_index, int ifIndex)
423
ierr = ROWAPI_new(table_ptr, ctrl_index);
426
ag_trace("max. number exedes\n");
429
ag_trace("malloc failed");
432
ag_trace("ClbkCreate failed");
437
ag_trace("Unknown code %d", ierr);
442
register RMON_ENTRY_T *eptr = ROWAPI_find(table_ptr, ctrl_index);
444
ag_trace("cannot find it");
447
CRTL_ENTRY_T *body = (CRTL_ENTRY_T *) eptr->body;
449
body->data_source.objid[body->data_source.length - 1] =
452
eptr->new_status = RMON1_ENTRY_VALID;
453
ierr = ROWAPI_commit(table_ptr, ctrl_index);
455
ag_trace("ROWAPI_commit returned %d", ierr);
464
/***************************************************
465
* define Variables callbacks
466
***************************************************/
467
oid oidstatisticsVariablesOid[] = { 1, 3, 6, 1, 2, 1, 16, 1 };
469
struct variable7 oidstatisticsVariables[] = {
470
{IDetherStatsIndex, ASN_INTEGER, RONLY, var_etherStatsEntry, 3,
472
{IDetherStatsDataSource, ASN_OBJECT_ID, RWRITE, var_etherStatsEntry, 3,
474
{IDetherStatsDropEvents, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
476
{IDetherStatsOctets, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
478
{IDetherStatsPkts, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
480
{IDetherStatsBroadcastPkts, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
482
{IDetherStatsMulticastPkts, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
484
{IDetherStatsCRCAlignErrors, ASN_COUNTER, RONLY, var_etherStatsEntry,
486
{IDetherStatsUndersizePkts, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
488
{IDetherStatsOversizePkts, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
490
{IDetherStatsFragments, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
492
{IDetherStatsJabbers, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
494
{IDetherStatsCollisions, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
496
{IDetherStatsPkts64Octets, ASN_COUNTER, RONLY, var_etherStatsEntry, 3,
498
{IDetherStatsPkts65to127Octets, ASN_COUNTER, RONLY,
499
var_etherStatsEntry, 3, {1, 1, 15}},
500
{IDetherStatsPkts128to255Octets, ASN_COUNTER, RONLY,
501
var_etherStatsEntry, 3, {1, 1, 16}},
502
{IDetherStatsPkts256to511Octets, ASN_COUNTER, RONLY,
503
var_etherStatsEntry, 3, {1, 1, 17}},
504
{IDetherStatsPkts512to1023Octets, ASN_COUNTER, RONLY,
505
var_etherStatsEntry, 3, {1, 1, 18}},
506
{IDetherStatsPkts1024to1518Octets, ASN_COUNTER, RONLY,
507
var_etherStatsEntry, 3, {1, 1, 19}},
508
{IDetherStatsOwner, ASN_OCTET_STR, RWRITE, var_etherStatsEntry, 3,
510
{IDetherStatsStatus, ASN_INTEGER, RWRITE, var_etherStatsEntry, 3,
512
{IDetherStatsDroppedFrames, ASN_COUNTER, RONLY, var_etherStats2Entry,
514
{IDetherStatsCreateTime, ASN_TIMETICKS, RONLY, var_etherStats2Entry, 3,
518
/***************************************************
519
* Function:init_statistics
520
* Purpose: register statistics objects in the agent
521
***************************************************/
523
init_statistics(void)
525
REGISTER_MIB(MIB_DESCR, oidstatisticsVariables, variable7,
526
oidstatisticsVariablesOid);
528
ROWAPI_init_table(&StatCtrlTable, MIB_DESCR, 0, &stat_Create, NULL, /* &stat_Clone, */
529
NULL, /* &stat_Delete, */
531
&stat_Activate, &stat_Deactivate, &stat_Copy);
536
for (iii = 1; iii < 6; iii++) {
537
add_statistics_entry(iii, iii);
540
add_statistics_entry(10, 16);
541
add_statistics_entry(12, 11);
547
* end of file statistics.c