2 * Copyright (C) 2007 - Filippo Giunchedi
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * @brief vde_snmp library documentation
21 * @author Filippo Giunchedi
28 #define debug(...) fprintf(stderr, "%s: ", __FUNCTION__); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); fflush(NULL)
30 #define DESC_MAXLEN 255
31 #define PHYADDR_MAXLEN 17
33 #define MAX_MGMT_READ 1024
35 #define ADMINSTATUS_UP 1
36 #define ADMINSTATUS_DOWN 2
37 #define ADMINSTATUS_TESTING 3
39 #define OPERSTATUS_UP 1
40 #define OPERSTATUS_DOWN 2
41 #define OPERSTATUS_TESTING 3
42 #define OPERSTATUS_UNKNOWN 4
43 #define OPERSTATUS_DORMANT 5
44 #define OPERSTATUS_NOTPRESENT 6
45 #define OPERSTATUS_LOWERLAYERDOWN 7
47 /* events array, init done in vde_snmp_init() */
50 #define EVENT_PORT_UP 0
51 #define EVENT_PORT_DOWN 1
54 * @brief Collection of port status
56 typedef struct vde_stats
{
58 struct vde_port_stats
*ports
;
62 * @brief Enumeration of possible administrative status
64 typedef enum adminstatus
{
65 A_UP
= ADMINSTATUS_UP
,
66 A_DOWN
= ADMINSTATUS_DOWN
,
67 A_TESTING
= ADMINSTATUS_TESTING
71 * @brief Enumeration of possible operational status
73 typedef enum operstatus
{
75 O_DOWN
= OPERSTATUS_DOWN
,
76 O_TESTING
= OPERSTATUS_TESTING
,
77 O_UNKNOWN
= OPERSTATUS_UNKNOWN
,
78 O_DORMANT
= OPERSTATUS_DORMANT
,
79 O_NOTPRESENT
= OPERSTATUS_NOTPRESENT
,
80 O_LOWERLAYERDOWN
= OPERSTATUS_LOWERLAYERDOWN
84 * @brief Representation of traffic going thru a port
86 typedef struct traffic
{
95 * @brief Status of a single port
97 typedef struct vde_port_stats
{
98 short active
; /* port is active, i.e. shown on port/allprint */
100 char desc
[DESC_MAXLEN
];
103 char phyaddress
[PHYADDR_MAXLEN
];
104 adminstatus adminstatus
;
105 operstatus operstatus
;
106 long time_lastchange
;
112 * @brief Initialize vde_snmp structures.
114 * @param standalone if 1 listen for port events and print them on stdout, for testing purposes only
115 * @param sockpath path to VDE management socket
117 * @return 0 on success, -1 on error
119 int vde_snmp_init(char *sockpath
);
122 * @brief Get port statistics.
124 * @return pointer to actual port statistics
126 vde_stats_t
* vde_snmp_get_stats(void);
129 * @brief Collect and update statistics.
131 * @return 0 on success, -1 otherwise
133 int vde_snmp_update(void);
136 * @brief Invoke registered event handlers.
138 void vde_snmp_event(void);
141 * @brief Get console management file descriptor
143 * @return the file descriptor, -1 on error
145 int vde_snmp_getfd(void);
148 * @brief Register an event handler for event
150 * @param event the event type, either EVENT_PORT_UP or EVENT_PORT_DOWN
151 * @param (*callback)(int portindex) the pointer to function to be called when the event is received
153 * @return 0 on success, -1 otherwise
155 int vde_snmp_register_callback(int event
, int (*callback
)(int portindex
));
158 * @brief Reset time of last update for port structures
160 * @return 0 on success, -1 otherwise
162 int vde_snmp_reset_lastchange(void);
165 * @brief Dump port statistics on stdout
167 * @param stats the port list to be printed
169 void vde_snmp_dumpstats(vde_stats_t
*stats
);