Net-snmp开发流程:MG-SOFT套件生成C语言snmp set/get代码

在这里插入图片描述

C语言Net-snmp开发流程:实现SNMP set/get


RToax
2020年9月


>参考资料《深入理解net-snmp书籍》。 >本文提供编写&编译MIB文件的法、提供使用net-snmp工具开发代码、测试程序的方法。

1. net-snmp简介

1.1. 操作

net-snmp是SNMP的开源实现。SNMP即网络管理功能,主要包括以下操作:

  • get系列命令,网管发出请求,获取代理的管理信息;
  • set命令,网管发出请求,将报文中携带的数据写入代理中;
  • trap系列,代理主动向网管发出告警/事件报文的信息;

1.2. MIB中的管理对象

1.2.1. 标量对象

标量对象指的是在运行期间只有一个实例值的对象;

1.2.2. 表格对象

表格对象指的是在运行期间有多个实例值的对象;


1.3. OID

OID树,也称为MIB树,在SNMP中,所有的管理对象都以一颗树形结构来组织,管理对象则体现为树中的节点;在OID树中我们称没有子节点的OID为叶子节点,把具有子节点的OID分支称为子树。叶子节点是MIB中具体管理的对象,是可以使用命令直接管理的节点。
OID在整个树形结构中具有唯一标识。

我们可以使用mibs开发套件,如下图:

在这里插入图片描述


2. 数据类型

2.1. 基础数据类型

基础数据类型如下:常用的类型为Unsigned32OBJTCT STRING(char 类型)
在这里插入图片描述

2.1.1. DatAandTime

时间类型;

2.1.2. MacAddress

Mac地址;

2.1.3. TimeTicks

1秒为100ticks;
在这里插入图片描述

2.1.4. RowStatus

rowstatus类型;

2.1.5. TruthValue

true or false;

2.1.6. DispalyString

字符串;

2.1.7. OCTET STRING

十六进制字节流;


2.2. 宏

如上图右侧部分为宏,左侧部分为相关宏的应用。

2.2.1. OBJECT IDENTIFIER

用于扩展子树(文件夹);

2.2.2. OBJECT-TYPE(Scalar)

用于创建标量叶子节点对象;

2.2.3. OBJECT-TYPE(Table)

用于创建表格对象;

2.2.4. OBJECT-TYPE(Columnar)

用于创建表格列队向叶子节点;

2.2.5. NOTIFICATION-TYPE

用于创建trap对象;

2.2.6. MODULE-IDENTITY

用于描述模块的更新历史,相当于模块的父节点;

2.2.7. OBJECT-GROUP

将具有一致性需要的相关管理对象描述在一个组中,便于一致性说明、管理和实现;

2.2.8. NOTIFICATION-GROUP

将相关的通告类消息描述在一个组中,便于一致性说明、管理和实现;


3. MIB的编写

3.1. 编写建议

3.1.1. 如何组织OID

MIB的设计、编写过程中的主要困难是如何划分MIB中的对象,即如何组织MIB。一般来说一个MIB模块可分为3个主要分支:通告对象、普通对象和一致性描述的定义。顶层结构如下图:
在这里插入图片描述

除了顶层结构的划分,下面的分支定义往往也会按照某种规则继续划分,规则如下:

  • 根据业务功能进行分组:也就是将相似功能的对象分为一组;
  • 根据数据类型进行分组:如控制量分一组、只读对象分一组、只写对象分一组;
  • TRAP单独分一类;使用宏NOTIFICATION-GROUP将TRAP组织起来;
  • 建议使用OBJECT-GROUP宏将某一类中属性或关系更为相近的普通对象归纳为一个子类;

在这里插入图片描述


3.1.2. 如何命名

命名的规范主要体现在三个方面:名称的长度、名称的大小写和名称的含义。

  • 名称的长度:字符名称长度建议在32字节长度内;
  • 名称大小写:MODULE-IDENTITY定义的模块描述符一般形如”xxxMIB”、”xxxMib”、”xxxMibModule”,该模块中的其他描述符建议以相同的前缀”xxx”开头;
  • 名称的含义:名称应该体现明确的含义,能够见其名知其义,便于识别和记忆。名称设计缩写时,其缩写风格应该保持一致。定义MIB模块时,模块的名称也应该保持全局唯一,如果模块名重复,我们可能无法通过OID标签唯一的确认MIB中的对象。

3.1.3. 如何正确使用数据类型

比较容易混淆的时整数数据类型,32位整数数据类型有INTEGERInteger32Gauge32Unsigned3264位整数数据类型为Counter64
使用32位数据类型时有以下使用建议:

  • 定义整形的枚举对象时只能使用INTEGER;
  • 取值范围是[-2^31 , (2^31)- 1]时最好使用Integer32、也可使用INTEGER,不要使用其他两种类型;
  • 当对象的取值范围是[0, (2^32) - 1]时,建议使用Gauge32,也可以使用Unsigned32

3.2. MIB的编写和编译工具

MG-SOFT套件:
在这里插入图片描述

3.2.1. MIB Builder

MIB Builder是属于MG-SOFT套件中的MIB编写工具,具有可视化界面、简单、可拖放等操作特点,具有严格的规则检查机制,通过该工具能够准确的定义私有MIB。
MIB Builder软件界面如下:

在这里插入图片描述

对象属性设置,会生成对应的代码框架;(务必明确对象属性,否则生成多余垃圾代码)

在这里插入图片描述

编译检测未出现错误提示如下:

在这里插入图片描述

此时MIB对象的编写完成、编译语法正确,可导出MIB文件的文本文件,使用mib2c工具生成对应的框架代码。导出文本文件操作如下:

在这里插入图片描述

在这里插入图片描述


