Example #1
0
        /// <summary>
        /// Validates the MIB file.This will resolve all type and value
        /// references in the MIB symbols, while also validating them for
        /// consistency.Note that this method shouldn't be called until
        /// all referenced MIB files (and their respective references)
        /// have been initialized.
        /// </summary>
        /// <exception cref="MibLoaderException">
        /// If the MIB file couldn't be  analyzed correctly
        /// </exception>
        public void Validate()
        {
            int errors = this.log.ErrorCount;

            // Validate all symbols
            foreach (MibSymbol symbol in this.symbolList)
            {
                try
                {
                    symbol.Initialize(this.log);
                }
                catch (MibException e)
                {
                    this.log.AddError(e.Location, e.Message);
                }

                MibValueSymbol value = symbol as MibValueSymbol;
                if (value != null && (value.Value is NumberValue || value.Value is ObjectIdentifierValue))
                {
                    this.symbolValueMap.Add(value.Value.ToString(), value);
                }
            }

            // Check for errors
            if (errors != this.log.ErrorCount)
            {
                throw new MibLoaderException(this.log);
            }
        }
Example #2
0
        /// <summary>
        /// Returns the root MIB value symbol. This value symbol is
        /// normally the module identifier (in SMIv2), but may also be
        /// just the base object identifier in the MIB.
        /// </summary>
        /// <returns>The root MIB value symbol</returns>
        public MibValueSymbol GetRootSymbol()
        {
            MibValueSymbol root = null;
            MibValueSymbol parent;

            root = this.symbolList.Where(s => s is MibValueSymbol).FirstOrDefault() as MibValueSymbol;

            /*
             * foreach (MibSymbol m in this.symbolList)
             * {
             *  root = m as MibValueSymbol;
             *  if (root != null)
             *  {
             *      break;
             *  }
             * }
             */
            while (root != null && (parent = root.Parent) != null)
            {
                if (!root.Mib.Equals(parent.Mib))
                {
                    break;
                }

                root = parent;
            }

            return(root);
        }
Example #3
0
        /// <summary>
        /// Returns a value symbol from this MIB. The search is performed
        /// by using the strictly numerical OID value specified. Differing
        /// from the getSymbolByValue() methods, this method may return a
        /// symbol with only a partial OID match. If an exact match for
        /// the OID is present in the MIB, this method will always return
        /// the same result as getSymbolByValue(). Otherwise, the symbol
        /// with the longest matching OID will be returned, making it
        /// possible to identify a MIB symbol from an OID containing table
        /// row indices or similar.
        /// </summary>
        /// <param name="oid">The numeric OID value</param>
        /// <returns>The MIB value symbol, or null if not found</returns>
        public MibValueSymbol GetSymbolByOid(string oid)
        {
            int pos;

            do
            {
                MibValueSymbol sym = this.GetSymbolByValue(oid);
                if (sym != null)
                {
                    return(sym);
                }

                pos = oid.LastIndexOf(".");
                if (pos > 0)
                {
                    oid = oid.Substring(0, pos);
                }
            }while (pos > 0);

            return(null);
        }
Example #4
0
        /// <summary>
        /// Initializes this context by creating all default symbols.
        /// </summary>
        private void Initialize()
        {
            MibSymbol             symbol;
            ObjectIdentifierValue oid;

            // Add the ccitt symbol
            oid    = new ObjectIdentifierValue(CCITT, 0);
            symbol = new MibValueSymbol(
                new FileLocation(null, -1, -1),
                null,
                CCITT,
                new ObjectIdentifierType(),
                oid);
            oid.Symbol = (MibValueSymbol)symbol;
            this.symbols.Add(CCITT, symbol);

            // Add the iso symbol
            oid    = new ObjectIdentifierValue(ISO, 1);
            symbol = new MibValueSymbol(
                new FileLocation(null, -1, -1),
                null,
                ISO,
                new ObjectIdentifierType(),
                oid);
            oid.Symbol = (MibValueSymbol)symbol;
            this.symbols.Add(ISO, symbol);

            // Add the joint-iso-ccitt symbol
            oid    = new ObjectIdentifierValue(JOINTISOCCITT, 2);
            symbol = new MibValueSymbol(
                new FileLocation(null, -1, -1),
                null,
                JOINTISOCCITT,
                new ObjectIdentifierType(),
                oid);
            oid.Symbol = (MibValueSymbol)symbol;
            this.symbols.Add(JOINTISOCCITT, symbol);
        }
Example #5
0
 /// <summary>
 /// Clears and prepares this value for garbage collection. This
 /// method will recursively clear any associated types or values,
 /// making sure that no data structures references this object.
 /// NOTE: This is an internal method that should only be called
 /// by the MIB loader.
 /// </summary>
 public virtual void Clear()
 {
     this.reference = null;
 }