Example #1
0
 public GetRequestPdu(int requestId, ErrorCode errorStatus, int errorIndex, IList<Variable> variables)
 {
     RequestId = new Integer32(requestId);
     ErrorStatus = new Integer32((int)errorStatus);
     ErrorIndex = new Integer32(errorIndex);
     Variables = variables;
     _varbindSection = Variable.Transform(variables);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SetRequestPdu"/> class.
 /// </summary>
 /// <param name="stream">The stream.</param>
 public SetRequestPdu(Stream stream)
 {
     RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorStatus = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorIndex = (Integer32)DataFactory.CreateSnmpData(stream);
     _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
     Variables = Variable.Transform(_varbindSection);
 }
 /// <summary>
 /// Creates a <see cref="InformRequestPdu"/> instance for discovery.
 /// </summary>
 /// <param name="requestId">The request id.</param>
 public InformRequestPdu(int requestId)
 {
     Enterprise = null;
     RequestId = new Integer32(requestId);
     _time = new TimeTicks(0);
     Variables = new List<Variable>();
     _varbindSection = Variable.Transform(Variables);
 }
 /// <summary>
 /// Creates a <see cref="SetRequestPdu"/> instance with all contents.
 /// </summary>
 /// <param name="requestId">The request id.</param>
 /// <param name="errorStatus">Error status</param>
 /// <param name="errorIndex">Error index</param>
 /// <param name="variables">Variables</param>
 private SetRequestPdu(Integer32 requestId, Integer32 errorStatus, Integer32 errorIndex, IList<Variable> variables)
 {
     RequestId = requestId;
     ErrorStatus = errorStatus;
     ErrorIndex = errorIndex;
     Variables = variables;
     _varbindSection = Variable.Transform(Variables);
 }
 /// <summary>
 /// Creates a <see cref="ResponsePdu"/> with all contents.
 /// </summary>
 /// <param name="requestId">The request ID.</param>
 /// <param name="errorStatus">Error status.</param>
 /// <param name="errorIndex">Error index.</param>
 /// <param name="variables">Variables.</param>
 public ResponsePdu(int requestId, ErrorCode errorStatus, int errorIndex, IList<Variable> variables)
 {
     RequestId = new Integer32(requestId);
     ErrorStatus = new Integer32((int)errorStatus);
     ErrorIndex = new Integer32(errorIndex);
     Variables = variables;
     _varbindSection = Variable.Transform(variables);
     ////_raw = ByteTool.ParseItems(_sequenceNumber, _errorStatus, _errorIndex, _varbindSection);
 }
 private GetBulkRequestPdu(Integer32 requestId, Integer32 nonRepeaters, Integer32 maxRepetitions, IList<Variable> variables)
 {
     RequestId = requestId;
     ErrorStatus = nonRepeaters;
     ErrorIndex = maxRepetitions;
     Variables = variables;
     _varbindSection = Variable.Transform(variables);
     ////_raw = ByteTool.ParseItems(_seq, _nonRepeaters, _maxRepetitions, _varbindSection);
 }
 private GetNextRequestPdu(Integer32 requestId, Integer32 errorStatus, Integer32 errorIndex, IList<Variable> variables)
 {
     RequestId = requestId;
     ErrorStatus = errorStatus;
     ErrorIndex = errorIndex;
     Variables = variables;
     _varbindSection = Variable.Transform(variables);
     ////_raw = ByteTool.ParseItems(_seq, _errorStatus, _errorIndex, _varbindSection);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResponsePdu"/> class.
 /// </summary>
 /// <param name="stream">The stream.</param>
 public ResponsePdu(Stream stream)
 {
     RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorStatus = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorIndex = (Integer32)DataFactory.CreateSnmpData(stream);
     _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
     Variables = Variable.Transform(_varbindSection);
     ////_raw = ByteTool.ParseItems(_sequenceNumber, _errorStatus, _errorIndex, _varbindSection);
     ////Debug.Assert(length >= _raw.Length, "length not match");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetBulkRequestPdu"/> class.
 /// </summary>
 /// <param name="stream">The stream.</param>
 public GetBulkRequestPdu(Stream stream)
 {
     RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorStatus = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorIndex = (Integer32)DataFactory.CreateSnmpData(stream);
     _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
     Variables = Variable.Transform(_varbindSection);
     ////_raw = ByteTool.ParseItems(_seq, _nonRepeaters, _maxRepetitions, _varbindSection);
     ////Debug.Assert(length >= _raw.Length, "length not match");
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Scope"/> class.
 /// </summary>
 /// <param name="data">The data.</param>
 public Scope(Sequence data)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     
     ContextEngineId = (OctetString)data[0];
     ContextName = (OctetString)data[1];
     Pdu = (ISnmpPdu)data[2];
 }
Example #11
0
 public TrapV2Pdu(int requestId, ObjectIdentifier enterprise, uint time, IList<Variable> variables)
 {
     Enterprise = enterprise;
     RequestId = new Integer32(requestId);
     _time = new TimeTicks(time);
     Variables = variables;
     IList<Variable> full = new List<Variable>(variables);
     full.Insert(0, new Variable(new uint[] { 1, 3, 6, 1, 2, 1, 1, 3, 0 }, _time));
     full.Insert(1, new Variable(new uint[] { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }, Enterprise));
     _varbindSection = Variable.Transform(full);
 }
 public InformRequestPdu(int requestId, ObjectIdentifier enterprise, uint time, IList<Variable> variables)
 {
     Enterprise = enterprise;
     RequestId = new Integer32(requestId);
     _time = new TimeTicks(time);
     Variables = variables;
     IList<Variable> full = new List<Variable>(variables);
     full.Insert(0, new Variable(new uint[] { 1, 3, 6, 1, 2, 1, 1, 3, 0 }, _time));
     full.Insert(1, new Variable(new uint[] { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }, Enterprise));
     _varbindSection = Variable.Transform(full);
     ////_raw = ByteTool.ParseItems(_seq, new Integer32(0), new Integer32(0), _varbindSection);
 }        
Example #13
0
        /// <summary>
        /// Creates a <see cref="ResponsePdu"/> with all contents.
        /// </summary>
        /// <param name="requestId">The request ID.</param>
        /// <param name="errorStatus">Error status.</param>
        /// <param name="errorIndex">Error index.</param>
        /// <param name="variables">Variables.</param>
        public ResponsePdu(int requestId, ErrorCode errorStatus, int errorIndex, IList<Variable> variables)
        {
            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }

            RequestId = new Integer32(requestId);
            ErrorStatus = new Integer32((int)errorStatus);
            ErrorIndex = new Integer32(errorIndex);
            Variables = variables;
            _varbindSection = Variable.Transform(variables);
        }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReportPdu"/> class.
 /// </summary>        
 /// <param name="stream">The stream.</param>
 public ReportPdu(Stream stream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     
     RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorStatus = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorIndex = (Integer32)DataFactory.CreateSnmpData(stream);
     _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
     Variables = Variable.Transform(_varbindSection);
 }
        /// <summary>
        /// Creates a <see cref="GetNextRequestPdu"/> with all contents.
        /// </summary>
        /// <param name="requestId">The request id.</param>
        /// <param name="variables">Variables</param>
        public GetNextRequestPdu(int requestId, IList<Variable> variables)
        {
            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }

            RequestId = new Integer32(requestId);
            ErrorStatus = Integer32.Zero;
            ErrorIndex = Integer32.Zero;
            Variables = variables;
            _varbindSection = Variable.Transform(variables);
        }
Example #16
0
        /// <summary>
        /// Creates a <see cref="GetBulkRequestPdu"/> with all contents.
        /// </summary>
        /// <param name="requestId">The request id.</param>
        /// <param name="nonRepeaters">Non-repeaters.</param>
        /// <param name="maxRepetitions">Max repetitions.</param>
        /// <param name="variables">Variables.</param>
        public GetBulkRequestPdu(int requestId, int nonRepeaters, int maxRepetitions, IList<Variable> variables)
        {
            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }

            RequestId = new Integer32(requestId);
            ErrorStatus = new Integer32(nonRepeaters);
            ErrorIndex = new Integer32(maxRepetitions);
            Variables = variables;
            _varbindSection = Variable.Transform(variables);
        }
