/// <summary> /// Creates a <see cref="GetBulkRequestMessage"/> with a specific <see cref="Sequence"/>. /// </summary> /// <param name="version">The version.</param> /// <param name="messageId">The message id.</param> /// <param name="requestId">The request id.</param> /// <param name="userName">Name of the user.</param> /// <param name="nonRepeaters">The non repeaters.</param> /// <param name="maxRepetitions">The max repetitions.</param> /// <param name="variables">The variables.</param> /// <param name="privacy">The privacy provider.</param> /// <param name="maxMessageSize">Size of the max message.</param> /// <param name="report">The report.</param> public GetBulkRequestMessage( VersionCode version, int messageId, int requestId, OctetString userName, int nonRepeaters, int maxRepetitions, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report) { if (variables == null) { throw new ArgumentNullException("variables"); } if (userName == null) { throw new ArgumentNullException("userName"); } if (version != VersionCode.V3) { throw new ArgumentException("only v3 is supported", "version"); } if (report == null) { throw new ArgumentNullException("report"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } if (nonRepeaters > variables.Count) { throw new ArgumentException("nonRepeaters should not be greater than variable count", "nonRepeaters"); } if (maxRepetitions < 1) { throw new ArgumentException("maxRepetitions should be greater than 0", "maxRepetitions"); } Version = version; Privacy = privacy; // TODO: define more constants. Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable); var parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters(parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); var pdu = new GetBulkRequestPdu(requestId, nonRepeaters, maxRepetitions, variables); var scope = report.Scope; var contextEngineId = scope.ContextEngineId == OctetString.Empty ? parameters.EngineId : scope.ContextEngineId; Scope = new Scope(contextEngineId, scope.ContextName, pdu); authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = this.PackMessage(null).ToBytes(); }
public void TestException() { Assert.Throws <ArgumentNullException>(() => new GetBulkRequestPdu(new Tuple <int, byte[]>(0, new byte[] { 0 }), null)); Assert.Throws <ArgumentNullException>(() => new GetBulkRequestPdu(0, 0, 0, null)); var pdu = new GetBulkRequestPdu(0, 0, 0, new List <Variable>()); Assert.Throws <ArgumentNullException>(() => pdu.AppendBytesTo(null)); Assert.AreEqual("GET BULK request PDU: seq: 0; non-repeaters: 0; max-repetitions: 0; variable count: 0", pdu.ToString()); }
public void TestException() { Assert.Throws<ArgumentNullException>(() => new GetBulkRequestPdu(new Tuple<int, byte[]>(0, new byte[] { 0 }), null)); Assert.Throws<ArgumentNullException>(() => new GetBulkRequestPdu(0, 0, 0, null)); var pdu = new GetBulkRequestPdu(0, 0, 0, new List<Variable>()); Assert.Throws<ArgumentNullException>(() => pdu.AppendBytesTo(null)); Assert.AreEqual("GET BULK request PDU: seq: 0; non-repeaters: 0; max-repetitions: 0; variable count: 0", pdu.ToString()); }
/// <summary> /// Creates a <see cref="GetBulkRequestMessage"/> with a specific <see cref="Sequence"/>. /// </summary> /// <param name="version">The version.</param> /// <param name="messageId">The message id.</param> /// <param name="requestId">The request id.</param> /// <param name="contextName">Context name.</param> /// <param name="nonRepeaters">The non repeaters.</param> /// <param name="maxRepetitions">The max repetitions.</param> /// <param name="variables">The variables.</param> /// <param name="privacy">The privacy provider.</param> /// <param name="maxMessageSize">Size of the max message.</param> public GetBulkRequestMessage(VersionCode version, int messageId, int requestId, OctetString contextName, int nonRepeaters, int maxRepetitions, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (contextName == null) { throw new ArgumentNullException(nameof(contextName)); } if (version != VersionCode.V3) { throw new ArgumentException("Only v3 is supported.", nameof(version)); } if (privacy == null) { throw new ArgumentNullException(nameof(privacy)); } if (nonRepeaters > variables.Count) { throw new ArgumentException("nonRepeaters should not be greater than variable count.", nameof(nonRepeaters)); } if (maxRepetitions < 1) { throw new ArgumentException("maxRepetitions should be greater than 0.", nameof(maxRepetitions)); } Version = version; Privacy = privacy; // TODO: define more constants. Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable, new Integer32((int)SecurityModel.Tsm)); Parameters = SecurityParameters.Empty; var pdu = new GetBulkRequestPdu( requestId, nonRepeaters, maxRepetitions, variables); var contextEngineId = OctetString.Empty; Scope = new Scope(contextEngineId, contextName, pdu); Privacy.ComputeHash(Version, Header, Parameters, Scope); _bytes = this.PackMessage(null).ToBytes(); }
/// <summary> /// Creates a <see cref="GetBulkRequestMessage"/> with all contents. /// </summary> /// <param name="requestId">The request ID.</param> /// <param name="version">Protocol version.</param> /// <param name="community">Community name.</param> /// <param name="nonRepeaters">Non-repeaters.</param> /// <param name="maxRepetitions">Max repetitions.</param> /// <param name="variables">Variables.</param> public GetBulkRequestMessage(int requestId, VersionCode version, OctetString community, int nonRepeaters, int maxRepetitions, List <Variable> variables) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (community == null) { throw new ArgumentNullException(nameof(community)); } if (version != VersionCode.V2) { throw new ArgumentException("Only v2c are supported.", nameof(version)); } if (nonRepeaters > variables.Count) { throw new ArgumentException("nonRepeaters should not be greater than variable count.", nameof(nonRepeaters)); } if (maxRepetitions < 1) { throw new ArgumentException("maxRepetitions should be greater than 0.", nameof(maxRepetitions)); } Version = version; Header = Header.Empty; Parameters = SecurityParameters.Create(community); var pdu = new GetBulkRequestPdu( requestId, nonRepeaters, maxRepetitions, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = this.PackMessage(null).ToBytes(); }
/// <summary> /// Creates a <see cref="GetBulkRequestMessage"/> with all contents. /// </summary> /// <param name="requestId">The request ID.</param> /// <param name="version">Protocol version.</param> /// <param name="community">Community name.</param> /// <param name="nonRepeaters">Non-repeaters.</param> /// <param name="maxRepetitions">Max repetitions.</param> /// <param name="variables">Variables.</param> public GetBulkRequestMessage(int requestId, VersionCode version, OctetString community, int nonRepeaters, int maxRepetitions, IList <Variable> variables) { if (variables == null) { throw new ArgumentNullException("variables"); } if (community == null) { throw new ArgumentNullException("community"); } if (version != VersionCode.V2) { throw new ArgumentException("only v2c are supported", "version"); } if (nonRepeaters > variables.Count) { throw new ArgumentException("nonRepeaters should not be greater than variable count", "nonRepeaters"); } if (maxRepetitions < 1) { throw new ArgumentException("maxRepetitions should be greater than 0", "maxRepetitions"); } Version = version; Header = Header.Empty; Parameters = new SecurityParameters(null, null, null, community, null, null); GetBulkRequestPdu pdu = new GetBulkRequestPdu( requestId, nonRepeaters, maxRepetitions, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes(); }
/// <summary> /// Creates a <see cref="GetBulkRequestMessage"/> with all contents. /// </summary> /// <param name="requestId">The request ID.</param> /// <param name="version">Protocol version.</param> /// <param name="community">Community name.</param> /// <param name="nonRepeaters">Non-repeaters.</param> /// <param name="maxRepetitions">Max repetitions.</param> /// <param name="variables">Variables.</param> public GetBulkRequestMessage(int requestId, VersionCode version, OctetString community, int nonRepeaters, int maxRepetitions, IList<Variable> variables) { if (variables == null) { throw new ArgumentNullException("variables"); } if (community == null) { throw new ArgumentNullException("community"); } if (version != VersionCode.V2) { throw new ArgumentException("only v2c are supported", "version"); } if (nonRepeaters > variables.Count) { throw new ArgumentException("nonRepeaters should not be greater than variable count", "nonRepeaters"); } if (maxRepetitions < 1) { throw new ArgumentException("maxRepetitions should be greater than 0", "maxRepetitions"); } Version = version; Header = Header.Empty; Parameters = SecurityParameters.Create(community); var pdu = new GetBulkRequestPdu( requestId, nonRepeaters, maxRepetitions, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = this.PackMessage(null).ToBytes(); }
/// <summary> /// Creates a <see cref="GetBulkRequestMessage"/> with a specific <see cref="Sequence"/>. /// </summary> /// <param name="version">The version.</param> /// <param name="messageId">The message id.</param> /// <param name="requestId">The request id.</param> /// <param name="userName">Name of the user.</param> /// <param name="contextName">Name of context.</param> /// <param name="nonRepeaters">The non repeaters.</param> /// <param name="maxRepetitions">The max repetitions.</param> /// <param name="variables">The variables.</param> /// <param name="privacy">The privacy provider.</param> /// <param name="maxMessageSize">Size of the max message.</param> /// <param name="report">The report.</param> public GetBulkRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, OctetString contextName, int nonRepeaters, int maxRepetitions, IList<Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report) { if (variables == null) { throw new ArgumentNullException("variables"); } if (userName == null) { throw new ArgumentNullException("userName"); } if (contextName == null) { throw new ArgumentNullException("contextName"); } if (version != VersionCode.V3) { throw new ArgumentException("only v3 is supported", "version"); } if (report == null) { throw new ArgumentNullException("report"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } if (nonRepeaters > variables.Count) { throw new ArgumentException("nonRepeaters should not be greater than variable count", "nonRepeaters"); } if (maxRepetitions < 1) { throw new ArgumentException("maxRepetitions should be greater than 0", "maxRepetitions"); } Version = version; Privacy = privacy; // TODO: define more constants. Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable); var parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); var pdu = new GetBulkRequestPdu( requestId, nonRepeaters, maxRepetitions, variables); var scope = report.Scope; var contextEngineId = scope.ContextEngineId == OctetString.Empty ? parameters.EngineId : scope.ContextEngineId; Scope = new Scope(contextEngineId, contextName, pdu); authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = this.PackMessage(null).ToBytes(); }
/// <summary> /// Creates a <see cref="GetBulkRequestMessage"/> with a specific <see cref="Sequence"/>. /// </summary> /// <param name="version">The version.</param> /// <param name="messageId">The message id.</param> /// <param name="requestId">The request id.</param> /// <param name="userName">Name of the user.</param> /// <param name="contextName">Context name.</param> /// <param name="nonRepeaters">The non repeaters.</param> /// <param name="maxRepetitions">The max repetitions.</param> /// <param name="variables">The variables.</param> /// <param name="privacy">The privacy provider.</param> /// <param name="maxMessageSize">Size of the max message.</param> /// <param name="report">The report.</param> /// <param name="securityModel">The security model.</param> public GetBulkRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, OctetString contextName, int nonRepeaters, int maxRepetitions, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report, SecurityModel securityModel) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (userName == null) { throw new ArgumentNullException(nameof(userName)); } if (contextName == null) { throw new ArgumentNullException(nameof(contextName)); } if (version != VersionCode.V3) { throw new ArgumentException("Only v3 is supported.", nameof(version)); } if (report == null) { throw new ArgumentNullException(nameof(report)); } if (nonRepeaters > variables.Count) { throw new ArgumentException("nonRepeaters should not be greater than variable count.", nameof(nonRepeaters)); } if (maxRepetitions < 1) { throw new ArgumentException("maxRepetitions should be greater than 0.", nameof(maxRepetitions)); } Version = version; Privacy = privacy ?? throw new ArgumentNullException(nameof(privacy)); // TODO: define more constants. Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable, new Integer32((int)securityModel)); var parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; if (securityModel == SecurityModel.Tsm) { Parameters = SecurityParameters.Empty; } else { Parameters = new SecurityParameters( parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); } var pdu = new GetBulkRequestPdu( requestId, nonRepeaters, maxRepetitions, variables); var scope = report.Scope; var contextEngineId = scope.ContextEngineId == OctetString.Empty ? parameters.EngineId : scope.ContextEngineId; if (contextEngineId == null) { throw new SnmpException("invalid REPORT message"); } Scope = new Scope(contextEngineId, contextName, pdu); Privacy.ComputeHash(Version, Header, Parameters, Scope); _bytes = this.PackMessage(null).ToBytes(); }