Commit 1406bc93 authored by bradomyn's avatar bradomyn

added slfow api

parent ef526d0e
/* Copyright (c) 2002-2006 InMon Corp. Licensed under the terms of the InMon sFlow licence: */
/* http://www.inmon.com/technology/sflowlicense.txt */
/* $Header: /usr/src/redhat/SOURCES/InMon_Agent-5.6/RCS/sflow.h,v 1.10 2006/07/10 18:22:37 root Exp $ */
/////////////////////////////////////////////////////////////////////////////////
/////////////////////// sFlow Sampling Packet Data Types ////////////////////////
/////////////////////////////////////////////////////////////////////////////////
#ifndef SFLOW_H
#define SFLOW_H 1
#if defined(__cplusplus)
extern "C" {
#endif
enum SFLAddress_type {
SFLADDRESSTYPE_IP_V4 = 1,
SFLADDRESSTYPE_IP_V6 = 2
};
#incl
typedef union _SFLAddress_value {
struct in_addr ip_v4;
struct in6_addr ip_v6;
} SFLAddress_value;
typedef struct _SFLAddress {
u_int32_t type; /* enum SFLAddress_type */
SFLAddress_value address;
} SFLAddress;
/* Packet header data */
#define SFL_DEFAULT_HEADER_SIZE 128
#define SFL_DEFAULT_COLLECTOR_PORT 6343
#define SFL_DEFAULT_SAMPLING_RATE 400
/* The header protocol describes the format of the sampled header */
enum SFLHeader_protocol {
SFLHEADER_ETHERNET_ISO8023 = 1,
SFLHEADER_ISO88024_TOKENBUS = 2,
SFLHEADER_ISO88025_TOKENRING = 3,
SFLHEADER_FDDI = 4,
SFLHEADER_FRAME_RELAY = 5,
SFLHEADER_X25 = 6,
SFLHEADER_PPP = 7,
SFLHEADER_SMDS = 8,
SFLHEADER_AAL5 = 9,
SFLHEADER_AAL5_IP = 10, /* e.g. Cisco AAL5 mux */
SFLHEADER_IPv4 = 11,
SFLHEADER_IPv6 = 12,
SFLHEADER_MPLS = 13
};
/* raw sampled header */
typedef struct _SFLSampled_header {
u_int32_t header_protocol; /* (enum SFLHeader_protocol) */
u_int32_t frame_length; /* Original length of packet before sampling */
u_int32_t stripped; /* header/trailer bytes stripped by sender */
u_int32_t header_length; /* length of sampled header bytes to follow */
u_int8_t *header_bytes; /* Header bytes */
} SFLSampled_header;
/* decoded ethernet header */
typedef struct _SFLSampled_ethernet {
u_int32_t eth_len; /* The length of the MAC packet excluding
lower layer encapsulations */
u_int8_t src_mac[8]; /* 6 bytes + 2 pad */
u_int8_t dst_mac[8];
u_int32_t eth_type;
} SFLSampled_ethernet;
/* decoded IP version 4 header */
typedef struct _SFLSampled_ipv4 {
u_int32_t length; /* The length of the IP packet
excluding lower layer encapsulations */
u_int32_t protocol; /* IP Protocol type (for example, TCP = 6, UDP = 17) */
struct in_addr src_ip; /* Source IP Address */
struct in_addr dst_ip; /* Destination IP Address */
u_int32_t src_port; /* TCP/UDP source port number or equivalent */
u_int32_t dst_port; /* TCP/UDP destination port number or equivalent */
u_int32_t tcp_flags; /* TCP flags */
u_int32_t tos; /* IP type of service */
} SFLSampled_ipv4;
/* decoded IP version 6 data */
typedef struct _SFLSampled_ipv6 {
u_int32_t length; /* The length of the IP packet
excluding lower layer encapsulations */
u_int32_t protocol; /* IP Protocol type (for example, TCP = 6, UDP = 17) */
struct in6_addr src_ip; /* Source IP Address */
struct in6_addr dst_ip; /* Destination IP Address */
u_int32_t src_port; /* TCP/UDP source port number or equivalent */
u_int32_t dst_port; /* TCP/UDP destination port number or equivalent */
u_int32_t tcp_flags; /* TCP flags */
u_int32_t priority; /* IP priority */
} SFLSampled_ipv6;
/* Extended data types */
/* Extended switch data */
typedef struct _SFLExtended_switch {
u_int32_t src_vlan; /* The 802.1Q VLAN id of incomming frame */
u_int32_t src_priority; /* The 802.1p priority */
u_int32_t dst_vlan; /* The 802.1Q VLAN id of outgoing frame */
u_int32_t dst_priority; /* The 802.1p priority */
} SFLExtended_switch;
/* Extended router data */
typedef struct _SFLExtended_router {
SFLAddress nexthop; /* IP address of next hop router */
u_int32_t src_mask; /* Source address prefix mask bits */
u_int32_t dst_mask; /* Destination address prefix mask bits */
} SFLExtended_router;
/* Extended gateway data */
enum SFLExtended_as_path_segment_type {
SFLEXTENDED_AS_SET = 1, /* Unordered set of ASs */
SFLEXTENDED_AS_SEQUENCE = 2 /* Ordered sequence of ASs */
};
typedef struct _SFLExtended_as_path_segment {
u_int32_t type; /* enum SFLExtended_as_path_segment_type */
u_int32_t length; /* number of AS numbers in set/sequence */
union {
u_int32_t *set;
u_int32_t *seq;
} as;
} SFLExtended_as_path_segment;
typedef struct _SFLExtended_gateway {
SFLAddress nexthop; /* Address of the border router that should
be used for the destination network */
u_int32_t as; /* AS number for this gateway */
u_int32_t src_as; /* AS number of source (origin) */
u_int32_t src_peer_as; /* AS number of source peer */
u_int32_t dst_as_path_segments; /* number of segments in path */
SFLExtended_as_path_segment *dst_as_path; /* list of seqs or sets */
u_int32_t communities_length; /* number of communities */
u_int32_t *communities; /* set of communities */
u_int32_t localpref; /* LocalPref associated with this route */
} SFLExtended_gateway;
typedef struct _SFLString {
u_int32_t len;
char *str;
} SFLString;
/* Extended user data */
typedef struct _SFLExtended_user {
u_int32_t src_charset; /* MIBEnum value of character set used to encode a string - See RFC 2978
Where possible UTF-8 encoding (MIBEnum=106) should be used. A value
of zero indicates an unknown encoding. */
SFLString src_user;
u_int32_t dst_charset;
SFLString dst_user;
} SFLExtended_user;
/* Extended URL data */
enum SFLExtended_url_direction {
SFLEXTENDED_URL_SRC = 1, /* URL is associated with source address */
SFLEXTENDED_URL_DST = 2 /* URL is associated with destination address */
};
typedef struct _SFLExtended_url {
u_int32_t direction; /* enum SFLExtended_url_direction */
SFLString url; /* URL associated with the packet flow.
Must be URL encoded */
SFLString host; /* The host field from the HTTP header */
} SFLExtended_url;
/* Extended MPLS data */
typedef struct _SFLLabelStack {
u_int32_t depth;
u_int32_t *stack; /* first entry is top of stack - see RFC 3032 for encoding */
} SFLLabelStack;
typedef struct _SFLExtended_mpls {
SFLAddress nextHop; /* Address of the next hop */
SFLLabelStack in_stack;
SFLLabelStack out_stack;
} SFLExtended_mpls;
/* Extended NAT data
Packet header records report addresses as seen at the sFlowDataSource.
The extended_nat structure reports on translated source and/or destination
addesses for this packet. If an address was not translated it should
be equal to that reported for the header. */
typedef struct _SFLExtended_nat {
SFLAddress src; /* Source address */
SFLAddress dst; /* Destination address */
} SFLExtended_nat;
/* additional Extended MPLS stucts */
typedef struct _SFLExtended_mpls_tunnel {
SFLString tunnel_lsp_name; /* Tunnel name */
u_int32_t tunnel_id; /* Tunnel ID */
u_int32_t tunnel_cos; /* Tunnel COS value */
} SFLExtended_mpls_tunnel;
typedef struct _SFLExtended_mpls_vc {
SFLString vc_instance_name; /* VC instance name */
u_int32_t vll_vc_id; /* VLL/VC instance ID */
u_int32_t vc_label_cos; /* VC Label COS value */
} SFLExtended_mpls_vc;
/* Extended MPLS FEC
- Definitions from MPLS-FTN-STD-MIB mplsFTNTable */
typedef struct _SFLExtended_mpls_FTN {
SFLString mplsFTNDescr;
u_int32_t mplsFTNMask;
} SFLExtended_mpls_FTN;
/* Extended MPLS LVP FEC
- Definition from MPLS-LDP-STD-MIB mplsFecTable
Note: mplsFecAddrType, mplsFecAddr information available
from packet header */
typedef struct _SFLExtended_mpls_LDP_FEC {
u_int32_t mplsFecAddrPrefixLength;
} SFLExtended_mpls_LDP_FEC;
/* Extended VLAN tunnel information
Record outer VLAN encapsulations that have
been stripped. extended_vlantunnel information
should only be reported if all the following conditions are satisfied:
1. The packet has nested vlan tags, AND
2. The reporting device is VLAN aware, AND
3. One or more VLAN tags have been stripped, either
because they represent proprietary encapsulations, or
because switch hardware automatically strips the outer VLAN
encapsulation.
Reporting extended_vlantunnel information is not a substitute for
reporting extended_switch information. extended_switch data must
always be reported to describe the ingress/egress VLAN information
for the packet. The extended_vlantunnel information only applies to
nested VLAN tags, and then only when one or more tags has been
stripped. */
typedef SFLLabelStack SFLVlanStack;
typedef struct _SFLExtended_vlan_tunnel {
SFLVlanStack stack; /* List of stripped 802.1Q TPID/TCI layers. Each
TPID,TCI pair is represented as a single 32 bit
integer. Layers listed from outermost to
innermost. */
} SFLExtended_vlan_tunnel;
enum SFLFlow_type_tag {
/* enterprise = 0, format = ... */
SFLFLOW_HEADER = 1, /* Packet headers are sampled */
SFLFLOW_ETHERNET = 2, /* MAC layer information */
SFLFLOW_IPV4 = 3, /* IP version 4 data */
SFLFLOW_IPV6 = 4, /* IP version 6 data */
SFLFLOW_EX_SWITCH = 1001, /* Extended switch information */
SFLFLOW_EX_ROUTER = 1002, /* Extended router information */
SFLFLOW_EX_GATEWAY = 1003, /* Extended gateway router information */
SFLFLOW_EX_USER = 1004, /* Extended TACAS/RADIUS user information */
SFLFLOW_EX_URL = 1005, /* Extended URL information */
SFLFLOW_EX_MPLS = 1006, /* Extended MPLS information */
SFLFLOW_EX_NAT = 1007, /* Extended NAT information */
SFLFLOW_EX_MPLS_TUNNEL = 1008, /* additional MPLS information */
SFLFLOW_EX_MPLS_VC = 1009,
SFLFLOW_EX_MPLS_FTN = 1010,
SFLFLOW_EX_MPLS_LDP_FEC = 1011,
SFLFLOW_EX_VLAN_TUNNEL = 1012, /* VLAN stack */
};
typedef union _SFLFlow_type {
SFLSampled_header header;
SFLSampled_ethernet ethernet;
SFLSampled_ipv4 ipv4;
SFLSampled_ipv6 ipv6;
SFLExtended_switch sw;
SFLExtended_router router;
SFLExtended_gateway gateway;
SFLExtended_user user;
SFLExtended_url url;
SFLExtended_mpls mpls;
SFLExtended_nat nat;
SFLExtended_mpls_tunnel mpls_tunnel;
SFLExtended_mpls_vc mpls_vc;
SFLExtended_mpls_FTN mpls_ftn;
SFLExtended_mpls_LDP_FEC mpls_ldp_fec;
SFLExtended_vlan_tunnel vlan_tunnel;
} SFLFlow_type;
typedef struct _SFLFlow_sample_element {
struct _SFLFlow_sample_element *nxt;
u_int32_t tag; /* SFLFlow_type_tag */
u_int32_t length;
SFLFlow_type flowType;
} SFLFlow_sample_element;
enum SFL_sample_tag {
SFLFLOW_SAMPLE = 1, /* enterprise = 0 : format = 1 */
SFLCOUNTERS_SAMPLE = 2, /* enterprise = 0 : format = 2 */
SFLFLOW_SAMPLE_EXPANDED = 3, /* enterprise = 0 : format = 3 */
SFLCOUNTERS_SAMPLE_EXPANDED = 4 /* enterprise = 0 : format = 4 */
};
/* Format of a single flow sample */
typedef struct _SFLFlow_sample {
/* u_int32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 1 */
/* u_int32_t length; */
u_int32_t sequence_number; /* Incremented with each flow sample
generated */
u_int32_t source_id; /* fsSourceId */
u_int32_t sampling_rate; /* fsPacketSamplingRate */
u_int32_t sample_pool; /* Total number of packets that could have been
sampled (i.e. packets skipped by sampling
process + total number of samples) */
u_int32_t drops; /* Number of times a packet was dropped due to
lack of resources */
u_int32_t input; /* SNMP ifIndex of input interface.
0 if interface is not known. */
u_int32_t output; /* SNMP ifIndex of output interface,
0 if interface is not known.
Set most significant bit to indicate
multiple destination interfaces
(i.e. in case of broadcast or multicast)
and set lower order bits to indicate
number of destination interfaces.
Examples:
0x00000002 indicates ifIndex = 2
0x00000000 ifIndex unknown.
0x80000007 indicates a packet sent
to 7 interfaces.
0x80000000 indicates a packet sent to
an unknown number of
interfaces greater than 1.*/
u_int32_t num_elements;
SFLFlow_sample_element *elements;
} SFLFlow_sample;
/* same thing, but the expanded version (for full 32-bit ifIndex numbers) */
typedef struct _SFLFlow_sample_expanded {
/* u_int32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 1 */
/* u_int32_t length; */
u_int32_t sequence_number; /* Incremented with each flow sample
generated */
u_int32_t ds_class; /* EXPANDED */
u_int32_t ds_index; /* EXPANDED */
u_int32_t sampling_rate; /* fsPacketSamplingRate */
u_int32_t sample_pool; /* Total number of packets that could have been
sampled (i.e. packets skipped by sampling
process + total number of samples) */
u_int32_t drops; /* Number of times a packet was dropped due to
lack of resources */
u_int32_t inputFormat; /* EXPANDED */
u_int32_t input; /* SNMP ifIndex of input interface.
0 if interface is not known. */
u_int32_t outputFormat; /* EXPANDED */
u_int32_t output; /* SNMP ifIndex of output interface,
0 if interface is not known. */
u_int32_t num_elements;
SFLFlow_sample_element *elements;
} SFLFlow_sample_expanded;
/* Counter types */
/* Generic interface counters - see RFC 1573, 2233 */
typedef struct _SFLIf_counters {
u_int32_t ifIndex;
u_int32_t ifType;
u_int64_t ifSpeed;
u_int32_t ifDirection; /* Derived from MAU MIB (RFC 2668)
0 = unknown, 1 = full-duplex,
2 = half-duplex, 3 = in, 4 = out */
u_int32_t ifStatus; /* bit field with the following bits assigned:
bit 0 = ifAdminStatus (0 = down, 1 = up)
bit 1 = ifOperStatus (0 = down, 1 = up) */
u_int64_t ifInOctets;
u_int32_t ifInUcastPkts;
u_int32_t ifInMulticastPkts;
u_int32_t ifInBroadcastPkts;
u_int32_t ifInDiscards;
u_int32_t ifInErrors;
u_int32_t ifInUnknownProtos;
u_int64_t ifOutOctets;
u_int32_t ifOutUcastPkts;
u_int32_t ifOutMulticastPkts;
u_int32_t ifOutBroadcastPkts;
u_int32_t ifOutDiscards;
u_int32_t ifOutErrors;
u_int32_t ifPromiscuousMode;
} SFLIf_counters;
/* Ethernet interface counters - see RFC 2358 */
typedef struct _SFLEthernet_counters {
u_int32_t dot3StatsAlignmentErrors;
u_int32_t dot3StatsFCSErrors;
u_int32_t dot3StatsSingleCollisionFrames;
u_int32_t dot3StatsMultipleCollisionFrames;
u_int32_t dot3StatsSQETestErrors;
u_int32_t dot3StatsDeferredTransmissions;
u_int32_t dot3StatsLateCollisions;
u_int32_t dot3StatsExcessiveCollisions;
u_int32_t dot3StatsInternalMacTransmitErrors;
u_int32_t dot3StatsCarrierSenseErrors;
u_int32_t dot3StatsFrameTooLongs;
u_int32_t dot3StatsInternalMacReceiveErrors;
u_int32_t dot3StatsSymbolErrors;
} SFLEthernet_counters;
/* Token ring counters - see RFC 1748 */
typedef struct _SFLTokenring_counters {
u_int32_t dot5StatsLineErrors;
u_int32_t dot5StatsBurstErrors;
u_int32_t dot5StatsACErrors;
u_int32_t dot5StatsAbortTransErrors;
u_int32_t dot5StatsInternalErrors;
u_int32_t dot5StatsLostFrameErrors;
u_int32_t dot5StatsReceiveCongestions;
u_int32_t dot5StatsFrameCopiedErrors;
u_int32_t dot5StatsTokenErrors;
u_int32_t dot5StatsSoftErrors;
u_int32_t dot5StatsHardErrors;
u_int32_t dot5StatsSignalLoss;
u_int32_t dot5StatsTransmitBeacons;
u_int32_t dot5StatsRecoverys;
u_int32_t dot5StatsLobeWires;
u_int32_t dot5StatsRemoves;
u_int32_t dot5StatsSingles;
u_int32_t dot5StatsFreqErrors;
} SFLTokenring_counters;
/* 100 BaseVG interface counters - see RFC 2020 */
typedef struct _SFLVg_counters {
u_int32_t dot12InHighPriorityFrames;
u_int64_t dot12InHighPriorityOctets;
u_int32_t dot12InNormPriorityFrames;
u_int64_t dot12InNormPriorityOctets;
u_int32_t dot12InIPMErrors;
u_int32_t dot12InOversizeFrameErrors;
u_int32_t dot12InDataErrors;
u_int32_t dot12InNullAddressedFrames;
u_int32_t dot12OutHighPriorityFrames;
u_int64_t dot12OutHighPriorityOctets;
u_int32_t dot12TransitionIntoTrainings;
u_int64_t dot12HCInHighPriorityOctets;
u_int64_t dot12HCInNormPriorityOctets;
u_int64_t dot12HCOutHighPriorityOctets;
} SFLVg_counters;
typedef struct _SFLVlan_counters {
u_int32_t vlan_id;
u_int64_t octets;
u_int32_t ucastPkts;
u_int32_t multicastPkts;
u_int32_t broadcastPkts;
u_int32_t discards;
} SFLVlan_counters;
/* Processor Information */
/* opaque = counter_data; enterprise = 0; format = 1001 */
typedef struct _SFLProcessor_counters {
u_int32_t five_sec_cpu; /* 5 second average CPU utilization */
u_int32_t one_min_cpu; /* 1 minute average CPU utilization */
u_int32_t five_min_cpu; /* 5 minute average CPU utilization */
u_int64_t total_memory; /* total memory (in bytes) */
u_int64_t free_memory; /* free memory (in bytes) */
} SFLProcessor_counters;
/* Counters data */
enum SFLCounters_type_tag {
/* enterprise = 0, format = ... */
SFLCOUNTERS_GENERIC = 1,
SFLCOUNTERS_ETHERNET = 2,
SFLCOUNTERS_TOKENRING = 3,
SFLCOUNTERS_VG = 4,
SFLCOUNTERS_VLAN = 5,
SFLCOUNTERS_PROCESSOR = 1001
};
typedef union _SFLCounters_type {
SFLIf_counters generic;
SFLEthernet_counters ethernet;
SFLTokenring_counters tokenring;
SFLVg_counters vg;
SFLVlan_counters vlan;
SFLProcessor_counters processor;
} SFLCounters_type;
typedef struct _SFLCounters_sample_element {
struct _SFLCounters_sample_element *nxt; /* linked list */
u_int32_t tag; /* SFLCounters_type_tag */
u_int32_t length;
SFLCounters_type counterBlock;
} SFLCounters_sample_element;
typedef struct _SFLCounters_sample {
/* u_int32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 2 */
/* u_int32_t length; */
u_int32_t sequence_number; /* Incremented with each counters sample
generated by this source_id */
u_int32_t source_id; /* fsSourceId */
u_int32_t num_elements;
SFLCounters_sample_element *elements;
} SFLCounters_sample;
/* same thing, but the expanded version, so ds_index can be a full 32 bits */
typedef struct _SFLCounters_sample_expanded {
/* u_int32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 2 */
/* u_int32_t length; */
u_int32_t sequence_number; /* Incremented with each counters sample
generated by this source_id */
u_int32_t ds_class; /* EXPANDED */
u_int32_t ds_index; /* EXPANDED */
u_int32_t num_elements;
SFLCounters_sample_element *elements;
} SFLCounters_sample_expanded;
#define SFLADD_ELEMENT(_sm, _el) do { (_el)->nxt = (_sm)->elements; (_sm)->elements = (_el); } while(0)
/* Format of a sample datagram */
enum SFLDatagram_version {
SFLDATAGRAM_VERSION2 = 2,
SFLDATAGRAM_VERSION4 = 4,
SFLDATAGRAM_VERSION5 = 5
};
typedef struct _SFLSample_datagram_hdr {
u_int32_t datagram_version; /* (enum SFLDatagram_version) = VERSION5 = 5 */
SFLAddress agent_address; /* IP address of sampling agent */
u_int32_t sub_agent_id; /* Used to distinguishing between datagram
streams from separate agent sub entities
within an device. */
u_int32_t sequence_number; /* Incremented with each sample datagram
generated */
u_int32_t uptime; /* Current time (in milliseconds since device
last booted). Should be set as close to
datagram transmission time as possible.*/
u_int32_t num_records; /* Number of tag-len-val flow/counter records to follow */
} SFLSample_datagram_hdr;
#define SFL_MAX_DATAGRAM_SIZE 1500
#define SFL_MIN_DATAGRAM_SIZE 200
#define SFL_DEFAULT_DATAGRAM_SIZE 1400
#define SFL_DATA_PAD 400
#if defined(__cplusplus)
} /* extern "C" */
#endif
#endif /* SFLOW_H */
/* Copyright (c) 2002-2006 InMon Corp. Licensed under the terms of the InMon sFlow licence: */
/* http://www.inmon.com/technology/sflowlicense.txt */
/* $Header: /root/InMon_Agent-5.7/RCS/sflow_api.h,v 1.12 2006/07/10 18:34:27 root Exp root $ */
/////////////////////////////////////////////////////////////////////////////////
/////////////////////// sFlow Sampling Agent API ////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
#ifndef SFLOW_API_H
#define SFLOW_API_H 1
#if defined(__cplusplus)
extern "C" {
#endif
#include <sys/socket.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include "sflow.h"
/*
uncomment this preprocessor flag (or compile with -DSFL_USE_32BIT_INDEX)
if your ds_index numbers can ever be >= 2^30-1 (i.e. >= 0x3FFFFFFF)
*/
/* #define SFL_USE_32BIT_INDEX */
/* Used to combine ds_class, ds_index and instance into
a single 64-bit number like this:
__________________________________
| cls| index | instance |
----------------------------------
but now is opened up to a 12-byte struct to ensure
that ds_index has a full 32-bit field, and to make
accessing the components simpler. The macros have
the same behavior as before, so this change should
be transparent. The only difference is that these
objects are now passed around by reference instead
of by value, and the comparison is done using a fn.
*/
typedef struct _SFLDataSource_instance {
u_int32_t ds_class;
u_int32_t ds_index;
u_int32_t ds_instance;
} SFLDataSource_instance;
#ifdef SFL_USE_32BIT_INDEX
#define SFL_FLOW_SAMPLE_TYPE SFLFlow_sample_expanded
#define SFL_COUNTERS_SAMPLE_TYPE SFLCounters_sample_expanded
#else
#define SFL_FLOW_SAMPLE_TYPE SFLFlow_sample
#define SFL_COUNTERS_SAMPLE_TYPE SFLCounters_sample
/* if index numbers are not going to use all 32 bits, then we can use
the more compact encoding, with the dataSource class and index merged */
#define SFL_DS_DATASOURCE(dsi) (((dsi).ds_class << 24) + (dsi).ds_index)
#endif
#define SFL_DS_INSTANCE(dsi) (dsi).ds_instance
#define SFL_DS_CLASS(dsi) (dsi).ds_class
#define SFL_DS_INDEX(dsi) (dsi).ds_index
#define SFL_DS_SET(dsi,clss,indx,inst) \
do { \
(dsi).ds_class = (clss); \
(dsi).ds_index = (indx); \
(dsi).ds_instance = (inst); \
} while(0)
typedef struct _SFLSampleCollector {
u_int32_t data[(SFL_MAX_DATAGRAM_SIZE + SFL_DATA_PAD) / sizeof(u_int32_t)];
u_int32_t *datap; /* packet fill pointer */
u_int32_t pktlen; /* accumulated size */
u_int32_t packetSeqNo;
u_int32_t numSamples;
} SFLSampleCollector;
struct _SFLAgent; /* forward decl */
typedef struct _SFLReceiver {
struct _SFLReceiver *nxt;
/* MIB fields */
char *sFlowRcvrOwner;
time_t sFlowRcvrTimeout;
u_int32_t sFlowRcvrMaximumDatagramSize;
SFLAddress sFlowRcvrAddress;
u_int32_t sFlowRcvrPort;
u_int32_t sFlowRcvrDatagramVersion;
/* public fields */
struct _SFLAgent *agent; /* pointer to my agent */
/* private fields */
SFLSampleCollector sampleCollector;
struct sockaddr_in receiver4;
struct sockaddr_in6 receiver6;
} SFLReceiver;
typedef struct _SFLSampler {
/* for linked list */
struct _SFLSampler *nxt;
/* for hash lookup table */
struct _SFLSampler *hash_nxt;
/* MIB fields */
SFLDataSource_instance dsi;
u_int32_t sFlowFsReceiver;
u_int32_t sFlowFsPacketSamplingRate;
u_int32_t sFlowFsMaximumHeaderSize;
/* public fields */
struct _SFLAgent *agent; /* pointer to my agent */
/* private fields */
SFLReceiver *myReceiver;
u_int32_t skip;
u_int32_t samplePool;
u_int32_t flowSampleSeqNo;
/* rate checking */
u_int32_t samplesThisTick;
u_int32_t samplesLastTick;
u_int32_t backoffThreshold;
} SFLSampler;
/* declare */
struct _SFLPoller;
typedef void (*getCountersFn_t)(void *magic, /* callback to get counters */
struct _SFLPoller *sampler, /* called with self */
SFL_COUNTERS_SAMPLE_TYPE *cs); /* struct to fill in */
typedef struct _SFLPoller {
/* for linked list */
struct _SFLPoller *nxt;
/* MIB fields */
SFLDataSource_instance dsi;
u_int32_t sFlowCpReceiver;
time_t sFlowCpInterval;
/* public fields */
struct _SFLAgent *agent; /* pointer to my agent */
void *magic; /* ptr to pass back in getCountersFn() */
getCountersFn_t getCountersFn;
/* private fields */
SFLReceiver *myReceiver;
time_t countersCountdown;
u_int32_t countersSampleSeqNo;
} SFLPoller;
typedef void *(*allocFn_t)(void *magic, /* callback to allocate space on heap */
struct _SFLAgent *agent, /* called with self */
size_t bytes); /* bytes requested */
typedef int (*freeFn_t)(void *magic, /* callback to free space on heap */
struct _SFLAgent *agent, /* called with self */
void *obj); /* obj to free */
typedef void (*errorFn_t)(void *magic, /* callback to log error message */
struct _SFLAgent *agent, /* called with self */
char *msg); /* error message */
typedef void (*sendFn_t)(void *magic, /* optional override fn to send packet */
struct _SFLAgent *agent,
SFLReceiver *receiver,
u_char *pkt,
u_int32_t pktLen);
/* prime numbers are good for hash tables */
#define SFL_HASHTABLE_SIZ 199
typedef struct _SFLAgent {
SFLSampler *jumpTable[SFL_HASHTABLE_SIZ]; /* fast lookup table for samplers (by ifIndex) */
SFLSampler *samplers; /* the list of samplers */
SFLPoller *pollers; /* the list of samplers */
SFLReceiver *receivers; /* the array of receivers */
time_t bootTime; /* time when we booted or started */
time_t now; /* time now */
SFLAddress myIP; /* IP address of this node */
u_int32_t subId; /* sub_agent_id */
void *magic; /* ptr to pass back in logging and alloc fns */
allocFn_t allocFn;
freeFn_t freeFn;
errorFn_t errorFn;
sendFn_t sendFn;
int receiverSocket4;
int receiverSocket6;
} SFLAgent;
/* call this at the start with a newly created agent */
void sfl_agent_init(SFLAgent *agent,
SFLAddress *myIP, /* IP address of this agent */
u_int32_t subId, /* agent_sub_id */
time_t bootTime, /* agent boot time */
time_t now, /* time now */
void *magic, /* ptr to pass back in logging and alloc fns */
allocFn_t allocFn,
freeFn_t freeFn,
errorFn_t errorFn,
sendFn_t sendFn);
/* call this to create samplers */
SFLSampler *sfl_agent_addSampler(SFLAgent *agent, SFLDataSource_instance *pdsi);
/* call this to create pollers */
SFLPoller *sfl_agent_addPoller(SFLAgent *agent,
SFLDataSource_instance *pdsi,
void *magic, /* ptr to pass back in getCountersFn() */
getCountersFn_t getCountersFn);
/* call this to create receivers */
SFLReceiver *sfl_agent_addReceiver(SFLAgent *agent);
/* call this to remove samplers */
int sfl_agent_removeSampler(SFLAgent *agent, SFLDataSource_instance *pdsi);
/* call this to remove pollers */
int sfl_agent_removePoller(SFLAgent *agent, SFLDataSource_instance *pdsi);
/* note: receivers should not be removed. Typically the receivers
list will be created at init time and never changed */
/* call these fns to retrieve sampler, poller or receiver (e.g. for SNMP GET or GETNEXT operation) */
SFLSampler *sfl_agent_getSampler(SFLAgent *agent, SFLDataSource_instance *pdsi);
SFLSampler *sfl_agent_getNextSampler(SFLAgent *agent, SFLDataSource_instance *pdsi);
SFLPoller *sfl_agent_getPoller(SFLAgent *agent, SFLDataSource_instance *pdsi);
SFLPoller *sfl_agent_getNextPoller(SFLAgent *agent, SFLDataSource_instance *pdsi);
SFLReceiver *sfl_agent_getReceiver(SFLAgent *agent, u_int32_t receiverIndex);
SFLReceiver *sfl_agent_getNextReceiver(SFLAgent *agent, u_int32_t receiverIndex);
/* jump table access - for performance */
SFLSampler *sfl_agent_getSamplerByIfIndex(SFLAgent *agent, u_int32_t ifIndex);
/* call these functions to GET and SET MIB values */
/* receiver */
char * sfl_receiver_get_sFlowRcvrOwner(SFLReceiver *receiver);
void sfl_receiver_set_sFlowRcvrOwner(SFLReceiver *receiver, char *sFlowRcvrOwner);
time_t sfl_receiver_get_sFlowRcvrTimeout(SFLReceiver *receiver);
void sfl_receiver_set_sFlowRcvrTimeout(SFLReceiver *receiver, time_t sFlowRcvrTimeout);
u_int32_t sfl_receiver_get_sFlowRcvrMaximumDatagramSize(SFLReceiver *receiver);
void sfl_receiver_set_sFlowRcvrMaximumDatagramSize(SFLReceiver *receiver, u_int32_t sFlowRcvrMaximumDatagramSize);
SFLAddress *sfl_receiver_get_sFlowRcvrAddress(SFLReceiver *receiver);
void sfl_receiver_set_sFlowRcvrAddress(SFLReceiver *receiver, SFLAddress *sFlowRcvrAddress);
u_int32_t sfl_receiver_get_sFlowRcvrPort(SFLReceiver *receiver);
void sfl_receiver_set_sFlowRcvrPort(SFLReceiver *receiver, u_int32_t sFlowRcvrPort);
/* sampler */
u_int32_t sfl_sampler_get_sFlowFsReceiver(SFLSampler *sampler);
void sfl_sampler_set_sFlowFsReceiver(SFLSampler *sampler, u_int32_t sFlowFsReceiver);
u_int32_t sfl_sampler_get_sFlowFsPacketSamplingRate(SFLSampler *sampler);
void sfl_sampler_set_sFlowFsPacketSamplingRate(SFLSampler *sampler, u_int32_t sFlowFsPacketSamplingRate);
u_int32_t sfl_sampler_get_sFlowFsMaximumHeaderSize(SFLSampler *sampler);
void sfl_sampler_set_sFlowFsMaximumHeaderSize(SFLSampler *sampler, u_int32_t sFlowFsMaximumHeaderSize);
/* poller */
u_int32_t sfl_poller_get_sFlowCpReceiver(SFLPoller *poller);
void sfl_poller_set_sFlowCpReceiver(SFLPoller *poller, u_int32_t sFlowCpReceiver);
u_int32_t sfl_poller_get_sFlowCpInterval(SFLPoller *poller);
void sfl_poller_set_sFlowCpInterval(SFLPoller *poller, u_int32_t sFlowCpInterval);
/* call this to indicate a discontinuity with a counter like samplePool so that the
sflow collector will ignore the next delta */
void sfl_sampler_resetFlowSeqNo(SFLSampler *sampler);
/* call this to indicate a discontinuity with one or more of the counters so that the
sflow collector will ignore the next delta */
void sfl_poller_resetCountersSeqNo(SFLPoller *poller);
/* software sampling: call this with every packet - returns non-zero if the packet
should be sampled (in which case you then call sfl_sampler_writeFlowSample()) */
int sfl_sampler_takeSample(SFLSampler *sampler);
/* call this to set a maximum samples-per-second threshold. If the sampler reaches this
threshold it will automatically back off the sampling rate. A value of 0 disables the
mechanism */
void sfl_sampler_set_backoffThreshold(SFLSampler *sampler, u_int32_t samplesPerSecond);
u_int32_t sfl_sampler_get_backoffThreshold(SFLSampler *sampler);
/* call this once per second (N.B. not on interrupt stack i.e. not hard real-time) */
void sfl_agent_tick(SFLAgent *agent, time_t now);
/* call this with each flow sample */
void sfl_sampler_writeFlowSample(SFLSampler *sampler, SFL_FLOW_SAMPLE_TYPE *fs);
/* call this to push counters samples (usually done in the getCountersFn callback) */
void sfl_poller_writeCountersSample(SFLPoller *poller, SFL_COUNTERS_SAMPLE_TYPE *cs);
/* call this to deallocate resources */
void sfl_agent_release(SFLAgent *agent);
/* internal fns */
void sfl_receiver_init(SFLReceiver *receiver, SFLAgent *agent);
void sfl_sampler_init(SFLSampler *sampler, SFLAgent *agent, SFLDataSource_instance *pdsi);
void sfl_poller_init(SFLPoller *poller, SFLAgent *agent, SFLDataSource_instance *pdsi, void *magic, getCountersFn_t getCountersFn);
void sfl_receiver_tick(SFLReceiver *receiver, time_t now);
void sfl_poller_tick(SFLPoller *poller, time_t now);
void sfl_sampler_tick(SFLSampler *sampler, time_t now);
int sfl_receiver_writeFlowSample(SFLReceiver *receiver, SFL_FLOW_SAMPLE_TYPE *fs);
int sfl_receiver_writeCountersSample(SFLReceiver *receiver, SFL_COUNTERS_SAMPLE_TYPE *cs);
void sfl_agent_resetReceiver(SFLAgent *agent, SFLReceiver *receiver);
void sfl_agent_error(SFLAgent *agent, char *modName, char *msg);
void sfl_agent_sysError(SFLAgent *agent, char *modName, char *msg);
u_int32_t sfl_receiver_samplePacketsSent(SFLReceiver *receiver);
#define SFL_ALLOC malloc
#define SFL_FREE free
#if defined(__cplusplus)
} /* extern "C" */
#endif
#endif /* SFLOW_API_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment