SNMP:ASN.1 MIB 定义。在表中引用表

标签 snmp asn.1

自从我编写 ASN.1 以来已经有一段时间了,所以..

我们的数据模型由表中的多个表定义组成。这在 SNMP 中是行不通的,因此我们需要扁平化定义。最简单的方法是让嵌入表由与父表相同的 OID 进行索引。因此

someTableEntry ::= SEQUENCE {
   someTableIndex
        Integer32,
   someTableDomain
        Integer32,
   someTableFooTable
        SEQUENCE OF SomeTableFooTable
} 

变成了

    someTableEntry ::= SEQUENCE {
       someTableIndex
            Integer32,
       someTableDomain
            Integer32,
    } 

someTableFooTable ::= SEQUENCE {
    someTableIndex
       Integer32,
....
} 

好处是,在我们的应用程序中永远不会有任何类型的 SET、GET 或 GET NEXT,因此不需要 SNMP walk(有一些很好的理由取代了对网络管理优雅的需求。所有属性仅通过陷阱进行报告。我认为这是有效的 SNMP MIB 定义,但希望获得一些反馈。

提前致谢。

最佳答案

听起来您走在正确的道路上。为了将一个表定义为另一个表的子表,您只需通过父表的索引加上子表的索引对其进行索引(例如,0.1.8.23.7.2.42,其中 2 是父索引,42 是子索引)。

例如,您可以定义一个父级,如下所示:

parentTable OBJECT-TYPE
    SYNTAX       SEQUENCE OF parentEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION  "Parent table"
    ::= { example 1 }

parentEntry OBJECT-TYPE
    SYNTAX       ParentEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION  "Entry in Parent table"
    INDEX        { parentIndex }
    ::= { parentTable 1 }

ParentEntry ::= SEQUENCE {
    parentIndex            Unsigned32,
    -- other columns in the table
    }

-- define the columns in the parent table

子表定义为:

childTable OBJECT-TYPE
    SYNTAX       SEQUENCE OF childEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION  "Child table"
    ::= { example 2 }

childEntry OBJECT-TYPE
    SYNTAX       ChildEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION  "Entry in Child table"
    INDEX        { parentIndex,
                   childIndex }
    ::= { childTable 1 }

ChildEntry ::= SEQUENCE {
    childIndex            Unsigned32,
    -- other columns in the table
    }

-- define the columns in the child table

请注意,不必在 ChildEntry 序列中列出parentIndex,因为它已在 MIB 中的其他位置声明。

此方法效果很好,甚至可以毫无问题地响应 snmp 遍历。

一旦您拥有了您认为准确定义了所需结构的 MIB,您就可以使用 smilint 来验证它。如果您使用的是 Linux 计算机或安装了 cygwin,或者您可以 validate it online .

更新

此模式也适用于更深的嵌套。

孙子表可以定义为:

grandChildTable OBJECT-TYPE
    SYNTAX       SEQUENCE OF grandChildEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION  "Grandchild table"
    ::= { example 3 }

grandChildEntry OBJECT-TYPE
    SYNTAX       GrandChildEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION  "Entry in Grandchild table"
    INDEX        { parentIndex,
                   childIndex,
                   grandChildIndex }
    ::= { grandChildTable 1 }

grandChildEntry ::= SEQUENCE {
    grandChildIndex            Unsigned32,
    -- other columns in the table
    }

-- define the columns in the grandChild table

嵌套深度的唯一限制是最大 OID 长度(我认为是 127):列的基本 OID 长度加上表的索引数量必须小于最大 OID 长度。

另一个需要注意的事项是,每个级别都可以有多个同级。

第二个 child 可以定义为:

secondchildTable OBJECT-TYPE
    SYNTAX       SEQUENCE OF secondchildEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION  "Second child table"
    ::= { example 4 }

secondchildEntry OBJECT-TYPE
    SYNTAX       SecondchildEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION  "Entry in Second child table"
    INDEX        { parentIndex,
                   secondchildIndex }
    ::= { secondchildTable 1 }

SecondchildEntry ::= SEQUENCE {
    secondchildIndex            Unsigned32,
    -- other columns in the table
    }

-- define the columns in the second child table

关于SNMP:ASN.1 MIB 定义。在表中引用表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2510211/

相关文章:

c++ - 与开发 SNMP 扩展代理 DLL 相关吗?

c - 为什么我的 snmp 数据包无效

linux - 解析asn1文件

asn.1 - 如何在 BER 中以不定长度编码的八位字节字符串中转义双空八位字节?

content-management-system - 识别未知的 ASN.1 对象

java - 编码 java Double as asn1 Real {sign, mantissa, base, exponent}

node.js - 如何使用nodejs控制UDP数据包的源ip或端口

snmp - SNMPv3 是否需要使用用户名/身份验证和社区字符串?

python - snmp-从 pass 获取值丢失

java - 如何在 Java 中解码 DER 编码的字符串?