Ejemplo n.º 1
0
        private static bool ProcessGetTable(GetTableState state,
                                            IAsyncResult ar, ref int nRequests)
        {
            Pdu pdu = state.pdu;

            Oid[] oids;
            try
            {
                Pdu resp = state.invoke(ar);
                oids = ProcessResponse(
                    state.columnOids, resp.Vbs, state.endRowIndex, state.rows);
            }
            catch (SnmpException e)
            {
                oids = ProcessSnmpv1EndOfMIB(
                    state.target.Version, state.columnOids, pdu, e);
                if (oids == null)
                {
                    throw;
                }
            }
            nRequests++;

            if (oids.Length == 0 || state.rows.Count >= state.maxRows)
            {
                return(true);
            }
            else
            {
                state.vbs = CreateNullVbs(oids, state.vbs);
                state.pdu = pdu.Clone(state.vbs);
                return(false);
            }
        }
Ejemplo n.º 2
0
        private static void GetTableCallback(IAsyncResult ar)
        {
            GetTableState state = (GetTableState)ar.AsyncState;
            Exception     exc   = null;

            try
            {
                bool done;
                lock (state.SyncRoot)
                {
                    done = ProcessGetTable(state, ar, ref state.nRequests);
                }
                if (!done)
                {
                    state.pdu.MaxRepetitions = GetMaxRepetitions(state);
                    state.snmp.BeginInvoke(state.pdu, state.target,
                                           new AsyncCallback(GetTableCallback), state);
                    return;
                }
            }
            catch (Exception e)
            {
                exc = e;
            }

            state.Done(exc);
        }
Ejemplo n.º 3
0
        private static int GetMaxRepetitions(GetTableState state)
        {
            Pdu pdu = state.pdu;

            return(GetMaxRepetitions(pdu.Type, state.target.Version,
                                     pdu.Count, state.rows.Count, state.maxRows, state.rowsPerQuery));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts an asynchronous SNMP table retrieval operation.
        /// </summary>
        /// <param name="snmp">The SNMP session object to use.</param>
        /// <param name="pdu">The PDU object used to convey the request type
        /// and some security parameters (variable bindings are ignored; may
        /// be an empty array).</param>
        /// <param name="target">The SNMP target.</param>
        /// <param name="columnOids">The OIDs of table columns to retrieve. The
        /// columns should share table indexes  (e.g., be a part of the same or
        /// AUGMENTed table).</param>
        /// <param name="startRowIndex">The row index to start from or <b>null</b>.</param>
        /// <param name="endRowIndex">The row index to finish at or <b>null</b>.</param>
        /// <param name="maxRows">Maximum number of rows to retrieve. Specify 0
        /// to read the whole table.</param>
        /// <param name="rowsPerQuery">Number of rows to read in a single query.
        /// Only valid if the request used will be GetBulk. Specify 0 to enable
        /// a simple heuristic algorithm that dynamically computes this value
        /// so that the response fits a single Ethernet packet.</param>
        /// <param name="callback">Callback method to invoke when a table is read
        /// or <b>null</b>.</param>
        /// <param name="callbackData">User state.</param>
        /// <returns><see cref="IAsyncResult"/> object.</returns>
        /// <remarks>
        /// This method starts asynchronous table retrieval for the specified set
        /// of columns. A typical example includes the retrieval of a whole table
        /// but a number of parameters makes this method more flexible.  In order
        /// to complete the operation and free related resources, <see cref="EndGetTable"/>
        /// must be later called,  usually, in the callback method specified
        /// by <b>callback</b> parameter.
        /// </remarks>
        public static IAsyncResult BeginGetTable(Snmp snmp, Pdu pdu, SnmpTarget target,
                                                 Oid[] columnOids, Oid startRowIndex, Oid endRowIndex,
                                                 int maxRows, int rowsPerQuery,
                                                 AsyncCallback callback, object callbackData)
        {
            GetTableState state = PrepareGetTable(snmp, pdu, target, columnOids,
                                                  startRowIndex, endRowIndex, maxRows, rowsPerQuery,
                                                  callback, callbackData, false);

            state.pdu.MaxRepetitions = GetMaxRepetitions(state);
            snmp.BeginInvoke(state.pdu, state.target,
                             new AsyncCallback(GetTableCallback), state);
            return(state);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Retrieves an SNMP table from an agent.
        /// </summary>
        /// <param name="snmp">The SNMP session object to use.</param>
        /// <param name="pdu">The PDU object used to convey the request type
        /// and some security parameters (variable bindings are ignored; may
        /// be an empty array).</param>
        /// <param name="target">The SNMP target.</param>
        /// <param name="columnOids">The OIDs of table columns to retrieve. The
        /// columns should share table indexes  (e.g., be a part of the same or
        /// AUGMENTed table).</param>
        /// <param name="startRowIndex">The row index to start from or <b>null</b>.</param>
        /// <param name="endRowIndex">The row index to finish at or <b>null</b>.</param>
        /// <param name="maxRows">Maximum number of rows to retrieve. Specify 0
        /// to read the whole table.</param>
        /// <param name="rowsPerQuery">Number of rows to read in a single query.
        /// Only valid if the request used will be GetBulk. Specify 0 to enable
        /// a simple heuristic algorithm that dynamically computes this value
        /// so that the response fits a single Ethernet packet.</param>
        /// <param name="nRequests">Will be incremented every time a response
        /// is received.</param>
        /// <returns>The retrieved rows. Due to performance reasons, the rows
        /// are returned as a jagged array  but the array is guaranteed to be
        /// rectangular.  It contains either valid variable bindings or <b>null</b>
        /// values for table "holes".</returns>
        /// <remarks>This method returns table rows for the specified set of
        /// columns. A typical example includes the retrieval of a complete
        /// table but a number of parameters makes this method more flexible.
        /// For more information on internal behavior, see the
        /// <see cref="TableReader.UseAsyncInvoke"/> property.</remarks>
        public static Vb[][] GetTable(Snmp snmp, Pdu pdu, SnmpTarget target,
                                      Oid[] columnOids, Oid startRowIndex, Oid endRowIndex,
                                      int maxRows, int rowsPerQuery, ref int nRequests)
        {
            GetTableState state = PrepareGetTable(snmp, pdu, target, columnOids,
                                                  startRowIndex, endRowIndex, maxRows, rowsPerQuery,
                                                  null, null, true);

            do
            {
                state.pdu.MaxRepetitions = GetMaxRepetitions(state);
            }while (!ProcessGetTable(state, null, ref nRequests));

            return(ExtractRows(state.rows));
        }