Exemplo n.º 1
0
 public void TestParse3()
 {
     const string test = "::=BEGIN";
     Lexer lexer = new Lexer();
     StringReader reader = new StringReader(test);
     lexer.Parse(reader);
     Assert.AreEqual("::=", lexer.NextSymbol.ToString());
     Assert.AreEqual("BEGIN", lexer.NextSymbol.ToString());
 }       
 public void TestMethod()
 {
     Lexer lexer = new Lexer();
     lexer.Parse(new StringReader("{ iso org(3) dod(6) 1 }"));
     string parent;
     uint value;
     lexer.ParseOidValue(out parent, out value);
     Assert.AreEqual("iso.org(3).dod(6)", parent);
     Assert.AreEqual(1, value);
 }
Exemplo n.º 3
0
 public void TestParse()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.SNMPv2_SMI);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     Assert.AreEqual(909, lexer.SymbolCount);
 }
        public void TestMethod1()
        {
            Lexer lexer = new Lexer();
            lexer.Parse(new StringReader("{ iso(1) std(0) iso8802(8802) ieee802dot1(1)" + Environment.NewLine +
"     ieee802dot1mibs(1) 1 }"));
            string parent;
            uint value;
            lexer.ParseOidValue(out parent, out value);
            Assert.AreEqual("iso(1).std(0).iso8802(8802).ieee802dot1(1).ieee802dot1mibs(1)", parent);
            Assert.AreEqual(1, value);
        }
        public void TestException()
        {
            Lexer lexer = new Lexer();
            MemoryStream m = new MemoryStream(Resources.fivevarbinds);
            using (StreamReader reader = new StreamReader(m))
            {
                lexer.Parse("temp.txt", reader);
                reader.Close();
            }

            new MibDocument(lexer);
        }
Exemplo n.º 6
0
        public void TestOverlappingRanges3()
        {
            const string test = "SomeEnum ::= INTEGER (8 | 8 | 31 .. 60 )";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.Integer);

            Assert.Throws<MibException>(() => new IntegerType("module", "name", lexer));
        }
Exemplo n.º 7
0
        public void Test()
        {
            const string test = "SomeIp ::= IpAddress";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.IpAddress);

            IpAddressType i = new IpAddressType("module", "name", lexer);
        }
Exemplo n.º 8
0
        public void TestEnumerable()
        {
            const string test = "SomeEnum ::= Counter64";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.Counter64);

            Counter64Type i = new Counter64Type("module", "name", lexer);
        }
Exemplo n.º 9
0
        public void TestNegative()
        {
            const string test = "SomeEnum ::= OCTET STRING ( SIZE (8 | -5 .. 20 | 31 .. 60 ))";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.Octet);
            lexer.GetNextSymbol().Expect(Symbol.String);

            Assert.Throws<MibException>(delegate { new OctetStringType("module", "name", lexer); });
        }
Exemplo n.º 10
0
        public void Test()
        {
            const string test = "SomeEnum ::= BITS {first(1), second(2)}";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.Bits);

            BitsType i = new BitsType("module", "name", lexer);
            Assert.AreEqual("first(1)", i[1]);
        }
Exemplo n.º 11
0
        public void TestEnumerable()
        {
            const string test = "SomeEnum ::= INTEGER {first(1), second(2)}";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.Integer);

            IntegerType i = new IntegerType("module", "name", lexer);
            Assert.IsTrue(i.IsEnumeration);
            Assert.AreEqual("first(1)", i[1]);
        }
Exemplo n.º 12
0
        private static IList <IModule> CompileToModules(string file, TextReader stream)
        {
            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();
            Lexer lexer = new Lexer();

            lexer.Parse(file, stream);
            MibDocument doc = new MibDocument(lexer);

            Logger.Info(watch.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture) + "-ms used to parse " + file);
            watch.Stop();
            return(doc.Modules);
        }
Exemplo n.º 13
0
 public void TestEmpty()
 {
     // issue 4978
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.empty);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual("SNMPV2-CONF", file.Modules[0].Name);
     Assert.AreEqual(0, file.Modules[0].Dependents.Count);
     Assert.AreEqual(0, file.Modules[0].Entities.Count);
 }
