Пример #1
0
        /// <summary>
        /// Directs the Messenger to perform a Set with this Session Information
        /// </summary>
        /// <param name="valuse">The Variable to Get from this Session</param>
        /// <returns></returns>
        public ProtocolDataUnit Get(List <string> values)
        {
            ProtocolDataUnit outBound, inBound;

            byte[]      outBytes, recieved;
            List <byte> inBytes;

            if (TrasnportProtocol == ProtocolType.Udp)
            {
                outBound = new ProtocolDataUnit()
                {
                    CommunityName = this.CommunityName,
                    RequestId     = this.NextRequestId,
                    PduType       = SnmpType.GetRequestPdu
                };
                outBound.Bindings.AddRange(values);

                SentLog.Add(outBound);

                outBytes = outBound.ToPacket(PmppEndPoint).ToArray();

                recieved = UdpTransport.Request(IPEndPoint.Address, IPEndPoint.Port, outBytes, outBytes.Length, SendRecieveTimeout, MaxRetries);

                inBytes = new List <byte>(recieved);

                if (PmppEndPoint.HasValue)
                {
                    inBytes.PmppDecode(false, this);
                }

                inBound = new ProtocolDataUnit(inBytes);

                if (inBound.ErrorStatus == ErrorStatus.GenErr)
                {
                    GeneralErrors++;
                }

                RecieveLog.Add(inBound);
            }
            else if (TrasnportProtocol == ProtocolType.Tcp)
            {
                outBound = new ProtocolDataUnit()
                {
                    CommunityName = this.CommunityName,
                    RequestId     = this.NextRequestId,
                    PduType       = SnmpType.GetRequestPdu
                };
                outBound.Bindings.AddRange(values);

                SentLog.Add(outBound);

                outBytes = outBound.ToPacket(PmppEndPoint).ToArray();

                recieved = TcpTransport.Request(IPEndPoint.Address, IPEndPoint.Port, outBytes, outBytes.Length, SendRecieveTimeout, MaxRetries);

                inBytes = new List <byte>(recieved);

                if (PmppEndPoint.HasValue)
                {
                    inBytes.PmppDecode(false, this);
                }

                inBound = new ProtocolDataUnit(inBytes);

                if (inBound.ErrorStatus == ErrorStatus.GenErr)
                {
                    GeneralErrors++;
                }

                RecieveLog.Add(inBound);
            }
            else
            {
                throw new System.NotImplementedException("Only Tcp and Udp Protocols are Supported");
            }

            outBound = null;
            outBytes = null;
            recieved = null;
            inBytes  = null;

            return(inBound);
        }
Пример #2
0
        /// <summary>
        /// Performs a GetBulk Request after getting the maxRepitions value by getting the IdentifierMaxRepitions which should be Integer32
        /// </summary>
        /// <param name="Identifier"></param>
        /// <param name="nonRepeaters"></param>
        /// <param name="IdentifierMaxRepitions"></param>
        /// <returns></returns>
        public ProtocolDataUnit GetBulk(string identifier, int nonRepeaters, string identifierMaxRepitions)
        {
            ProtocolDataUnit outBound, inBound;

            byte[]      outBytes, recieved;
            List <byte> inBytes;
            Variable    maxRepitions = Get(identifierMaxRepitions).Bindings[0];

            if (maxRepitions.TypeCode != SnmpType.Integer32)
            {
                throw new Exception("identifierMaxRepitions is not a Integer");
            }
            outBound = new ProtocolDataUnit()
            {
                Version       = this.SnmpVersion,
                CommunityName = this.CommunityName,
                RequestId     = this.NextRequestId,
                PduType       = SnmpType.GetBulkRequestPdu,
                ErrorStatus   = (ErrorStatus)nonRepeaters,
                ErrorIndex    = maxRepitions.ToInt32()
            };

            outBound.Bindings.Add(identifier);

            SentLog.Add(outBound);

            outBytes = outBound.ToPacket(PmppEndPoint).ToArray();

            if (TrasnportProtocol == ProtocolType.Udp)
            {
                recieved = UdpTransport.Request(IPEndPoint.Address, IPEndPoint.Port, outBytes, outBytes.Length, SendRecieveTimeout, MaxRetries);

                inBytes = new List <byte>(recieved);

                if (PmppEndPoint.HasValue)
                {
                    inBytes.PmppDecode(false, this);
                }

                inBound = new ProtocolDataUnit(inBytes);

                if (inBound.ErrorStatus == ErrorStatus.GenErr)
                {
                    GeneralErrors++;
                }

                RecieveLog.Add(inBound);
            }
            else if (TrasnportProtocol == ProtocolType.Tcp)
            {
                recieved = TcpTransport.Request(IPEndPoint.Address, IPEndPoint.Port, outBytes, outBytes.Length, SendRecieveTimeout, MaxRetries);

                inBytes = new List <byte>(recieved);

                if (PmppEndPoint.HasValue)
                {
                    inBytes.PmppDecode(false, this);
                }

                inBound = new ProtocolDataUnit(inBytes);

                if (inBound.ErrorStatus == ErrorStatus.GenErr)
                {
                    GeneralErrors++;
                }

                RecieveLog.Add(inBound);
            }
            else
            {
                throw new System.NotImplementedException("Only Tcp and Udp Protocols are Supported");
            }

            outBound = null;
            outBytes = null;
            recieved = null;
            inBytes  = null;

            return(inBound);
        }