Inheritance: UInteger32, System.ICloneable
Beispiel #1
0
 /// <summary>
 /// Return difference between two Counter32 values taking counter roll-over into account.
 /// </summary>
 /// <param name="first">First or older value</param>
 /// <param name="second">Second or newer value</param>
 /// <returns>Difference between the two values</returns>
 public static UInt32 Diff(Counter32 first, Counter32 second)
 {
     UInt32 f = first.Value;
     UInt32 s = second.Value;
     UInt32 res = 0;
     if (s > f)
     {
         // in case of a roll-over event
         res = (UInt32.MaxValue - f) + s;
     }
     else
     {
         res = s - f;
     }
     return res;
 }
Beispiel #2
0
        /// <summary>
        ///     Return difference between two Counter32 values taking counter roll-over into account.
        /// </summary>
        /// <param name="first">First or older value</param>
        /// <param name="second">Second or newer value</param>
        /// <returns>Difference between the two values</returns>
        public static uint Diff(Counter32 first, Counter32 second)
        {
            var  f   = first.Value;
            var  s   = second.Value;
            uint res = 0;

            if (s > f)
            {
                res = uint.MaxValue - f + s;
            }
            else
            {
                res = s - f;
            }
            return(res);
        }
        /// <summary>
        /// Return SNMP type object of the type specified by name. Supported variable types are:
        /// * <see cref="Integer32"/>
        /// * <see cref="Counter32"/>
        /// * <see cref="Gauge32"/>
        /// * <see cref="Counter64"/>
        /// * <see cref="TimeTicks"/>
        /// * <see cref="OctetString"/>
        /// * <see cref="IpAddress"/>
        /// * <see cref="Oid"/>
        /// * <see cref="Null"/>
        /// </summary>
        /// <param name="name">Name of the object type</param>
        /// <returns>New <see cref="AsnType"/> object.</returns>
        public static AsnType GetSyntaxObject(string name)
        {
            AsnType obj = null;

            if (name == "Integer32")
            {
                obj = new Integer32();
            }
            else if (name == "Counter32")
            {
                obj = new Counter32();
            }
            else if (name == "Gauge32")
            {
                obj = new Gauge32();
            }
            else if (name == "Counter64")
            {
                obj = new Counter64();
            }
            else if (name == "TimeTicks")
            {
                obj = new TimeTicks();
            }
            else if (name == "OctetString")
            {
                obj = new OctetString();
            }
            else if (name == "IpAddress")
            {
                obj = new IpAddress();
            }
            else if (name == "Oid")
            {
                obj = new Oid();
            }
            else if (name == "Null")
            {
                obj = new Null();
            }
            else
            {
                throw new ArgumentException("Invalid value type name");
            }

            return(obj);
        }
Beispiel #4
0
        /// <summary>
        /// Return SNMP type object of the type specified by name. Supported variable types are:
        /// <see cref="Integer32"/>, <see cref="Counter32"/>, <see cref="Gauge32"/>, <see cref="Counter64"/>,
        /// <see cref="TimeTicks"/>, <see cref="OctetString"/>, <see cref="IpAddress"/>, <see cref="Oid"/>, and
        /// <see cref="Null"/>.
        ///
        /// Type names are the same as support class names compared without case sensitivity (e.g. Integer == INTEGER).
        /// </summary>
        /// <param name="name">Name of the object type (not case sensitive)</param>
        /// <returns>New <see cref="AsnType"/> object.</returns>
        public static AsnType GetSyntaxObject(string name)
        {
            AsnType obj = null;

            if (name.ToUpper().Equals("INTEGER32") || name.ToUpper().Equals("INTEGER"))
            {
                obj = new Integer32();
            }
            else if (name.ToUpper().Equals("COUNTER32"))
            {
                obj = new Counter32();
            }
            else if (name.ToUpper().Equals("GAUGE32"))
            {
                obj = new Gauge32();
            }
            else if (name.ToUpper().Equals("COUNTER64"))
            {
                obj = new Counter64();
            }
            else if (name.ToUpper().Equals("TIMETICKS"))
            {
                obj = new TimeTicks();
            }
            else if (name.ToUpper().Equals("OCTETSTRING"))
            {
                obj = new OctetString();
            }
            else if (name.ToUpper().Equals("IPADDRESS"))
            {
                obj = new IpAddress();
            }
            else if (name.ToUpper().Equals("OID"))
            {
                obj = new Oid();
            }
            else if (name.ToUpper().Equals("NULL"))
            {
                obj = new Null();
            }
            else
            {
                throw new ArgumentException("Invalid value type name");
            }

            return(obj);
        }
