Exemple #1
0
        public TextualConvention(IModule module, string name, ISymbolEnumerator symbols)
        {
            _module = module;
            _name = name;

            _displayHint = ParseDisplayHint(symbols);
            _status      = ParseStatus(symbols);
            _description = ParseDescription(symbols);
            _reference   = ParseReference(symbols);
            _syntax      = ParseSyntax(module, symbols);
        }
Exemple #2
0
        public TextualConvention(IModule module, string name, ISymbolEnumerator symbols)
        {
            _module = module;
            _name   = name;

            _displayHint = ParseDisplayHint(symbols);
            _status      = ParseStatus(symbols);
            _description = ParseDescription(symbols);
            _reference   = ParseReference(symbols);
            _syntax      = ParseSyntax(module, symbols);
        }
        private void ShowTypeChain(ListView lv, ITypeAssignment type)
        {
            ShowTypeDetails(lv, this.listviewgroupTypeChain, type);

            ITypeReferrer tr = type as ITypeReferrer;

            if ((tr != null) && (tr.ReferredType != null))
            {
                lv.Items.Add(new ListViewItem(new string[] { " >>>", "" }, this.listviewgroupTypeChain));
                ShowTypeChain(listviewNodeDetails, tr.ReferredType);
            }
        }
Exemple #4
0
        private void ParseProperties(SymbolList header)
        {
            ISymbolEnumerator headerSymbols = header.GetSymbolEnumerator();
            Symbol temp = headerSymbols.NextNonEOLSymbol();

            // Skip name
            temp = headerSymbols.NextNonEOLSymbol();
            temp.Expect(Symbol.ObjectType);

            _syntax         = ParseSyntax       (Module, headerSymbols);
            _units          = ParseUnits        (headerSymbols);
            _access         = ParseAccess       (headerSymbols);
            _status         = ParseStatus       (headerSymbols);
            _description    = ParseDescription  (headerSymbols);
            _reference      = ParseReference    (headerSymbols);
            _indices        = ParseIndices      (headerSymbols);
            _augments        = ParseAugments     (headerSymbols);
            _defVal         = ParseDefVal       (headerSymbols);
        }
        private void ParseProperties(SymbolList header)
        {
            ISymbolEnumerator headerSymbols = header.GetSymbolEnumerator();
            Symbol            temp          = headerSymbols.NextNonEOLSymbol();

            // Skip name
            temp = headerSymbols.NextNonEOLSymbol();
            temp.Expect(Symbol.ObjectType);

            _syntax      = ParseSyntax(Module, headerSymbols);
            _units       = ParseUnits(headerSymbols);
            _access      = ParseAccess(headerSymbols);
            _status      = ParseStatus(headerSymbols);
            _description = ParseDescription(headerSymbols);
            _reference   = ParseReference(headerSymbols);
            _indices     = ParseIndices(headerSymbols);
            _augments    = ParseAugments(headerSymbols);
            _defVal      = ParseDefVal(headerSymbols);
        }
Exemple #6
0
        private void ParseProperties(IEnumerable <Symbol> header)
        {
            IEnumerator <Symbol> enumerator = header.GetEnumerator();
            Symbol temp = enumerator.NextNonEOLSymbol();

            // Skip name
            temp = enumerator.NextNonEOLSymbol();

            temp.Expect(Symbol.ObjectType);
            temp = enumerator.NextNonEOLSymbol();

            _syntax      = ParseSyntax(_module, _name, enumerator, ref temp);
            _units       = ParseUnits(enumerator, ref temp);
            _access      = ParseAccess(enumerator, ref temp);
            _status      = ParseStatus(enumerator, ref temp);
            _description = ParseDescription(enumerator, ref temp);
            _reference   = ParseReference(enumerator, ref temp);
            _indices     = ParseIndices(enumerator, ref temp);
            _augment     = ParseAugments(enumerator, ref temp);
            _defVal      = ParseDefVal(enumerator, ref temp);
        }
