-
Notifications
You must be signed in to change notification settings - Fork 6
Developpment guide
In order to parse protocol grammar file (.asn), it uses ANTLR to generate a tree model of the grammar file. Once it's done, mts-asn1 generates translators based on the tree model which will encode and decode messages.
There are two levels in a translator definition
- Parser side which is created by mts-core aim to parse ASN.1 protocol file and extract informations in order to encode and decode data later.
- Encoder side which is initialized with informations from below and is created by encoding modules (mts-per)
Binary is decoded following ASN.1 encoding rules into a dataformat. There is actually 1 ASN.1 encoding rules (PER) and 2 dataformats (JSON and XML).
mts-asn1 is split in multiple sub-modules :
mts-antlr : Generate ANTLR source file for mts-core and mts-asn1-plugin
mts-core : Parse grammar and give tools to other modules
mts-asn1-plugin : Generate java classes to help using dataformat
mts-per : PER encoding/decoding
mts-json : JSON dataformat
mts-xml : XML dataformat
First of all, you need to choose which encoding rules you want to test. Tests are located under src/test/mts/asn1 and are a great start to understand this library. First of all, you need to load protocol asn.1 file.
Example :
@BeforeAll
static void init() {
try {
asn1Translator = new ASN1Translator(new PERTranslatorFactory(true), Collections.singletonList(S1APENodeBSetup.class.getResourceAsStream("/grammar/S1AP/S1AP.asn")));
} catch (Exception e) {
e.printStackTrace();
}
}
Once it's done, you need to add resource files. You need at least 2 files, one binary file and one dataformat file (xml or json). In order to create binary file, you need to convert your hexadecimal string (ex : coming from wireshark) to a binary file (ex with this website).
Once the conversion is done, you need to add result file, XML and JSON files if you use default method test(). In order to do that, you can use method updateDataformatFileTest() to generate result files in target/test-classes. However be carefull, you will need to check manually if result files are correct !
If result file are correct, copy paste them directly the resource test folder and replace updateDataformatFileTest() by test.
Example :
@Test
void testS1AP1() throws Exception {
test("S1AP-PDU", "/data/S1AP/InitialContextSetup/InitialContextSetupRequest/S1AP-1.bin", "/data/S1AP/InitialContextSetup/InitialContextSetupRequest/S1AP-1.json", "/data/S1AP/InitialContextSetup/InitialContextSetupRequest/S1AP-1.xml");
}
In addition, you can test if data from asn.1 file are just. For that, use testParsingANTLR() and debugger (asn1Translator -> registry -> XXXXParsedRegistry)
@Test
void parseS1APGrammar() {
testParsingANTLR();
}