Example #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetBulkRequestPdu"/> class.
        /// </summary>
        /// <param name="length">The length data.</param>
        /// <param name="stream">The stream.</param>
        public GetBulkRequestPdu(Tuple<int, byte[]> length, Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
            ErrorStatus = (Integer32)DataFactory.CreateSnmpData(stream);
            ErrorIndex = (Integer32)DataFactory.CreateSnmpData(stream);
            _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
            Variables = Variable.Transform(_varbindSection);
            _length = length.Item2;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InformRequestPdu"/> class.
 /// </summary>    
 /// <param name="stream">The stream.</param>
 public InformRequestPdu(Stream stream)
 {
     RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorStatus = (Integer32)DataFactory.CreateSnmpData(stream);
     ErrorIndex = (Integer32)DataFactory.CreateSnmpData(stream);
     _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
     Variables = Variable.Transform(_varbindSection);
     _time = (TimeTicks)Variables[0].Data;
     Variables.RemoveAt(0);
     Enterprise = (ObjectIdentifier)Variables[0].Data;
     Variables.RemoveAt(0);
     ////_raw = ByteTool.ParseItems(_seq, _errorStatus, _errorIndex, _varbindSection);
     ////Debug.Assert(length >= _raw.Length, "length not match");
 }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Header"/> class.
        /// </summary>
        /// <param name="data">The data.</param>
        public Header(ISnmpData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            _container = (Sequence)data;
            _messageId = (Integer32)_container[0];
            _maxSize = (Integer32)_container[1];
            _flags = (OctetString)_container[2];
            SecurityLevel = _flags.ToLevels();
            _securityModel = (Integer32)_container[3];
        }
Example #20
0
        public TrapV2Pdu(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            
            RequestId = (Integer32)DataFactory.CreateSnmpData(stream); // request
#pragma warning disable 168
            Integer32 temp1 = (Integer32)DataFactory.CreateSnmpData(stream); // 0
            Integer32 temp2 = (Integer32)DataFactory.CreateSnmpData(stream); // 0
#pragma warning restore 168
            _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
            Variables = Variable.Transform(_varbindSection); // v[0] is timestamp. v[1] oid, v[2] value.
            _time = (TimeTicks)Variables[0].Data;
            Variables.RemoveAt(0);
            Enterprise = (ObjectIdentifier)Variables[0].Data;
            Variables.RemoveAt(0);
        }
        public InformRequestPdu(int requestId, ObjectIdentifier enterprise, uint time, IList<Variable> variables)
        {
            if (enterprise == null)
            {
                throw new ArgumentNullException("enterprise");
            }

            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }

            Enterprise = enterprise;
            RequestId = new Integer32(requestId);
            _time = new TimeTicks(time);
            Variables = variables;
            IList<Variable> full = new List<Variable>(variables);
            full.Insert(0, new Variable(_timeId, _time));
            full.Insert(1, new Variable(_enterpriseId, Enterprise));
            _varbindSection = Variable.Transform(full);
        }