Exemple #7
0
        private void ParseProperties(IEnumerable<Symbol> header)
        {
            IEnumerator<Symbol> enumerator = header.GetEnumerator();
            Symbol temp = enumerator.NextNonEOLSymbol();

            // Skip name
            temp = enumerator.NextNonEOLSymbol();

            temp.Expect(Symbol.ObjectType);
            temp = enumerator.NextNonEOLSymbol();

            _syntax         = ParseSyntax       (_module, _name, enumerator, ref temp);
            _units          = ParseUnits        (enumerator, ref temp);
            _access         = ParseAccess       (enumerator, ref temp);
            _status         = ParseStatus       (enumerator, ref temp);
            _description    = ParseDescription  (enumerator, ref temp);
            _reference      = ParseReference    (enumerator, ref temp);
            _indices        = ParseIndices      (enumerator, ref temp);
            _augment        = ParseAugments     (enumerator, ref temp);
            _defVal         = ParseDefVal       (enumerator, ref temp);
        }
        public TextualConvention(string module, string name, Lexer lexer)
        {
            _name = name;

            Symbol temp = lexer.GetNextNonEOLSymbol();

            if (temp == Symbol.DisplayHint)
            {
                // TODO: this needs decoding to a useful format.
                _displayHint = new DisplayHint(lexer.GetNextNonEOLSymbol().ToString().Trim(new[] { '"' }));
                temp         = lexer.GetNextNonEOLSymbol();
            }

            temp.Expect(Symbol.Status);
            try
            {
                _status = StatusHelper.CreateStatus(lexer.GetNextNonEOLSymbol().ToString());
                temp    = lexer.GetNextNonEOLSymbol();
            }
            catch (ArgumentException)
            {
                temp.Throw("Invalid status");
            }

            temp.Expect(Symbol.Description);
            _description = lexer.GetNextNonEOLSymbol().ToString().Trim(new[] { '"' });
            temp         = lexer.GetNextNonEOLSymbol();

            if (temp == Symbol.Reference)
            {
                _reference = lexer.GetNextNonEOLSymbol().ToString();
                temp       = lexer.GetNextNonEOLSymbol();
            }

            temp.Expect(Symbol.Syntax);

            /*
             * RFC2579 definition:
             *       Syntax ::=   -- Must be one of the following:
             *                    -- a base type (or its refinement), or
             *                    -- a BITS pseudo-type
             *               type
             *             | "BITS" "{" NamedBits "}"
             *
             * From section 3.5:
             *      The data structure must be one of the alternatives defined
             *      in the ObjectSyntax CHOICE or the BITS construct.  Note
             *      that this means that the SYNTAX clause of a Textual
             *      Convention can not refer to a previously defined Textual
             *      Convention.
             *
             *      The SYNTAX clause of a TEXTUAL CONVENTION macro may be
             *      sub-typed in the same way as the SYNTAX clause of an
             *      OBJECT-TYPE macro.
             *
             * Therefore the possible values are (grouped by underlying type):
             *      INTEGER, Integer32
             *      OCTET STRING, Opaque
             *      OBJECT IDENTIFIER
             *      IpAddress
             *      Counter64
             *      Unsigned32, Counter32, Gauge32, TimeTicks
             *      BITS
             * With appropriate sub-typing.
             */

            temp = lexer.GetNextNonEOLSymbol();
            if (temp == Symbol.Bits)
            {
                _syntax = new BitsType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Integer || temp == Symbol.Integer32)
            {
                _syntax = new IntegerType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Octet)
            {
                temp = lexer.GetNextSymbol();
                temp.Expect(Symbol.String);
                _syntax = new OctetStringType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Opaque)
            {
                _syntax = new OctetStringType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.IpAddress)
            {
                _syntax = new IpAddressType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Counter64)
            {
                _syntax = new Counter64Type(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Unsigned32 || temp == Symbol.Counter32 || temp == Symbol.Gauge32 || temp == Symbol.TimeTicks)
            {
                _syntax = new UnsignedType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Object)
            {
                temp = lexer.GetNextSymbol();
                temp.Expect(Symbol.Identifier);
                _syntax = new ObjectIdentifierType(module, string.Empty, lexer);
            }
            else
            {
                //temp.Throw("illegal syntax for textual convention");
                _syntax = new CustomType(module, string.Empty, lexer);
            }
        }
 private void ShowTypeDetails(ListView lv, ListViewGroup lvg, ITypeAssignment type)
 {
     lv.Items.Add(new ListViewItem(new string[] { "Module", (type.Module != null) ? type.Module.Name : "" }, lvg));
     lv.Items.Add(new ListViewItem(new string[] { "Type", type.GetType().Name }, lvg));
     lv.Items.Add(new ListViewItem(new string[] { "Name", type.Name }, lvg));
 }
        private static SnmpScalarNode GenerateSnmpScalarNode(ObjectType ote, SnmpTreeNode parentNode, bool ignoreAccessibleFlag = false)
        {
            SnmpScalarNode result;

            ITypeAssignment mibType = ote.BaseType;
            IntegerType     it      = (mibType as IntegerType);

            if (it != null)
            {
                if (ote.ReferredType.Name == Symbol.TruthValue.ToString())
                {
                    result = new SnmpScalarNodeTruthValue(parentNode);
                }
                else if ((it.Type == IntegerType.Types.Integer) || (it.Type == IntegerType.Types.Integer32))
                {
                    result = new SnmpScalarNodeInt(parentNode);
                }
                else
                {
                    Console.WriteLine(String.Format("Unsupported IntegerType '{0}'!", it.Type));
                    return(null);
                }
                if (it.IsEnumeration)
                {
                    result.Restrictions.AddRange(CreateRestrictions(it.Enumeration));
                }
                else
                {
                    result.Restrictions.AddRange(CreateRestrictions(it.Ranges));
                }
            }
            else
            {
                UnsignedType ut = (mibType as UnsignedType);
                if (ut != null)
                {
                    if ((ut.Type == UnsignedType.Types.Unsigned32) ||
                        (ut.Type == UnsignedType.Types.Gauge32))
                    {
                        result = new SnmpScalarNodeUint(SnmpDataType.Gauge, parentNode);
                    }
                    else if (ut.Type == UnsignedType.Types.Counter32)
                    {
                        result = new SnmpScalarNodeUint(SnmpDataType.Counter, parentNode);
                    }
                    else if (ut.Type == UnsignedType.Types.TimeTicks)
                    {
                        result = new SnmpScalarNodeUint(SnmpDataType.TimeTicks, parentNode);
                    }
                    else if (ut.Type == UnsignedType.Types.Counter64)
                    {
                        result = new SnmpScalarNodeCounter64(parentNode);
                        if ((ut.Ranges != null) && (ut.Ranges.Count > 0))
                        {
                            Console.WriteLine(String.Format("Generation of ranges is not supported for Counter64 type!"));
                            return(null);
                        }
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Unsupported UnsignedType '{0}'!", ut.Type));
                        return(null);
                    }
                    result.Restrictions.AddRange(CreateRestrictions(ut.Ranges));
                }
                else if (mibType is IpAddressType)
                {
                    result = new SnmpScalarNodeOctetString(SnmpDataType.IpAddress, parentNode);
                    result.Restrictions.AddRange(CreateRestrictions((mibType as OctetStringType).Size));
                }
                else if (mibType is OpaqueType)
                {
                    result = new SnmpScalarNodeOctetString(SnmpDataType.Opaque, parentNode);
                    result.Restrictions.AddRange(CreateRestrictions((mibType as OctetStringType).Size));
                }
                else if (mibType is OctetStringType)
                {
                    result = new SnmpScalarNodeOctetString(SnmpDataType.OctetString, parentNode);
                    result.Restrictions.AddRange(CreateRestrictions((mibType as OctetStringType).Size));
                }
                else if (mibType is ObjectIdentifierType)
                {
                    result = new SnmpScalarNodeObjectIdentifier(parentNode);
                }
                else if (mibType is BitsType)
                {
                    result = new SnmpScalarNodeBits(parentNode, (uint)((mibType as BitsType).Map.GetHighestValue() + 1));
                    result.Restrictions.AddRange(CreateRestrictions(mibType as BitsType));
                }
                else
                {
                    TypeAssignment ta = mibType as TypeAssignment;
                    if (ta != null)
                    {
                        Console.WriteLine(String.Format("Unsupported BaseType: Module='{0}', Name='{1}', Type='{2}'!", ta.Module.Name, ta.Name, ta.Type));
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Unsupported BaseType: Module='{0}', Name='{1}'!", mibType.Module, mibType.Name));
                    }

                    return(null);
                }
            }

            result.Name = _alphaNumericRegex.Replace(ote.Name, "");
            result.Oid  = ote.Value;

            if (ote.Access == MaxAccess.readWrite)
            {
                result.AccessMode = SnmpAccessMode.ReadWrite;
            }
            else if (ote.Access == MaxAccess.readOnly)
            {
                result.AccessMode = SnmpAccessMode.ReadOnly;
            }
            else if (ote.Access == MaxAccess.readCreate)
            {
                result.AccessMode = SnmpAccessMode.ReadOnly;
            }
            else if (ignoreAccessibleFlag && (ote.Access == MaxAccess.notAccessible))
            {
                result.AccessMode = SnmpAccessMode.NotAccessible;
            }
            else
            {
                // not accessible or unsupported access type
                return(null);
            }

            return(result);
        }
        public static ITypeAssignment ResolveType(IModule module, TypeAssignment type)
        {
            ITypeAssignment result = ResolveDeclaration(module, type.Type) as ITypeAssignment;

            return((result != null) ? result : type);
        }
Exemple #12
0
		private void ShowTypeDetails(ListView lv, ListViewGroup lvg, ITypeAssignment type)
		{
			lv.Items.Add(new ListViewItem(new string[] { "Module", (type.Module != null) ? type.Module.Name : "" }, lvg));
			lv.Items.Add(new ListViewItem(new string[] { "Type", type.GetType().Name }, lvg));
			lv.Items.Add(new ListViewItem(new string[] { "Name", type.Name }, lvg));
		}
Exemple #13
0
		private void ShowTypeChain(ListView lv, ITypeAssignment type)
		{
			ShowTypeDetails(lv, this.listviewgroupTypeChain, type);

			ITypeReferrer tr = type as ITypeReferrer;
			if ((tr != null) && (tr.ReferredType != null))
			{
				lv.Items.Add(new ListViewItem(new string[] { " >>>", "" }, this.listviewgroupTypeChain));
				ShowTypeChain(listviewNodeDetails, tr.ReferredType);
			}
		}
Exemple #14
0
        public TextualConvention(string module, string name, Lexer lexer)
        {
            _name = name;

            Symbol temp = lexer.GetNextNonEOLSymbol();

            if (temp == Symbol.DisplayHint)
            {
                // TODO: this needs decoding to a useful format.
                _displayHint = new DisplayHint(lexer.GetNextNonEOLSymbol().ToString().Trim(new[] { '"' }));
                temp = lexer.GetNextNonEOLSymbol();
            }

            temp.Expect(Symbol.Status);
            try
            {
                _status = StatusHelper.CreateStatus(lexer.GetNextNonEOLSymbol().ToString());
                temp = lexer.GetNextNonEOLSymbol();
            }
            catch (ArgumentException)
            {
                temp.Throw("Invalid status");
            }

            temp.Expect(Symbol.Description);
            _description = lexer.GetNextNonEOLSymbol().ToString().Trim(new[] { '"' });
            temp = lexer.GetNextNonEOLSymbol();

            if (temp == Symbol.Reference)
            {
                _reference = lexer.GetNextNonEOLSymbol().ToString();
                temp = lexer.GetNextNonEOLSymbol();
            }

            temp.Expect(Symbol.Syntax);

            /* 
             * RFC2579 definition:
             *       Syntax ::=   -- Must be one of the following:
             *                    -- a base type (or its refinement), or
             *                    -- a BITS pseudo-type
             *               type
             *             | "BITS" "{" NamedBits "}"
             *
             * From section 3.5:
             *      The data structure must be one of the alternatives defined
             *      in the ObjectSyntax CHOICE or the BITS construct.  Note
             *      that this means that the SYNTAX clause of a Textual
             *      Convention can not refer to a previously defined Textual
             *      Convention.
             *      
             *      The SYNTAX clause of a TEXTUAL CONVENTION macro may be
             *      sub-typed in the same way as the SYNTAX clause of an
             *      OBJECT-TYPE macro.
             * 
             * Therefore the possible values are (grouped by underlying type):
             *      INTEGER, Integer32
             *      OCTET STRING, Opaque
             *      OBJECT IDENTIFIER
             *      IpAddress
             *      Counter64
             *      Unsigned32, Counter32, Gauge32, TimeTicks
             *      BITS
             * With appropriate sub-typing.
             */

            temp = lexer.GetNextNonEOLSymbol();
            if (temp == Symbol.Bits)
            {
                _syntax = new BitsType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Integer || temp == Symbol.Integer32)
            {
                _syntax = new IntegerType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Octet)
            {
                temp = lexer.GetNextSymbol();
                temp.Expect(Symbol.String);
                _syntax = new OctetStringType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Opaque)
            {
                _syntax = new OctetStringType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.IpAddress)
            {
                _syntax = new IpAddressType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Counter64)
            {
                _syntax = new Counter64Type(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Unsigned32 || temp == Symbol.Counter32 || temp == Symbol.Gauge32 || temp == Symbol.TimeTicks)
            {
                _syntax = new UnsignedType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Object)
            {
                temp = lexer.GetNextSymbol();
                temp.Expect(Symbol.Identifier);
                _syntax = new ObjectIdentifierType(module, string.Empty, lexer);
            }
            else
            {
                //temp.Throw("illegal syntax for textual convention");
                _syntax = new CustomType(module, string.Empty, lexer);
            }
        }