ひとつのOIDの小さい問題

3874 ワード

最近の作業では、SNMPプロトコルを使用してネットワークデバイスの起動時間を取得するタスクがあります.最初は、メーカーに連絡したり、OIDを要求したり、テストしたり、フィードバックしたりする簡単な体力労働でした.午後からできると思っていたことが、テスト中に「不思議な問題」を発見して2、3日も引きずった.ここでは探索の過程を簡単に記録します.

1.問題の説明:


公式サイトの検索結果によると、Ciscoの各シリーズIOSルータ、スイッチのsysUpTime OIDは以下の通りである.
Name
Value
Object
sysUpTime
OID
1.3.6.1.2.1.1.3
Type
TimeTicks
Permission
read-only
MIB
SNMPv2-MIB
SNMPツールを使用して、最近オンラインになったデバイスをテストします.このOIDで取得した値は、ログインデバイスshow versionで見たUpTimeと一致します.もともとはここで终わっていたが、なぜか数年前にオンラインになった6509台を选んでテストした.結果を見ると:
sysUpTime.0 = Timeticks: (254716234) 29 days, 11:32:42.34
一瞬にしてばかになった.

2.エラー処理


問題を発見した後、頭の中で最初の反応は、OIDに問題があり、配置変更時間など、別の時間を取ったのかもしれない.しかし、私が考えることができるすべての時間に関する値を調べたところ、上の兄弟たちと同じ顔をしている人は一人もいなかった.さらに詳しく見ると、公式サイトで提供されているMIBはSNMPv 2-MIB:RFC 3418で定義された標準OIDで、値タイプは「TimeTicks」
sysUpTime OBJECT-TYPE
SYNTAX      TimeTicks
   MAX-ACCESS  read-only
   STATUS      current
   DESCRIPTION
           "The time (in hundredths of a second) since the
           network management portion of the system was last
           re-initialized."
   ::= { system 3 }

正確に1%秒まで何を考えているのか分からない.しかし、少し眉目があるようです.これは記号のない整数ですね.子供の頃、先生は私たちにデータの計算範囲を教えてくれました.最大値の最小値の精度がないコンピュータはごろつきです.ちょっと当ててみましょう.
![][1] [1]: http://latex.codecogs.com/gif.latex?\frac{2^{32}}{100\times&space;24\times&space;60&space;\times&space;60}=497.1026963=497&space;days,02:27:53
さっきの29日間を加えて、show version・・・
uptime is 1 year, 23 weeks, 13 hours, 32 minutes

365+23*7、日があまり違わないようですが、時間がどうして間違っていますか.あれこれ考えてみると......これがこの二つの命令を叩く時間の差ではないか.

3.その理由を知る


子はかつて曰わく、外事は決して谷兄に聞かない.実はネットのこの、RFCはあなたの最後の砦で、究極の大殺器です.TimeTicks
7.1.8.  TimeTicks
The TimeTicks type represents a non-negative integer which represents
the time, modulo 2^32 (4294967296 decimal), in hundredths of a second
between two epochs.  When objects are defined which use this ASN.1
type, the description of the object identifies both of the reference
epochs.

For example, [3] defines the TimeStamp textual convention which is
based on the TimeTicks type.  With a TimeStamp, the first reference
epoch is defined as the time when sysUpTime [5] was zero, and the
second reference epoch is defined as the current value of sysUpTime.

The TimeTicks type may not be sub-typed.

このCounter 32を見てみましょう
7.1.6.  Counter32

   The Counter32 type represents a non-negative integer which
   monotonically increases until it reaches a maximum value of 2^32-1
   (4294967295 decimal), when it wraps around and starts increasing
   again from zero.

   Counters have no defined "initial" value, and thus, a single value of
   a Counter has (in general) no information content.  Discontinuities
   in the monotonically increasing value normally occur at re-
   initialization of the management system, and at other times as
   specified in the description of an object-type using this ASN.1 type.
   If such other times can occur, for example, the creation of an object
   instance at times other than re-initialization, then a corresponding
   object should be defined, with an appropriate SYNTAX clause, to
   indicate the last discontinuity.  Examples of appropriate SYNTAX
   clause include:  TimeStamp (a textual convention defined in [3]),
   DateAndTime (another textual convention from [3]) or TimeTicks.

   The value of the MAX-ACCESS clause for objects with a SYNTAX clause
   value of Counter32 is either "read-only" or "accessible-for-notify".

   A DEFVAL clause is not allowed for objects with a SYNTAX clause value
   of Counter32.

これは人の基準で定義されたもので、Bugではありません.この値が2^32に増加すると、自動的に0にリセットされ、カウントが再開されます.私を忙しく働かせた.さすがに功力が足りない.
Update:この文章を書いたとき、この問題について、公式フォーラムでさらに議論があったことがわかりました.