Ejemplo n.º 1
0
        public void TestFakeTrapTransform()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap));

            Assert.IsNotNull(transform);

            var transformedOutput = transform(this.fakeIpPacket) as FakeTrap;

            Assert.IsNotNull(transformedOutput);
            Assert.AreEqual(506009u, transformedOutput.SysUpTime);
            Assert.AreEqual(5L, transformedOutput.Integer);
            Assert.IsNotNull(transformedOutput.Objects);
            Assert.AreEqual(4, transformedOutput.Objects.Count);
            Assert.AreEqual(IPAddress.Parse(this.fakeIpPacket.SourceIpAddress), transformedOutput.SourceAddress);
            Assert.AreEqual(this.fakeIpPacket.ReceivedTime, transformedOutput.ReceivedTime);

            var varbinds = transformedOutput.Objects;
            var extraneous = varbinds.FirstOrDefault(vb => vb.Oid.Equals(new ObjectIdentifier("1.3.6.1.6.3.1.1.42.42.42.0")));

            Assert.IsNotNull(extraneous);
            Assert.AreNotEqual(default(VarBind), extraneous);
            Assert.AreEqual(8938ul, extraneous.Value);
        }
Ejemplo n.º 2
0
        public void TestFakeTrapTransform()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap));

            Assert.IsNotNull(transform);

            var transformedOutput = transform(this.fakeIpPacket) as FakeTrap;

            Assert.IsNotNull(transformedOutput);
            Assert.AreEqual(506009u, transformedOutput.SysUpTime);
            Assert.AreEqual(5L, transformedOutput.Integer);
            Assert.IsNotNull(transformedOutput.Objects);
            Assert.AreEqual(4, transformedOutput.Objects.Count);
            Assert.AreEqual(IPAddress.Parse(this.fakeIpPacket.SourceIpAddress), transformedOutput.SourceAddress);
            Assert.AreEqual(this.fakeIpPacket.ReceivedTime, transformedOutput.ReceivedTime);

            var varbinds   = transformedOutput.Objects;
            var extraneous = varbinds.FirstOrDefault(vb => vb.Oid.Equals(new ObjectIdentifier("1.3.6.1.6.3.1.1.42.42.42.0")));

            Assert.IsNotNull(extraneous);
            Assert.AreNotEqual(default(VarBind), extraneous);
            Assert.AreEqual(8938ul, extraneous.Value);
        }
Ejemplo n.º 3
0
        public void TestUnattributedClassReturnsNullTransform()
        {
            var typeMap   = new TrapTypeMap();
            var transform = typeMap.GetTransform(typeof(UnmarkedTrap));

            Assert.IsNull(transform);
        }
Ejemplo n.º 4
0
        public void TestNullTrap()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap));

            Assert.IsNotNull(transform);

            var transformedOutput = transform(null) as FakeTrap;

            Assert.IsNull(transformedOutput);
        }
Ejemplo n.º 5
0
        public void TestFakeTrapStringIpTransform()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrapStringIp));

            Assert.IsNotNull(transform);

            var transformedOutput = transform(this.fakeIpPacket) as FakeTrapStringIp;

            Assert.IsNotNull(transformedOutput);
            Assert.AreEqual("1.1.1.1", transformedOutput.SourceAddress);
        }
Ejemplo n.º 6
0
        public void TestFakeTrapStringIpTransform()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrapStringIp));

            Assert.IsNotNull(transform);

            var transformedOutput = transform(this.fakeIpPacket) as FakeTrapStringIp;

            Assert.IsNotNull(transformedOutput);
            Assert.AreEqual("1.1.1.1", transformedOutput.SourceAddress);
        }
Ejemplo n.º 7
0
        public void Test_OctetStringAsByteArray_1()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap2));

            Assert.IsNotNull(transform);

            var octetStringVarBind = new VarBind(
                new ObjectIdentifier("1.3.6.1.4.1.562.29.6.2.2"),
                "Hello",
                new Asn1TagInfo(Asn1Tag.OctetString, ConstructType.Primitive, Asn1Class.Universal));

            var sysUpTime = new VarBind(new ObjectIdentifier("1.3.6.1.2.1.1.3.0"),
                                        506009u,
                                        new Asn1TagInfo(Asn1SnmpTag.TimeTicks));

            var trapVb = new VarBind(new ObjectIdentifier("1.3.6.1.6.3.1.1.4.1.0"),
                                     new ObjectIdentifier("1.3.6.1.4.1.500.12"),
                                     new Asn1TagInfo(Asn1Tag.ObjectIdentifier, ConstructType.Primitive, Asn1Class.Universal));

            var packet = new SnmpDatagramV2C(
                DateTimeOffset.MinValue,
                "1.1.1.1",
                new SnmpHeader(SnmpVersion.V2C, "Community"),
                new[] { sysUpTime, trapVb, octetStringVarBind },
                PduType.SNMPv2Trap,
                50000,
                SnmpErrorStatus.NoError,
                0);

            var transformedOutput = transform(packet) as FakeTrap2;

            Assert.IsNotNull(transformedOutput);
            Assert.IsNotNull(transformedOutput.Property);
            Assert.AreEqual("Hello", Encoding.UTF8.GetString(transformedOutput.Property));
            Assert.AreEqual("Hello", transformedOutput.StringProperty);
        }