Beispiel #5
0
        /// <summary>
        /// Return difference between two Counter32 values taking counter roll-over into account.
        /// </summary>
        /// <param name="first">First or older value</param>
        /// <param name="second">Second or newer value</param>
        /// <returns>Difference between the two values</returns>
        public static UInt32 Diff(Counter32 first, Counter32 second)
        {
            UInt32 f   = first.Value;
            UInt32 s   = second.Value;
            UInt32 res = 0;

            if (s > f)
            {
                // in case of a roll-over event
                res = (UInt32.MaxValue - f) + s;
            }
            else
            {
                res = s - f;
            }
            return(res);
        }
Beispiel #6
0
        /// <summary>
        /// Return difference between two Counter32 values taking counter roll-over into account.
        /// </summary>
        /// <param name="first">First or older value</param>
        /// <param name="second">Second or newer value</param>
        /// <returns>Difference between the two values</returns>
        public static uint Diff(Counter32 first, Counter32 second)
        {
            uint f   = first.Value;
            uint s   = second.Value;
            uint res = 0;

            if (s > f)
            {
                // in case of a roll-over event
                res = (uint.MaxValue - f) + s;
            }
            else
            {
                res = s - f;
            }
            return(res);
        }
Beispiel #7
0
        /// <summary>Used to create correct variable type object for the specified encoded type</summary>
        /// <param name="asnType">ASN.1 type code</param>
        /// <returns>A new object matching type supplied or null if type was not recognized.</returns>
        public static AsnType GetSyntaxObject(SMIDataTypeCode asnType)
        {
            AsnType obj = null;
            if (asnType == SMIDataTypeCode.Integer)
                obj = new Integer32 ();
            else if (asnType == SMIDataTypeCode.Counter32)
                obj = new Counter32 ();
            else if (asnType == SMIDataTypeCode.Gauge32)
                obj = new Gauge32 ();
            else if (asnType == SMIDataTypeCode.Counter64)
                obj = new Counter64 ();
            else if (asnType == SMIDataTypeCode.TimeTicks)
                obj = new TimeTicks ();
            else if (asnType == SMIDataTypeCode.OctetString)
                obj = new OctetString ();
            else if (asnType == SMIDataTypeCode.Opaque)
                obj = new Opaque ();
            else if (asnType == SMIDataTypeCode.IPAddress)
                obj = new IpAddress ();
            else if (asnType == SMIDataTypeCode.ObjectId)
                obj = new Oid ();
            else if (asnType == SMIDataTypeCode.PartyClock)
                obj = new V2PartyClock ();
            else if (asnType == SMIDataTypeCode.NoSuchInstance)
                obj = new NoSuchInstance ();
            else if (asnType == SMIDataTypeCode.NoSuchObject)
                obj = new NoSuchObject ();
            else if (asnType == SMIDataTypeCode.EndOfMibView)
                obj = new EndOfMibView ();
            else if (asnType == SMIDataTypeCode.Null)
            {
                obj = new Null ();
            }

            return obj;
        }
Beispiel #8
0
        /// <summary>
        /// Return SNMP type object of the type specified by name. Supported variable types are:
        /// * <see cref="Integer32"/>
        /// * <see cref="Counter32"/>
        /// * <see cref="Gauge32"/>
        /// * <see cref="Counter64"/>
        /// * <see cref="TimeTicks"/>
        /// * <see cref="OctetString"/>
        /// * <see cref="IpAddress"/>
        /// * <see cref="Oid"/>
        /// * <see cref="Null"/>
        /// </summary>
        /// <param name="name">Name of the object type</param>
        /// <returns>New <see cref="AsnType"/> object.</returns>
        public static AsnType GetSyntaxObject(string name)
        {
            AsnType obj = null;
            if (name == "Integer32")
                obj = new Integer32();
            else if (name == "Counter32")
                obj = new Counter32();
            else if (name == "Gauge32")
                obj = new Gauge32();
            else if (name == "Counter64")
                obj = new Counter64();
            else if (name == "TimeTicks")
                obj = new TimeTicks();
            else if (name == "OctetString")
                obj = new OctetString();
            else if (name == "IpAddress")
                obj = new IpAddress();
            else if (name == "Oid")
                obj = new Oid();
            else if (name == "Null")
                obj = new Null();
            else
                throw new ArgumentException("Invalid value type name");

            return obj;
        }
