Friday, 19 September 2014

Import objects should link to proper source MIB definition - Part 2

Now will apply the same changes to Mib project.

As preparation, need to get all dependent MIB files:
  • RFC1155-SMI.mib (Extract from rfc, section 6 - Definitions)
  • RFC-1212.mib (Extract from rfc, section 4 - Defining Objects, need to complete it manually)
  • RFC1158-MIB.mib (Extract from rfc, section 6 - Definitions) - This is dependent for RFC-1212 on "DisplayString" definition only. This is obsoleted by RFC1213.
Open each files in Xtext Editor, make sure MIB grammar able to handle them.

 

RFC1155-SMI.mib

Following format is not supported:

RFC1155-SMI.mib
internet      OBJECT IDENTIFIER ::= { iso org(3) dod(6) 1 }

Therefore, modify the file to following

RFC1155-SMI.mib
-- internet      OBJECT IDENTIFIER ::= { iso org(3) dod(6) 1 }

iso           OBJECT IDENTIFIER ::= { 0 }

org           OBJECT IDENTIFIER ::= { iso 3 }

dod           OBJECT IDENTIFIER ::= { org 6 }

internet      OBJECT IDENTIFIER ::= { dod 1 }

"iso" is the root most, so make an exception for it.

Mib.xtext
OidValue:

// '::=' '{' parent=[Object] oidnum=INT '}';

'::=' '{' parent=[Object]? oidnum=INT '}';


After this, error there will be :



This file also contains a new type called MACRO.

RFC1155-SMI.mib
OBJECT-TYPE MACRO ::= BEGIN
  TYPE NOTATION ::= "SYNTAX" type (TYPE ObjectSyntax)
    "ACCESS" Access
    "STATUS" Status
  VALUE NOTATION ::= value (VALUE ObjectName)
    Access ::= "read-only"
    | "read-write"
    | "write-only"
    | "not-accessible"
    Status ::= "mandatory"
    | "optional"
    | "obsolete"
END

In order to support Macro, modify as follow:

Mib.xtext
Macro:
 name=ID 'MACRO' '::=' 'BEGIN'
 (ID 'NOTATION' '::=' MacroType+)+
 (ID '::=' (MacroList | MacroType | MacroCompound | MacroEnum) ('|' MacroType)?)*
 'END';

MacroList:
 ID '|' ID '","' ID;

MacroCompound:
 STRING? '"{"' MacroType '"}"';

MacroType:
 STRING? ID ('(' ID? mibType ')')?;

MacroEnum:
 STRING ('|' STRING)*;



RFC-1212.mib

Should display without any error.


Therefore the final Mib.xtext should look something like:

Mib.xtext
grammar com.ravi.mib.xtext.Mib hidden(WS, ML_COMMENT, SL_COMMENT)

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate mib "http://www.ravi.com/mib/xtext/Mib"

MibModel:
 definitions+=Definition*;

Definition:
 name=ID 'DEFINITIONS' '::=' 'BEGIN'
 Export?
 imports=Import?
 (identifiers+=Identifier | DataType | macros+=Macro)+
 'END';

Import:
 'IMPORTS' defs+=ImpDef+ ';';

ImpDef:
 objects+=MibObject (',' objects+=MibObject)* 'FROM' defname=ID;

MibObject:
 name=ID;

Export:
 'EXPORTS' ID (',' ID)* ';';

Identifier:
 ObjectType | (name=MibObject mibType value=OidValue);

ObjectType:
 name=MibObject imp=[MibObject] 'SYNTAX' mibType 'ACCESS' ID 'STATUS' ID
 ('DESCRIPTION' STRING)?
 ('REFERENCE' STRING)?
 ('INDEX' '{' mibType (',' mibType)* '}')?
 ('DEFVAL' '{' INT | STRING '}')?
 value=OidValue;

OidValue:
 '::=' '{' parent=[MibObject]? oidnum=INT '}';

DataType:
 ID '::=' ('[' 'APPLICATION' INT ']')? 'IMPLICIT'? (Choice | Sequence | mibType);

Choice:
 'CHOICE' '{' ID mibType (',' ID mibType)* '}';

Sequence:
 'SEQUENCE' '{' ID mibType (',' ID mibType)* '}';

mibType:
 ('SEQUENCE' 'OF')?
 ('OCTET' 'STRING' | ID | 'INTEGER' | 'OBJECT' 'IDENTIFIER')
 ('(' 'SIZE' '(' (INT '..')? INT ')' ')')?
 ('(' (INT '..')? (INT | 'MAX') ')')?
 ('{' ID '(' INT ')' (',' ID '(' INT ')')* '}')?;

Macro:
 name=ID 'MACRO' '::=' 'BEGIN'
 // TYPE NOTATION vs VALUE NOTATION
 (ID 'NOTATION' '::=' MacroType+)+
 (ID '::=' (MacroList | MacroType | MacroCompound | MacroEnum) ('|' MacroType)?)*
 'END';

MacroList:
 ID '|' ID '","' ID;

MacroCompound:
 STRING? '"{"' MacroType '"}"';

MacroType:
 STRING? ID ('(' ID? mibType ')')?;

MacroEnum:
 STRING ('|' STRING)*;

 
 /* 
  * -------------------------------------------------------------
    * Unfortunately need to overwrite following lexers
   * -------------------------------------------------------------
   */
terminal ID:
 '^'? ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '-' | '0'..'9')*;

terminal INT returns ecore::EInt:
 ('0'..'9')+;

terminal STRING:
 '"' ('\\' ('b' | 't' | 'n' | 'f' | 'r' | 'u' | '"' | "'" | '\\') | !('\\' | '"'))* '"' |
 "'" ('\\' ('b' | 't' | 'n' | 'f' | 'r' | 'u' | '"' | "'" | '\\') | !('\\' | "'"))* "'";

terminal ML_COMMENT:
 '/*'->'*/';

terminal SL_COMMENT:
 '--' !('\n' | '\r')* ('\r'? '\n')?;

terminal WS:
 (' ' | '\t' | '\r' | '\n')+;

terminal ANY_OTHER:
 .;

TODO: 
1) Support OidValue with multiple definition "{ iso org(3) dod(6) 1 }"

No comments:

Post a Comment