3.2.2. MIB Compiler

MIB Compiler是编译MIB的工具。其主要功能是对MIB文件进行编写规则的检查,并提示相应的编译信息或告警信息。输入为MIB builder中编译完成后导出的文本文件,输出为MG-SOFT可识别的二进制文件,该文件的格式为SMIDB。该文件可用于MIB Browser(MIB浏览器)测试使用。
编译方法如下:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述


4. 使用mib2c工具生成框架代码

4.1. 简述

mib2c顾名思义是将MIB转化为C语言代码的开发工具,它是net-snmp开发中最直接和高效的开发工具。它的输入时是某种代码框架的配置文件和MIB文件中的某一节点(树),输出是该节点(树)对应的C代码框架,也就是个半成品。只要在输出的代码框架中添加具体业务的实现,就可以实现net-snmp的二次开发。


4.2. 生成框架代码前的准备

MIB文件中有标量、表格,按照标准的MIB设计方法,这些管理对象都是组织在某个父节点下。mib2c的输入要求是某个这样的父节点或者单独的某个节点,而不是整个文件名(注入文件名)。这样针对不同的对象类型产生对应的代码实现,所以mib2c需要以某种方式找到MIB文件中对应的节点,需要做一下事情:

  • 把新的MIB文本文件复制到路径/usr/local/share/snmp/mibs下;
  • 进入/usr/local/share/snmp/mibs路径下执行 export MIBS=ALL命令;
export MIBS=ALL

上述操作完成后新的MIB文件被导入系统,可使用下面的命令查看MIB文件中的节点是否被系统接纳:

snmptranslate –TB S

S为节点名称;如下图:
在这里插入图片描述

至此,生成框架代码的前期工作准备完毕,即可使用命令生成对应节点的某种代码框架。


4.3. 常用的框架代码配置文件

系统默认的各类框架代码的配置文件在/usr/local/share/snmp目录下,一般不需要对框架类的配置文件做修改,有需求再了解。

  • mib2c.scalar.conf:适用于所有的标量对象;
  • mib2c.iterate.conf:适用于对象的实例值需要某种迭代、反复查询的操作,该配置文件生成的代码使用的API对GET和GETNEXT请求效率较高。该代码框架的API核心函数中使用了大量的case处理get和set请求,代码不太美观;
  • mib2c.old-api.conf:能够同时处理标量和表格的配置文件,代码紧凑、直观。比较常用;(统一使用这个模板)
  • mib2c.notify.conf:生成通告消息相关的模板代码;

4.4. 生成代码命令

进入/usr/local/share/snmp/mibs路径:

  • mib2c.scalar.conf,生成scalar框架代码:
mib2c -c mib2c.scalar.conf S1::S2
  • mib2c.iterate.conf,生成iterate框架代码:
mib2c -c mib2c.iterate.conf S1::S2
  • mib2c.old-api.conf,生成oil-api框架代码:
mib2c -c mib2c.old-api.conf S1::S2

S1为MIB模块名称,S2为节点名称。命令执行完成后生成以S2命名的.c.h文件在当前目录下。


4.5. 框架代码二次开发

使用上述命令生成的代码有两个文件,一个.c文件和一个.h文件;.h文件基本不用修改,.c文件主要需要完成具体对象get/set操作的实现。


4.5.1. 动态表header函数

下面这个是一个例子,里面的逻辑关系都一样,大家只需要根据自己的需求,修改索引长度以及getfirstgetnext函数。

int header_onuVlanConfigTable(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
			long * pvid,
			long * pdev)
{
	int ret = MATCH_FAILED;

	long var_oid_len = vp->namelen;

	if(pdev && pvid )
	{
		if(exact)
		{
			if(*length == var_oid_len+VLAN_CONFIG_TABLE_INDEX_LEN)
			{
				*pvid = name[var_oid_len];
				*pdev = name[var_oid_len+1];

				ret = MATCH_SUCCEEDED;
			}
		}
		else
		{
			int rt = snmp_oid_compare(name, var_oid_len, vp->name, var_oid_len);
			if(rt < 0 || (rt == 0 && (*length < var_oid_len+VLAN_CONFIG_TABLE_INDEX_LEN)))
			{
				if(rtVlanConfigEntryGetFirst(pvid,pdev) == 0)
				{
					memcpy(name, vp->name, sizeof(oid)*vp->namelen);
					ret = MATCH_SUCCEEDED;
				}
			}
			else if(rt == 0)
			{
				*pvid = name[var_oid_len];
				*pdev = name[var_oid_len+1];

				if(rtVlanConfigEntryGetNext(pvid,pdev) == 0)
				{
					ret = MATCH_SUCCEEDED;
				}
			}
			else
			{
			}
		}
		if(ret == MATCH_SUCCEEDED)
		{
			*length = var_oid_len+VLAN_CONFIG_TABLE_INDEX_LEN;
			name[var_oid_len] = *pvid;
			name[var_oid_len+1] = *pdev;
		}
	}
	return ret;
}

4.5.2. write函数(set操作)

int
write_gwEthLoopVlanId(int      action,
            u_char   *var_val,
            u_char   var_val_type,
            size_t   var_val_len,
            u_char   *statP,
            oid      *name,
            size_t   name_len)
{
    long value;
    int size;

    switch ( action ) {
        case RESERVE1:
          if (var_val_type != ASN_OCTET_STR) {
              return SNMP_ERR_WRONGTYPE;
          }
          if (var_val_len > ETH_LOOPVLANLIST_LEN) {
              return SNMP_ERR_WRONGLENGTH;
          }
          break;

        case RESERVE2:
          break;

        case ACTION: /参考示例.c文件中action动作的逻辑处理/
            if(setGwEthLoopVlanList(var_val)==VOS_ERROR)
		return SNMP_ERR_COMMITFAILED;
          break;

        case COMMIT:
          break;
    }
    return SNMP_ERR_NOERROR;
}

