SNMP_PP_CHS Charpter 15

1.         Pdu Class

SNMP++Pdu Class的对象模型(Object Modeling Technique)视图

SNMP++Pdu classSMI Protocol Data Unit (PDU)C++封装。PDU是管理端和代理端进行SNMP通讯的基本概念。通过Pdu classSNMP++使得对PDU的操作变得简单、安全。Pdu class允许简单的构造、析构,以及在Pdu对象上加载、卸载Vb对象。因为SNMP++是双效的API,所以Pdu class也是抽象化的,并没有包含SNMPv1或者SNMPv2的特征性的信息。所有发出请求的Snmp class成员函数都可以只使用一个Pdu对象。Pdu class作为Snmp class的接口,处理SNMP请求,同时还可作为异步请求和接收notification的回调函数的参数。注意,关于对Vb的存储,Pdu对象是从0开始的(Pdu中第一个vbVb #0)。

大多数地方,SNMP++中的所有Pdu对象都是一样的。即,所有的Pdu对象都有同一性(identity)。唯一的例外是当Pdu对象被用作发送otifications , trapsinforms的时候。为了(支持)notifications,有3个附加的Pdu Class成员函数来用作:设置同一性(identity)、时间信息,及Pdu对象的enterprise

1.1.        Pdu Class成员函数列表

Pdu Class Member Functions

Description

Constructors

 

     Pdu::Pdu( void);

构造一个空的Pdu

     Pdu::Pdu( Vb* pvbs, const int pvb_count);

用一个数组类型的Vb及其长度构造一个Pdu

     Pdu::Pdu( const Pdu &pdu);

用一个Pdu构造另一个

Member Functions

 

     int get_vblist( Vb* pvbs, const int pvb_count);

Vb拷贝到调用的参数列表中(vblist

     int set_vblist( Vb* pvbs, const int pvb_count);

设置Pdu调用的参数列表中的Vb

     int get_vb( Vb &vb, const int index);

获取Pdu中一个指定的Vb

     int set_vb( Vb &vb, const int index);

Pdu设置一个指定的Vb

     int get_vb_count();

获取PduVb的个数

     int get_error_status();

获取Pdu的错误状态

     int get_error_index();

获取Pdu的错误索引

     unsigned long get_request_id();

获取Pdu的请求标示

     unsigned short get_type();

获取Pdu的类型

     int valid();

判断Pdu的有效性

     Int delete_vb( const int position);

删除Pdu指定位置上的Vb

     int trim(const int i=1);

删除Pud最后位置上的Vb,默认删除1

Member Functions For Inform and Trap Usage

 

     void set_notify_timestamp( const TimeTicks

                                                 & timestamp);

trapinformPdu设置时间信息

     void get_notify_timestamp( TimeTicks

                                                  & timestamp);

trapinformPdu获取时间信息

     void set_notify_id( const Oid id);

设置trapinformPduID

     void get_notify_id( Oid &id);

获取trapinformPduID

     void set_notify_enterprise( const Oid

                                                &enterprise);

设置trapinformPduenterprise ID

     void get_notify_enterprise( Oid & enterprise);

获取trapinformPduenterprise ID

Overloaded Operators    重载操作符

 

     Pdu& operator=( const Pdu &pdu);

将一个Pdu付给另一个

     Pdu& operator+=( Vb &vb);

给一个Pdu增加一个Vb

1.2.        Pdu Class的构造和析构

有多种方法构造Pdu对象,可以有也可以没有构造参数

// constructor, no args

Pdu::Pdu( void);

 

// constructor with Vbs and count

Pdu::Pdu( Vb *vbs, const int vb_count);

 

// constructor with another Pdu instance

Pdu::Pdu( const Pdu &pdu);

 

// destructor

Pdu::~Pdu();

1.3.        访问Pdu的成员函数

Pdu class通过多种成员函数来支持获取和设置Pdu成员变量。包括获取和设置绑定变量、错误信息、请求信息,和类型信息。

// extract all the Vbs from a Pdu

int Pdu::get_vblist( Vb* vbs, const int  vb_count);

 

// deposit Vbs to a Pdu

int Pdu::set_vblist( Vb* vbs, const int vb_count);

 

// get a particular vb

// where index 0 is the 1st vb

int Pdu::get_vb( Vb &vb, const int index);

 

// set a particular Vb

// where index 0 is the 1st Vb

int Pdu::set_vb( Vb &vb, const int index);

 

// return the number of Vbs

int Pdu::get_vb_count();

 

// return the error index

int Pdu::get_error_index();

 

// get the error status

int Pdu::get_error_status();

 

// return the request id

unsigned long Pdu::get_request_id();

 

// get the Pdu type

unsigned short Pdu::get_type();

 

// return the validity of a Pdu

int Pdu::valid();

1.4.        Pdu Class重载操作符

Pdu class可通过重载操作符,赋值或串连Vb对象到Pdu

// assignment operator for assigning one Pdu to another

Pdu& operator=( const Pdu &pdu);

 

// append a Vb object to the Pdu’s var bind list

Pdy& operator+=( Vb vb);

1.5.        Pdu Class处理TrapsInforms的成员函数

当处理notifications, trapsinforms的时候,SNMP++提供了成员函数来获取和设置指定的notification value。当使用这些成员函数时,请查阅发送trapsinforms的部分。

// set notify timestamp

void Pdu::set_notify_timestamp( const TimeTicks & timestamp);

 

// get notify timestamp

void Pdu::get_notify_timestamp( TimeTicks & timestamp);

 

// set the notify id

void Pdu::set_notify_id( const Oid id);

 

// get the notify id

void Pdu::get_notify_id( Oid &id);

 

// set the notify enterprise

void Pdu::set_notify_enterprise( const Oid &enterprise);

 

// get the notify enterprise

void Pdu::get_notify_enterprise( Oid & enterprise);

1.6.        加载Pdu对象

为了在管理应用中使用Pdu对象,必须在Pdu实例中加载绑定变量表vblist)。这可以通过从多种方法中选择你需要的来处理。一般在发送SNMP请求前加载Pdu

// set notify timestamp

void Pdu::set_notify_timestamp( const TimeTicks & timestamp);

 

// get notify timestamp

void Pdu::get_notify_timestamp( TimeTicks & timestamp);

 

// set the notify id

void Pdu::set_notify_id( const Oid id);

 

// get the notify id

void Pdu::get_notify_id( Oid &id);

 

// set the notify enterprise

void Pdu::set_notify_enterprise( const Oid &enterprise);

 

// get the notify enterprise

void Pdu::get_notify_enterprise( Oid & enterprise);

1.7.        加载Pdu对象

为了在管理应用中使用Pdu对象,必须在Pdu实例中加载绑定变量表vblist)。这可以通过从多种方法中选择你需要的来处理。一般在发送SNMP请求前加载Pdu

