Christian Dickmann
Applied Computer Science student at the University of Göttingen |
| HomeProjectsPublicationsAboutImpressum |
NSIS![]() Homepage![]() HOWTOs![]() ![]() Testbed setup![]() ![]() Create your own NSLP |
Create your own NSLP
This tutorial will guide you through creating an initial NSLP similar to the
Ping tool NSLP shipped with our NSIS implementation.
Contents1. Prerequirements2. Start creating your own NSLP 3. Extend the NSLP messages with a new object 4. Use the new object to send a new message type 5. Add a state machine to the NSLP 6. Extend HopDiscoveryMessage to gather IP address of all nodes along the path 1. PrerequirementsYou should set up a testbed like the one descriped here. You should at least perform Test I of that tutorial.You need PHP5 and automake 1.7. TODO 2. Start creating your own NSLPCreate NSLP from skeleton and register the created NSLPIn this section we start creating a new NSLP named SampleNslp. The initial step is to create the basic file structure from a skeleton NSLP. To do so, please change to the nslp/ directory and run the script createFromSkeleton.php with the large and the short name as the arguments. For example:php -f createFromSkeleton.php SampleNslp sample
This will create a directory called sample and initital NSLP code. Before compiling or
testing the newly created NSLP you need to register it.
./autogen.sh
This will run automake, autoconf, autoheader and run the configure script. If you compiled NSIS
with parameters after ./configure, use these parameters here too. Now you should find a Makefile
in the nslp/sample/ directory../configure Change to this directory and run make: make
After compiling your NSLP you should find two new binaries (nsis-sampled and nsis-sample)
in the bin/ directory.What is the new NSLP capable of?
Testing the new NSLPRun bin/nsis on all network nodes that should take part in the test. You should use the same setup that you used in the initial test of the ping tool NSLP. In addition run bin/nsis-sampled on all those network nodes. The nsis daemon should confirm that the sample NSLP connected.On the initior you now need to run the NSLP client to trigger a sample message: bin/nsis-sample <destinationIP>
Confirm that the client shows a returncode of 0.Congratulations, your first NSLP actually works. How does the client side of the new NSLP work?The executable main()-function is contained in sample-client.cpp. It transforms the provided command line arguments into calls to the SampleNslpClient class contained in the clientapi directory.The SampleNslpClient class is the API to your NSLP. This class could be used in an complex application using your NSLP. It communicates with the NSLP daemon over unix sockets and utilizes the helper methods of clientapi/SampleNslpCommunicator.cpp. How does the server side of the new NSLP work?The main component of the server/daemon is the SampleNslpServer class. It initializes and manages the communication with NSLP clients and with the API to GIST (called NSLP API). It also provides helper methods used across your NSLP. The most important parts are:
The SampleNslpFsm class uses objects of the container class SampleNslpFsmData to get a proper context for all methods provided by the Fsm. Last but not least, the NSLP message and objects classes are an important component of the NSLP. The skeleton already provides a basic message structure:
3. Extend the NSLP messages with a new objectThe new objectThe new object created in this chapter of the tutorial is just ment as an example. It is named HopCount object and consists of a 16 bit HopCount and 16 bit padding (simply left empty).What needs to be done?
Extend objects/objects.xmlThe objects.xml file contains a list of objects, their names and byte format. This XML is transformed to C++ classes by objects.php. The resulting classes are capable of composing and parsing these objects, as well as providing getter and setter access to the fields.Example: <object> <name>SampleNslpHeader</name> <type>commonheader</type> <elements> <element> <name>version</name> <type>unsigned char</type> <length>8</length> </element> <element> <name>length</name> <type>unsigned char</type> <length>8</length> </element> <element> <length>16</length> </element> </elements> </object> The type-tag is optional and needs to be supplied for special objects, like type "commonheader". Normal objects (like our new one) must ommit the type-tag. The fields of the object are provided in the elements-tag. Each field is represented by an element-tag, which itself is composed of:
<object> <name>SampleNslpHopCountObject</name> <elements> <element> <name>hopcount</name> <type>unsigned short</type> <length>16</length> </element> <element> <length>16</length> </element> </elements> </object> Extend class SampleNslpMessageThe message class must support the newly created SampleNslpHopCountObject.We start in the SampleNslpMessage.h file:
void addHopCountObject(SampleNslpHopCountObject * hopCount) {
this-> hopCountObject = hopCount; addObject(hopCount);
}
After changing the header file, we change the SampleNslpMessage.cpp file:
case SAMPLENSLPHOPCOUNTOBJECT: hopCountObject = new SampleNslpHopCountObject(buffer + offset, objectPayloadLength); break; Add the newly created file to Makefile.amThe new file objects/SampleNslpHopCountObject.cpp needs to be added to the list of source files in the Makefile.am.Afterwards you need to run autogen.sh and configure again. Now you can try to run "make" in your NSLP directory. 4. Use the new object to send a new message typeWhat needs to be done?Add sendHopDiscoveryMessage() to SampleNslpClientChange sample_client.cpp to use new message typeAdd sendHopDiscoveryMessage() to SampleNslpFsmAdd handler for new client trigger to SampleNslpServerHandle HopDiscoveryMessage in intermediate NodesPass discovered HopCount to the clientTesting5. Add a state machine to the NSLPGoal of this chapterIn this section we add a finite state machine to the SampleNSLP. As an example we add a new message type to authorize ourselfs in a first step and only then we are allowed to get the HopCount. Does not really makes sense, but illustrates how things work.What needs to be done?Create a new SampleNslpAuthorizationObject that consists of a 32 bit integer password.Register this object in the message class. (see Chapter 3 on how to do so) Add the FSM to our NSLP. Add a new autorization message type that contains only the autorization object. (only in SampleNslpFsm) Add the logic Add the FSM to our NSLPAdd sendAuthorizationMessage() to SampleNslpFsmAdd handler for AuthorizationMessages in intermediate nodesChange the logic of HopCount forwardingOnly forward when we are in state authorizedAdd support in the clientSend HopDiscovery message directlySend HopDiscovery after sending Authorization message Test6. Extend HopDiscoveryMessage to gather IP address of all nodes along the path |