4.5.3. RowStatus逻辑

参考示例.c文件中RowStatus的处理逻辑;


5. 测试MIB

5.1. MIB Browser测试

MIB浏览器提供了丰富的可视化测试方法,下图简单说明:
在这里插入图片描述

set命令:
在这里插入图片描述

5.2. 示例代码

oid vlanManagementObjects_variables_oid[] = { 1,3,6,1,4,1,17409,2,3,7 };

extern void cs_printf(const cs_int8 *String, ...);
/* 
 * variable4 vlanManagementObjects_variables:
 *   this variable defines function callbacks and type return information 
 *   for the vlanManagementObjects mib section 
 */

struct variable8 vlanManagementObjects_variables[] = {
/*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
#if(VLAN_TRANSLATION_TABLE_SUPPORT)

#define PVTDEVICEINDEX		1
{PVTDEVICEINDEX,  ASN_UNSIGNED,  RONLY,
 var_portVlanTranslationTable, 4,  { 3,2 , 1, 1 }},
#define PVTCARDINDEX		2
{PVTCARDINDEX,  ASN_UNSIGNED,  RONLY,
 var_portVlanTranslationTable, 4,  { 3,2 , 1, 2 }},
#define PVTPORTINDEX		3
{PVTPORTINDEX,  ASN_INTEGER,  RONLY,
 var_portVlanTranslationTable, 4,  { 3,2 , 1, 3 }},
#define PORTVIDINDEX		4
{PORTVIDINDEX,  ASN_UNSIGNED,  RONLY,
 var_portVlanTranslationTable, 4,  { 3,2 , 1, 4 }},
#define TRANSLATIONNEWVID		5
{TRANSLATIONNEWVID,  ASN_UNSIGNED,  RWRITE,
 var_portVlanTranslationTable, 4,  { 3,2 , 1, 5 }},
#define TRANSLATIONROWSTATUS		6
{TRANSLATIONROWSTATUS,  ASN_INTEGER,  RWRITE,
 var_portVlanTranslationTable, 4,  { 3,2 , 1, 6 }},

#endif /* end of #if(VLAN_TRANSLATION_TABLE_SUPPORT) */
};


/** Initializes the vlanManagementObjects module */
void init_vlanManagementObjects(void)
{

    DEBUGMSGTL(("vlanManagementObjects", "Initializing\n"));

    /* register ourselves with the agent to handle our mib tree */
    REGISTER_MIB("vlanManagementObjects", vlanManagementObjects_variables, variable8,
               vlanManagementObjects_variables_oid);

    /* place any other initialization junk you need here */
}


#if 1	/***************参考header函数逻辑,注意header函数的参数(索引个数)*/
		/*实现get_first、get_next*****************/

int rtVlanConfigEntryGetFirst(long *vid, long *dev)
{
	int  ret = -1;

	if(dev && vid)
	{
		
		ret = mib_vlan_get_first(vid,dev);
	}

	return ret;
}

int rtVlanConfigEntryGetNext(long *nextvid, long *nextdev)
{
	int ret = -1;

	if(nextdev && nextvid)
	{
		ret = mib_vlan_get_next(nextvid,nextdev);
	}

	return ret;
}


/*参数,注意表索引个数*/
int header_onuVlanConfigTable(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
			long * pvid,
			long * pdev)
{
	int ret = MATCH_FAILED;

	long var_oid_len = vp->namelen;

	if(pdev && pvid )
	{
		if(exact)
		{
			if(*length == var_oid_len+VLAN_CONFIG_TABLE_INDEX_LEN) /*VLAN_CONFIG_TABLE_INDEX_LEN 索引个数*/
			{
				*pvid = name[var_oid_len];
				*pdev = name[var_oid_len+1];
				
				ret = MATCH_SUCCEEDED;
			}
		}
		else
		{
			int rt = snmp_oid_compare(name, var_oid_len, vp->name, var_oid_len);
			if(rt < 0 || (rt == 0 && (*length < var_oid_len+VLAN_CONFIG_TABLE_INDEX_LEN)))
			{
				if(rtVlanConfigEntryGetFirst(pvid,pdev) == 0)
				{
					memcpy(name, vp->name, sizeof(oid)*vp->namelen);
					ret = MATCH_SUCCEEDED;
				}
			}
			else if(rt == 0)
			{
				*pvid = name[var_oid_len];
				*pdev = name[var_oid_len+1];

				if(rtVlanConfigEntryGetNext(pvid,pdev) == 0)
				{
					ret = MATCH_SUCCEEDED;
				}
			}
			else
			{

			}

		}

		if(ret == MATCH_SUCCEEDED)
		{
			*length = var_oid_len+VLAN_CONFIG_TABLE_INDEX_LEN;
			name[var_oid_len] = *pvid;
			name[var_oid_len+1] = *pdev;
		}
	}

	return ret;
}


/*
 * var_onuVlanConfigTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_vlanManagementObjects above.
 */
