AF_IPN is no longer protocol #34 (assigned to AF_ISDN).
[vde.git] / vde-2 / include / libvdesnmp.h
blob73876981bd5f0b4fe2761eef7c59a0679590fe55
1 /*
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.
18 /**
19 * @file libvdesnmp.h
20 * @brief vde_snmp library documentation
21 * @author Filippo Giunchedi
22 * @date 2007-11-01
25 #ifndef _VDE_SNMP_H_
26 #define _VDE_SNMP_H_
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() */
48 #define EVENTS_NUM 2
50 #define EVENT_PORT_UP 0
51 #define EVENT_PORT_DOWN 1
53 /**
54 * @brief Collection of port status
56 typedef struct vde_stats {
57 int numports;
58 struct vde_port_stats *ports;
59 } vde_stats_t;
61 /**
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
68 } adminstatus;
70 /**
71 * @brief Enumeration of possible operational status
73 typedef enum operstatus {
74 O_UP = OPERSTATUS_UP,
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
81 } operstatus;
83 /**
84 * @brief Representation of traffic going thru a port
86 typedef struct traffic {
87 long octects;
88 long ucastpkts;
89 long discards;
90 long errors;
91 long unknownprotos;
92 } traffic_t;
94 /**
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 */
99 int index;
100 char desc[DESC_MAXLEN];
101 int mtu;
102 int speed;
103 char phyaddress[PHYADDR_MAXLEN];
104 adminstatus adminstatus;
105 operstatus operstatus;
106 long time_lastchange;
107 traffic_t *in;
108 traffic_t *out;
109 } vde_port_stats;
111 /**
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);
121 /**
122 * @brief Get port statistics.
124 * @return pointer to actual port statistics
126 vde_stats_t* vde_snmp_get_stats(void);
128 /**
129 * @brief Collect and update statistics.
131 * @return 0 on success, -1 otherwise
133 int vde_snmp_update(void);
135 /**
136 * @brief Invoke registered event handlers.
138 void vde_snmp_event(void);
140 /**
141 * @brief Get console management file descriptor
143 * @return the file descriptor, -1 on error
145 int vde_snmp_getfd(void);
147 /**
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));
157 /**
158 * @brief Reset time of last update for port structures
160 * @return 0 on success, -1 otherwise
162 int vde_snmp_reset_lastchange(void);
164 /**
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);
171 #endif