public static async Task SendTrapV1Async( EndPoint receiver, IPAddress agent, OctetString community, ObjectIdentifier enterprise, GenericCode generic, int specific, uint timestamp, IList <Variable> variables) { var message = new TrapV1Message(VersionCode.V1, agent, community, enterprise, generic, specific, timestamp, variables); await message.SendAsync(receiver).ConfigureAwait(false); }
public static void SendTrapV1( EndPoint receiver, IPAddress agent, OctetString community, ObjectIdentifier enterprise, GenericCode generic, int specific, uint timestamp, IList <Variable> variables) { var message = new TrapV1Message(VersionCode.V1, agent, community, enterprise, generic, specific, timestamp, variables); message.Send(receiver); }
public void Test() { var mock = new Mock<ISnmpContext>(); var mock2 = new Mock<IListenerBinding>(); IList<Variable> v = new List<Variable>(); var message = new TrapV1Message(VersionCode.V1, IPAddress.Any, new OctetString("community"), new ObjectIdentifier("1.3.6"), GenericCode.ColdStart, 0, 0, v); mock.Setup(foo => foo.Binding).Returns(mock2.Object); mock.Setup(foo => foo.Request).Returns(message); mock.Setup(foo => foo.Sender).Returns(new IPEndPoint(IPAddress.Any, 0)); var handler = new TrapV1MessageHandler(); Assert.Throws<ArgumentNullException>(() => handler.Handle(null, null)); Assert.Throws<ArgumentNullException>(() => handler.Handle(mock.Object, null)); handler.MessageReceived += delegate(object args, TrapV1MessageReceivedEventArgs e) { Assert.AreEqual(mock2.Object, e.Binding); Assert.AreEqual(message, e.TrapV1Message); Assert.IsTrue(new IPEndPoint(IPAddress.Any, 0).Equals(e.Sender)); }; handler.Handle(mock.Object, new ObjectStore()); }
/// <summary> /// Initializes a new instance of the <see cref="TrapV1MessageReceivedEventArgs"/> class. /// </summary> /// <param name="sender">The sender.</param> /// <param name="request">The request.</param> /// <param name="binding">The binding.</param> public TrapV1MessageReceivedEventArgs(IPEndPoint sender, TrapV1Message request, IListenerBinding binding) { if (sender == null) { throw new ArgumentNullException("sender"); } if (request == null) { throw new ArgumentNullException("request"); } if (binding == null) { throw new ArgumentNullException("binding"); } Sender = sender; TrapV1Message = request; Binding = binding; }
public void TestSendTrap() { TrapV1Message message = new TrapV1Message(VersionCode.V1, IPAddress.Parse("127.0.0.1"), new OctetString("public"), new ObjectIdentifier(new uint[] {1,3,6}), GenericCode.AuthenticationFailure, 0, 0, new List<Variable>()); byte[] bytes = message.ToBytes(); ISnmpMessage parsed = MessageFactory.ParseMessages(bytes, new UserRegistry())[0]; Assert.AreEqual(SnmpType.TrapV1Pdu, parsed.Pdu.TypeCode); TrapV1Message m = (TrapV1Message)parsed; Assert.AreEqual(GenericCode.AuthenticationFailure, m.Generic); Assert.AreEqual(0, m.Specific); Assert.AreEqual("public", m.Community.ToString()); Assert.AreEqual(IPAddress.Parse("127.0.0.1"), m.AgentAddress); Assert.AreEqual(new uint[] {1,3,6}, m.Enterprise.ToNumerical()); Assert.AreEqual(0, m.TimeStamp); Assert.AreEqual(0, m.Variables.Count); }
public static void SendTrapV1(EndPoint receiver, IPAddress agent, OctetString community, ObjectIdentifier enterprise, GenericCode generic, int specific, uint timestamp, IList<Variable> variables) { var message = new TrapV1Message(VersionCode.V1, agent, community, enterprise, generic, specific, timestamp, variables); message.Send(receiver); }