Vb item. Stores Oid => value pair for each value
Inheritance: AsnType, ICloneable
Exemplo n.º 1
0
 /// <summary>
 /// Copy constructor. Initialize class with cloned values from second class.
 /// </summary>
 /// <param name="second">Vb class to clone data from.</param>
 public Vb(Vb second)
     : this()
 {
     Set(second);
 }
Exemplo n.º 2
0
 /// <summary>
 /// SET class value from supplied Vb class
 /// </summary>
 /// <param name="value">Vb class to clone data from</param>
 public void Set(Vb value)
 {
     this._oid   = (Oid)value.Oid.Clone();
     this._value = (Oid)value.Value.Clone();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Copy constructor. Initialize class with cloned values from second class.
 /// </summary>
 /// <param name="second">Vb class to clone data from.</param>
 public Vb(Vb second)
     : this()
 {
     Set(second);
 }
Exemplo n.º 4
0
    /// <summary>
    /// Process a received SNMP SetRequest
    /// </summary>
    /// <param name="Ooid"></param>
    /// <param name="valuePair"></param>
    public void ProcessSetRequest(Oid Ooid, Vb valuePair)
    {

        switch (Ooid.ToString())
        {
            case "1.3.2.5.1":
                Debug.Log("SysUp set request -- error read only");
                break;
            case "1.3.2.5.2":
                Debug.Log("location set request -- error read only");
                break;
            case "1.3.2.5.3":
                metalGear.moveToX = int.Parse(valuePair.Value.ToString());
                Debug.Log("moveX set request");
                break;
            case "1.3.2.5.4":
                metalGear.moveToY = int.Parse(valuePair.Value.ToString());
                Debug.Log("moveY set request");
                break;
            case "1.3.2.5.5":
                metalGear.lookAt = (uint)int.Parse(valuePair.Value.ToString());
                Debug.Log("LookAt set request");
                break;
            /*case "1.3.2.5.6":
                Debug.Log("weapontable request");
                break;
                */
            case "1.3.2.5.7":
                Debug.Log("nukeState set request --read only");
                break;

            case "1.3.2.5.8":
                Debug.Log("nukeLaunch set request --read only");
                break;
            case "1.3.2.5.9":
                Debug.Log("radarTable request");
                break;
            case "1.3.2.5.10":
                Debug.Log("radarState set request --read only");
                break;
            case "1.3.2.5.11":
                Debug.Log("cameraTable request");
                break;
            case "1.3.2.5.12":
                metalGear.selectedCamera = (uint)int.Parse(valuePair.Value.ToString());
                Debug.Log("selectedCamera request");
                break;
            case "1.3.2.5.13":
                Debug.Log("bodyTable request");
                break;
            case "1.3.2.5.14":
                metalGear.selectedTarget = int.Parse(valuePair.Value.ToString());
                Debug.Log("selectedTarget set request");
                break;
            case "1.3.2.5.15":
                metalGear.selectdGun = int.Parse(valuePair.Value.ToString());
                Debug.Log("selectedGun set request");
                break;
            case "1.3.2.5.16":
                metalGear.attacking = int.Parse(valuePair.Value.ToString());
                Debug.Log("attacking request");
                break;
            case "1.3.2.5.17":
                Debug.Log("under attacking set request error - read only");
                break;
            default:
                Debug.Log("Wroing OID");
                responsePacket.Pdu.ErrorStatus = 1; // no error
                break;
        }

    }
Exemplo n.º 5
0
 /// <summary>
 /// SET class value from supplied Vb class
 /// </summary>
 /// <param name="value">Vb class to clone data from</param>
 public void Set(Vb value)
 {
     _oid   = (Oid)value.Oid.Clone();
     _value = (Oid)value.Value.Clone();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Encode Pdu class to BER byte buffer
        /// </summary>
        /// <remarks>
        /// Encodes the protocol data unit using the passed encoder and stores
        /// the results in the passed buffer. An exception is thrown if an
        /// error occurs with the encoding of the information.
        /// </remarks>
        /// <param name="buffer">The buffer to write the encoded information.</param>
        public override void encode(MutableByte buffer)
        {
            MutableByte tmpBuffer = new MutableByte();

            // if request id is 0, get a random value
            if (_requestId.Value == 0)
            {
                _requestId.SetRandom();
            }

            _requestId.encode(tmpBuffer);
            _errorStatus.encode(tmpBuffer);
            _errorIndex.encode(tmpBuffer);

            MutableByte tmpVbBuffer = new MutableByte();

            // if V2TRAP PDU type, add sysUpTime and trapObjectID OIDs before encoding VarBind

            if (Type == PduType.V2Trap || Type == PduType.Inform)
            {
                if (_vbs.Count == 0)
                {
                    // add sysUpTime and trapObjectID to the VbList
                    _vbs.Add(SnmpConstants.SysUpTime, _trapTimeStamp);
                    _vbs.Add(SnmpConstants.TrapObjectId, _trapObjectID);
                }
                else
                {
                    // Make sure user didn't manually add sysUpTime and trapObjectID values
                    // to the pdu

                    // if we have more then one item in the VarBinds array check for sysUpTime
                    if (_vbs.Count > 0)
                    {
                        // if the first Vb in the VarBinds array is not sysUpTime append it in the
                        // encoded byte array
                        if (!_vbs[0].Oid.Equals(SnmpConstants.SysUpTime))
                        {
                            Vb sysUpTimeVb = new Vb(SnmpConstants.SysUpTime, _trapTimeStamp);
                            _vbs.Insert(0, sysUpTimeVb);
                        }
                    }
                    // if we have 2 or more Vbs in the VarBinds array check for trapObjectID Vb
                    if (_vbs.Count > 1)
                    {
                        // if second Vb in the VarBinds array is not trapObjectId encode the value
                        if (!_vbs[1].Oid.Equals(SnmpConstants.TrapObjectId))
                        {
                            Vb trapObjectIdVb = new Vb(SnmpConstants.TrapObjectId, _trapObjectID);
                            _vbs.Insert(1, trapObjectIdVb);
                        }
                    }
                }
            }

            // encode variable bindings
            _vbs.encode(tmpBuffer);

            // Now encode the header for the PDU
            BuildHeader(buffer, (byte)Type, tmpBuffer.Length);
            buffer.Append(tmpBuffer);
        }
Exemplo n.º 7
0
 /// <summary>
 /// SNMP SET request
 /// </summary>
 /// <example>Set operation in SNMP version 1:
 /// <code>
 /// String snmpAgent = "10.10.10.1";
 /// String snmpCommunity = "private";
 /// SimpleSnmp snmp = new SimpleSnmp(snmpAgent, snmpCommunity);
 /// // Create a request Pdu
 /// List&lt;Vb&gt; vbList = new List&lt;Vb&gt;();
 /// Oid setOid = new Oid("1.3.6.1.2.1.1.1.0"); // sysDescr.0
 /// OctetString setValue = new OctetString("My personal toy");
 /// vbList.Add(new Vb(setOid, setValue));
 /// Dictionary&lt;Oid, AsnType&gt; result = snmp.Set(SnmpVersion.Ver1, list.ToArray());
 /// if( result == null ) {
 ///   Console.WriteLine("Request failed.");
 /// } else {
 ///   Console.WriteLine("Success!");
 /// }
 /// </code>
 /// 
 /// To use SNMP version 2, change snmp.Set() method call first parameter to SnmpVersion.Ver2.
 /// </example>
 /// <param name="version">SNMP protocol version number. Acceptable values are SnmpVersion.Ver1 and SnmpVersion.Ver2</param>
 /// <param name="vbs">Vb array containing Oid/AsnValue pairs for the SET operation</param>
 /// <returns>Result of the SNMP request in a dictionary format with Oid => AsnType values</returns>
 public Dictionary<Oid, AsnType> Set(SnmpVersion version, Vb[] vbs)
 {
     if (!Valid)
     {
         if (!_suppressExceptions)
         {
             throw new SnmpException("SimpleSnmp class is not valid.");
         }
         return null;
     }
     // function only works on SNMP version 1 and SNMP version 2 requests
     if (version != SnmpVersion.Ver1 && version != SnmpVersion.Ver2)
     {
         if (!_suppressExceptions)
         {
             throw new SnmpInvalidVersionException("SimpleSnmp support SNMP version 1 and 2 only.");
         }
         return null;
     }
     Pdu pdu = new Pdu(PduType.Set);
     foreach (Vb vb in vbs)
     {
         pdu.VbList.Add(vb);
     }
     return Set(version, pdu);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Faz o logging do resultado de um SNMPRequest
 /// </summary>
 internal void Log(Vb item)
 {
     this.Log(item.Value.ToString(), LogType.RESPONSE);
 }
Exemplo n.º 9
-1
 /// <summary>
 /// SET class value from supplied Vb class
 /// </summary>
 /// <param name="value">Vb class to clone data from</param>
 public void Set(Vb value)
 {
     this._oid = (Oid)value.Oid.Clone();
     this._value = (Oid)value.Value.Clone();
 }