unsigned char *
var_onuVlanConfigTable(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
    	    WriteMethod **write_method)
{
    /* variables we may use later */
    static long long_ret;
   /* static u_long ulong_ret;
    
    static oid objid[MAX_OID_LEN];
    static struct counter64 c64;*/

	static unsigned char string[VLAN_NAME_SIZE];

	long vid = 0,dev = 0;

    /* 
   * This assumes that the table is a 'simple' table.
   *	See the implementation documentation for the meaning of this.
   *	You will need to provide the correct value for the TABLE_SIZE parameter
   *
   * If this table does not meet the requirements for a simple table,
   *	you will need to provide the replacement code yourself.
   *	Mib2c is not smart enough to write this for you.
   *    Again, see the implementation documentation for what is required.
   */
    if (header_onuVlanConfigTable(vp,name,length,exact,var_len, &vid, &dev)
                                                == MATCH_FAILED )
    return NULL;

	memset(string,0,sizeof(string));
	long_ret = 0;
	
    /* 
   * this is where we do the value assignments for the mib results.
   */
    switch(vp->magic) {
    case ONUVLANINDEX:
        long_ret = vid;	
		*var_len = sizeof(long int);
        return (u_char*) &long_ret;
	case ONUVLANDEVICEINDEX:
		long_ret = dev;	
		*var_len = sizeof(long int);
        return (u_char*) &long_ret;
    case ONUVLANNAME:
        *write_method = write_onuVlanName;
		mib_vlan_get_name(vid,dev,string);
        *var_len = sizeof(string);
        return (u_char*) string;
    case ONUVLANTAGGEDPORT:
        *write_method = write_onuVlanTaggedPort;
		mib_vlan_get_tagged_port(vid,dev,string);
        *var_len = VLAN_MEMBER_MAP_SIZE;
        return (u_char*) string;
    case ONUVLANUNTAGGEDPORT:
        *write_method = write_onuVlanUntaggedPort;
        mib_vlan_get_untagged_port(vid,dev,string);
        *var_len = VLAN_MEMBER_MAP_SIZE;
        return (u_char*) string;
    case ONUVLANROWSTATUS:
        *write_method = write_onuVlanRowStatus;
        mib_vlan_get_rowstatus(vid,dev,&long_ret);
		*var_len = sizeof(long int);
        return (u_char*) &long_ret;
    default:
      ERROR_MSG("");
    }
    return NULL;
}

#endif



#if 1       /*动态表     参考RowStatus处理逻辑、以及配置set(case action:)的逻辑*/

 /*debug switch*/
 INT bfd_snmp_debug = 0;
 
 /*bfd Sess Table*/
#define	BFDSESSINDEX					1
#define	BFDSESSVERSIONNUMBER			2
#define	BFDSESSTYPE					3
#define	BFDSESSDISCRIMINATOR			4
#define	BFDSESSREMOTEDISCR			5
#define	BFDSESSDESTINATIONUDPPORT	6
#define	BFDSESSSOURCEUDPPORT			7
#define	BFDSESSECHOSOURCEUDPPORT	8
#define	BFDSESSADMINSTATUS			9
#define	BFDSESSOPERSTATUS				10
#define	BFDSESSSTATE					11
#define	BFDSESSREMOTEHEARDFLAG		12
#define	BFDSESSDIAG					13
#define	BFDSESSOPERMODE				14
#define	BFDSESSDEMANDMODEDESIREDFLAG	15
#define	BFDSESSCONTROLPLANEINDEPFLAG	16
#define	BFDSESSMULTIPOINTFLAG			17
#define	BFDSESSINTERFACE				18
#define	BFDSESSSRCADDRTYPE			19
#define	BFDSESSSRCADDR				20
#define	BFDSESSDSTADDRTYPE			21
#define	BFDSESSDSTADDR				22
#define	BFDSESSGTSM				    23
#define	BFDSESSGTSMTTL				24
#define	BFDSESSDESIREDMINTXINTERVAL	25
#define	BFDSESSREQMINRXINTERVAL		26
#define	BFDSESSREQMINECHORXINTERVAL	27
#define	BFDSESSDETECTMULT				28
#define	BFDSESSNEGOTIATEDINTERVAL	29
#define	BFDSESSNEGOTIATEDECHOINTERVAL	30
#define	BFDSESSNEGOTIATEDDETECTMULT	31
#define	BFDSESSAUTHPRESFLAG			32
#define	BFDSESSAUTHENTICATIONTYPE	33
#define	BFDSESSAUTHENTICATIONKEYID	34
#define	BFDSESSAUTHENTICATIONKEY		35
#define	BFDSESSSTORAGETYPE			36
#define	BFDSESSROWSTATUS				37
 /*global point*/
#define	BFDSESSINDEXNEXT				4
 
 
#define GWD_ERR_OUT VOS_Printf("error! %s(%u),%s,\r\n",__FILE__,__LINE__,__func__)	
 /*define for array length to last charcater*/
