分析MIB文件主要为了提取MIB文件中的oid定义及其对应的OID值,包含(OBJECT-IDENTIFIER 和OBJECT-TYPE等具有OID值的对象).
2. 提取OID对象和其值后,有何用户呢?
搞SNMP网管开发时,业务对象一般是居于C++,Java,C#等类,而且这些类一般只包含基础成员,没有指针,没有对象成员,没有集合成员等。这些业务对象再也SNMP Agent进行交互时,需要转换为SNMP 消息。 这个转换虽然比较简单。但是很繁琐,特别是网管的规模大的时候,oid不可能只有几个,往往都是上千个oid。这个工作量大,而且容易出错。---如果避免工作量和错误的重复出现,只有自动化的工具才可以。市面上有一些工具,大部分是针对Agent的代码自动生成,都是商业的。
3. 目标
分析提取oid后,根据OBJECT-GROUP,和NOTIFITION-TYPE 等构造对应的C++类。并根据每个OID的属性(SYNTAX,ACCESS,INDEX)等构造SNMP Get,SNMPSet,和SNMP RSP或者Trap包的解析方法。
4.此工程主要使用Scala语言,包含文法分析、文法分析中间结果和文法分析的结果
SnmpToolkit.scala 包含一些辅助数据结构
package cn.newzai.parser.snmp.result import scala.collection.mutable import cn.newzai.parser.snmp.SnmpParser object SnmpGroupType extends Enumeration{ val OBJECT_GROUP =Value val NOTIFICATION_TYPE = Value //val NOTIFICATION_GROUP = Value } object SnmpSyntax extends Enumeration{ val NA = Value val OCTET = Value val INTEGER = Value val Gauge = Value val Counter32 = Value val Counter = Value val Counter64 = Value val OBJECT = Value val IpAddress = Value val TimeTicks = Value val Integer32 = Value val Unsigned32 = Value val cplusplus_type= Map( OCTET->"std::string", INTEGER->"int", Gauge->"unsigned int", Counter32->"unsigned int", Counter->"unsigned int", Counter64->"unsigned int", OBJECT->"std::string", IpAddress->"std::string", TimeTicks->"unsigned int", Integer32->"int", Unsigned32->"unsigned int") //ASNMP 库对应的数据类型 val snmp_type = Map( OCTET->"OctetStr", INTEGER->"SnmpInt32", Gauge->"Gauge32", Counter32->"Counter32", Counter->"Counter32", Counter64->"Counter64", OBJECT->"Oid", IpAddress->"IpAddress", TimeTicks->"TimeTicks", Integer32->"SnmpInt32", Unsigned32->"SnmpUInt32") val convert_to_snmp = Map( OCTET->".c_str()", INTEGER->"long", Gauge->"unsigned long", Counter32->"unsigned long", Counter->"unsigned long", Counter64->"unsigned long", OBJECT->".c_str()", IpAddress->".c_str()", TimeTicks->"unsigned long", Integer32->"long", Unsigned32->"unsigned long" ) val convert_to_cplusplus = Map( OCTET->".to_string()", INTEGER->"int", Gauge->"unsigned int", Counter32->"unsigned int", Counter->"unsigned int", Counter64->"unsigned int", OBJECT->".to_string()", IpAddress->".to_string()", TimeTicks->"unsigned int", Integer32->"int", Unsigned32->"unsigned int" ) val is_ref_type = Map( OCTET->true, INTEGER->false, Gauge->false, Counter32->false, Counter->false, Counter64->false, OBJECT->true, IpAddress->true, TimeTicks->false, Integer32->false, Unsigned32->false ) val default_value = Map( OCTET->"\"\"", INTEGER->"0", Gauge->"0", Counter32->"0", Counter->"0", Counter64->"0", OBJECT->"\"\"", IpAddress->"\"\"", TimeTicks->"0", Integer32->"0", Unsigned32->"0" ) val format = Map( OCTET->"%s", INTEGER->"%d", Gauge->"%d", Counter32->"%d", Counter->"%d", Counter64->"%d", OBJECT->"%s", IpAddress->"%s", TimeTicks->"%d", Integer32->"%d", Unsigned32->"%d" ) def getSyntax( name :String) ={ try{ withName(name) } catch{ case e : NoSuchElementException => NA } } def getCPlusPlusType( syntax : Value) = cplusplus_type(syntax) def getSnmpType( syntax :Value) = snmp_type(syntax) def getConvertToSnmp( syntax : Value) = convert_to_snmp(syntax) def getConvertToCPlusPlus(syntax : Value) = convert_to_cplusplus(syntax) def getFormat(syntax : Value) = format(syntax) } object SnmpAccess extends Enumeration { val accesses = new mutable.HashSet[String]() val read_only , accessible_for_notify, read_write, read_create, not_accessible = Value def getAccess( access : String) ={ try{ withName(access.trim.replaceAll("-","_")) }catch { case e : NoSuchElementException => not_accessible } } } object SnmpToolkit { def toMethodName( name :String) ={ var first = true val r =for( c <-name) yield { if( first){ first = false c.toUpper }else{ c } } r.mkString("") } def toClassName( name :String) ={ toMethodName(name) } def toFieldName( name :String) ={ var lastIsUpper = false val r = for ( c<- name) yield { if( lastIsUpper){ if( c.isUpper){ s"${c.toLower}" }else{ lastIsUpper = false; s"${c}" } }else{ if( c.isUpper){ lastIsUpper = true s"_${c.toLower}" } else{ s"${c}" } } } r.mkString("").concat("_") } }
package cn.newzai.parser.snmp import scala.util.parsing.combinator.lexical.StdLexical import scala.util.parsing.input.CharArrayReader._ import scala.util.parsing.combinator.syntactical.StandardTokenParsers import scala.io.Source import scala.collection.mutable import cn.newzai.parser.snmp.result._ /** * * @param name oid节点的名称 * @param parent 除了oid为1(iso) 和o(zeroDotZero)两个节点以为,其它oid节点都有一个父节点 * @param instance 本oid节点在父节点中的位置 */ class MibNode(val name :String,val parent : String, val instance : Int){ override def toString: String = s" ${name} ::= { ${parent} ${instance}}" } /** * nodes 保存解析过程中得到的所有 oid节点信息 * zeroDotZero oid值为0的节点 * iso oid值为1的节点 绝大部分OID为iso的下级节点 */ object MibNode { private val nodes =new mutable.HashMap[String, MibNode]() private val zeroDotZero = MibNode("0",0) private val iso = MibNode("iso",1) def clear() { nodes.clear() } def apply( name :String, parent :String, instance : Int) = { new MibNode(name,parent,instance) } def apply( name :String,instance : Int) = { new MibNode(name,null,instance) } def addMibNode( name :String,parent :String, instance : Int){ val newNode = MibNode(name,parent,instance) nodes(name) = newNode } def hasMibNode( name :String) = { name match { case "0" => true case "iso" => true case _ => nodes.contains(name) } } def getMibNode(name :String) ={ name match { case "0" => zeroDotZero case "iso" => iso case _ => nodes(name) } } private def getOid_(name :String) : List[Int]={ name match { case "0" => List(0) case "iso" => List(1) case _ => val node = nodes(name) node.instance :: getOid_(node.parent) } } private def getOid( name :String ) = getOid_(name).reverse /** * * @param name oid名称 * @return 获取name对于的oid只,得到的是点分号的格式, eg “1.3.4.1334” */ def getOidString( name :String) = { val oids = getOid(name) val oidsStr = for( o <- oids) yield { o.toString } oidsStr.mkString(".") } } /** * SNMP 词法分析,Scala提供的标准的词法分析无法满足SNMP的词法分析。 * 主要为 标识符,snmp可以包含 破折号(-) * 注释 SNMP注释以 两个破折号(--)考开始,直到行尾. */ class SnmpLexical extends StdLexical{ // SNMP MIB文件的标识符(OID名称等包含 - 符号 override def identChar = letter | elem('_') | elem('-') // SNMP MIB文件的注释,包含 -- ,均为含注释 override def whitespace:Parser[Any] = rep( whitespaceChar | '/' ~ '*' ~ comment | '/' ~ '/' ~ rep( chrExcept(EofCh, '\n') ) | '-' ~ '-' ~ rep( chrExcept(EofCh, '\n') ) | '/' ~ '*' ~ failure("unclosed comment") ) override def token: Parser[Token] = ( identChar ~ rep( identChar | digit ) ^^ { case first ~ rest => processIdent(first :: rest mkString "") } | digit ~ rep( digit ) ^^ { case first ~ rest => NumericLit(first :: rest mkString "") } | '\'' ~ rep( chrExcept('\'', '\n', EofCh) ) ~ '\'' ^^ { case '\'' ~ chars ~ '\'' => StringLit(chars mkString "") } | '\"' ~ rep( chrExcept('\"', EofCh) ) ~ '\"' ^^ { case '\"' ~ chars ~ '\"' => StringLit(chars mkString "") } | EofCh ^^^ EOF | '\'' ~> failure("unclosed string literal") | '\"' ~> failure("unclosed string literal") | delim | failure("illegal character") ) } /** * SNMP MIB文件词法分析,每个SnmpParser对于一个SNMP MIB 文件 , 从StandardTokenParsers继承 * @param dir SNMP MIB文件的所在文件夹,被import进来的文件都在相同的文件夹 * @param file 当前解析的MIB文件 * @param importFile 标识是因和原因解析该文件,true时,表示该文件为import文件,不提取OBJECT-GROUP信息,只提供OID值。 * 顶层文件时为false,分析所有内容. */ class SnmpParser(val dir :String, val file :String, val importFile : Boolean) extends StandardTokenParsers { /** * 覆盖基类的lexical字段,scala 的字段和方法统一处理,也可以被覆盖. */ override val lexical = new SnmpLexical /* 定义SNMP MIB 文件的分隔符,分隔符定义时,采用最大化匹配原则 */ lexical.delimiters +=("::=","(",")","{","}",",",";","..","-","+") /* SNMP MIB 的保留字(包含关键字和一部分SNMP MIB的类型定义) */ lexical.reserved +=("DEFINITIONS","BEGIN","END","IMPORTS","FROM","MODULE-IDENTITY","MODULE-IDENTITY", "OBJECT-TYPE", "NOTIFICATION-TYPE", "MODULE-COMPLIANCE", "OBJECT-GROUP", "NOTIFICATION-GROUP","OBJECT", "IDENTIFIER","OBJECT-TYPE","SIZE","MAX-ACCESS","ACCESS","MIN-ACCESS","SYNTAX","STATUS","INDEX","SEQUENCE", "MANDATORY-GROUPS","GROUP","MODULE","OBJECTS","NOTIFICATIONS","TEXTUAL-CONVENTION","OCTET","STRING","OF","AUGMENTS", "DEFVAL","OBJECT-IDENTITY") def keyword: Parser[String] = "MODULE-IDENTITY"|"MODULE-IDENTITY"|"OBJECT-TYPE"|"NOTIFICATION-TYPE"| "MODULE-COMPLIANCE"|"OBJECT-GROUP"|"NOTIFICATION-GROUP"|"OBJECT"|"IDENTIFIER"|"SEQUENCE"|"OF"| "TEXTUAL-CONVENTION"|"OBJECT-IDENTITY"|"OCTET"|"STRING" ^^ { case x => x} /** * * @param oid "::={ parent instance } " 格式的定义, * @return Option[(String,String)] 提取 parent,instance 值 */ def getOidParent( oid :String) ={ val matchParent = """\s*::=\s+\{\s*([\w-]+)\s+([\d]+)\s*\}""".r oid match { case matchParent(parent,instance) => Some((parent,instance)) case _ => None } } /** * 解析SNMP 内容 * @return */ def parserContent : Parser[Any] = { parserObjectIdentifier| parserObjectIdentify| parserTextualConvention | parserSimpleTextualConvention| parserObjectType| parserSequence| parserNotificationType| parserModuleCompliance| parserObjectGroup } /** * 解析SNMP文件的定义,SNMP 文件解析的入口方法. * @return */ def parserDefinitions : Parser[Any] = { ident ~ "DEFINITIONS" ~ "::=" ~ "BEGIN" ~opt(parserImports)~opt(parserMODULE_IDENTITY)~rep(parserContent)~ "END" ^^ { case n~ "DEFINITIONS" ~ "::=" ~ "BEGIN"~ im~mi~contents ~ "END" => s"""${n} DEFINITIONS ::= BEGIN |${im.getOrElse("")} |${mi.getOrElse("")} |${contents mkString("\n")} |END """.stripMargin } } /* 解析导入的文件名,并且进入被导入的文件进行递归解析 */ def parserFrom : Parser[String] ={ repsep(ident|keyword,",")~"FROM"~ident ^^ { case f ~ "FROM"~n => val macroMibFile = Set("SNMPv2-CONF","RFC-1212") if( !macroMibFile.contains(n) && !SnmpParser.parseredFile.contains(n)) { SnmpParser.parseredFile.add(n) val fromParser = new SnmpParser(this.dir, n, true) val r = fromParser.parserFile(fromParser.parserDefinitions) if (!r.successful) { println(s"parser file ${n} error.") println(r) } else { println(s"parser file ${n} OK") } } s"""${f.mkString(",")} FROM ${n}""" } } /** * 解析IMPORTS 段 * @return */ def parserImports : Parser[String] = { "IMPORTS"~rep(parserFrom)~";" ^^ { case "IMPORTS"~f~";" => s""" |IMPORTS |${f.mkString("\n")} |;""".stripMargin } } /** * 解析 DESCRIPTION和那些以字符串作为值的属性,例如LAST-UPDATED等。 * @return */ def parserDescription : Parser[String] = { ident~stringLit ^^ {case f ~ d => s"""${f} "${d}" """} } def parserOIDPath : Parser[Any] = { ident~"("~numericLit~")" ^^ { case p~"("~i~")" => s"${p}(${i})" } } def parserOIDPaths : Parser[Any] ={ rep(parserOIDPath) ^^ { case paths => paths.mkString(" ") } } /** * 解析OID 值 * * @return */ def parserOID : Parser[String] ={ "::="~"{"~ident~parserOIDPaths~numericLit~"}" ^^ { case "::="~"{"~i~p~n~"}" => s"::= { ${i} ${n}}" } } def parserOIDGetValue : Parser[(String,Int)] = { "::="~"{"~ident~numericLit~"}" ^^ { case "::="~"{"~i~n~"}" =>(i, n.toInt) } } def getOIDValue( parentOID : String) = { val r = phrase(parserOIDGetValue)( new lexical.Scanner(parentOID)) r.get } /** * 捕获解析结果,保存在中间变量中. * @param name oid名称 * @param parent parent 路径 */ def insertOid( name :String, parent : String){ val p = getOIDValue(parent) MibNode.addMibNode(name,p._1,p._2) } /** * 解析模块定义 * @return */ def parserMODULE_IDENTITY : Parser[String] ={ ident ~ "MODULE-IDENTITY" ~rep(parserDescription)~parserOID ^^ { case i ~ "MODULE-IDENTITY" ~ d ~ oid => insertOid(i, oid) s"""${i} MODULE-IDENTITY |${d mkString("\n")} |${oid} """.stripMargin } } /** * 解析 OBJECT IDENTITIFER * @return */ def parserObjectIdentifier : Parser[Any] = { ident ~ "OBJECT"~"IDENTIFIER"~parserOID ^^ { case i ~ "OBJECT"~"IDENTIFIER" ~ oid => insertOid(i,oid) s"${i} OBJECT IDENTIFIER ${oid}" } } def parserObjectIdentify : Parser[Any] = { ident ~"OBJECT-IDENTITY"~parserStatus~parserDescription~parserOID ^^ { case i ~"OBJECT-IDENTITY"~s~d~oid => insertOid(i,oid) s"""${i} OBJECT-IDENTITY |${s} |${d} |${oid} """.stripMargin } } /** * 解析OCTET STRING 的大小限制 * @return */ def parserSize :Parser[Any] = { "("~"SIZE"~"("~numericLit~".."~numericLit~")"~")" ^^ { case "("~"SIZE"~"("~start~".."~end~")"~")" => s"(SIZE(${start}..${end}))" } } /** * 解析整数的 范围限制 * @return */ def parserRange:Parser[Any] = { "("~numericLit~".."~numericLit~")" ^^ { case "("~start~".."~end~")" => s"(${start}..${end})" } } def parserEnumSimple : Parser[Any] ={ ident ~ "("~numericLit~")" ^^ { case n ~ "("~v~")" => s"${n}(${v})" } } /** * 解析枚举值的取值范围 * @return */ def parserEnum : Parser[Any] ={ "{" ~repsep(parserEnumSimple,",")~"}" ^^ { case "{"~values ~"}" =>s"{ ${values mkString(",")}}" } } def parserSyntaxOCTETString : Parser[Any] ={ "OCTET"~"STRING" ^^ { case _ => "OCTET STRING" } } def parserSyntaxOBJECTIDENTIFIER : Parser[Any] ={ "OBJECT"~"IDENTIFIER" ^^ { case _ => "OBJECT IDENTIFIER" } } def parserSyntaxSEQUENCE : Parser[Any] = { "SEQUENCE"~"OF"~ident ^^ { case "SEQUENCE"~"OF"~i => s"SEQUENCE OF ${i}" } } def parserSyntaxType : Parser[Any] ={ ident|parserSyntaxOCTETString|parserSyntaxOBJECTIDENTIFIER|parserSyntaxSEQUENCE ^^ { case n => n } } /** * 解析 OBJECT-TYPE的 SYNTAX属性 * @return */ def parserSyntax : Parser[String]= { "SYNTAX"~parserSyntaxType~opt(parserSize|parserEnum|parserRange) ^^ { case "SYNTAX" ~ns ~ None => s"SYNTAX ${ns}" case "SYNTAX" ~ns ~ Some(r) => s"SYNTAX ${ns} ${r}" } } /** * 解析OBJECT-TYPE的ACCES属性 * @return */ def parserAccess : Parser[String] = { ("MAX-ACCESS"|"ACCESS"|"MIN-ACCESS")~ident ^^ { case t ~ a => s"${t} ${a}" } } def parserStatus : Parser[String] ={ "STATUS"~ident ^^ { case s~i => s"${s} ${i}" } } /** * 解析OBJECT-TYPE的 INDEX等属性 * @return */ def parserIndex : Parser[String] ={ ("INDEX"|"AUGMENTS"|"DEFVAL")~"{"~repsep(ident,",")~"}" ^^ { case t~"{"~indexes~"}" => s"${t} { ${indexes mkString ","} }" } } /** * 解析OBJECT-TYPE * @return */ def parserObjectType : Parser[Any] ={ ident ~ "OBJECT-TYPE" ~rep(parserSyntax|parserAccess|parserStatus|parserDescription|parserIndex)~ parserOID ^^ { case i ~ "OBJECT-TYPE" ~ m ~ oid => insertOid(i,oid) SnmpObject(i,m) s"""${i} OBJECT-TYPE |${m mkString "\n"} |${oid} """.stripMargin } } def parserSequenceOneMember : Parser[Any] ={ ident ~ rep(ident|keyword)~opt("("~numericLit~".."~numericLit~")") ^^ { case i ~ t~range => s"""${i} ${t mkString " "}""" } } def parserSequence : Parser[Any] ={ ident ~ "::="~ "SEQUENCE" ~"{"~repsep(parserSequenceOneMember,",")~"}" } def parserNotificationType : Parser[Any] ={ ident~"NOTIFICATION-TYPE"~rep(parserStatus|parserDescription|parserGroups)~parserOID ^^ { case n ~"NOTIFICATION-TYPE"~s~oid => val currentOid = insertOid(n,oid) //cn.newzai.parser.snmp.result.SnmpObject(n,s,currentOid.getOrElse("")) for( x <-s if (x.contains("OBJECTS"))){ val matchObjects = """\s*OBJECTS\s+\{(.*)\}\s*""".r x match { case matchObjects(v) => SnmpGroup(n,SnmpGroupType.NOTIFICATION_TYPE, v.split(',')) case _ => } } s"""${n} NOTIFICATION-TYPE |${s mkString "\n"} |${oid} """.stripMargin } } /** * 解析分组的具体成员 * @return */ def parserGroups : Parser[String] ={ ("MANDATORY-GROUPS"|"OBJECTS"|"NOTIFICATIONS")~"{"~repsep(ident,",")~"}" ^^ { case t ~"{"~m ~ "}" => s" ${t} { ${m mkString ","}}" } } def parserModuleGroup : Parser[Any] = { ("GROUP"|"OBJECT")~ ident ^^ { case t~i => s"${t} ${i}" } } def parserModule : Parser[Any] ={ "MODULE"~rep(parserGroups|parserModuleGroup|parserDescription|parserAccess|parserSyntax) ^^ { case "MODULE"~l => s"""MODULE |${l mkString "\n"} """.stripMargin } } def parserModuleCompliance : Parser[Any] ={ ident ~ "MODULE-COMPLIANCE"~rep(parserStatus|parserDescription|parserModule)~parserOID ^^ { case n ~ "MODULE-COMPLIANCE" ~ l ~ oid => insertOid(n,oid) s"""${n} MODULE-COMPLIANCE |${ l mkString "\n"} |${oid} """.stripMargin } } /** * 解析GROUP对象,并提取相关的输入存入解析缓冲区. * @return */ def parserObjectGroup : Parser[Any] ={ ident ~ ("OBJECT-GROUP"|"NOTIFICATION-GROUP")~rep(parserGroups|parserStatus|parserDescription)~parserOID ^^ { case n ~g~l~oid => insertOid(n,oid) for{ x <- l if(x.contains("OBJECTS") || x.contains("NOTIFICATIONS")) } { val matchObjects = """\s*OBJECTS\s*\{(.*)\}\s*""".r val matchNotifications ="""\s*NOTIFICATIONS\s*\{(.*)\}\s*""".r x match { case matchObjects(v) => SnmpGroup(n, SnmpGroupType.OBJECT_GROUP, v.split(',')) //创建SnmpGou对象,后续生成代码时使用. case matchNotifications(v) => //ignore //cn.newzai.parser.snmp.result.SnmpGroup(n, SnmpGroupType.NOTIFICATION_GROUP, v.split(',')) case _ => } } s""" |${n} ${g} |${l mkString "\n"} |${oid} """.stripMargin } } /** * 解析类型定义 * TEXTUAL-CONVENTION 类似与C++ 的宏定义或者typedef * 最后我们需要的是最直接的数据类型,而不是TEXTUAL-CONVENTION定义的数据类型 * @return */ def parserTextualConvention : Parser[Any] ={ ident ~ "::="~ "TEXTUAL-CONVENTION"~opt(parserDescription)~parserStatus~parserDescription~parserSyntax ^^ { case n ~"::="~ "TEXTUAL-CONVENTION"~d1~s~d2~sy => val matchSyntax = """\s*SYNTAX\s+(.*)""".r sy match { case matchSyntax(v) => SnmpObject.textual_convention(n) = v.trim.replace('\n',' ') case _ => } s"""${n} ::= TEXTUAL-CONVENTION |${d1.getOrElse("")} |${s} |${d2} |${sy} """.stripMargin } } def parserSimpleTextualConvention : Parser[Any] = { ident ~ "::="~"OCTET"~"STRING" ^^ { case n ~ "::="~"OCTET"~"STRING"=> SnmpObject.textual_convention(n)="OCTET STRING" "" } } def parserAll[T]( p :Parser[T] , in : String) = phrase(p)(new lexical.Scanner(in)) /** * 解析文件入口方法 * @param p 解析方法,一般传入parserDefinitions方法 * @tparam T * @return */ def parserFile[T](p : Parser[T]) ={ val fileName = s"${this.dir}\\${this.file}" parserAll(p,Source.fromFile(fileName).getLines().mkString("\n")) } } object SnmpParser{ // 每个SNMP MIB文件都会导入其它SNMP文件,类似于C++中的include,分析SNMP文件时,会递归进入被导入的文件, // 由于每个文件,可能被过个Mib文件导入,但在分析时,又只需要分析一次即可。因此 parseredFile 由于记录那些已经 // 分析过的Mib文件,避免重复分析 val parseredFile = mutable.HashSet[String]() def clear() { //oid.clear() MibNode.clear() parseredFile.clear() SnmpObject.clear() SnmpGroup.clear() } }
package cn.newzai.parser.snmp.result import scala.collection.mutable import scala.util.parsing.combinator.syntactical.StandardTokenParsers import cn.newzai.parser.snmp.MibNode /** * 为SNMP OBJECT-TYPE对于的数据,作为SnmpGoup的成员,映射为C++类的某个字段 * @param name oid名称,映射为C++字段的名称 * @param syntax 语法规则,也就是数据类型及其取值范围 * @param access SNMP 读写属性,在生成Get/Set/Rsp代码时需要该属性。 * @param status * @param description */ class SnmpObject(val name : String , val syntax :String, val access :String, val status :String, val description :String ) extends StandardTokenParsers { /** * OID字符串值。 */ lazy val oid:String = MibNode.getOidString(name) val snmp_syntax = getSyntax() val snmp_access =getAccess() val field_name = SnmpToolkit.toFieldName(name) val method_name = SnmpToolkit.toMethodName(name) val get_method_name = s"Get${method_name}" val set_method_name = s"Set${method_name}" lazy val cplusplus_type = SnmpSyntax.getCPlusPlusType(snmp_syntax) lazy val cplusplus_return_type = if (SnmpSyntax.is_ref_type(snmp_syntax)) s"const ${cplusplus_type} &" else cplusplus_type lazy val cplusplus_param_type = cplusplus_return_type lazy val format = SnmpSyntax.getFormat(snmp_syntax) override def toString: String = { //s"SnmpObject:{\n${name} \n ${oid} \n ${getSyntax}\n ${access} Index: ${SnmpObject.isIndex(this)}\n ${getRange()} \n }\n" getAccess.toString } lexical.delimiters +=("(",")","{","}","..",",") lexical.reserved += ("SIZE","SYNTAX","OCTET","STRING") def parserSIZERange : Parser[(Int,Int)] ={ "SYNTAX"~"OCTET"~"STRING"~"("~"SIZE"~"("~>numericLit~".."~numericLit<~")"~")" ^^{ case start ~".."~end => (start.toInt,end.toInt) //case _ =>(-1,-1) } } def parserIntRange :Parser[(Int,Int)] ={ "SYNTAX"~ident~"("~>numericLit~".."~numericLit<~")" ^^ { case start ~".."~end => (start.toInt,end.toInt) // case _ => (-1,-1) } } def parserEnumOne : Parser[Int] = { ident~"("~>numericLit<~")" ^^ { case value => value.toInt } } def parserEnumRange : Parser[Set[Int]] ={ "SYNTAX"~ident~"{"~>repsep(parserEnumOne,",")<~"}" ^^ { case values => values.toSet } } def getSyntax() ={ val matchSyntax = """\s*SYNTAX\s+([\w]+)\s*.*""".r syntax match { case matchSyntax(t) => SnmpObject.syntaxs.add(t) SnmpSyntax.getSyntax(t) case _ => SnmpSyntax.NA } } def hasRange() = { getRange()._1 } def getRange() ={ getSyntax() match { case SnmpSyntax.OCTET => val r = phrase(parserSIZERange)( new lexical.Scanner(syntax)) if(r.successful){ (true,r.get._1,r.get._2) }else{ (false,0,0) } case SnmpSyntax.INTEGER => val r = phrase(parserEnumRange) ( new lexical.Scanner(syntax)) if ( r.successful){ (true, r.get.min, r.get.max) }else{ (false,0,0) } case _ => val r = phrase(parserIntRange) ( new lexical.Scanner(syntax)) if ( r.successful ){ (true,r.get._1, r.get._2) }else{ (false,0,0) } } } def getAccess() ={ val matchAccess = """\s*(ACCESS|MIN-ACCESS|MAX-ACCESS)\s+(.*)""".r access match { case matchAccess(t,v) => SnmpAccess.getAccess(v.trim) case _ => SnmpAccess.not_accessible } } /** * 可读属性 * @return true 构造Get方法时,可以在变量绑定集合中加入该oid */ def canGet() = snmp_access == SnmpAccess.read_only || snmp_access == SnmpAccess.read_write || snmp_access == SnmpAccess.read_create /** * 可写属性 * @return true 构造Set方法时可以在变量绑定集合中加入该oid */ def canSet() = snmp_access == SnmpAccess.read_write /** * * @return true 解析RSP或者Trap消息时,可能包含该属性. */ def canRsp() = canGet() || snmp_access == SnmpAccess.accessible_for_notify def getDefaultValue () = { if( snmp_syntax != SnmpSyntax.NA) { val defVal = SnmpSyntax.default_value(snmp_syntax) val (ok,start,end) = getRange() if( ok && snmp_syntax != SnmpSyntax.OCTET){ start.toString() }else{ defVal } } else{ "" } } def generate_code_for_cplusplus_declare()= { if ( snmp_syntax != SnmpSyntax.NA) { s"${cplusplus_type} ${this.field_name};" }else{ "" } } def generate_code_for_cplusplus_set_check() ={ val range = getRange() if( range._1 && snmp_syntax != SnmpSyntax.OCTET ){ s"""assert("${syntax}" && ${field_name} >= ${range._2} && ${field_name} <= ${range._3});""" }else{ "" } } def generate_code_for_cplusplus_getset() = { if( snmp_syntax != SnmpSyntax.NA){ s"""void ${set_method_name}( ${cplusplus_param_type} value) { ${field_name} = value;} |${cplusplus_return_type} ${get_method_name}() const { return ${field_name};} """.stripMargin } else{ "" } } def generate_code_for_cplusplus_default_construction() = s" ${field_name}(${getDefaultValue()})" def generate_code_for_cplusplus_copy_construction() = s" ${field_name}(other.${field_name})" def generate_code_for_cplusplus_assign = s" ${field_name} = other.${field_name}" def generate_code_for_cplusplus_pdu_get( format : String, args : String) = { if( canGet()){ s"""{ | Vb vb_${field_name}; | char szOid[128] ={0}; | sprintf(szOid,"${oid}.${format}",${args}); | Oid oid(szOid); | vb_${field_name}.set_oid(oid); | pdu += vb_${field_name}; |} """.stripMargin } else{ s"/*${field_name} ACCESS is ${snmp_access}*/" } } def generate_code_for_cplusplus_pdu_set(format :String , args : String) ={ if( canSet()){ val asnmptype = SnmpSyntax.getSnmpType(snmp_syntax) val convert = SnmpSyntax.getConvertToSnmp(snmp_syntax) val value = convert match { case ".c_str()" => s"${field_name}.c_str()" case _ => s"(${convert})${field_name}" } s"""{ | ${generate_code_for_cplusplus_set_check()} | Vb vb_${field_name}; | char szOid[128] ={0}; | sprintf(szOid,"${oid}.${format}",${args}); | Oid oid(szOid); | vb_${field_name}.set_oid(oid); | vb_${field_name}.set_value( ${asnmptype}(${value})); | pdu += vb_${field_name}; |} """.stripMargin } else{ s"/*${field_name} ACCESS is ${snmp_access}*/" } } def generate_code_for_cplusplus_pdu_rsp( format :String, args : String) ={ val convert = SnmpSyntax.getConvertToCPlusPlus(snmp_syntax) match { case ".to_string()" => "value.to_string()" case x => s"(${x})value" } if( canRsp()){ s"""{ | char szOid[128] ={0}; | sprintf(szOid,"${oid}.${format}",${args}); | Oid oid(szOid); | if( oid == oid_ ) | { | ${SnmpSyntax.getSnmpType(snmp_syntax)} value; | if( vb.get_value(value) == 0 ) | { | ${field_name} = ${convert}; | continue; | } | } | } """.stripMargin } else{ s"/*${field_name} ACCESS is ${snmp_access}*/" } } } /** * Created with IntelliJ IDEA. * User: chenxiaohong * Date: 13-5-22 * Time: 下午2:26 * To change this template use File | Settings | File Templates. */ object SnmpObject{ val objects = new mutable.HashMap[String,SnmpObject]() val indexObjects = new mutable.HashSet[String]() val textual_convention = new mutable.HashMap[String,String]() val syntaxs = new mutable.HashSet[String]() def clear() { objects.clear() indexObjects.clear() textual_convention.clear() syntaxs.clear() } def apply( name :String, attributes : List[String]/*, oid :String*/) = { var syntax = "" var access = "" var status = "" var description = "" var index = "" for( attr <- attributes){ if( attr.indexOf("SYNTAX") != -1){ syntax = attr }else if ( attr.indexOf("ACCESS") != -1){ access = attr }else if( attr.indexOf("STATUS") != -1) { status = attr }else if( attr.indexOf("DESCRIPTION") != -1){ description = attr }else if ( attr.indexOf("INDEX") != -1 ){ index = attr }else if ( attr.indexOf("AUGMENTS") != -1 ){ index = attr } } val matchIndex = """\s*INDEX\s*\{(.*)\}\s*""".r val matchAUGMENTS="""\s*AUGMENTS\s*\{(.*)\}\s*""".r index match { case matchIndex(v)=> for( obj <- v.split(',')){ indexObjects.add( obj.trim) } case matchAUGMENTS(v)=> for( obj <- v.split(',')){ indexObjects.add( obj.trim) } case _ => } //replace syntax for( tc <- textual_convention if(syntax.contains(tc._1))){ syntax = syntax.replace(tc._1,tc._2) } val newobject = new SnmpObject(name,syntax,access,status,description) objects(name.trim) = newobject newobject } def isIndex( obj : SnmpObject ) ={ indexObjects.contains(obj.name.trim) } }
package cn.newzai.parser.snmp.result import scala.collection.mutable import scala.collection.mutable.ArrayBuffer /** * * @param name SNMP OID 名称 * @param group_type GROUP的类型 * @param members_ GROUP包含的OBJECTS成员,生成C++类时,对于C++的数据成员 */ class SnmpGroup(val name :String, val group_type :SnmpGroupType.Value, members_ : Array[String]){ /** * lazy ,在用到时才初始化,因为SnmpGroup是在分析文件的过程中创建的,此时其成员的某些oid对象可能还没有被创建, * 在文件分析结束后,能确保SnmpObject都已经创建. */ lazy val members : Array[SnmpObject] = for( m <- members_) yield { SnmpObject.objects(m.trim)} /** * 同members,索引属性,也只有在分析文件结束后才能正确的知道 */ lazy val indexes = for( m <- members if(SnmpObject.isIndex(m))) yield {m} lazy val instance = getIndexes() /** * C++类名称,把OBJECT-GROUP的名称映射成C++类名 */ val class_name = s"C${SnmpToolkit.toClassName(name)}" override def toString: String = { //s"SnmpGroup:{${name} \n ${group_type} \n ${members.mkString("\n")}}" generate_code_for_cplusplus_declare } /** * 获取本SnmpObject的索引集合格式化集合,及其值的集合, * 如果没有索引,则默认返回的值为0,这是SNMP的默认oid实例. * @return */ def getIndexes() = { if( indexes.length > 0){ val f = indexes.map( _.format).mkString(".") val args = indexes.map( _.field_name) .mkString(",") (f,args) }else{ ("%d","0") } } def generate_code_for_cplusplus_declare () ={ s""" |class ${class_name} |{ |public: | ${class_name}(); | ${class_name}( const ${class_name} & other); | ~${class_name}(); | | ${class_name} & operator=( const ${class_name} & other); | | void BuildGetPdu( Pdu & pdu); | void BuildSetPdu( Pdu & pdu); | void BuildRspPdu( Pdu & pdu); | |${ val codes = for( m <- members) yield { m.generate_code_for_cplusplus_getset()}; codes.mkString("\n")} |private: |${ val codes = for( m <- members) yield { m.generate_code_for_cplusplus_declare()} ; codes.mkString("\n")} |}; """.stripMargin } //def generate_member_code_for_cplusplus( ) def generate_code_for_cplusplus_define () ={ s"""${class_name}::${class_name}(): |${ members.map(_.generate_code_for_cplusplus_default_construction()).mkString(",\n")}{} |${class_name}::${class_name}( const ${class_name} & other): |${members.map(_.generate_code_for_cplusplus_copy_construction()).mkString(",\n")}{} |${class_name} & ${class_name}::operator=( const ${class_name} & other) |{ | if( &other == this ) | { | return *this; | } |${members.map(_.generate_code_for_cplusplus_assign).mkString(";\n")}; | return *this; |} | |void ${class_name}::BuildGetPdu( Pdu & pdu ) |{ | ${members.map( _.generate_code_for_cplusplus_pdu_get(instance._1,instance._2)).mkString("\n")} |} | |void ${class_name}::BuildSetPdu( Pdu & pdu) |{ | ${ members.map( _.generate_code_for_cplusplus_pdu_set(instance._1,instance._2)).mkString("\n")} |} |void ${class_name}::BuildRspPdu( Pdu & pdu) |{ | VbIter iter(pdu); | Vb vb; | Oid oid_; | while( iter.next(vb) ) | { | vb.get_oid(oid_); |${ members.map(_.generate_code_for_cplusplus_pdu_rsp(instance._1,instance._2)).mkString("\n")} | } |} """.stripMargin } } /** * 生成的C++代码是基于ACE ASNMP库。如果使用其它库和语言,可以继续添加或者修改. */ object SnmpGroup{ val groups = new mutable.HashSet[SnmpGroup]() def apply(name :String ,group_type :SnmpGroupType.Value, members : Array[String]) = { val group = new SnmpGroup(name,group_type,members) groups.add(group) group } def clear() { groups.clear() } def generate_cplusplus_declare(fileName :String) ={ s""" |#ifndef __${fileName}_H__ |#define __${fileName}_H__ |#include<string> |#include<asnmp/snmp.h> | |${ groups.map( _.generate_code_for_cplusplus_declare()) .mkString("\n")} |#endif """.stripMargin } def generate_cplusplus_define( fileName :String) = { s""" |#include "${fileName}.h" |#include<ace/os_include/os_assert.h> | |${ groups.map( _.generate_code_for_cplusplus_define()) .mkString("\n")} """.stripMargin } }
测试MIB为Gnugk的mib文件,可以到Gnugk网站下载
其它SNMP MIB文件,只要安装了相关的工具就有,例如wireshark,的snmp目录下
object Main { def main( args : Array[String]) { try { val parser = new SnmpParser("""D:\AdventNet\AdventNet\C-Agent\mibs""", "GNU-GATEKEEPER-MIB", false) val r = parser.parserFile(parser.parserDefinitions) if (r.successful) { println(SnmpGroup.generate_cplusplus_declare("GNU-GATEKEEPER-MIB")) println("/****************************************************************************/") println(SnmpGroup.generate_cplusplus_define("GNU-GATEKEEPER-MIB")) } else { println("parser error:"+r.toString) } }catch { case e : Exception => println("exception:"+e.getMessage) } } }
输出结果:
"C:\Program Files\Java\jdk1.7.0_01\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=G:\Program Files\JetBrains\IntelliJ IDEA 12.1.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_01\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.7.0_01\jre\lib\ext\zipfs.jar;H:\IDEAProject\BNFParser\out\production\BNFParser;H:\scala-2.10.1\lib\scala-library.jar;H:\scala-2.10.1\lib\scala-swing.jar;H:\scala-2.10.1\lib\scala-actors.jar;F:\OpenSource\apache-pivot-2.0.2\lib\pivot-charts-2.0.2.jar;F:\OpenSource\apache-pivot-2.0.2\lib\pivot-core-2.0.2.jar;F:\OpenSource\apache-pivot-2.0.2\lib\pivot-web-2.0.2.jar;F:\OpenSource\apache-pivot-2.0.2\lib\pivot-web-server-2.0.2.jar;F:\OpenSource\apache-pivot-2.0.2\lib\pivot-wtk-2.0.2.jar;F:\OpenSource\apache-pivot-2.0.2\lib\pivot-wtk-terra-2.0.2.jar;G:\Program Files\JetBrains\IntelliJ IDEA 12.1.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain cn.newzai.parser.Main parser file SNMPv2-SMI OK parser file SNMPv2-TC OK #ifndef __GNU-GATEKEEPER-MIB_H__ #define __GNU-GATEKEEPER-MIB_H__ #include<string> #include<asnmp/snmp.h> class CGnugkStatusConf { public: CGnugkStatusConf(); CGnugkStatusConf( const CGnugkStatusConf & other); ~CGnugkStatusConf(); CGnugkStatusConf & operator=( const CGnugkStatusConf & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkVersion( const std::string & value) { gnugk_version_ = value;} const std::string & GetGnugkVersion() const { return gnugk_version_;} void SetGnugkFeatures( const std::string & value) { gnugk_features_ = value;} const std::string & GetGnugkFeatures() const { return gnugk_features_;} void SetGnugkRegistrations( unsigned int value) { gnugk_registrations_ = value;} unsigned int GetGnugkRegistrations() const { return gnugk_registrations_;} void SetGnugkOngoingCalls( unsigned int value) { gnugk_ongoing_calls_ = value;} unsigned int GetGnugkOngoingCalls() const { return gnugk_ongoing_calls_;} void SetGnugkTracelevel( unsigned int value) { gnugk_tracelevel_ = value;} unsigned int GetGnugkTracelevel() const { return gnugk_tracelevel_;} void SetGnugkCatchAllDestination( const std::string & value) { gnugk_catch_all_destination_ = value;} const std::string & GetGnugkCatchAllDestination() const { return gnugk_catch_all_destination_;} void SetGnugkTotalCalls( unsigned int value) { gnugk_total_calls_ = value;} unsigned int GetGnugkTotalCalls() const { return gnugk_total_calls_;} void SetGnugkSuccessfulCalls( unsigned int value) { gnugk_successful_calls_ = value;} unsigned int GetGnugkSuccessfulCalls() const { return gnugk_successful_calls_;} private: std::string gnugk_version_; std::string gnugk_features_; unsigned int gnugk_registrations_; unsigned int gnugk_ongoing_calls_; unsigned int gnugk_tracelevel_; std::string gnugk_catch_all_destination_; unsigned int gnugk_total_calls_; unsigned int gnugk_successful_calls_; }; class CGnugkEncodingError { public: CGnugkEncodingError(); CGnugkEncodingError( const CGnugkEncodingError & other); ~CGnugkEncodingError(); CGnugkEncodingError & operator=( const CGnugkEncodingError & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkStarted { public: CGnugkStarted(); CGnugkStarted( const CGnugkStarted & other); ~CGnugkStarted(); CGnugkStarted & operator=( const CGnugkStarted & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkAuthenticationError { public: CGnugkAuthenticationError(); CGnugkAuthenticationError( const CGnugkAuthenticationError & other); ~CGnugkAuthenticationError(); CGnugkAuthenticationError & operator=( const CGnugkAuthenticationError & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkTrapObjectsConf { public: CGnugkTrapObjectsConf(); CGnugkTrapObjectsConf( const CGnugkTrapObjectsConf & other); ~CGnugkTrapObjectsConf(); CGnugkTrapObjectsConf & operator=( const CGnugkTrapObjectsConf & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkNetworkError { public: CGnugkNetworkError(); CGnugkNetworkError( const CGnugkNetworkError & other); ~CGnugkNetworkError(); CGnugkNetworkError & operator=( const CGnugkNetworkError & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkDatabaseError { public: CGnugkDatabaseError(); CGnugkDatabaseError( const CGnugkDatabaseError & other); ~CGnugkDatabaseError(); CGnugkDatabaseError & operator=( const CGnugkDatabaseError & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkGeneralError { public: CGnugkGeneralError(); CGnugkGeneralError( const CGnugkGeneralError & other); ~CGnugkGeneralError(); CGnugkGeneralError & operator=( const CGnugkGeneralError & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkIOError { public: CGnugkIOError(); CGnugkIOError( const CGnugkIOError & other); ~CGnugkIOError(); CGnugkIOError & operator=( const CGnugkIOError & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkStopped { public: CGnugkStopped(); CGnugkStopped( const CGnugkStopped & other); ~CGnugkStopped(); CGnugkStopped & operator=( const CGnugkStopped & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkModuleFailed { public: CGnugkModuleFailed(); CGnugkModuleFailed( const CGnugkModuleFailed & other); ~CGnugkModuleFailed(); CGnugkModuleFailed & operator=( const CGnugkModuleFailed & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkConfigReload { public: CGnugkConfigReload(); CGnugkConfigReload( const CGnugkConfigReload & other); ~CGnugkConfigReload(); CGnugkConfigReload & operator=( const CGnugkConfigReload & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; class CGnugkNeighborError { public: CGnugkNeighborError(); CGnugkNeighborError( const CGnugkNeighborError & other); ~CGnugkNeighborError(); CGnugkNeighborError & operator=( const CGnugkNeighborError & other); void BuildGetPdu( Pdu & pdu); void BuildSetPdu( Pdu & pdu); void BuildRspPdu( Pdu & pdu); void SetGnugkTrapSeverity( int value) { gnugk_trap_severity_ = value;} int GetGnugkTrapSeverity() const { return gnugk_trap_severity_;} void SetGnugkTrapGroup( int value) { gnugk_trap_group_ = value;} int GetGnugkTrapGroup() const { return gnugk_trap_group_;} void SetGnugkTrapDisplayString( const std::string & value) { gnugk_trap_display_string_ = value;} const std::string & GetGnugkTrapDisplayString() const { return gnugk_trap_display_string_;} private: int gnugk_trap_severity_; int gnugk_trap_group_; std::string gnugk_trap_display_string_; }; #endif /****************************************************************************/ #include "GNU-GATEKEEPER-MIB.h" #include<ace/os_include/os_assert.h> CGnugkNeighborError::CGnugkNeighborError(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkNeighborError::CGnugkNeighborError( const CGnugkNeighborError & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkNeighborError & CGnugkNeighborError::operator=( const CGnugkNeighborError & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkNeighborError::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkNeighborError::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkNeighborError::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkTrapObjectsConf::CGnugkTrapObjectsConf(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkTrapObjectsConf::CGnugkTrapObjectsConf( const CGnugkTrapObjectsConf & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkTrapObjectsConf & CGnugkTrapObjectsConf::operator=( const CGnugkTrapObjectsConf & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkTrapObjectsConf::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkTrapObjectsConf::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkTrapObjectsConf::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkStopped::CGnugkStopped(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkStopped::CGnugkStopped( const CGnugkStopped & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkStopped & CGnugkStopped::operator=( const CGnugkStopped & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkStopped::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkStopped::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkStopped::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkIOError::CGnugkIOError(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkIOError::CGnugkIOError( const CGnugkIOError & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkIOError & CGnugkIOError::operator=( const CGnugkIOError & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkIOError::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkIOError::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkIOError::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkGeneralError::CGnugkGeneralError(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkGeneralError::CGnugkGeneralError( const CGnugkGeneralError & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkGeneralError & CGnugkGeneralError::operator=( const CGnugkGeneralError & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkGeneralError::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkGeneralError::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkGeneralError::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkModuleFailed::CGnugkModuleFailed(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkModuleFailed::CGnugkModuleFailed( const CGnugkModuleFailed & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkModuleFailed & CGnugkModuleFailed::operator=( const CGnugkModuleFailed & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkModuleFailed::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkModuleFailed::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkModuleFailed::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkConfigReload::CGnugkConfigReload(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkConfigReload::CGnugkConfigReload( const CGnugkConfigReload & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkConfigReload & CGnugkConfigReload::operator=( const CGnugkConfigReload & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkConfigReload::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkConfigReload::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkConfigReload::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkNetworkError::CGnugkNetworkError(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkNetworkError::CGnugkNetworkError( const CGnugkNetworkError & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkNetworkError & CGnugkNetworkError::operator=( const CGnugkNetworkError & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkNetworkError::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkNetworkError::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkNetworkError::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkAuthenticationError::CGnugkAuthenticationError(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkAuthenticationError::CGnugkAuthenticationError( const CGnugkAuthenticationError & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkAuthenticationError & CGnugkAuthenticationError::operator=( const CGnugkAuthenticationError & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkAuthenticationError::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkAuthenticationError::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkAuthenticationError::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkEncodingError::CGnugkEncodingError(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkEncodingError::CGnugkEncodingError( const CGnugkEncodingError & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkEncodingError & CGnugkEncodingError::operator=( const CGnugkEncodingError & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkEncodingError::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkEncodingError::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkEncodingError::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkDatabaseError::CGnugkDatabaseError(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkDatabaseError::CGnugkDatabaseError( const CGnugkDatabaseError & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkDatabaseError & CGnugkDatabaseError::operator=( const CGnugkDatabaseError & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkDatabaseError::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkDatabaseError::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkDatabaseError::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkStarted::CGnugkStarted(): gnugk_trap_severity_(1), gnugk_trap_group_(1), gnugk_trap_display_string_(""){} CGnugkStarted::CGnugkStarted( const CGnugkStarted & other): gnugk_trap_severity_(other.gnugk_trap_severity_), gnugk_trap_group_(other.gnugk_trap_group_), gnugk_trap_display_string_(other.gnugk_trap_display_string_){} CGnugkStarted & CGnugkStarted::operator=( const CGnugkStarted & other) { if( &other == this ) { return *this; } gnugk_trap_severity_ = other.gnugk_trap_severity_; gnugk_trap_group_ = other.gnugk_trap_group_; gnugk_trap_display_string_ = other.gnugk_trap_display_string_; return *this; } void CGnugkStarted::BuildGetPdu( Pdu & pdu ) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkStarted::BuildSetPdu( Pdu & pdu) { /*gnugk_trap_severity_ ACCESS is accessible_for_notify*/ /*gnugk_trap_group_ ACCESS is accessible_for_notify*/ /*gnugk_trap_display_string_ ACCESS is accessible_for_notify*/ } void CGnugkStarted::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_severity_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpInt32 value; if( vb.get_value(value) == 0 ) { gnugk_trap_group_ = (int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.2.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_trap_display_string_ = value.to_string(); continue; } } } } } CGnugkStatusConf::CGnugkStatusConf(): gnugk_version_(""), gnugk_features_(""), gnugk_registrations_(0), gnugk_ongoing_calls_(0), gnugk_tracelevel_(0), gnugk_catch_all_destination_(""), gnugk_total_calls_(0), gnugk_successful_calls_(0){} CGnugkStatusConf::CGnugkStatusConf( const CGnugkStatusConf & other): gnugk_version_(other.gnugk_version_), gnugk_features_(other.gnugk_features_), gnugk_registrations_(other.gnugk_registrations_), gnugk_ongoing_calls_(other.gnugk_ongoing_calls_), gnugk_tracelevel_(other.gnugk_tracelevel_), gnugk_catch_all_destination_(other.gnugk_catch_all_destination_), gnugk_total_calls_(other.gnugk_total_calls_), gnugk_successful_calls_(other.gnugk_successful_calls_){} CGnugkStatusConf & CGnugkStatusConf::operator=( const CGnugkStatusConf & other) { if( &other == this ) { return *this; } gnugk_version_ = other.gnugk_version_; gnugk_features_ = other.gnugk_features_; gnugk_registrations_ = other.gnugk_registrations_; gnugk_ongoing_calls_ = other.gnugk_ongoing_calls_; gnugk_tracelevel_ = other.gnugk_tracelevel_; gnugk_catch_all_destination_ = other.gnugk_catch_all_destination_; gnugk_total_calls_ = other.gnugk_total_calls_; gnugk_successful_calls_ = other.gnugk_successful_calls_; return *this; } void CGnugkStatusConf::BuildGetPdu( Pdu & pdu ) { { Vb vb_gnugk_version_; char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.1.%d",0); Oid oid(szOid); vb_gnugk_version_.set_oid(oid); pdu += vb_gnugk_version_; } { Vb vb_gnugk_features_; char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.2.%d",0); Oid oid(szOid); vb_gnugk_features_.set_oid(oid); pdu += vb_gnugk_features_; } { Vb vb_gnugk_registrations_; char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.3.%d",0); Oid oid(szOid); vb_gnugk_registrations_.set_oid(oid); pdu += vb_gnugk_registrations_; } { Vb vb_gnugk_ongoing_calls_; char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.4.%d",0); Oid oid(szOid); vb_gnugk_ongoing_calls_.set_oid(oid); pdu += vb_gnugk_ongoing_calls_; } { Vb vb_gnugk_tracelevel_; char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.5.%d",0); Oid oid(szOid); vb_gnugk_tracelevel_.set_oid(oid); pdu += vb_gnugk_tracelevel_; } { Vb vb_gnugk_catch_all_destination_; char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.6.%d",0); Oid oid(szOid); vb_gnugk_catch_all_destination_.set_oid(oid); pdu += vb_gnugk_catch_all_destination_; } { Vb vb_gnugk_total_calls_; char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.7.%d",0); Oid oid(szOid); vb_gnugk_total_calls_.set_oid(oid); pdu += vb_gnugk_total_calls_; } { Vb vb_gnugk_successful_calls_; char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.8.%d",0); Oid oid(szOid); vb_gnugk_successful_calls_.set_oid(oid); pdu += vb_gnugk_successful_calls_; } } void CGnugkStatusConf::BuildSetPdu( Pdu & pdu) { /*gnugk_version_ ACCESS is read_only*/ /*gnugk_features_ ACCESS is read_only*/ /*gnugk_registrations_ ACCESS is read_only*/ /*gnugk_ongoing_calls_ ACCESS is read_only*/ /*gnugk_tracelevel_ ACCESS is read_only*/ /*gnugk_catch_all_destination_ ACCESS is read_only*/ /*gnugk_total_calls_ ACCESS is read_only*/ /*gnugk_successful_calls_ ACCESS is read_only*/ } void CGnugkStatusConf::BuildRspPdu( Pdu & pdu) { VbIter iter(pdu); Vb vb; Oid oid_; while( iter.next(vb) ) { vb.get_oid(oid_); { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.1.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_version_ = value.to_string(); continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.2.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_features_ = value.to_string(); continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.3.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpUInt32 value; if( vb.get_value(value) == 0 ) { gnugk_registrations_ = (unsigned int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.4.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpUInt32 value; if( vb.get_value(value) == 0 ) { gnugk_ongoing_calls_ = (unsigned int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.5.%d",0); Oid oid(szOid); if( oid == oid_ ) { SnmpUInt32 value; if( vb.get_value(value) == 0 ) { gnugk_tracelevel_ = (unsigned int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.6.%d",0); Oid oid(szOid); if( oid == oid_ ) { OctetStr value; if( vb.get_value(value) == 0 ) { gnugk_catch_all_destination_ = value.to_string(); continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.7.%d",0); Oid oid(szOid); if( oid == oid_ ) { Counter32 value; if( vb.get_value(value) == 0 ) { gnugk_total_calls_ = (unsigned int)value; continue; } } } { char szOid[128] ={0}; sprintf(szOid,"1.3.6.1.4.1.27938.11.1.8.%d",0); Oid oid(szOid); if( oid == oid_ ) { Counter32 value; if( vb.get_value(value) == 0 ) { gnugk_successful_calls_ = (unsigned int)value; continue; } } } } } Process finished with exit code 0