Ejemplo n.º 8
0
        public void Test_OctetStringAsByteArray_2()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap2));

            Assert.IsNotNull(transform);

            var payload = new byte[] { 0x07, 0xE0, 0x06, 0x0E, 0x0E, 0x1E, 0x0E, 0x00 };

            var octetStringVarBind = new VarBind(
                new ObjectIdentifier("1.3.6.1.4.1.562.29.6.2.2"),
                payload.ReadOctetString(0, payload.Length),
                new Asn1TagInfo(Asn1Tag.OctetString, ConstructType.Primitive, Asn1Class.Universal));

            var sysUpTime = new VarBind(new ObjectIdentifier("1.3.6.1.2.1.1.3.0"),
                                        506009u,
                                        new Asn1TagInfo(Asn1SnmpTag.TimeTicks));

            var trapVb = new VarBind(new ObjectIdentifier("1.3.6.1.6.3.1.1.4.1.0"),
                                     new ObjectIdentifier("1.3.6.1.4.1.500.12"),
                                     new Asn1TagInfo(Asn1Tag.ObjectIdentifier, ConstructType.Primitive, Asn1Class.Universal));

            var packet = new SnmpDatagram(
                DateTimeOffset.MinValue,
                "1.2.3.4",
                new SnmpHeader(SnmpVersion.V2C, "Community"),
                new[] { sysUpTime, trapVb, octetStringVarBind });

            var transformedOutput = transform(packet) as FakeTrap2;

            Assert.IsNotNull(transformedOutput);
            Assert.IsNotNull(transformedOutput.Property);

            Assert.AreEqual(payload.Length, transformedOutput.Property.Length);
            Assert.IsTrue(payload.Zip(transformedOutput.Property, (b, b1) => b == b1).All(i => i));
        }
Ejemplo n.º 9
0
        public void Test_Enum()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap3));

            Assert.IsNotNull(transform);

            var integerVarBind = new VarBind(
                new ObjectIdentifier("1.3.6.1.4.1.562.29.6.1.1.1.6"),
                1L,
                new Asn1TagInfo(Asn1Tag.Integer, ConstructType.Primitive, Asn1Class.Universal));

            var sysUpTime = new VarBind(new ObjectIdentifier("1.3.6.1.2.1.1.3.0"),
                                        506009u,
                                        new Asn1TagInfo(Asn1SnmpTag.TimeTicks));

            var trapVb = new VarBind(new ObjectIdentifier("1.3.6.1.6.3.1.1.4.1.0"),
                                     new ObjectIdentifier("1.3.6.1.4.1.500.12"),
                                     new Asn1TagInfo(Asn1Tag.ObjectIdentifier, ConstructType.Primitive, Asn1Class.Universal));

            var packet = new SnmpDatagramV2C(
                DateTimeOffset.MinValue,
                "1.1.1.1",
                new SnmpHeader(SnmpVersion.V2C, "Community"),
                new[] { sysUpTime, trapVb, integerVarBind },
                PduType.SNMPv2Trap,
                50000,
                SnmpErrorStatus.NoError,
                0);

            var transformedOutput = transform(packet) as FakeTrap3;

            Assert.IsNotNull(transformedOutput);
            Assert.AreEqual(SimpleEnum.B, transformedOutput.EnumProperty);
        }