// example of how to load a Pdu object

void load_pdu_examples()

{

   Pdu pdu;                                  // create a Pdu object

   Vb vb;                                          // create a Vb object

   vb.set_oid(  SYSDECR);             // set the oid portion of the Vb to System Descriptor

   pdu += vb;                                  // loads the Vb to the Pdu

 

   Pdu my_pdu;                          // create another Pdu object

   Vb vbs[5];                                  // create 5 vbs

   pdu.set_vblist( vbs,5);                // load all 5 to the pdu

}

1.8.        卸载Pdu对象

从阻塞或异步请求中得到请求的Pdu后,都需要将Vb卸载下来才能把SMI values取出。

// example of how to unload a Pdu

void unload_pdu_example( Pdu &pdu)

{

   ins staus;

   Pdu pdu;                                  // create a Pdu object

   Vb vb;                                          // create a Vb object

   vb.set_oid(  SYSDECR);             // set the oid portion of the Vb to System Descriptor

   pdu += vb;                                  // loads the Vb to the Pdu

   char message[100];                  // for the system descriptor printable octet

 

   Snmp snmp( status);

   if ( status != SNMP_CLASS_SUCCESS) {

      cout < “SNMP++ error = “ << snmp.error_msg( status) ;

      return;

   }

 

   pdu.get_vb( vb,0);                        // unload the vb

   vb.get_value( message);         // pull the message out of the vb

   cout << message;                         // print it out

 

};


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ewebeditor_aspx_v10.9_chs 是一个中文的在线文本编辑器。它是基于ASP.NET开发的,可以方便地嵌入到网站中,用于编辑网页的内容。它提供了一系列的功能,如文字编辑、图片插入、表格编辑、超链接插入等,使用户可以在网页上进行灵活的编辑和排版。 这个编辑器具有简单易用的界面,用户可以直接在界面上进行文本的编辑和格式调整。编辑器提供了各种字体、字号、颜色等选项供用户选择,以满足不同风格和需求的编辑。此外,编辑器还支持实时预览功能,用户可以即时查看编辑后的页面效果,提高编辑效率。 此外,ewebeditor_aspx_v10.9_chs还支持图片的插入和编辑,用户可以选择本地图片进行上传,也可以通过指定图片URL来插入网络图片。同时,编辑器还提供了图片的基本编辑功能,如大小调整、对齐方式、边框设置等,使用户可以灵活地进行图片的布局和美化。 此外,编辑器还支持表格的插入和编辑,用户可以根据需要插入不同大小和样式的表格,并对表格的行列进行增删操作。编辑器还提供了表格的边框设置、背景颜色设置等功能,以满足用户对表格样式的需求。 总之,ewebeditor_aspx_v10.9_chs是一个功能丰富、易于使用的中文在线文本编辑器,适用于各种网站的内容编辑和排版需求,提高用户的编辑效率和网页的质量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值