SNMP -- 数据结构

SNMP对话的结构:

struct snmp_session {

    int        Version;                /* SNMP Version for this session */

   u_char   *community;         /* community for outgoing requests. */

   int       community_len;     /* Length of community name. */

   int       retries;                  /* Number of retries before timeout. */

   int       timeout;             /* Number of uS until first timeout */

   char       *peername;            /* Domain name or dotted IP address of default    peer */

   u_short  remote_port;          /* UDP port number of peer. */

   u_short  local_port;            /* My UDP port number */

   u_char   *(*authenticator)();

    /* Function to interpret incoming data */

   int       (*callback)(int, struct snmp_session *, int, struct snmp_pdu *, void *);

   /* Pointer to data that the callback function may consider important */

   void   *callback_magic;

   struct synch_state * snmp_synch_state;

   int    s_errno;        /* copy of system errno */

   int    s_snmp_errno;   /* copy of library errno */

 };

 

/* fully decleartion of snmp_session. from snmp_api.h. all right, types.h actually*/ 

struct snmp_session {
    /*
     * Protocol-version independent fields
     */
    /** snmp version */
    long            version;
    /** Number of retries before timeout. */
    int             retries;
    /** Number of uS until first timeout, then exponential backoff */
    long            timeout;       
    u_long          flags;
    struct snmp_session *subsession;
    struct snmp_session *next;

    /** name or address of default peer (may include transport specifier and/or port number) */
    char           *peername;
    /** UDP port number of peer. (NO LONGER USED - USE peername INSTEAD) */
    u_short         remote_port;
    /** My Domain name or dotted IP address, 0 for default */
    char           *localname;
    /** My UDP port number, 0 for default, picked randomly */
    u_short         local_port;    
    /**
     * Authentication function or NULL if null authentication is used
     */
    u_char         *(*authenticator) (u_char *, size_t *, u_char *, size_t);
    /** Function to interpret incoming data */
    netsnmp_callback callback;     
    /**
     * Pointer to data that the callback function may consider important
     */
    void           *callback_magic;
    /** copy of system errno */
    int             s_errno;
    /** copy of library errno */
    int             s_snmp_errno;  
    /** Session id - AgentX only */
    long            sessid;

    /*
     * SNMPv1 & SNMPv2c fields
     */
    /** community for outgoing requests. */
    u_char         *community;
    /** Length of community name. */
    size_t          community_len; 
    /**  Largest message to try to receive.  */
    size_t          rcvMsgMaxSize;
    /**  Largest message to try to send.  */
    size_t          sndMsgMaxSize; 

    /*
     * SNMPv3 fields
     */
    /** are we the authoritative engine? */
    u_char          isAuthoritative;
    /** authoritative snmpEngineID */
    u_char         *contextEngineID;
    /** Length of contextEngineID */
    size_t          contextEngineIDLen;    
    /** initial engineBoots for remote engine */
    u_int           engineBoots;
    /** initial engineTime for remote engine */
    u_int           engineTime;
    /** authoritative contextName */
    char           *contextName;
    /** Length of contextName */
    size_t          contextNameLen;
    /** authoritative snmpEngineID */
    u_char         *securityEngineID;
    /** Length of contextEngineID */
    size_t          securityEngineIDLen;   
    /** on behalf of this principal */
    char           *securityName;
    /** Length of securityName. */
    size_t          securityNameLen;

    /** auth protocol oid */
    oid            *securityAuthProto;
    /** Length of auth protocol oid */
    size_t          securityAuthProtoLen;
    /** Ku for auth protocol XXX */
    u_char          securityAuthKey[USM_AUTH_KU_LEN];      
    /** Length of Ku for auth protocol */
    size_t          securityAuthKeyLen;
    /** Kul for auth protocol */
    u_char          *securityAuthLocalKey;      
    /** Length of Kul for auth protocol XXX */
    size_t          securityAuthLocalKeyLen;      

    /** priv protocol oid */
    oid            *securityPrivProto;
    /** Length of priv protocol oid */
    size_t          securityPrivProtoLen;
    /** Ku for privacy protocol XXX */
    u_char          securityPrivKey[USM_PRIV_KU_LEN];      
    /** Length of Ku for priv protocol */
    size_t          securityPrivKeyLen;
    /** Kul for priv protocol */
    u_char          *securityPrivLocalKey;      
    /** Length of Kul for priv protocol XXX */
    size_t          securityPrivLocalKeyLen;      

    /** snmp security model, v1, v2c, usm */
    int             securityModel;
    /** noAuthNoPriv, authNoPriv, authPriv */
    int             securityLevel; 
    /** target param name */
    char           *paramName;

    /**
     * security module specific
     */
    void           *securityInfo;

    /**
     * transport specific configuration
     */
   struct netsnmp_container_s *transport_configuration;