Exemplo n.º 14
0
        public void TestHttpMib()
        {
            // issue 4978
            Lexer lexer = new Lexer();
            MemoryStream m = new MemoryStream(Resources.httpmib);
            using (StreamReader reader = new StreamReader(m))
            {
                lexer.Parse(reader);
                reader.Close();
            }

            MibDocument file = new MibDocument(lexer);
            Assert.AreEqual("HTTPSERVER-MIB", file.Modules[0].Name);
            Assert.AreEqual(0, file.Modules[0].Dependents.Count);
            Assert.AreEqual(0, file.Modules[0].Entities.Count);
        }        
Exemplo n.º 15
0
 // TODO: [Test]
 public void TestSNMPv2_PDU()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.SNMPV2_PDU);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual("SNMPv2-PDU", file.Modules[0].Name);
     Assert.AreEqual(5, file.Modules[0].Dependents.Count);
     Assert.AreEqual(55, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[54];
     Assert.AreEqual("casConfigGroup", node.Name);
     Assert.AreEqual(2, node.Value);
     Assert.AreEqual("casMIBGroups", node.Parent);
 }
Exemplo n.º 16
0
        public void TestRanges()
        {
            const string test = "SomeEnum ::= INTEGER (8 |10 ..20| 31..60 )";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.Integer);

            IntegerType i = new IntegerType("module", "name", lexer);
            Assert.IsFalse(i.IsEnumeration);
            Assert.IsTrue(i.Contains(8));
            Assert.IsTrue(i.Contains(10));
            Assert.IsTrue(i.Contains(15));
            Assert.IsTrue(i.Contains(20));
            Assert.IsTrue(i.Contains(35));
            Assert.IsFalse(i.Contains(4));
            Assert.IsFalse(i.Contains(-9));
            Assert.IsFalse(i.Contains(25));
            Assert.IsFalse(i.Contains(61));
        }
Exemplo n.º 17
0
        public void TestRanges()
        {
            const string test = "SomeEnum ::= OCTET STRING ( SIZE (5 | 8 .. 20 | 31 .. 60 ))";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.Octet);
            lexer.GetNextSymbol().Expect(Symbol.String);

            OctetStringType i = new OctetStringType("module", "name", lexer);
            Assert.IsTrue(i.Contains(8));
            Assert.IsTrue(i.Contains(5));
            Assert.IsTrue(i.Contains(15));
            Assert.IsTrue(i.Contains(20));
            Assert.IsTrue(i.Contains(35));
            Assert.IsFalse(i.Contains(4));
            Assert.IsFalse(i.Contains(-9));
            Assert.IsFalse(i.Contains(25));
            Assert.IsFalse(i.Contains(61));
        }
Exemplo n.º 18
0
 public void TestNet_Snmp_System_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NET_SNMP_SYSTEM_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NET-SNMP-SYSTEM-MIB", file.Modules[0].Name);
     Assert.AreEqual(6, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[5];
     Assert.AreEqual("nsDiskIO", node.Name);
     Assert.AreEqual(35, node.Value);
     Assert.AreEqual("netSnmpObjects", node.Parent);
 }
Exemplo n.º 19
0
 public void TestIPv6_Flow_Label_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.IPV6_FLOW_LABEL_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("IPV6-FLOW-LABEL-MIB", file.Modules[0].Name);
     Assert.AreEqual(1, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[0];
     Assert.AreEqual("ipv6FlowLabelMIB", node.Name);
     Assert.AreEqual(103, node.Value);
     Assert.AreEqual("mib-2", node.Parent);
 }
Exemplo n.º 20
0
 public void TestUDP_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.UDP_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("UDP-MIB", file.Modules[0].Name);
     Assert.AreEqual(31, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[30];
     Assert.AreEqual("udpEndpointGroup", node.Name);
     Assert.AreEqual(4, node.Value);
     Assert.AreEqual("udpMIBGroups", node.Parent);
 }
Exemplo n.º 21
0
 public void TestNetwork_Service_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NETWORK_SERVICES_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NETWORK-SERVICES-MIB", file.Modules[0].Name);
     Assert.AreEqual(44, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[43];
     Assert.AreEqual("applUDPProtoID", node.Name);
     Assert.AreEqual(5, node.Value);
     Assert.AreEqual("application", node.Parent);
 }
