public void TestConstructor()
        {
            byte[] buffer2 = new byte[] {01, 44};
            Gauge32 c2 = new Gauge32(buffer2);
            Assert.AreEqual(300, c2.ToUInt32());

            
            byte[] buffer1 = new byte[] {13};
            Gauge32 c1 = new Gauge32(buffer1);
            Assert.AreEqual(13, c1.ToUInt32());
            
            byte[] buffer3 = new byte[] {1, 17, 112};
            Gauge32 c3 = new Gauge32(buffer3);
            Assert.AreEqual(70000, c3.ToUInt32());
            
            byte[] buffer4 = new byte[] {1, 201, 195, 128};
            Gauge32 c4 = new Gauge32(buffer4);
            Assert.AreEqual(30000000, c4.ToUInt32());
            
            byte[] buffer5 = new byte[] {0, 255, 255, 255, 255};
            Gauge32 c5 = new Gauge32(buffer5);
            Assert.AreEqual(uint.MaxValue, c5.ToUInt32());
            
            byte[] buffer0 = new byte[] {0};
            Gauge32 c0 = new Gauge32(buffer0);
            Assert.AreEqual(uint.MinValue, c0.ToUInt32());
        }
        public void TestConstructor()
        {
            byte[]  buffer2 = new byte[] { 01, 44 };
            Gauge32 c2      = new Gauge32(buffer2);

            Assert.AreEqual(300, c2.ToUInt32());


            byte[]  buffer1 = new byte[] { 13 };
            Gauge32 c1      = new Gauge32(buffer1);

            Assert.AreEqual(13, c1.ToUInt32());

            byte[]  buffer3 = new byte[] { 1, 17, 112 };
            Gauge32 c3      = new Gauge32(buffer3);

            Assert.AreEqual(70000, c3.ToUInt32());

            byte[]  buffer4 = new byte[] { 1, 201, 195, 128 };
            Gauge32 c4      = new Gauge32(buffer4);

            Assert.AreEqual(30000000, c4.ToUInt32());

            byte[]  buffer5 = new byte[] { 0, 255, 255, 255, 255 };
            Gauge32 c5      = new Gauge32(buffer5);

            Assert.AreEqual(uint.MaxValue, c5.ToUInt32());

            byte[]  buffer0 = new byte[] { 0 };
            Gauge32 c0      = new Gauge32(buffer0);

            Assert.AreEqual(uint.MinValue, c0.ToUInt32());
        }
Beispiel #3
0
        /// <summary>
        /// Returns two LONG values, in and out octets for plotting.
        /// </summary>
        /// <param name="interfaceIndex"></param>
        /// <returns></returns>
        private long[] getInterfaceOctets(int interfaceIndex)
        {
            // Where our SNMP results are going.
            List <Variable> oidResults = new List <Variable>();

            ObjectIdentifier oidSpeed     = new ObjectIdentifier(".1.3.6.1.2.1.2.2.1.5." + interfaceIndex);
            ObjectIdentifier oidType      = new ObjectIdentifier(".1.3.6.1.2.1.2.2.1.3." + interfaceIndex);
            ObjectIdentifier oidInOctets  = new ObjectIdentifier(".1.3.6.1.2.1.2.2.1.10. " + interfaceIndex);
            ObjectIdentifier oidOutOctets = new ObjectIdentifier(".1.3.6.1.2.1.2.2.1.16." + interfaceIndex);

            // OID's we're going to retrieve.
            List <Variable> oidList = new List <Variable>();

            oidList.Add(new Variable(oidSpeed));
            oidList.Add(new Variable(oidType));
            oidList.Add(new Variable(oidInOctets));
            oidList.Add(new Variable(oidOutOctets));

            long[] returnValue = new long[3];

            oidResults = snmp.GetOidValues(oidList);

            Integer32 vIfType = (Integer32)oidResults.Find(o => o.Id == oidType).Data;
            int       dIfType = vIfType.ToInt32();

            Gauge32  guageIfSpeed = (Gauge32)oidResults.Find(o => o.Id == oidSpeed).Data;
            Variable vInOctets    = oidResults.Find(o => o.Id == oidInOctets);
            Variable vOutOctets   = oidResults.Find(o => o.Id == oidOutOctets);

            if (dIfType != 94 && dIfType != 117 && dIfType != 6 && dIfType != 131)
            {
                return new long[] { 0, 0, 0 }
            }
            ;

            if (vInOctets.Data.TypeCode == SnmpType.NoSuchInstance || vOutOctets.Data.TypeCode == SnmpType.NoSuchInstance)
            {
                return(new long[] { 0, 0, 0 });
            }
            Counter32 counterInOctets  = (Counter32)vInOctets.Data;
            Counter32 counterOutOctets = (Counter32)vOutOctets.Data;

            returnValue[0] = Convert.ToInt64(guageIfSpeed.ToUInt32());
            returnValue[1] = Convert.ToInt64(counterInOctets.ToString());
            returnValue[2] = Convert.ToInt64(counterOutOctets.ToString());

            return(returnValue);
        }