示例#1
0
        /// <summary>
        /// Initializes the MIB type. This will remove all levels of
        /// indirection present, such as references to types or values. No
        /// information is lost by this operation. This method may modify
        /// this object as a side-effect, and will return the basic
        /// type.
        /// </summary>
        /// <remarks>
        /// This is an internal method that should
        /// only be called by the MIB loader.
        /// </remarks>
        /// <param name="symbol">The MIB symbol containing this type</param>
        /// <param name="log">The MIB loader log</param>
        /// <returns>The MIB type</returns>
        public override MibType Initialize(MibSymbol symbol, MibLoaderLog log)
        {
            this.SetTag(true, MibTypeTag.Sequence);

            this.baseType = this.baseType.Initialize(symbol, log);
            if (this.baseType != null && this.constraint != null)
            {
                this.constraint.Initialize(this, log);
            }

            return(this);
        }
示例#2
0
        /// <summary>
        /// Initializes the object. This will remove all levels of
        /// indirection present, such as references to other types and
        /// values.No information is lost by this operation.This method
        /// may modify this object as a side-effect, and will be called by
        /// the MIB loader.
        /// </summary>
        /// <param name="symbol">the MIB symbol containing this object</param>
        /// <param name="log">the MIB loader log</param>
        /// <exception cref="MibException">
        /// If an error was encountered during the initialization
        /// </exception>
        public void Initialize(MibSymbol symbol, MibLoaderLog log)
        {
            if (this.value != null)
            {
                this.value = this.value.Initialize(log, null);
            }

            if (this.type != null)
            {
                this.type = this.type.Initialize(symbol, log);
            }
        }
示例#3
0
        /// <summary>
        /// Initializes the MIB value. This will remove all levels of
        /// indirection present, such as references to other values. No
        /// value information is lost by this operation. This method may
        /// modify this object as a side-effect, and will return the basic
        /// value.
        /// </summary>
        /// <remarks>
        /// This is an internal method that should only be called by
        /// the MIB loader.
        /// </remarks>
        /// <param name="log">The MIB loader log</param>
        /// <param name="type">The value type</param>
        /// <returns>The basic MIB value</returns>
        public override MibValue Initialize(MibLoaderLog log, MibType type)
        {
            int bytes  = (this.minLength / 2) + ((this.minLength % 2 > 0) ? 1 : 0);
            int length = NumberValue.GetByteSize(type, bytes) * 2;

            if (length > this.minLength)
            {
                this.minLength = length;
            }

            return(this);
        }