Exemplo n.º 22
0
 public void TestNotification_Log_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NOTIFICATION_LOG_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NOTIFICATION-LOG-MIB", file.Modules[0].Name);
     Assert.AreEqual(55, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[54];
     Assert.AreEqual("notificationLogDateGroup", node.Name);
     Assert.AreEqual(4, node.Value);
     Assert.AreEqual("notificationLogMIBGroups", node.Parent);
 }
Exemplo n.º 23
0
 public void TestNet_Snmp_TC()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NET_SNMP_TC);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NET-SNMP-TC", file.Modules[0].Name);
     Assert.AreEqual(24, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[23];
     Assert.AreEqual("netSnmpCallbackDomain", node.Name);
     Assert.AreEqual(6, node.Value);
     Assert.AreEqual("netSnmpDomains", node.Parent);
 }
Exemplo n.º 24
0
 public void TestNet_Snmp_VACM_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NET_SNMP_VACM_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NET-SNMP-VACM-MIB", file.Modules[0].Name);
     Assert.AreEqual(8, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[7];
     Assert.AreEqual("nsVacmStatus", node.Name);
     Assert.AreEqual(5, node.Value);
     Assert.AreEqual("nsVacmAccessEntry", node.Parent);
 }
Exemplo n.º 25
0
 public void TestMTA_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.MTA_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("MTA-MIB", file.Modules[0].Name);
     Assert.AreEqual(81, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[80];
     Assert.AreEqual("mtaRFC2789ErrorGroup", node.Name);
     Assert.AreEqual(9, node.Value);
     Assert.AreEqual("mtaGroups", node.Parent);
 }
Exemplo n.º 26
0
 public void TestNet_Snmp_Examples_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NET_SNMP_EXAMPLES_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NET-SNMP-EXAMPLES-MIB", file.Modules[0].Name);
     Assert.AreEqual(25, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[24];
     Assert.AreEqual("netSnmpExampleNotification", node.Name);
     Assert.AreEqual(1, node.Value);
     Assert.AreEqual("netSnmpExampleNotifications", node.Parent);
 }
Exemplo n.º 27
0
 public void TestNet_Snmp_Monitor_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NET_SNMP_MONITOR_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NET-SNMP-MONITOR-MIB", file.Modules[0].Name);
     Assert.AreEqual(5, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[4];
     Assert.AreEqual("nsLog", node.Name);
     Assert.AreEqual(24, node.Value);
     Assert.AreEqual("netSnmpObjects", node.Parent);
 }
Exemplo n.º 28
0
 public void TestNet_Snmp_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NET_SNMP_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NET-SNMP-MIB", file.Modules[0].Name);
     Assert.AreEqual(14, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[13];
     Assert.AreEqual("netSnmpGroups", node.Name);
     Assert.AreEqual(2, node.Value);
     Assert.AreEqual("netSnmpConformance", node.Parent);
 }
Exemplo n.º 29
0
 public void TestNet_Snmp_Extend_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NET_SNMP_EXTEND_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NET-SNMP-EXTEND-MIB", file.Modules[0].Name);
     Assert.AreEqual(27, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[26];
     Assert.AreEqual("nsExtendOutputGroup", node.Name);
     Assert.AreEqual(2, node.Value);
     Assert.AreEqual("nsExtendGroups", node.Parent);
 }
Exemplo n.º 30
0
 public void TestNet_Snmp_Agent_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.NET_SNMP_AGENT_MIB);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("NET-SNMP-AGENT-MIB", file.Modules[0].Name);
     Assert.AreEqual(54, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[53];
     Assert.AreEqual("nsAgentNotifyGroup", node.Name);
     Assert.AreEqual(9, node.Value);
     Assert.AreEqual("netSnmpGroups", node.Parent);
 }
Exemplo n.º 31
0
 public void TestRFC1157_SNMP_MIB()
 {
     Lexer lexer = new Lexer();
     MemoryStream m = new MemoryStream(Resources.RFC1157_SNMP);
     using (StreamReader reader = new StreamReader(m))
     {
         lexer.Parse(reader);
         reader.Close();
     }
     MibDocument file = new MibDocument(lexer);
     Assert.AreEqual("RFC1157-SNMP", file.Modules[0].Name);
     Assert.AreEqual(1, file.Modules[0].Dependents.Count);
     Assert.AreEqual(0, file.Modules[0].Entities.Count);
 }