internal object Decode(Variable v) { if (_syntax is IntegerType) { Integer32 i = v.Data as Integer32; if (i == null || (_syntax as IntegerType).IsEnumeration) { return(null); } else if (_displayHint != null) { return(_displayHint.Decode(i.ToInt32())); } else { return(i.ToInt32()); } } else if (_syntax is UnsignedType) { Integer32 i = v.Data as Integer32; if (i == null) { return(null); } else if (_displayHint != null) { return(_displayHint.Decode(i.ToInt32())); } else { return(i.ToInt32()); } } else if (_syntax is OctetStringType) { OctetString o = v.Data as OctetString; if (o == null) { return(null); } else { // TODO: Follow the format specifier for octet strings. return(null); } } else { return(null); } }
public void TestToInt32() { const int result = -26955; byte[] expected = new byte[] {0x96, 0xB5}; Integer32 test = new Integer32(expected); Assert.AreEqual(result, test.ToInt32()); Assert.AreEqual(255, new Integer32(new byte[] {0x00, 0xFF}).ToInt32()); }
public void TestCreateInteger() { byte[] expected = new byte[] { 0x02, 0x01, 0x00 }; ISnmpData data = DataFactory.CreateSnmpData(expected); Assert.Equal(SnmpType.Integer32, data.TypeCode); Integer32 i = (Integer32)data; Assert.Equal(0, i.ToInt32()); }
public void TestNegative() { const int i = -2147418240; Integer32 data = new Integer32(i); byte[] bytes = data.ToBytes(); Integer32 other = (Integer32)DataFactory.CreateSnmpData(bytes); Assert.Equal(i, other.ToInt32()); }
public void TestToInt32() { const int result = -26955; byte[] expected = new byte[] { 0x96, 0xB5 }; Integer32 test = new Integer32(expected); Assert.Equal(result, test.ToInt32()); Assert.Equal(255, new Integer32(new byte[] { 0x00, 0xFF }).ToInt32()); }
public void TestConstructor() { Integer32 test = new Integer32(100); Assert.AreEqual(100, test.ToInt32()); Integer32 test2 = new Integer32(new byte[] {0x00}); Assert.AreEqual(0, test2.ToInt32()); Integer32 test3 = new Integer32(new byte[] {0xFF}); Assert.AreEqual(-1, test3.ToInt32()); }
public void TestConstructor() { Integer32 test = new Integer32(100); Assert.AreEqual(100, test.ToInt32()); Assert.Throws<InvalidCastException>(() => test.ToErrorCode()); Assert.Throws<InvalidCastException>(() => new Integer32(-1).ToErrorCode()); Integer32 test2 = new Integer32(new byte[] {0x00}); Assert.AreEqual(0, test2.ToInt32()); Integer32 test3 = new Integer32(new byte[] {0xFF}); Assert.AreEqual(-1, test3.ToInt32()); }
public void TestConstructor() { Integer32 test = new Integer32(100); Assert.AreEqual(100, test.ToInt32()); Integer32 test2 = new Integer32(new byte[] { 0x00 }); Assert.AreEqual(0, test2.ToInt32()); Integer32 test3 = new Integer32(new byte[] { 0xFF }); Assert.AreEqual(-1, test3.ToInt32()); }
/// <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); }
public void TestConstructor() { Integer32 test = new Integer32(100); Assert.Equal(100, test.ToInt32()); Assert.Throws <InvalidCastException>(() => test.ToErrorCode()); Assert.Throws <InvalidCastException>(() => new Integer32(-1).ToErrorCode()); Integer32 test2 = new Integer32(new byte[] { 0x00 }); Assert.Equal(0, test2.ToInt32()); Integer32 test3 = new Integer32(new byte[] { 0xFF }); Assert.Equal(-1, test3.ToInt32()); }