Ejemplo n.º 10
0
        public void Test_OctetStringAsByteArray_2()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap2));

            Assert.IsNotNull(transform);

            var payload = new byte[] { 0x07, 0xE0, 0x06, 0x0E, 0x0E, 0x1E, 0x0E, 0x00 };

            var octetStringVarBind = new VarBind(
                new ObjectIdentifier("1.3.6.1.4.1.562.29.6.2.2"),
                payload.ReadOctetString(0, payload.Length),
                new Asn1TagInfo(Asn1Tag.OctetString, ConstructType.Primitive, Asn1Class.Universal));

            var sysUpTime = new VarBind(new ObjectIdentifier("1.3.6.1.2.1.1.3.0"),
                506009u,
                new Asn1TagInfo(Asn1SnmpTag.TimeTicks));

            var trapVb = new VarBind(new ObjectIdentifier("1.3.6.1.6.3.1.1.4.1.0"),
                new ObjectIdentifier("1.3.6.1.4.1.500.12"),
                new Asn1TagInfo(Asn1Tag.ObjectIdentifier, ConstructType.Primitive, Asn1Class.Universal));

            var packet = new SnmpDatagram(
                DateTimeOffset.MinValue,
                "1.2.3.4",
                new SnmpHeader(SnmpVersion.V2C, "Community"),
                new[] { sysUpTime, trapVb, octetStringVarBind });

            var transformedOutput = transform(packet) as FakeTrap2;

            Assert.IsNotNull(transformedOutput);
            Assert.IsNotNull(transformedOutput.Property);

            Assert.AreEqual(payload.Length, transformedOutput.Property.Length);
            Assert.IsTrue(payload.Zip(transformedOutput.Property, (b, b1) => b == b1).All(i => i));
        }
Ejemplo n.º 11
0
        public void Test_OctetStringAsByteArray_1()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap2));

            Assert.IsNotNull(transform);

            var octetStringVarBind = new VarBind(
                new ObjectIdentifier("1.3.6.1.4.1.562.29.6.2.2"),
                "Hello",
                new Asn1TagInfo(Asn1Tag.OctetString, ConstructType.Primitive, Asn1Class.Universal));

            var sysUpTime = new VarBind(new ObjectIdentifier("1.3.6.1.2.1.1.3.0"),
                506009u,
                new Asn1TagInfo(Asn1SnmpTag.TimeTicks));

            var trapVb = new VarBind(new ObjectIdentifier("1.3.6.1.6.3.1.1.4.1.0"),
                new ObjectIdentifier("1.3.6.1.4.1.500.12"),
                new Asn1TagInfo(Asn1Tag.ObjectIdentifier, ConstructType.Primitive, Asn1Class.Universal));

            var packet = new SnmpDatagramV2C(
                DateTimeOffset.MinValue,
                "1.1.1.1",
                new SnmpHeader(SnmpVersion.V2C, "Community"),
                new[] { sysUpTime, trapVb, octetStringVarBind },
                PduType.SNMPv2Trap,
                50000,
                SnmpErrorStatus.NoError,
                0);

            var transformedOutput = transform(packet) as FakeTrap2;

            Assert.IsNotNull(transformedOutput);
            Assert.IsNotNull(transformedOutput.Property);
            Assert.AreEqual("Hello", Encoding.UTF8.GetString(transformedOutput.Property));
            Assert.AreEqual("Hello", transformedOutput.StringProperty);
        }
Ejemplo n.º 12
0
        public void Test_Enum()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap3));

            Assert.IsNotNull(transform);

            var integerVarBind = new VarBind(
                new ObjectIdentifier("1.3.6.1.4.1.562.29.6.1.1.1.6"),
                1L,
                new Asn1TagInfo(Asn1Tag.Integer, ConstructType.Primitive, Asn1Class.Universal));

            var sysUpTime = new VarBind(new ObjectIdentifier("1.3.6.1.2.1.1.3.0"),
                506009u,
                new Asn1TagInfo(Asn1SnmpTag.TimeTicks));

            var trapVb = new VarBind(new ObjectIdentifier("1.3.6.1.6.3.1.1.4.1.0"),
                new ObjectIdentifier("1.3.6.1.4.1.500.12"),
                new Asn1TagInfo(Asn1Tag.ObjectIdentifier, ConstructType.Primitive, Asn1Class.Universal));

            var packet = new SnmpDatagramV2C(
                DateTimeOffset.MinValue,
                "1.1.1.1",
                new SnmpHeader(SnmpVersion.V2C, "Community"),
                new[] { sysUpTime, trapVb, integerVarBind },
                PduType.SNMPv2Trap,
                50000,
                SnmpErrorStatus.NoError,
                0);

            var transformedOutput = transform(packet) as FakeTrap3;

            Assert.IsNotNull(transformedOutput);
            Assert.AreEqual(SimpleEnum.B, transformedOutput.EnumProperty);
        }
Ejemplo n.º 13
0
        public void TestNullTrap()
        {
            var typeMap = new TrapTypeMap();

            var transform = typeMap.GetTransform(typeof(FakeTrap));

            Assert.IsNotNull(transform);

            var transformedOutput = transform(null) as FakeTrap;

            Assert.IsNull(transformedOutput);
        }