#define COMPLEMENT_INDEX_LEN		1
 
 /*bfd session table oid*/
  oid BFDObjects_variables_oid[] = { 1,3,6,1,2,1,222,1 };
 
 struct variable4 BFD_Sess_Group_variables[] = {
 {BFDSESSINDEXNEXT,ASN_INTEGER,RONLY,var_gpnBfdScalarObjects,2,{1,4}},
 
 {BFDSESSINDEX, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,1}},
 
 {BFDSESSVERSIONNUMBER, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,2}},
 
 {BFDSESSTYPE, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,3}},
 
 {BFDSESSDISCRIMINATOR, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,4}},
 
 {BFDSESSREMOTEDISCR, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,5}},
 
 {BFDSESSDESTINATIONUDPPORT, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,6}},
 
 {BFDSESSSOURCEUDPPORT, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,7}},
 
 {BFDSESSECHOSOURCEUDPPORT, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,8}},
 
 {BFDSESSADMINSTATUS, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,9}},
 
 {BFDSESSOPERSTATUS, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,10}},
 
 {BFDSESSSTATE, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,11}},
 
 {BFDSESSREMOTEHEARDFLAG, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,12}},
 
 {BFDSESSDIAG, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,13}},
 
 {BFDSESSOPERMODE, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,14}},
 
 {BFDSESSDEMANDMODEDESIREDFLAG, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,15}},
 
 {BFDSESSCONTROLPLANEINDEPFLAG, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,16}},
 
 {BFDSESSMULTIPOINTFLAG, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,17}},
 
 {BFDSESSINTERFACE, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,18}},
 
 {BFDSESSSRCADDRTYPE, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,19}},
 
 {BFDSESSSRCADDR, ASN_OCTET_STR, RONLY, var_bfdsessTable, 3, {2,1,20}},
 
 {BFDSESSDSTADDRTYPE, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,21}},
 
 {BFDSESSDSTADDR, ASN_OCTET_STR, RWRITE, var_bfdsessTable, 3, {2,1,22}},
 
 {BFDSESSGTSM, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,23}},
 
 {BFDSESSGTSMTTL, ASN_UNSIGNED, RWRITE, var_bfdsessTable, 3, {2,1,24}},
 
 {BFDSESSDESIREDMINTXINTERVAL, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,25}},
 
 {BFDSESSREQMINRXINTERVAL, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,26}},
 
 {BFDSESSREQMINECHORXINTERVAL, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,27}},
 
 {BFDSESSDETECTMULT, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,28}},
 
 {BFDSESSNEGOTIATEDINTERVAL, ASN_UNSIGNED, RONLY, var_bfdsessTable, 3, {2,1,29}},
 
 {BFDSESSNEGOTIATEDECHOINTERVAL, ASN_UNSIGNED, RONLY, var_bfdsessTable, 3, {2,1,30}},
 
 {BFDSESSNEGOTIATEDDETECTMULT, ASN_UNSIGNED, RONLY, var_bfdsessTable, 3, {2,1,31}},
 
 {BFDSESSAUTHPRESFLAG, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,32}},
 
 {BFDSESSAUTHENTICATIONTYPE, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,33}},
 
 {BFDSESSAUTHENTICATIONKEYID, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,34}},
 
 {BFDSESSAUTHENTICATIONKEY, ASN_OCTET_STR, RONLY, var_bfdsessTable, 3, {2,1,35}},
 
 {BFDSESSSTORAGETYPE, ASN_INTEGER, RONLY, var_bfdsessTable, 3, {2,1,36}},
 
 {BFDSESSROWSTATUS, ASN_INTEGER, RWRITE, var_bfdsessTable, 3, {2,1,37}},
 
 
 };
 extern INT32
 header_generic( struct variable *vp,
						 oid *name,
						 size_t *length,
						 INT32 exact,
						 size_t *var_len,
						 WriteMethod **write_method );
 
 STRUCT_BFDROWBUF bfd_RowBuf;
 
 
 
 void init_gpnBFDMib(void)
 {
	 REGISTER_MIB("bfdobjectsession", BFD_Sess_Group_variables, variable4,BFDObjects_variables_oid);
 }
 
 STATUS headerbfdsessionTable(struct variable * vp, 
									 oid * name, 
									 size_t * length, 
									 INT32 exact,
									 ulong_t  *pNextSessIfIndex)
 {
	 LONG	 ret;
	 ulong_t sessIfIndex, nextSessIfIndex;
	 STATUS  lret;
	 STATUS rc = MATCH_FAILED;
	 const	ulong_t namelen = vp->namelen;
	 const	ulong_t qnamelen = *length;
 
	 if((qnamelen > MAX_OID_LEN)||(pNextSessIfIndex==NULL))
		 return rc;
 
	 ret = snmp_oid_compare( name, namelen, vp->name, namelen );
 
	 if(ret < 0 )
	 {
		 lret = bfdGetFirstSessionIndex(&sessIfIndex);
	 if(sessIfIndex < 1 || sessIfIndex > g_ulSessionMax)
	 return rc;
		 if( lret != VOS_ERROR )
		 {
			 rc = MATCH_SUCCEEDED;
			 VOS_MemCpy( name, vp->name, sizeof(oid)*namelen );
		 }
	 }
	 else if( 0 == ret )
	 {
		 if( 0 == exact )
		 {
				 /*oidΪֻìһڽûԐո̷ӽ*/
			 if(qnamelen < (namelen + COMPLEMENT_INDEX_LEN))
			 {
				 lret = bfdGetFirstSessionIndex(&sessIfIndex);
			 if(sessIfIndex < 1 || sessIfIndex > g_ulSessionMax)
			 return rc;
				 if( lret != VOS_ERROR )
			{
			 rc = MATCH_SUCCEEDED;
			}
			 }
			 /*oidΪֻìҢȒո̷ӽ*/
			 else if( qnamelen == (namelen+COMPLEMENT_INDEX_LEN) )
			 {
				 sessIfIndex = name[namelen];
				 lret = bfdGetNextSessionIndex( sessIfIndex,&nextSessIfIndex);
			if(nextSessIfIndex < 1 || nextSessIfIndex > g_ulSessionMax)
			 return rc;
				 if( lret == VOS_OK )
				 {	 
					 sessIfIndex = nextSessIfIndex;
					 rc = MATCH_SUCCEEDED;
				 }
			 }
		 }		 
		 else
		 {
			 if( qnamelen == namelen + COMPLEMENT_INDEX_LEN)
			 {
				 sessIfIndex = name[namelen];
				 rc = MATCH_SUCCEEDED;
			 }
		 }
	 }
 
	 if( rc == MATCH_SUCCEEDED )
	 {
		 *pNextSessIfIndex = sessIfIndex;
		 *length = namelen + COMPLEMENT_INDEX_LEN;
		 name[namelen] = sessIfIndex;
	 }		 
	 return rc;
 }
 
 unsigned char *var_gpnBfdScalarObjects(struct variable *vp,
												 oid	 *name,
												 size_t  *length,
												 int	 exact,
												 size_t  *var_len,
												 WriteMethod **write_method)
 {
	 /* variables we may use later */
	 ULONG ntnewsessIndex;
	 static u_long ulong_ret;
	 if (header_generic(vp, name, length, exact, var_len, write_method) == MATCH_FAILED)
	 {
		 GWD_ERR_OUT;
		 *name = 0;
		 *length = 0;
		 *var_len = 0;
		 return NULL;
	 }
 
	 /*ܱȡޚֵ֣׵ܘ,Ң׵ܘǤӤ׈*/
	 switch(vp->magic)
	 {
		 case BFDSESSINDEXNEXT:
			 if(bfdGetNewIndex(&ntnewsessIndex) == VOS_OK)
			 {
				 ulong_ret = ntnewsessIndex;
				 *var_len = sizeof( u_long);
				 return (u_char*) &ulong_ret;
			 }
			 else
				 GWD_ERR_OUT;
#if 0
			 if(NULL == name[*length-COMPLEMENT_INDEX_LEN])
			 {
				 if(VOS_OK == bfdGetFirstSessionIndex(&ulong_ret))
				 {
					 *var_len = sizeof(ULONG);
					 return (uchar_t*)&ulong_ret;
				 }
			 }
			 else 
				 if(VOS_OK == bfdGetNextSessionIndex(name[*length-COMPLEMENT_INDEX_LEN],&ulong_ret))
				 {
					 *var_len = sizeof(ULONG);
					 return (uchar_t*)&ulong_ret;
				 }
#endif
		 default:
			 GWD_ERR_OUT;
			 break;
	 }
	 
	 return NULL;
 }
 
 unsigned char *var_bfdsessTable(struct variable *vp,
											 oid	 *name,
											 size_t  *length,
											 int	 exact,
											 size_t  *var_len,
											 WriteMethod **write_method)
 
 {	 
	 u_long min_num ,max_num;
	 static u_long ulong_ret; /*׵ܘֵ*/
	 static u_long stat;
	 ULONG sessionIndex;
	 STRUCT_BFDROWBUF stResult;
 
	 if ( headerbfdsessionTable( vp, name, length, exact, &sessionIndex) == MATCH_FAILED)
	 {
		 GWD_ERR_OUT;
		 return NULL;
	 }
 
	 VOS_MemZero((CHAR*)&stResult,sizeof(STRUCT_BFDROWBUF));
	 
	 switch(vp->magic)	
	 {
		 case BFDSESSINDEX:
			 ulong_ret = sessionIndex;
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;
 
		 case BFDSESSTYPE:
			 *write_method = bfdsess_write_sesstype;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdSesstype;
			 }
			 *var_len = sizeof(u_long);
			 return (u_char*)&ulong_ret;
			 
		 case BFDSESSDISCRIMINATOR:
			 *write_method = bfdsess_write_discri;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdDiscriminator;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*)&ulong_ret;
			 
		 case BFDSESSREMOTEDISCR:
			 *write_method = bfdsess_write_remotediscr;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdRemoteDiscri;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;	 
			 
		 case BFDSESSADMINSTATUS:
			 *write_method = bfdsess_write_bfdsessadminstatus;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdSessAdminStatus;
			 }
			 if(0==ulong_ret)
			 {
				 ulong_ret=2;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;
			 
		 case BFDSESSSTATE:
			 *write_method = bfdsess_write_state;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdsessState;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;
 
		 
		 case BFDSESSINTERFACE:
			 *write_method = bfdsess_write_interface;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdsessinterface;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;
			 
		 case BFDSESSDSTADDR:
			 *write_method = bfdsess_write_bfdsessdstaddr;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdSessDstAddr;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;
 
		 case BFDSESSGTSMTTL:
			 *write_method = bfdsess_write_bfdsessgtsmttl;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdSessGTSMTTL;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;
 
		 case BFDSESSDESIREDMINTXINTERVAL:
			 *write_method = bfdsess_write_desiredTxInterval;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdsessdiscriTxInterval;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;	 
 
		 case BFDSESSREQMINRXINTERVAL:
			 *write_method = bfdsess_write_ReqRxInterval;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdsessReqRxInterval;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;
			 
		 case BFDSESSDETECTMULT:
			 *write_method = bfdsess_write_detectMult;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdsessdetectMult;
			 }
			 *var_len = sizeof(ulong_t);
			 return (u_char*) &ulong_ret;		 
				 
		 case BFDSESSNEGOTIATEDINTERVAL:
			 if(VOS_OK != bfd_SessionValueGet(sessionIndex,&ulong_ret,BFD_NEGOTIATED_INTERVAL))
			 {
				 GWD_ERR_OUT;
				 return NULL;
			 }
			 *var_len = sizeof(ulong_t);
			 return (u_char*) &ulong_ret;
			 
		 case BFDSESSNEGOTIATEDECHOINTERVAL:
			 if(VOS_OK != bfd_SessionValueGet(sessionIndex,&ulong_ret,BFD_NEGOTIATED_ECHO_INTERVAL))
			 {
				 GWD_ERR_OUT;
				 return NULL;
			 }
			 *var_len = sizeof(ulong_t);
			 return (u_char*) &ulong_ret;
			 
		 case BFDSESSNEGOTIATEDDETECTMULT:
			 if(VOS_OK != bfd_SessionValueGet(sessionIndex,&ulong_ret,BFD_NEGOTIATED_DETECT_MULT))
			 {
				 GWD_ERR_OUT;
				 return NULL;
			 }
			 *var_len = sizeof(ulong_t);
			 return (u_char*) &ulong_ret;
			 
		 case BFDSESSROWSTATUS:
			 *write_method = bfdsess_write_RowStatus;
			 if(VOS_OK == bfdConfigGet(sessionIndex,&stResult))
			 {
				 ulong_ret = stResult.bfdsessRowStatus;
			 }
			 *var_len = sizeof( u_long);
			 return (u_char*) &ulong_ret;
		 default:
			 ERROR_MSG("");
			 break;
	 }
	 return NULL;
 }
 
 int bfdsess_write_sesstype(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
 
	 if(ulIndex < 0 ||ulIndex > g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_INTEGER)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
 
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdSesstype = value;
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 int bfdsess_write_discri(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
 
	 if(ulIndex < 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_GAUGE)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
 
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdDiscriminator = value;
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 int bfdsess_write_remotediscr(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
 
	 if(ulIndex < 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_GAUGE)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
 
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdRemoteDiscri = value;
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 
 int bfdsess_write_bfdsessadminstatus(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
	 ulong_t ret=0 ;
 
	 if(ulIndex < 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_INTEGER)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
 
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 if(2==value)
				 {
					 value=0;
				 }
				 bfd_RowBuf.bfdSessAdminStatus= value;
			 }
			 else if((SNMP_ROW_NONEXISTENT == bfd_RowBuf.bfdsessRowStatus)&&(ulIndex > 0 && ulIndex <g_ulSessionMax))
			 {
				 if(2==value)
				 {
					 value=0;
				 }
				 ret = bfd_SessAdminStatusSet(ulIndex,value);
				 if(ret == VOS_ERROR)
				 {
					 return SNMP_ERR_COMMITFAILED;
				 }
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 int bfdsess_write_state(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
 
	 if(ulIndex == 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_INTEGER)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdsessState = value;
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 int bfdsess_write_interface(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
 
	 if(ulIndex == 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_INTEGER)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdsessinterface = value;
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 /*begin  yanlei  20161028 */
 
 int bfdsess_write_bfdsessdstaddr(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
 
	 if(ulIndex < 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_OCTET_STR)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdSessDstAddr = value;
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 int bfdsess_write_bfdsessgtsmttl(int action,
									 u_char   *var_val,
									 u_char    var_val_type,
									 size_t    var_val_len,
									 u_char   *statP,
									 oid	  *name,
									 size_t    name_len)
 {
		 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
		 ulong_t value=0 ;
	 
		 if(ulIndex < 0 ||ulIndex >g_ulSessionMax)
		 {
			 return (SNMP_ERR_WRONGVALUE);
		 }
		 value = *(ULONG*)var_val;
		 
		 switch(action)
		 {
			 case RESERVE1:
				 if(var_val == NULL)
				 {
					 GWD_ERR_OUT;
					 return (SNMP_ERR_WRONGVALUE);
				 }
				 if(var_val_type != ASN_UNSIGNED)
				 {
					 GWD_ERR_OUT;
					 return (SNMP_ERR_WRONGTYPE);
				 }
				 if(var_val_len > sizeof(ulong_t))
				 {
					 GWD_ERR_OUT;
					 return (SNMP_ERR_WRONGLENGTH);
				 }
				 break;
	 
			 case RESERVE2:
				 break;
	 
			 case OP_FREE:
				 break;
	 
			 case ACTION:
				 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
				 {
					 bfd_RowBuf.bfdSessGTSMTTL = value;
				 }
				 else
				 {
					 return SNMP_ERR_COMMITFAILED;
				 }
					  break;
			 case UNDO:
				 break;
			 case COMMIT:
				 break;
			 default:
				 return (SNMP_ERR_WRONGVALUE);	   
		 }
		 
		 return (SNMP_ERR_NOERROR);
	 }
 
 /*end*/
 int bfdsess_write_desiredTxInterval(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
	 ulong_t ret=0 ;
 
	 if(ulIndex < 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_GAUGE)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdsessdiscriTxInterval = value;
			 }
			 else if((SNMP_ROW_NONEXISTENT == bfd_RowBuf.bfdsessRowStatus)&&(ulIndex > 0 && ulIndex < g_ulSessionMax))
			 {
			 
				 ret = bfd_SessionValueSet(ulIndex,value,1);
				 if(ret == VOS_ERROR)
				 {
					 return SNMP_ERR_COMMITFAILED;
				 }
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 int bfdsess_write_ReqRxInterval(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
	 ulong_t ret=0 ;
 
	 if(ulIndex < 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_GAUGE)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))	
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }	
			 break;    
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdsessReqRxInterval = value;
			 }
			 else if((SNMP_ROW_NONEXISTENT == bfd_RowBuf.bfdsessRowStatus)&&(ulIndex > 0 && ulIndex < g_ulSessionMax))
			 {
			 
				 ret = bfd_SessionValueSet(ulIndex,value,2);
				 if(ret == VOS_ERROR)
				 {
					 return SNMP_ERR_COMMITFAILED;
				 }
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 int bfdsess_write_detectMult(int action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 ulong_t ulIndex = (ULONG)name[name_len-COMPLEMENT_INDEX_LEN];
	 ulong_t value=0 ;
	 ulong_t ret=0 ;
 
	 if(ulIndex == 0 ||ulIndex >g_ulSessionMax)
	 {
		 return (SNMP_ERR_WRONGVALUE);
	 }
	 value = *(ULONG*)var_val;
	 
	 switch(action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_GAUGE)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len > sizeof(ulong_t))
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
			 if(SNMP_ROW_NOTREADY == bfd_RowBuf.bfdsessRowStatus)
			 {
				 bfd_RowBuf.bfdsessdetectMult = value;
			 }
			 else if((SNMP_ROW_NONEXISTENT == bfd_RowBuf.bfdsessRowStatus)&&(ulIndex > 0 && ulIndex < g_ulSessionMax))
			 {
			 
				 ret = bfd_SessionValueSet(ulIndex,value,4);
				 if(ret == VOS_ERROR)
				 {
					 return SNMP_ERR_COMMITFAILED;
				 }
			 }
			 else
			 {
				 return SNMP_ERR_COMMITFAILED;
			 }
				  break;
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);	   
	 }
	 
	 return (SNMP_ERR_NOERROR);
 }
 
 
 int bfdsess_write_RowStatus(int	   action,
								 u_char   *var_val,
								 u_char    var_val_type,
								 size_t    var_val_len,
								 u_char   *statP,
								 oid	  *name,
								 size_t    name_len)
 {
	 LONG	 lVar	= 0;			 /* ѨҪʨ׃քֵ	 */
	 LONG	 lIndex = 0;			 /* ҭ̷ӽ	 */
	 ULONG	 exist=0;
	 ULONG	 type = 0;
	 bfdSession_t *pSessionPre = NULL;
 
	 switch (action)
	 {
		 case RESERVE1:
			 if(var_val == NULL)
			 {
				 GWD_ERR_OUT;
				  return (SNMP_ERR_WRONGVALUE);
			 }
			 if(var_val_type != ASN_INTEGER)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGTYPE);
			 }
			 if(var_val_len <= 0)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGLENGTH);
			 }
			 break;
 
		 case RESERVE2:
			 break;
 
		 case OP_FREE:
			 break;
 
		 case ACTION:
			 lVar = *(LONG *)var_val;
			 if((lVar < 0) || (lVar > 6)) return(SNMP_ERR_WRONGVALUE);
			 lIndex = name[name_len-COMPLEMENT_INDEX_LEN];
			 if(lIndex <=0 ||lIndex >g_ulSessionMax)
			 {
				 GWD_ERR_OUT;
				 return (SNMP_ERR_WRONGVALUE);
			 }
			 switch(lVar)
			 {
				 case SNMP_ROW_CREATEANDWAIT: 
					 if(bfd_session_find(lIndex, &pSessionPre) != NULL) 
					 {
						 return(SNMP_ERR_WRONGVALUE);
					 }
					 memset(&bfd_RowBuf, 0x0, sizeof(bfd_RowBuf));
 
					 bfd_RowBuf.SessionIndex = lIndex;
					 bfd_RowBuf.bfdsessRowStatus = SNMP_ROW_NOTREADY;
					 break;   
 
				 case SNMP_ROW_ACTIVE: 
					 if((bfd_RowBuf.bfdsessRowStatus != SNMP_ROW_NOTREADY) ||
						 (bfd_RowBuf.SessionIndex != lIndex))
					 {
						 return (SNMP_ERR_INCONSISTENTVALUE);
					 }
					 else
					 {
						 bfd_RowBuf.bfdsessRowStatus = SNMP_ROW_ACTIVE;
					 }
					 if(bfd_snmp_debug)   
					 {
						 sys_console_printf("%s %d::bfdsessiondiscriminator:%d\r\nbfdsessionindex:%d\r\n",
										  __FUNCTION__,__LINE__,
									 bfd_RowBuf.bfdDiscriminator,bfd_RowBuf.SessionIndex);
					 }
					 if(VOS_OK != bfdConfigSet(&bfd_RowBuf))
					 {
						 return SNMP_ERR_COMMITFAILED;
					 }
					 if(bfd_snmp_debug)
					 {
						 sys_console_printf("######bfdconfigset seccessful######\r\n");
					 }
					 memset(&bfd_RowBuf, 0x0, sizeof(bfd_RowBuf));
					 bfd_RowBuf.bfdsessRowStatus = SNMP_ROW_NONEXISTENT; 
					 break;
 
				 case SNMP_ROW_DESTROY: 
					 if(2 == bfd_snmp_debug)
					 
					 {
						 sys_console_printf("%s,%d::inter destroy case !",__FUNCTION__,__LINE__);
					 }
					 if(bfd_RowBuf.bfdsessRowStatus == SNMP_ROW_NOTREADY
						 && bfd_RowBuf.SessionIndex == lIndex) 
					 {	
						 memset(&bfd_RowBuf, 0x0, sizeof(bfd_RowBuf));
						 bfd_RowBuf.bfdsessRowStatus = SNMP_ROW_NONEXISTENT; 
					 }
					 else
					 {
						 if(bfd_RowBuf.bfdsessRowStatus == SNMP_ROW_NONEXISTENT)
						 {
							 if(2 == bfd_snmp_debug)
							 {
								 sys_console_printf("%s %d::bfdsessRowStatus value is %d \r\n",__FUNCTION__,__LINE__,SNMP_ROW_NONEXISTENT);
							 }
							 bfd_RowBuf.bfdsessRowStatus = SNMP_ROW_DESTROY;
							 bfd_RowBuf.SessionIndex = lIndex;
							 if(VOS_OK != bfdConfigSet(&bfd_RowBuf))
							 {
								 memset(&bfd_RowBuf, 0x0, sizeof(bfd_RowBuf));
								 GWD_ERR_OUT;
								 return (SNMP_ERR_COMMITFAILED);
							 }
							 memset(&bfd_RowBuf, 0x0, sizeof(bfd_RowBuf));
						 }
					 }
					  break;
					  
				 default: 
					 return (SNMP_ERR_COMMITFAILED);
			 }
			 break;
 
		 case UNDO:
			 break;
		 case COMMIT:
			 break;
		 default:
			 return (SNMP_ERR_WRONGVALUE);
	 }
	 return (SNMP_ERR_NOERROR);
 }
#endif

以上内容由RTOAX整理自网络。
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页