Beispiel #9
0
        /// <summary>Used to create correct variable type object for the specified encoded type</summary>
        /// <param name="asnType">ASN.1 type code</param>
        /// <returns>A new object matching type supplied or null if type was not recognized.</returns>
        public static AsnType GetSyntaxObject(byte asnType)
        {
            AsnType obj = null;
            if (asnType == SnmpConstants.SMI_INTEGER)
                obj = new Integer32();
            else if (asnType == SnmpConstants.SMI_COUNTER32)
                obj = new Counter32();
            else if (asnType == SnmpConstants.SMI_GAUGE32)
                obj = new Gauge32();
            else if (asnType == SnmpConstants.SMI_COUNTER64)
                obj = new Counter64();
            else if (asnType == SnmpConstants.SMI_TIMETICKS)
                obj = new TimeTicks();
            else if (asnType == SnmpConstants.SMI_STRING)
                obj = new OctetString();
            else if (asnType == SnmpConstants.SMI_OPAQUE)
                obj = new Opaque();
            else if (asnType == SnmpConstants.SMI_IPADDRESS)
                obj = new IpAddress();
            else if (asnType == SnmpConstants.SMI_OBJECTID)
                obj = new Oid();
            else if (asnType == SnmpConstants.SMI_PARTY_CLOCK)
                obj = new V2PartyClock();
            else if (asnType == SnmpConstants.SMI_NOSUCHINSTANCE)
                obj = new NoSuchInstance();
            else if (asnType == SnmpConstants.SMI_NOSUCHOBJECT)
                obj = new NoSuchObject();
            else if (asnType == SnmpConstants.SMI_ENDOFMIBVIEW)
                obj = new EndOfMibView();
            else if (asnType == SnmpConstants.SMI_NULL)
            {
                obj = new Null();
            }

            return obj;
        }
        /// <summary>Used to create correct variable type object for the specified encoded type</summary>
        /// <param name="asnType">ASN.1 type code</param>
        /// <returns>A new object matching type supplied or null if type was not recognized.</returns>
        public static AsnType GetSyntaxObject(byte asnType)
        {
            AsnType obj = null;

            if (asnType == SnmpConstants.SMI_INTEGER)
            {
                obj = new Integer32();
            }
            else if (asnType == SnmpConstants.SMI_COUNTER32)
            {
                obj = new Counter32();
            }
            else if (asnType == SnmpConstants.SMI_GAUGE32)
            {
                obj = new Gauge32();
            }
            else if (asnType == SnmpConstants.SMI_COUNTER64)
            {
                obj = new Counter64();
            }
            else if (asnType == SnmpConstants.SMI_TIMETICKS)
            {
                obj = new TimeTicks();
            }
            else if (asnType == SnmpConstants.SMI_STRING)
            {
                obj = new OctetString();
            }
            else if (asnType == SnmpConstants.SMI_OPAQUE)
            {
                obj = new Opaque();
            }
            else if (asnType == SnmpConstants.SMI_IPADDRESS)
            {
                obj = new IpAddress();
            }
            else if (asnType == SnmpConstants.SMI_OBJECTID)
            {
                obj = new Oid();
            }
            else if (asnType == SnmpConstants.SMI_PARTY_CLOCK)
            {
                obj = new V2PartyClock();
            }
            else if (asnType == SnmpConstants.SMI_NOSUCHINSTANCE)
            {
                obj = new NoSuchInstance();
            }
            else if (asnType == SnmpConstants.SMI_NOSUCHOBJECT)
            {
                obj = new NoSuchObject();
            }
            else if (asnType == SnmpConstants.SMI_ENDOFMIBVIEW)
            {
                obj = new EndOfMibView();
            }
            else if (asnType == SnmpConstants.SMI_NULL)
            {
                obj = new Null();
            }

            return(obj);
        }