示例#4
0
        /// <summary>
        /// Initializes the constraint. This will remove all levels of
        /// indirection present, such as references to types or values. No
        /// information is lost by this operation. This method may modify
        /// this object as a side-effect, and will return the basic
        /// type.
        /// NOTE: This is an internal method that should
        /// only be called by the MIB loader.
        /// </summary>
        /// <param name="type">The MIB type</param>
        /// <param name="log">The MIB loader log</param>
        /// <exception cref="MibException">
        /// If an error is encountered during initialization
        /// </exception>
        public void Initialize(MibType type, MibLoaderLog log)
        {
            string message;

            this.values.Initialize(new IntegerType(), log);
            if (this.location != null && !this.IsCompatible(type))
            {
                message = "Size constraint not compatible with this type";
                log.AddWarning(this.location, message);
            }

            this.location = null;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpTextualConvention"/> class.
 /// </summary>
 /// <param name="displayHint">The display hint, or null</param>
 /// <param name="status">The type status</param>
 /// <param name="description">The type description</param>
 /// <param name="reference">The type reference, or null</param>
 /// <param name="syntax">The type syntax</param>
 public SnmpTextualConvention(
     string displayHint,
     SnmpStatus status,
     string description,
     string reference,
     MibType syntax)
     : base("TEXTUAL-CONVENTION", description)
 {
     this.displayHint = displayHint;
     this.status      = status;
     this.reference   = reference;
     this.syntax      = syntax;
 }
示例#6
0
        /// <summary>
        /// Finds the first SNMP textual convention reference for a type. If the
        /// type specified is a textual convention, it will be returned directly.
        /// </summary>
        /// <param name="type">The MIB type</param>
        /// <returns>The SNMP Textual Convention reference if found, null if not</returns>
        public static SnmpTextualConvention FindReference(MibType type)
        {
            if (type is SnmpObjectType type1)
            {
                type = type1.Syntax;
            }

            if (type is SnmpTextualConvention convention)
            {
                return(convention);
            }

            return((type.ReferenceSymbol == null) ? null : FindReference(type.ReferenceSymbol.Type));
        }
示例#7
0
        /// <summary>
        /// Initializes this object. This will remove all levels of
        /// indirection present, such as references to other types, and
        /// returns the basic type. No type information is lost by this
        /// operation. This method may modify this object as a
        /// side-effect, and will be called by the MIB loader.
        /// </summary>
        /// <param name="log">The MIB loader log</param>
        /// <exception cref="MibException">
        /// If an error was encountered during the initialization
        /// </exception>
        public void Initialize(MibLoaderLog log)
        {
            this.value = this.value.Initialize(log, null);

            if (this.syntax != null)
            {
                this.syntax = this.syntax.Initialize(null, log);
            }

            if (this.writeSyntax != null)
            {
                this.writeSyntax = this.writeSyntax.Initialize(null, log);
            }
        }
示例#8
0
        /// <summary>
        /// Initializes the MIB value. This will remove all levels of
        /// indirection present, such as references to other values. No
        /// value information is lost by this operation. This method may
        /// modify this object as a side-effect, and will return the basic
        /// value.
        /// </summary>
        /// <remarks>
        /// This is an internal method that should only be called by
        /// the MIB loader.
        /// </remarks>
        /// <param name="log">The MIB loader log</param>
        /// <param name="type">The value type</param>
        /// <returns>The basic MIB value</returns>
        /// <exception cref="MibException">If an error occurs during initialization</exception>
        public override MibValue Initialize(MibLoaderLog log, MibType type)
        {
            if (this.references != null)
            {
                foreach (ValueReference vref in this.references)
                {
                    this.Initialize(log, type, vref);
                }

                this.references = null;
            }

            return(this);
        }
示例#9
0
        /// <summary>
        /// Initializes a the MIB value from a value reference. This will
        /// resolve the reference, and set the bit corresponding to the
        /// value.
        /// </summary>
        /// <param name="log">The MIB loader log</param>
        /// <param name="type">The value type</param>
        /// <param name="vref">The value reference to resolve</param>
        /// <exception cref="MibException">
        /// If an error occurred during initialization
        /// </exception>
        private void Initialize(MibLoaderLog log, MibType type, ValueReference vref)
        {
            MibValue val = vref.Initialize(log, type);

            if (val is NumberValue nv)
            {
                this.value.Set((int)nv.Value, true);
            }
            else
            {
                throw new MibException(
                          vref.Location,
                          "referenced value is not a number");
            }
        }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpCompliance"/> class.
 /// </summary>
 /// <param name="group">The group compliance flag</param>
 /// <param name="value">The compliance value</param>
 /// <param name="syntax">The value syntax, or null</param>
 /// <param name="writeSyntax">The value write syntax, or null</param>
 /// <param name="access">The access mode, or null</param>
 /// <param name="description">The compliance description</param>
 public SnmpCompliance(
     bool group,
     MibValue value,
     MibType syntax,
     MibType writeSyntax,
     SnmpAccess access,
     string description)
 {
     this.group       = group;
     this.value       = value;
     this.syntax      = syntax;
     this.writeSyntax = writeSyntax;
     this.access      = access;
     this.description = description;
 }
示例#11
0
 /// <summary>
 /// Initializes the type tags for the specified type. The type tag
 /// may be part in a chain of type tags, in which case the chain
 /// is preserved. The last tag in the chain will be added first,
 /// in order to be able to override (or preserve) a previous tag.
 /// </summary>
 /// <param name="type">The MIB type</param>
 /// <param name="tag">The MIB type tag</param>
 private void InitializeTypeTag(MibType type, MibTypeTag tag)
 {
     if (tag == null)
     {
         return;
     }
     else if (tag.Next == null)
     {
         type.SetTag(this.implicitTag, tag);
     }
     else
     {
         this.InitializeTypeTag(type, tag.Next);
         type.SetTag(false, tag);
     }
 }
        /// <summary>
        /// Initializes the MIB value. This will remove all levels of
        /// indirection present, such as references to other values. No
        /// value information is lost by this operation. This method may
        /// modify this object as a side-effect, and will return the basic
        /// value.
        /// NOTE: This is an internal method that should
        /// only be called by the MIB loader.
        /// </summary>
        /// <param name="log">The MIB Loader log</param>
        /// <param name="type">The value type</param>
        /// <returns>The basic MIB value</returns>
        /// <exception cref="MibException">
        /// If an error was encountered during the initialization</exception>
        public override MibValue Initialize(MibLoaderLog log, MibType type)
        {
            MibSymbol sym;
            MibValue  value;
            string    message;

            sym = this.GetSymbol(log);
            if (sym is MibValueSymbol symbol)
            {
                value = symbol.Value;
                if (value != null)
                {
                    value = value.Initialize(log, type);
                }

                if (value == null)
                {
                    return(null);
                }

                try
                {
                    value = value.CreateReference();
                }
                catch (NotSupportedException e)
                {
                    throw new MibException(this.location, e.Message);
                }

                if (!(value is ObjectIdentifierValue))
                {
                    value.ReferenceSymbol = symbol;
                }

                return(value);
            }
            else if (sym == null)
            {
                message = "undefined symbol '" + this.name + "'";
                throw new MibException(this.location, message);
            }
            else
            {
                message = "referenced symbol '" + this.name + "' is not a value";
                throw new MibException(this.location, message);
            }
        }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpVariation"/> class.
 /// </summary>
 /// <param name="value">the variation value</param>
 /// <param name="syntax">the value syntax, or null</param>
 /// <param name="writeSyntax">the value write syntax, or null</param>
 /// <param name="access">the access mode, or null</param>
 /// <param name="requiredCells">the cell values required for creation</param>
 /// <param name="defaultValue">the default value, or null</param>
 /// <param name="description">the variation description</param>
 public SnmpVariation(
     MibValue value,
     MibType syntax,
     MibType writeSyntax,
     SnmpAccess access,
     IList <MibValue> requiredCells,
     MibValue defaultValue,
     string description)
 {
     this.value         = value;
     this.syntax        = syntax;
     this.writeSyntax   = writeSyntax;
     this.access        = access;
     this.requiredCells = requiredCells;
     this.defaultValue  = defaultValue;
     this.description   = description;
 }
 /// <summary>
 /// Validates a MIB type. This will check any sequences and make
 /// sure their elements are present in the MIB file. If they are
 /// not, new symbols will be added to the MIB.
 /// </summary>
 /// <param name="symbol">The MIB symbol containing this type</param>
 /// <param name="log">The MIB loader log</param>
 /// <param name="type">The MIB type to check</param>
 /// <exception cref="MibException">
 /// If an error was encountered during the validation
 /// </exception>
 private static void CheckType(
     MibValueSymbol symbol,
     MibLoaderLog log,
     MibType type)
 {
     if (type is SequenceOfType sequence)
     {
         SnmpObjectType.CheckType(symbol, log, sequence.ElementType);
     }
     else if (type is SequenceType tp)
     {
         IList <ElementType> elems = tp.AllElements.ToList();
         for (int i = 0; i < elems.Count(); i++)
         {
             SnmpObjectType.CheckElement(symbol, log, elems[i], i + 1);
         }
     }
 }
        /// <summary>
        /// Finds the first SNMP textual convention reference for a type. If the
        /// type specified is a textual convention, it will be returned directly.
        /// </summary>
        /// <param name="type">The MIB type</param>
        /// <returns>The SNMP Textual Convention reference if found, null if not</returns>
        public static SnmpTextualConvention FindReference(MibType type)
        {
            MibTypeSymbol sym;

            if (type is SnmpObjectType)
            {
                type = ((SnmpObjectType)type).Syntax;
            }

            if (type is SnmpTextualConvention)
            {
                return((SnmpTextualConvention)type);
            }

            sym = type.ReferenceSymbol;

            return((sym == null) ? null : SnmpTextualConvention.FindReference(sym.Type));
        }
示例#16
0
        /// <summary>
        /// Initializes the referenced MIB type symbol. This will remove
        /// all levels of indirection present, such as references to other
        /// types, and returns the basic type. This method will add any
        /// constraints or defined values if possible.
        /// </summary>
        /// <param name="symbol">the MIB symbol containing this type</param>
        /// <param name="log">The MIB loader log</param>
        /// <param name="tref">the referenced MIB type symbol</param>
        /// <returns>
        /// The basic MIB type, or null if the basic type was unresolved
        /// </returns>
        /// <exception cref="MibException">
        /// If an error was encountered during the
        /// initialization</exception>
        private MibType InitializeReference(
            MibSymbol symbol,
            MibLoaderLog log,
            MibTypeSymbol tref)
        {
            MibType type = tref.Type;

            if (type != null)
            {
                type = type.Initialize(symbol, log);
            }

            if (type == null)
            {
                return(null);
            }

            try
            {
                if (this.constraint != null)
                {
                    type = type.CreateReference(this.constraint);
                }
                else if (this.values != null)
                {
                    type = type.CreateReference(this.values);
                }
                else
                {
                    type = type.CreateReference();
                }

                type = type.Initialize(symbol, log);
            }
            catch (NotSupportedException e)
            {
                throw new MibException(this.location, e.Message);
            }

            type.ReferenceSymbol = tref;
            this.InitializeTypeTag(type, this.tag);
            return(type);
        }
        /// <summary>
        /// Initializes the MIB value. This will remove all levels of
        /// indirection present, such as references to other values. No
        /// value information is lost by this operation. This method may
        /// modify this object as a side-effect, and will return the basic
        /// value.
        /// </summary>
        /// <remarks>
        /// This is an internal method that should
        /// only be called by the MIB loader.
        /// </remarks>
        /// <param name="log">The MIB Loader log</param>
        /// <param name="type">The value type</param>
        /// <returns>The basic MIB value</returns>
        public override MibValue Initialize(MibLoaderLog log, MibType type)
        {
            ValueReference        vref = null;
            ObjectIdentifierValue oid;

            if (this.parent == null)
            {
                return(this);
            }
            else if (this.parent is ValueReference)
            {
                vref = (ValueReference)this.parent;
            }

            this.parent = this.parent.Initialize(log, type);

            if (vref != null)
            {
                if (this.parent is ObjectIdentifierValue)
                {
                    oid = (ObjectIdentifierValue)this.parent;
                    oid.AddChild(log, this.location, this);
                }
                else
                {
                    throw new MibException(
                              vref.Location,
                              "referenced value is not an object identifier");
                }
            }

            this.location = null;

            if (this.parent is ObjectIdentifierValue)
            {
                return(((ObjectIdentifierValue)this.parent).GetChildByValue(this.value));
            }
            else
            {
                return(this);
            }
        }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpObjectType"/> class.
 /// </summary>
 /// <param name="syntax">The object type syntax</param>
 /// <param name="units">The units description, or null</param>
 /// <param name="access">The access mode</param>
 /// <param name="status">The type status</param>
 /// <param name="description">The type description, or null</param>
 /// <param name="reference">The type reference, or null</param>
 /// <param name="index">The list of index objects</param>
 /// <param name="defaultValue">The default value, or null</param>
 public SnmpObjectType(
     MibType syntax,
     string units,
     SnmpAccess access,
     SnmpStatus status,
     string description,
     string reference,
     IList <SnmpIndex> index,
     MibValue defaultValue)
     : base("OBJECT-TYPE", description)
 {
     this.syntax       = syntax;
     this.units        = units;
     this.access       = access;
     this.status       = status;
     this.reference    = reference;
     this.index        = index;
     this.augments     = null;
     this.defaultValue = defaultValue;
 }
示例#19
0
        /// <summary>
        /// Returns the number of bytes required by the specified type and
        /// initial value size. If the type has no size requirement
        /// specified, a value of one (1) will always be returned. If the
        /// type size constraint allows for zero length, a zero might also
        /// be returned.
        /// </summary>
        /// <param name="type">The MIB value type</param>
        /// <param name="initialBytes">The initial number of bytes used</param>
        /// <returns>The number of bytes required</returns>
        protected static int GetByteSize(MibType type, int initialBytes)
        {
            IConstraint c   = null;
            int         res = -1;

            if (type is StringType)
            {
                c = ((StringType)type).Constraint;
            }

            if (c is SizeConstraint)
            {
                res = ((SizeConstraint)c).NextValue(initialBytes);
            }

            if (res < 0)
            {
                res = 1;
            }

            return(res);
        }
示例#20
0
        /// <summary>
        /// Initializes the object. This will remove all levels of
        /// indirection present, such as references to other types, and
        /// returns the basic type. No information is lost by this operation.
        /// This method may modify this object as a side-effect, and will
        /// be called by the MIB loader.
        /// </summary>
        /// <param name="log">The MIB loader log</param>
        /// <exception cref="MibException">
        /// If an error occurred during initialization
        /// </exception>
        public void Initialize(MibLoaderLog log)
        {
            MibType type = null;

            this.value = this.value.Initialize(log, null);

            if (this.BaseSymbol != null)
            {
                // TODO: use utility function to retrieve correct base type here
                type = this.BaseSymbol.Type;

                if (type is SnmpTextualConvention convention)
                {
                    type = convention.Syntax;
                }

                if (type is SnmpObjectType type1)
                {
                    type = type1.Syntax;
                }
            }

            if (this.syntax != null)
            {
                this.syntax = this.syntax.Initialize(null, log);
            }

            if (this.writeSyntax != null)
            {
                this.writeSyntax = this.writeSyntax.Initialize(null, log);
            }

            this.requiredCells = this.requiredCells.Select(rc => rc.Initialize(log, type)).ToList();

            if (this.defaultValue != null)
            {
                this.defaultValue = this.defaultValue.Initialize(log, type);
            }
        }
示例#21
0
        /// <summary>
        /// Initializes the MIB type. This will remove all levels of
        /// indirection present, such as references to types or values. No
        /// information is lost by this operation. This method may modify
        /// this object as a side-effect, and will return the basic
        /// type.
        /// NOTE: This is an internal method that should
        /// only be called by the MIB loader.
        /// </summary>
        /// <param name="symbol">The MIB symbol containing this type</param>
        /// <param name="log">The MIB loader log</param>
        /// <returns>The basic MIB type</returns>
        public override MibType Initialize(MibSymbol symbol, MibLoaderLog log)
        {
            MibSymbol sym = this.GetSymbol(log);

            if (sym is MibTypeSymbol symb)
            {
                this.type = this.InitializeReference(symbol, log, symb);
                if (this.type == null)
                {
                    throw new MibException(this.location, "referenced symbol '" + sym.Name + "' contains undefined type");
                }

                return(this.type);
            }
            else if (sym == null)
            {
                throw new MibException(this.location, "undefined symbol '" + this.Name + "'");
            }
            else
            {
                throw new MibException(this.location, "referenced symbol '" + this.Name + "' is not a type");
            }
        }
示例#22
0
        /// <summary>
        /// Initializes the MIB type. This will remove all levels of
        /// indirection present, such as references to types or values. No
        /// information is lost by this operation. This method may modify
        /// this object as a side-effect, and will return the basic
        /// type.
        /// NOTE: This is an internal method that should
        /// only be called by the MIB loader.
        /// </summary>
        /// <param name="type">The MIB type</param>
        /// <param name="log">The MIB loader log</param>
        /// <exception cref="MibException">
        /// If an error is encountered during initialization
        /// </exception>
        public void Initialize(MibType type, MibLoaderLog log)
        {
            string message;

            if (this.lower != null)
            {
                this.lower.Initialize(log, type);
            }

            if (this.upper != null)
            {
                this.upper.Initialize(log, type);
            }

            if (this.location != null && !this.IsCompatible(type))
            {
                message = "Value range constraint not compatible with " +
                          "this type";
                log.AddWarning(this.location, message);
            }

            this.location = null;
        }
示例#23
0
 /// <summary>
 /// Initializes the MIB value. This will remove all levels of
 /// indirection present, such as references to other values. No
 /// value information is lost by this operation. This method may
 /// modify this object as a side-effect, and will return the basic
 /// value.
 /// NOTE: This is an internal method that should
 /// only be called by the MIB loader.
 /// </summary>
 /// <param name="log">The Mib Loader log</param>
 /// <param name="type">The value type</param>
 /// <returns>The MIB value</returns>
 public override MibValue Initialize(MibLoaderLog log, MibType type)
 {
     return(this);
 }
 /// <summary>
 /// Initializes the MIB type. This will remove all levels of
 /// indirection present, such as references to types or values. No
 /// information is lost by this operation. This method may modify
 /// this object as a side-effect, and will return the basic
 /// type.
 /// NOTE: This is an internal method that should
 /// only be called by the MIB loader.
 /// </summary>
 /// <param name="symbol">The MIB symbol containing this type</param>
 /// <param name="log">The MIB loader log</param>
 /// <returns>The basic MIB type</returns>
 /// <exception cref="MibException">
 /// If an error was encountered during the initialization
 /// </exception>
 public override MibType Initialize(MibSymbol symbol, MibLoaderLog log)
 {
     this.syntax = this.syntax.Initialize(symbol, log);
     return(this);
 }
示例#25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SequenceOfType"/> class.
 /// </summary>
 /// <param name="baseType">The sequence element type</param>
 /// <param name="constraint">The sequence constraint</param>
 public SequenceOfType(MibType baseType, IConstraint constraint) : this(true, baseType, constraint)
 {
 }
示例#26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SequenceOfType"/> class.
 /// </summary>
 /// <param name="baseType">The sequence element type</param>
 public SequenceOfType(MibType baseType) : this(true, baseType, null)
 {
 }
 /// <summary>
 /// Initializes the MIB type. This will remove all levels of
 /// indirection present, such as references to types or values. No
 /// information is lost by this operation. This method may modify
 /// this object as a side-effect.
 /// </summary>
 /// <remarks>
 /// This is an internal method that should
 /// only be called by the MIB loader.
 /// </remarks>
 /// <param name="type">The MIB type</param>
 /// <param name="log">The MIB loader log</param>
 /// <exception cref="MibException">If an error occurred during initialization</exception>
 public void Initialize(MibType type, MibLoaderLog log)
 {
     this.first.Initialize(type, log);
     this.second.Initialize(type, log);
 }
 /// <summary>
 /// Checks if the specified value is compatible with this type. A
 /// values is considered compatible with this type, it is compatible with
 /// both constraints
 /// </summary>
 /// <param name="type">The type to check</param>
 /// <returns>True if the value is compatible, false if not</returns>
 public bool IsCompatible(MibType type)
 {
     return(this.first.IsCompatible(type) &&
            this.second.IsCompatible(type));
 }
示例#29
0
 /// <summary>
 /// Checks if the specified type is compatible with this
 /// constraint.
 /// </summary>
 /// <param name="type">The type to check</param>
 /// <returns>True if the type is compatible, false if not</returns>
 public bool IsCompatible(MibType type)
 {
     return(type is SequenceOfType ||
            type is StringType);
 }
示例#30
0
 /// <summary>
 /// Checks if the specified type is compatible with this
 /// constraint.
 /// </summary>
 /// <param name="type">The type to check</param>
 /// <returns>True if the type is compatible, false if not</returns>
 public bool IsCompatible(MibType type)
 {
     return((type == null || this.lower == null || type.IsCompatible(this.lower)) &&
            (type == null || this.upper == null || type.IsCompatible(this.upper)));
 }