Example #22
0
        /// <summary>
        /// Converts variable binds to variable binds section.
        /// </summary>
        /// <param name="variables"></param>
        /// <returns></returns>
        internal static Sequence Transform(IList<Variable> variables)
        {
            // TODO: use IEnumerable instead of IList.
            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }

            var varbinds = new List<ISnmpData>(variables.Count);
            varbinds.AddRange(variables.Select(v => new Sequence(null, v.Id, v.Data)).Cast<ISnmpData>());

            var result = new Sequence(varbinds);
            return result;
        }
Example #23
0
        /// <summary>
        /// Converts varbind section to variable binds list.
        /// </summary>
        /// <param name="varbindSection"></param>
        /// <returns></returns>
        internal static IList<Variable> Transform(Sequence varbindSection)
        {
            if (varbindSection == null)
            {
                throw new ArgumentNullException("varbindSection");
            }

            IList<Variable> result = new List<Variable>(varbindSection.Count);
            foreach (ISnmpData item in varbindSection)
            {
                if (item.TypeCode != SnmpType.Sequence)
                {
                    throw new ArgumentException("wrong varbind section data");
                }
                
                Sequence varbind = (Sequence)item;
                if (varbind.Count != 2 || varbind[0].TypeCode != SnmpType.ObjectIdentifier)
                {
                    throw new ArgumentException("wrong varbind data");
                }
                    
                result.Add(new Variable((ObjectIdentifier)varbind[0], varbind[1]));
            }
            
            return result;
        }
        public InformRequestPdu(Tuple<int, byte[]> length, Stream stream)
        {
            if (length == null)
            {
                throw new ArgumentNullException("length");
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
#pragma warning disable 168
            var temp1 = (Integer32)DataFactory.CreateSnmpData(stream); // 0
            var temp2 = (Integer32)DataFactory.CreateSnmpData(stream); // 0
#pragma warning restore 168
            _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
            Variables = Variable.Transform(_varbindSection);
            if (Variables.Count >= 2)
            {
                _time = (TimeTicks)Variables[0].Data;
                Variables.RemoveAt(0);
                Enterprise = (ObjectIdentifier)Variables[0].Data;
                Variables.RemoveAt(0);
            }
            else if (Variables.Count == 0)
            {
                _time = new TimeTicks(0);
                Enterprise = null;
            }
            else
            {
                throw new InvalidDataException("malformed inform message");
            }

            _length = length.Item2;
        }
Example #25
0
        public InformRequestPdu(Tuple<int, byte[]> length, Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
#pragma warning disable 168
            var temp1 = (Integer32)DataFactory.CreateSnmpData(stream); // 0
            var temp2 = (Integer32)DataFactory.CreateSnmpData(stream); // 0
#pragma warning restore 168
            _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
            Variables = Variable.Transform(_varbindSection);
            _time = (TimeTicks)Variables[0].Data;
            Variables.RemoveAt(0);
            Enterprise = (ObjectIdentifier)Variables[0].Data;
            Variables.RemoveAt(0);
            _length = length.Item2;
        }
Example #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TrapV1Pdu"/> class.
        /// </summary>
        /// <param name="length">The length data.</param>
        /// <param name="stream">The stream.</param>
        public TrapV1Pdu(Tuple<int, byte[]> length, Stream stream)
        {
            if (length == null)
            {
                throw new ArgumentNullException("length");
            }

            if (stream == null) 
            {
                throw new ArgumentNullException("stream");
            }
            
            Enterprise = (ObjectIdentifier)DataFactory.CreateSnmpData(stream);
            AgentAddress = (IP)DataFactory.CreateSnmpData(stream);
            _generic = (Integer32)DataFactory.CreateSnmpData(stream);
            _specific = (Integer32)DataFactory.CreateSnmpData(stream);
            TimeStamp = (TimeTicks)DataFactory.CreateSnmpData(stream);
            _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
            Variables = Variable.Transform(_varbindSection);
            _length = length.Item2;
        }
Example #27
0
        /// <summary>
        /// Converts variable binds section to variable binds list.
        /// </summary>
        /// <param name="varbindSection"></param>
        /// <returns></returns>
        internal static IList<Variable> Transform(Sequence varbindSection)
        {
            if (varbindSection == null)
            {
                throw new ArgumentNullException("varbindSection");
            }

            IList<Variable> result = new List<Variable>(varbindSection.Length);
            foreach (ISnmpData item in varbindSection)
            {
                if (item.TypeCode != SnmpType.Sequence)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "wrong varbind section data type: {0}", item.TypeCode));
                }
                
                var varbind = (Sequence)item;
                if (varbind.Length != 2)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "wrong varbind data length: {0}", varbind.Length));
                }
                
                if (varbind[0].TypeCode != SnmpType.ObjectIdentifier)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "wrong varbind first data type: {0}", varbind[0].TypeCode));
                }
                    
                result.Add(new Variable((ObjectIdentifier)varbind[0], varbind[1]));
            }
            
            return result;
        }