Beispiel #11
0
 /// <summary>Constructor</summary>
 /// <param name="second">Copy parameter</param>
 public Counter32(Counter32 second) : base(second)
 {
     _asnType = SnmpConstants.SMI_COUNTER32;
 }
Beispiel #12
0
        /// <summary>Used to create correct variable type object for the specified encoded type</summary>
        /// <param name="asnType">ASN.1 type code</param>
        /// <returns>A new object matching type supplied or null if type was not recognized.</returns>
        public static AsnType GetSyntaxObject(ESMIDataTypeCode asnType)
        {
            AsnType obj = null;

            if (asnType == ESMIDataTypeCode.Integer)
            {
                obj = new Integer32();
            }
            else if (asnType == ESMIDataTypeCode.Counter32)
            {
                obj = new Counter32();
            }
            else if (asnType == ESMIDataTypeCode.Gauge32)
            {
                obj = new Gauge32();
            }
            else if (asnType == ESMIDataTypeCode.Counter64)
            {
                obj = new Counter64();
            }
            else if (asnType == ESMIDataTypeCode.TimeTicks)
            {
                obj = new TimeTicks();
            }
            else if (asnType == ESMIDataTypeCode.OctetString)
            {
                obj = new OctetString();
            }
            else if (asnType == ESMIDataTypeCode.Opaque)
            {
                obj = new Opaque();
            }
            else if (asnType == ESMIDataTypeCode.IPAddress)
            {
                obj = new IpAddress();
            }
            else if (asnType == ESMIDataTypeCode.ObjectId)
            {
                obj = new Oid();
            }
            else if (asnType == ESMIDataTypeCode.PartyClock)
            {
                obj = new V2PartyClock();
            }
            else if (asnType == ESMIDataTypeCode.NoSuchInstance)
            {
                obj = new NoSuchInstance();
            }
            else if (asnType == ESMIDataTypeCode.NoSuchObject)
            {
                obj = new NoSuchObject();
            }
            else if (asnType == ESMIDataTypeCode.EndOfMibView)
            {
                obj = new EndOfMibView();
            }
            else if (asnType == ESMIDataTypeCode.Null)
            {
                obj = new Null();
            }

            return(obj);
        }
Beispiel #13
0
        /// <summary>
        /// Return SNMP type object of the type specified by name. Supported variable types are:
        /// <see cref="Integer32"/>, <see cref="Counter32"/>, <see cref="Gauge32"/>, <see cref="Counter64"/>,
        /// <see cref="TimeTicks"/>, <see cref="OctetString"/>, <see cref="IpAddress"/>, <see cref="Oid"/>, and
        /// <see cref="Null"/>.
        /// 
        /// Type names are the same as support class names compared without case sensitivity (e.g. Integer == INTEGER).
        /// </summary>
        /// <param name="name">Name of the object type (not case sensitive)</param>
        /// <returns>New <see cref="AsnType"/> object.</returns>
        public static AsnType GetSyntaxObject(string name)
        {
            AsnType obj = null;
            if (name.ToUpper ().Equals ("INTEGER32") || name.ToUpper ().Equals ("INTEGER"))
                obj = new Integer32 ();
            else if (name.ToUpper ().Equals ("COUNTER32"))
                obj = new Counter32 ();
            else if (name.ToUpper ().Equals ("GAUGE32"))
                obj = new Gauge32 ();
            else if (name.ToUpper ().Equals ("COUNTER64"))
                obj = new Counter64 ();
            else if (name.ToUpper ().Equals ("TIMETICKS"))
                obj = new TimeTicks ();
            else if (name.ToUpper ().Equals ("OCTETSTRING"))
                obj = new OctetString ();
            else if (name.ToUpper ().Equals ("IPADDRESS"))
                obj = new IpAddress ();
            else if (name.ToUpper ().Equals ("OID"))
                obj = new Oid ();
            else if (name.ToUpper ().Equals ("NULL"))
                obj = new Null ();
            else
                throw new ArgumentException ("Invalid value type name");

            return obj;
        }
Beispiel #14
0
 /// <summary>Constructor</summary>
 /// <param name="second">Copy parameter</param>
 public Counter32(Counter32 second)
     : base(second)
 {
     _asnType = SnmpConstants.SMI_COUNTER32;
 }