private static ISnmpData GetParam(SnmpType paramType, Object value = null) { switch (paramType) { case SnmpType.Integer32: return(new Lextm.SharpSnmpLib.Integer32(Convert.ToInt32(value))); case SnmpType.OctetString: if (null == value) { return(new Lextm.SharpSnmpLib.OctetString(String.Empty)); } else { return(new Lextm.SharpSnmpLib.OctetString(value.ToString())); } case SnmpType.Gauge32: return(new Lextm.SharpSnmpLib.Gauge32(Convert.ToUInt32(value))); case SnmpType.Counter32: return(new Lextm.SharpSnmpLib.Counter32(Convert.ToUInt32(value))); case SnmpType.Counter64: return(new Lextm.SharpSnmpLib.Counter64(Convert.ToUInt64(value))); default: throw new NotImplementedException("SnmtType Parse Pending Development. Not valid right now."); } }
/// <summary> /// Decrypts the specified data. /// </summary> /// <param name="data">The data.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public ISnmpData Decrypt(ISnmpData data, SecurityParameters parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (data == null) { throw new ArgumentNullException(nameof(data)); } SnmpType code = data.TypeCode; if (code != SnmpType.OctetString) { throw new ArgumentException($"Cannot decrypt the scope data: {code}.", nameof(data)); } OctetString octets = (OctetString)data; byte[] bytes = octets.GetRaw(); byte[] pkey = PasswordToKey(_phrase.GetRaw(), parameters.EngineId.GetRaw()); // decode encrypted packet byte[] decrypted = Decrypt(bytes, pkey, parameters.EngineBoots.ToInt32(), parameters.EngineTime.ToInt32(), parameters.PrivacyParameters.GetRaw()); return(DataFactory.CreateSnmpData(decrypted)); }
public static DataType TypeCodeToDataType(SnmpType typeCode) { switch (typeCode) { case SnmpType.Integer32: return(DataType.Int); case SnmpType.OctetString: return(DataType.String); case SnmpType.Null: case SnmpType.Opaque: return(DataType.Unknown); case SnmpType.IPAddress: case SnmpType.NetAddress: return(DataType.IPAddress); case SnmpType.Counter32: case SnmpType.Gauge32: return(DataType.UInt); case SnmpType.TimeTicks: return(DataType.TimeSpan); case SnmpType.Counter64: return(DataType.ULong); default: throw new UnsupportedTypeException(); } }
/// <summary> /// Sends this <see cref="ISnmpMessage"/> and handles the response from agent. /// </summary> /// <param name="request">The <see cref="ISnmpMessage"/>.</param> /// <param name="receiver">Port number.</param> /// <param name="registry">User registry.</param> /// <returns></returns> public static async Task <ISnmpMessage> GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry) { // TODO: make more usage of UserRegistry. if (request == null) { throw new ArgumentNullException(nameof(request)); } if (receiver == null) { throw new ArgumentNullException(nameof(receiver)); } SnmpType code = request.TypeCode(); if (code == SnmpType.TrapV1Pdu || code == SnmpType.TrapV2Pdu || code == SnmpType.ReportPdu) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "not a request message: {0}", code)); } using (Socket socket = receiver.GetSocket()) { return(await request.GetResponseAsync(receiver, registry, socket).ConfigureAwait(false)); } }
/// <summary> /// Create a Binary Sequence from the given parameters /// </summary> /// <param name="tag">The type of the sequence</param> /// <param name="values">The bytes of the sequence</param> /// <param name="includeType">Indicates to include the tag in the returned value</param> /// <returns>A ASN.1 Encoded Sequence of the given tag and values</returns> public static List <byte> EncodeSequence(SnmpType tag, ref List <byte> values, bool includeType) { List <byte> Sequence = EncodeSequenceHeader(tag, values.Count, includeType); Sequence.AddRange(values); return(Sequence); }
public static ISnmpMessage EndGetResponse(this ISnmpMessage request, IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException(nameof(asyncResult)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } SnmpMessageAsyncResult ar = (SnmpMessageAsyncResult)asyncResult; Socket s = ar.WorkSocket; int count = s.EndReceive(ar.Inner); // Passing 'count' is not necessary because ParseMessages should ignore it, but it offer extra safety (and would avoid an issue if parsing >1 response). ISnmpMessage response = MessageFactory.ParseMessages(ar.GetBuffer(), 0, count, ar.Users)[0]; SnmpType responseCode = response.TypeCode(); if (responseCode == SnmpType.ResponsePdu || responseCode == SnmpType.ReportPdu) { int requestId = request.MessageId(); int responseId = response.MessageId(); if (responseId != requestId) { throw OperationException.Create(string.Format(CultureInfo.InvariantCulture, "wrong response sequence: expected {0}, received {1}", requestId, responseId), ar.Receiver.Address); } return(response); } throw OperationException.Create(string.Format(CultureInfo.InvariantCulture, "wrong response type: {0}", responseCode), ar.Receiver.Address); }
private Operation DetectOperation(SnmpType pduType) { switch (pduType) { /* * case SnmpType.GetRequestPdu: * case SnmpType.GetNextRequestPdu: * case SnmpType.ResponsePdu: * case SnmpType.SetRequestPdu: * case SnmpType.TrapV1Pdu: * case SnmpType.GetBulkRequestPdu: * case SnmpType.InformRequestPdu: * case SnmpType.TrapV2Pdu: * case SnmpType.ReportPdu: */ case SnmpType.GetRequestPdu: return(Operation.Get); case SnmpType.SetRequestPdu: return(Operation.Set); default: throw new UnsupportedOperationException(); } }
/// <summary> /// Sends an <see cref="ISnmpMessage"/>. /// </summary> /// <param name="message">The <see cref="ISnmpMessage"/>.</param> /// <param name="manager">Manager</param> /// <param name="socket">The socket.</param> public static void Send(this ISnmpMessage message, EndPoint manager, Socket socket) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (socket == null) { throw new ArgumentNullException(nameof(socket)); } if (manager == null) { throw new ArgumentNullException(nameof(manager)); } SnmpType code = message.TypeCode(); if ((code != SnmpType.TrapV1Pdu && code != SnmpType.TrapV2Pdu) && code != SnmpType.ReportPdu) { throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, "not a trap message: {0}", code)); } byte[] bytes = message.ToBytes(); socket.SendTo(bytes, 0, bytes.Length, SocketFlags.None, manager); }
public MIBObject(string oid, SnmpType type, string value) { OID = oid; //_type = type; Type = type; Value = value; }
/// <summary> /// Constructs a Variable Binding from a known SnmpType with a Value /// </summary> /// <param name="Identifier">The Object Identifier of the Variable Binding</param> /// <param name="TypeCode">The SnmpType of the Variable Binding</param> /// <param name="Value">The byte Value of the Variable Binding</param> public Variable(String Identifier, SnmpType TypeCode, List <byte> Value) : this() { this.Identifier = Identifier; this.TypeCode = TypeCode; this.Value = Value; }
/// <summary> /// Sends an <see cref="ISnmpMessage"/>. /// </summary> /// <param name="message">The <see cref="ISnmpMessage"/>.</param> /// <param name="manager">Manager</param> public static async Task SendAsync(this ISnmpMessage message, EndPoint manager) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (manager == null) { throw new ArgumentNullException(nameof(manager)); } SnmpType code = message.TypeCode(); if ((code != SnmpType.TrapV1Pdu && code != SnmpType.TrapV2Pdu) && code != SnmpType.ReportPdu) { throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, "not a trap message: {0}", code)); } using (Socket socket = manager.GetSocket()) { await message.SendAsync(manager, socket).ConfigureAwait(false); } }
public override bool HandleMembership() { ISnmpMessage request = Request; SecurityParameters parameters = request.Parameters; SnmpType typeCode = Request.TypeCode(); if (typeCode == SnmpType.Unknown) { HandleFailure(Group.DecryptionError); return(false); } if (typeCode != SnmpType.TrapV2Pdu && parameters.EngineId != Group.EngineId) { HandleDiscovery(); return(true); } IPrivacyProvider user = Users.Find(parameters.UserName); if (user == null) { HandleFailure(Group.UnknownSecurityName); return(false); } if (typeCode == SnmpType.TrapV2Pdu && (user.EngineIds == null || !user.EngineIds.Contains(parameters.EngineId))) { HandleFailure(Group.UnknownEngineId); return(false); } if (parameters.IsInvalid) { HandleFailure(Group.AuthenticationFailure); return(false); } if (typeCode == SnmpType.TrapV2Pdu) { return(true); } if ((user.ToSecurityLevel() | Levels.Reportable) != request.Header.SecurityLevel) { HandleFailure(Group.UnsupportedSecurityLevel); return(false); } bool inTime = EngineGroup.IsInTime(Group.EngineTimeData, parameters.EngineBoots.ToInt32(), parameters.EngineTime.ToInt32()); if (!inTime) { HandleFailure(Group.NotInTimeWindow); return(false); } return(true); }
public SnmpBER(ulong c, SnmpType t) { type = new SnmpTag(t); e = true; b = new byte[ULongLength(c)]; int n = 0; PutULong(ref n, c); }
public Universal PDU(SnmpType t, params Universal[] vbinds) { seq += 10; return(new SnmpBER(t, new Universal(seq), new Universal(0), // errorStatus new Universal(0), // errorIndex new Universal(vbinds))); }
//----------------------------------------------------------------------------------- public static ISnmpData CreateSnmpDataFromStringSafe(SnmpType type, string strValeur) { try { return(CreateSnmpDataFromStringUnsafe(type, strValeur)); } catch { } return(null); }
/// <summary> /// Decodes a ASN.1 Sequence into Variable /// </summary> /// <param name="packet">The packet which contains the ASN.1 data</param> /// <param name="position">The current position in the packet</param> /// <returns>A Variable Constructed from the given packet at the given position</returns> public static Variable DecodeSequence(ref List <byte> packet, ref int position) { String Identifier = DecodeObjectId(ref packet, ref position); SnmpType TypeCode = (SnmpType)packet[position]; int Length = DecodeLength(ref packet, ref position, TypeCode); List <byte> Value = packet.GetRange(position, Length); position += Length; return(new Variable(Identifier, TypeCode, Value)); }
/// <summary> /// Variables. /// </summary> /// <param name="message">The <see cref="ISnmpMessage"/>.</param> public static IList <Variable> Variables(this ISnmpMessage message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } SnmpType code = message.TypeCode(); return(code == SnmpType.Unknown ? new List <Variable>(0) : message.Scope.Pdu.Variables); }
/// <summary> /// Create a Binary Sequence Header from the given parameters /// </summary> /// <param name="tag">The type of the sequence</param> /// <param name="length">The length of the sequence</param> /// <param name="includeType">Indicates to include the tag in the returned value</param> /// <returns>A ASN.1 Sequence Header for the given tag and length</returns> public static List <byte> EncodeSequenceHeader(SnmpType tag, int length, bool includeType) { List <byte> Sequence = new List <byte>(); if (includeType) { Sequence.Add((byte)tag); } Sequence.AddRange(EncodeLength(length)); return(Sequence); }
/// <summary> /// Decodes the ASN.1 Length from the given packet at the given position, checking for the given tag before decoding. /// </summary> /// <param name="packet">The packet which contains the ASN.1 data</param> /// <param name="position">The current position in the packet</param> /// <param name="tag">The SnmpType to Ensure is Preceeding the data</param> /// <returns>The decoded Integer32 Length of the ASN.1 data</returns> public static int DecodeLength(ref List <byte> packet, ref int position, SnmpType tag) { //if (tag == SnmpType.Null) return 1; if (packet[position++] != (byte)tag) { throw new System.Exception("ASN.1 " + System.String.Format(System.Globalization.CultureInfo.InvariantCulture, "0x{0:x}", tag) + " expected."); } else { return(DecodeLength(ref packet, ref position)); } }
public static IAsyncResult BeginGetResponse(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry, Socket udpSocket, AsyncCallback callback, object state) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (udpSocket == null) { throw new ArgumentNullException(nameof(udpSocket)); } if (receiver == null) { throw new ArgumentNullException(nameof(receiver)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } SnmpType requestCode = request.TypeCode(); if (requestCode == SnmpType.TrapV1Pdu || requestCode == SnmpType.TrapV2Pdu || requestCode == SnmpType.ReportPdu) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "not a request message: {0}", requestCode)); } // Whatever you change, try to keep the Send and the Receive close to each other. udpSocket.SendTo(request.ToBytes(), receiver); int bufferSize = udpSocket.ReceiveBufferSize = Messenger.MaxMessageSize; byte[] buffer = new byte[bufferSize]; // https://sharpsnmplib.codeplex.com/workitem/7234 if (callback != null) { AsyncCallback wrapped = callback; callback = asyncResult => { SnmpMessageAsyncResult result = new SnmpMessageAsyncResult(asyncResult, udpSocket, registry, receiver, buffer); wrapped(result); }; } IAsyncResult ar = udpSocket.BeginReceive(buffer, 0, bufferSize, SocketFlags.None, callback, state); return(new SnmpMessageAsyncResult(ar, udpSocket, registry, receiver, buffer)); }
//----------------------------------------------------- public void Init(IDefinition definition) { m_definition = definition; m_lblNomVariable.Text = m_definition.Name; ObjectType tp = m_definition.Entity as ObjectType; if (tp != null && tp.Syntax != null) { m_typeAttendu = tp.Syntax.SnmpType; m_lblTypeVariable.Text = m_typeAttendu.ToString(); } if (tp != null && tp.DefaultValue != null) { m_txtValeur.Text = tp.DefaultValue.ToString(); } }
internal static void AppendBytes(this Stream stream, SnmpType typeCode, byte[] raw) { if (stream == null) { throw new ArgumentNullException("stream"); } if (raw == null) { throw new ArgumentNullException("raw"); } stream.WriteByte((byte)typeCode); stream.WritePayloadLength(raw.Length); stream.Write(raw, 0, raw.Length); }
/// <summary> /// Initializes a new instance of the <see cref="Discovery"/> class. /// </summary> /// <param name="requestId">The request id.</param> /// <param name="messageId">The message id.</param> /// <param name="maxMessageSize">The max size of message.</param> /// <param name="type">Message type.</param> public Discovery(int messageId, int requestId, int maxMessageSize, SnmpType type) { switch (type) { case SnmpType.GetRequestPdu: { _discovery = new GetRequestMessage(VersionCode.V3, new Header(new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope(OctetString.Empty, OctetString.Empty, new GetRequestPdu(requestId, new List <Variable> ())), DefaultPrivacyProvider.DefaultPair, null); break; } case SnmpType.GetNextRequestPdu: { _discovery = new GetNextRequestMessage(VersionCode.V3, new Header(new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope(OctetString.Empty, OctetString.Empty, new GetNextRequestPdu(requestId, new List <Variable> ())), DefaultPrivacyProvider.DefaultPair, null); break; } case SnmpType.GetBulkRequestPdu: { _discovery = new GetBulkRequestMessage(VersionCode.V3, new Header(new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope(OctetString.Empty, OctetString.Empty, new GetBulkRequestPdu(requestId, 0, 0, new List <Variable> ())), DefaultPrivacyProvider.DefaultPair, null); break; } case SnmpType.SetRequestPdu: { _discovery = new SetRequestMessage(VersionCode.V3, new Header(new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope(OctetString.Empty, OctetString.Empty, new SetRequestPdu(requestId, new List <Variable> ())), DefaultPrivacyProvider.DefaultPair, null); break; } case SnmpType.InformRequestPdu: { _discovery = new InformRequestMessage(VersionCode.V3, new Header(new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope(OctetString.Empty, OctetString.Empty, new InformRequestPdu(requestId)), DefaultPrivacyProvider.DefaultPair, null); break; } default: throw new ArgumentException("discovery message must be a request", "type"); } }
internal static void AppendBytes(Stream stream, SnmpType typeCode, byte[] raw) { // TODO: make extension method. if (stream == null) { throw new ArgumentNullException("stream"); } if (raw == null) { throw new ArgumentNullException("raw"); } stream.WriteByte((byte)typeCode); WritePayloadLength(stream, raw.Length); stream.Write(raw, 0, raw.Length); }
/// ////////////////////////////////////////// public override CResultAErreur MyEval(CContexteEvaluationExpression ctx, object[] valeursParametres) { CResultAErreur result = CResultAErreur.True; try { SnmpType tp = (SnmpType)valeursParametres[0]; string strVal = valeursParametres[1].ToString(); result.Data = DataFactory.CreateSnmpDataFromStringUnsafe(tp, strVal); } catch (Exception e) { result.EmpileErreur("Error in ToSnmp"); result.EmpileErreur(new CErreurException(e)); } return(result); }
/// <summary> /// Decrypts the specified data. /// </summary> /// <param name="data">The data.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public ISnmpData Decrypt(ISnmpData data, SecurityParameters parameters) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } SnmpType code = data.TypeCode; if (code != SnmpType.OctetString) { throw new ArgumentException($"Cannot decrypt the scope data: {code}.", nameof(data)); } OctetString octets = (OctetString)data; byte[] bytes = octets.GetRaw(); byte[] pkey = PasswordToKey(_phrase.GetRaw(), parameters.EngineId.GetRaw()); try { // decode encrypted packet byte[] decrypted = Decrypt(bytes, pkey, parameters.PrivacyParameters.GetRaw()); ISnmpData result = DataFactory.CreateSnmpData(decrypted); if (result.TypeCode != SnmpType.Sequence) { DecryptionException newException = new DecryptionException("DES decryption failed"); newException.SetBytes(bytes); throw newException; } return(result); } catch (Exception ex) { DecryptionException newException = new DecryptionException("DES decryption failed", ex); newException.SetBytes(bytes); throw newException; } }
private ISnmpData ConvertStringValue2SnmpData(SnmpType type, string value) { ISnmpData data; try { switch (type) { case SnmpType.Integer32: data = new Integer32(int.Parse(value)); break; case SnmpType.Counter32: data = new Counter32(uint.Parse(value)); break; case SnmpType.Gauge32: data = new Gauge32(uint.Parse(value)); break; case SnmpType.TimeTicks: data = new TimeTicks(uint.Parse(value)); break; case SnmpType.OctetString: data = new OctetString(value); break; case SnmpType.IPAddress: data = new IP((IPAddress.Parse(value)).GetAddressBytes()); break; default: throw new InvalidDataType(); } } catch (InvalidCastException) { throw new InvalidDataType(); } return(data); }
private static async Task <object> SetOneAsync( string ip, string community, string oid, int timeout, Int32 port, VersionCode snmpVersion, SnmpType param1Type, Object param1Value) { List <Variable> lst = new List <Variable>(); ISnmpData paramValue = GetParam(param1Type, param1Value); lst.Add( new Variable( new ObjectIdentifier(oid), paramValue)); return(await Messenger.SetAsync( snmpVersion, new IPEndPoint(IPAddress.Parse(ip), port), new OctetString(community), lst)); }
internal static void AppendBytes(this Stream stream, SnmpType typeCode, byte[] length, byte[] raw) { if (stream == null) { throw new ArgumentNullException("stream"); } if (raw == null) { throw new ArgumentNullException("raw"); } stream.WriteByte((byte)typeCode); if (length == null) { length = raw.Length.WritePayloadLength(); } stream.Write(length, 0, length.Length); stream.Write(raw, 0, raw.Length); }
internal static void AppendBytes(this Stream stream, SnmpType typeCode, byte[] length, byte[] raw) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (raw == null) { throw new ArgumentNullException(nameof(raw)); } stream.WriteByte((byte)typeCode); if (length == null) { length = raw.Length.WritePayloadLength(); } stream.Write(length, 0, length.Length); stream.Write(raw, 0, raw.Length); }
private void HandleMessage(byte[] buffer, int count, IPEndPoint remote) { foreach (ISnmpMessage message in MessageFactory.ParseMessages(buffer, 0, count, Empty)) { SnmpType code = message.TypeCode(); if (code == SnmpType.ReportPdu) { ReportMessage report = (ReportMessage)message; if (report.RequestId() != _requestId) { continue; } if (report.Pdu().ErrorStatus.ToErrorCode() != ErrorCode.NoError) { continue; } AgentFound?.Invoke(this, new AgentFoundEventArgs(remote, null)); } if (code != SnmpType.ResponsePdu) { continue; } ResponseMessage response = (ResponseMessage)message; if (response.RequestId() != _requestId) { continue; } if (response.ErrorStatus != ErrorCode.NoError) { continue; } AgentFound?.Invoke(this, new AgentFoundEventArgs(remote, response.Variables()[0])); } }
/// <summary> /// Returns a new discovery request. /// </summary> /// <param name="type">Message type.</param> /// <returns></returns> public static Discovery GetNextDiscovery(SnmpType type) { return new Discovery(NextMessageId, NextRequestId, MaxMessageSize, type); }
public SnmpDataType ToSnmpDataType(SnmpType snmpType) { switch (snmpType) { case SnmpType.EndMarker: return SnmpDataType.EndMarker; case SnmpType.Integer32: return SnmpDataType.Integer32; case SnmpType.OctetString: return SnmpDataType.OctetString; case SnmpType.Null: return SnmpDataType.Null; case SnmpType.ObjectIdentifier: return SnmpDataType.ObjectIdentifier; case SnmpType.Sequence: return SnmpDataType.Sequence; case SnmpType.IPAddress: return SnmpDataType.IPAddress; case SnmpType.Counter32: return SnmpDataType.Counter32; case SnmpType.Gauge32: return SnmpDataType.Gauge32; case SnmpType.TimeTicks: return SnmpDataType.TimeTicks; case SnmpType.Opaque: return SnmpDataType.Opaque; case SnmpType.NetAddress: return SnmpDataType.NetAddress; case SnmpType.Counter64: return SnmpDataType.Counter64; case SnmpType.Unsigned32: return SnmpDataType.Unsigned32; case SnmpType.NoSuchObject: return SnmpDataType.NoSuchObject; case SnmpType.NoSuchInstance: return SnmpDataType.NoSuchInstance; case SnmpType.EndOfMibView: return SnmpDataType.EndOfMibView; case SnmpType.GetRequestPdu: return SnmpDataType.GetRequestPdu; case SnmpType.GetNextRequestPdu: return SnmpDataType.GetNextRequestPdu; case SnmpType.ResponsePdu: return SnmpDataType.ResponsePdu; case SnmpType.SetRequestPdu: return SnmpDataType.SetRequestPdu; case SnmpType.TrapV1Pdu: return SnmpDataType.TrapV1Pdu; case SnmpType.GetBulkRequestPdu: return SnmpDataType.GetBulkRequestPdu; case SnmpType.InformRequestPdu: return SnmpDataType.InformRequestPdu; case SnmpType.TrapV2Pdu: return SnmpDataType.TrapV2Pdu; case SnmpType.ReportPdu: return SnmpDataType.ReportPdu; case SnmpType.Unknown: return SnmpDataType.Unknown; default: throw new ArgumentOutOfRangeException(nameof(snmpType), snmpType, null); } }
/// <summary> /// Initializes a new instance of the <see cref="Discovery"/> class. /// </summary> /// <param name="requestId">The request id.</param> /// <param name="messageId">The message id.</param> /// <param name="maxMessageSize">The max size of message.</param> /// <param name="type">Message type.</param> public Discovery(int messageId, int requestId, int maxMessageSize, SnmpType type) { switch (type) { case SnmpType.GetRequestPdu: { _discovery = new GetRequestMessage( VersionCode.V3, new Header( new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope( OctetString.Empty, OctetString.Empty, new GetRequestPdu(requestId, new List<Variable>())), DefaultPrivacyProvider.DefaultPair, null); break; } case SnmpType.GetNextRequestPdu: { _discovery = new GetNextRequestMessage( VersionCode.V3, new Header( new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope( OctetString.Empty, OctetString.Empty, new GetNextRequestPdu(requestId, new List<Variable>())), DefaultPrivacyProvider.DefaultPair, null); break; } case SnmpType.GetBulkRequestPdu: { _discovery = new GetBulkRequestMessage( VersionCode.V3, new Header( new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope( OctetString.Empty, OctetString.Empty, new GetBulkRequestPdu(requestId, 0, 0, new List<Variable>())), DefaultPrivacyProvider.DefaultPair, null); break; } case SnmpType.SetRequestPdu: { _discovery = new SetRequestMessage( VersionCode.V3, new Header( new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope( OctetString.Empty, OctetString.Empty, new SetRequestPdu(requestId, new List<Variable>())), DefaultPrivacyProvider.DefaultPair, null); break; } case SnmpType.InformRequestPdu: { _discovery = new InformRequestMessage( VersionCode.V3, new Header( new Integer32(messageId), new Integer32(maxMessageSize), Levels.Reportable), DefaultSecurityParameters, new Scope( OctetString.Empty, OctetString.Empty, new InformRequestPdu(requestId)), DefaultPrivacyProvider.DefaultPair, null); break; } default: throw new ArgumentException("discovery message must be a request", "type"); } }