Example #28
0
        /// <summary>
        /// Creates a <see cref="TrapV1Pdu"/> instance with PDU elements.
        /// </summary>
        /// <param name="enterprise">Enterprise</param>
        /// <param name="agent">Agent address</param>
        /// <param name="generic">Generic trap type</param>
        /// <param name="specific">Specific trap type</param>
        /// <param name="timestamp">Time stamp</param>
        /// <param name="variables">Variable binds</param>
        public TrapV1Pdu(ObjectIdentifier enterprise, IP agent, Integer32 generic, Integer32 specific, TimeTicks timestamp, IList<Variable> variables)
        {
            if (enterprise == null)
            {
                throw new ArgumentNullException("enterprise");
            }

            if (agent == null)
            {
                throw new ArgumentNullException("agent");
            }

            if (generic == null)
            {
                throw new ArgumentNullException("generic");
            }

            if (specific == null)
            {
                throw new ArgumentNullException("specific");
            }

            if (timestamp == null)
            {
                throw new ArgumentNullException("timestamp");
            }

            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }

            Enterprise = enterprise;
            AgentAddress = agent;
            _generic = generic;
            _specific = specific;
            TimeStamp = timestamp;
            _varbindSection = Variable.Transform(variables);
            Variables = variables;
        }
Example #29
0
        /// <summary>
        /// Converts variable binds to varbind section.
        /// </summary>
        /// <param name="variables"></param>
        /// <returns></returns>
        internal static Sequence Transform(IList<Variable> variables)
        {
            // TODO: use IEnumerable instead of IList.
            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }

            List<ISnmpData> varbinds = new List<ISnmpData>(variables.Count);
            foreach (Variable v in variables)
            {
                varbinds.Add(new Sequence(v.Id, v.Data));
            }

            Sequence result = new Sequence(varbinds);
            return result;
        }