    /**
     * use as you want data
     *
     *     used by 'SNMP_FLAGS_RESP_CALLBACK' handling in the agent
     * XXX: or should we add a new field into this structure?
     */
    void           *myvoid;
};

/*end*/

 

 

SNMP PDU结构

struct snmp_pdu {

 int              command;             /* Type of this PDU */

 ipaddr        address;                /* Address of peer */

 int       reqid;              /* Integer32: Request id */

 int       errstat;            /* INTEGER:  Error status */

 int       errindex;          /* INTEGER:  Error index */

 struct variable_list *variables;     /* Variable Bindings */

 /* SNMPv2 Bulk Request */

 int non_repeaters;            /* INTEGER: */

 int max_repetitions;           /* INTEGER: */

 /* Trap information */

 oid    *enterprise;            /* System OID */

 int     enterprise_length;

 ipaddr agent_addr;             /* address of object generating trap */

 int     trap_type;                     /* generic trap type */

 int     specific_type;                  /* specific type */

 u_int time;                  /* Uptime */

};

 

      变量绑定表结构

struct variable_list

{

   struct variable_list*next_variable;     /* NULL for last variable */

   oid      *name;                     /* Object identifier of variable */

   int        name_length;     /* number of subid's in name */

   u_char    type;                 /* ASN type of variable */

   union

{        /* value of variable */

                    int          *integer;

                    u_char   *string;

                    oid         *objid;

   } val;

   int      val_len;

};

SNMP网管协议简单剖析
 
          SNMP体系结构模型是一系列网络管理台(NMS)和网络元素(NE)的集合。NMS执行网络管理应用(Manager),监视并控制NE的运行。在NE上运行网络管理代理进程(Agent),
    对Manager 发出的各种请求作出响应。对应于ATM交换机,所需管理的各种对象信息存放在前台MIB库中,后台OAM操作维护台上运行Manager进程,前台MP上运行Agent进程,各种操作维护命令在后台组装成SNMP报文,发送到前台Agent进程,Agent进程通过操作MIB库完成后台的请求,并且把结果送回给后台Manager进程。
 
 
一般过程如下:

过程解释:

InitialMIB:根据环境变量、注册表确定MIB文件路径,对此MIB文件进行语法分析,并把MIB中的所有变量读入一二叉树中。

WinsockStartup:调用WSAStartup()初始化Socket

Init _Snmp_Session:初始化SNMP对话Snmp_Session结构。

Snmp_Open :建立 SNMP 对话。包括建立 UDP Socket 连接,本地端口绑定等

 

Snmp_PDU_Create:根据传入的参数生成相应的PDU,但没有绑定变量。

Read_ObjId:根据输入的变量名,查找相应的Oid

Snmp_Add_Null_Var:把变量Oid和值(对于Set操作)绑定到PDU上。

Snmp_Synch_Response:把PDU组装成SNMP报文,发送SNMP报文,等待接收Response报文,并对接收的报文解释以进行出错判断处理。

Receive_Response_PDU:从Response报文中取出ResponsePDU

GetResult:从ResponsePDU中取出所需的数据,传递给界面。

Snmp_Free_PDU:释放ResponsePDU

Snmp_Close:释放Snmp_Session等资源,关闭Socket连接。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SNMP(简单网络管理协议)MIB(Management Information Base)是网络管理系统中的关键组件,它定义了一组标准化的管理信息对象及其属性。MIB数据结构通常包含一系列树状结构,也称为管理对象表(Management Object Tree),每个元素代表一个网络设备或服务的特定属性或状态。 MIB的主要组成部分有: 1. **OID(Object Identifier)**:这是一个唯一标识符,用于在整个网络中唯一标识一个管理对象。OID由一串数字组成,从1.3.6.1开始(通常被称为MIB-2),后面的数值递增表示层级和特定对象。 2. **MIB模块(MIB Module)**:一个独立的MIB文件定义了一组相关的OID和它们对应的变量。例如,TCP/IP MIB(RFC 1213)定义了网络接口、IP地址等对象。 3. **MIB树(MIB Tree)**:在OID的基础上,MIB对象按照层次结构组织,就像一棵树。根节点通常是网管系统的整体视图,子节点进一步细化到具体的配置参数或性能指标。 4. **管理对象(Management Objects)**:每个OID对应一个管理对象,可能是整数、字符串、布尔值或其他数据类型。这些对象可能是读取(get)的,写入(set)的,或者是只读或只写。 5. **操作(Operations)**:包括GET、SET、GET NEXT、TRAP等操作,用于检索、修改或监控管理对象。 6. **状态变化通知(Traps)**:当管理对象的状态发生变化时,SNMP代理会发送一个Trap消息给SNMP管理器,报告这一事件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值