This will require a separate development effort on NetSim. Briefly, the steps involved are:

  1. Understand the protocol you want to write and its requirements.
  2. Familiarize yourself with C programming language and MS Visual Studio development environment used by NetSim.
  3. Decide on an anchor protocol that would be similar to your protocol. This anchor protocol would run in the same layer as your new protocol and have similar functionality. For example, the anchor protocol could be DSR if you wish to write an ad hoc routing protocol in layer 3, or it could be TDMA if you wish to write a MAC protocol in layer 2.
  4. Understand the working of this anchor protocol
    • Debug through the code as explained in the User manual
    • Understand the different events and study the event trace
    • Understand the packet flow using the packet trace
    • Read and understand NetSim APIs section from the user manual 
    • Read through the source code documentation available inside NetSim → Help → NetSim source code Help
  5. Develop the detailed logic for your protocol. This must be extensive and similar to a standard / RFC so that it covers all the functionalities of a protocol
  6. Modify the header and source files of the anchor protocol code per the functioning of your new protocol. Note that this will on compilation give a DLL that will have the same name as the <Anchor_protocol> and this cannot be renamed to <Your_Protocol>. Therefore, use a different workspace when you start
  7. If your new protocol uses different parameters as compared to the anchor protocol then define and set the values for the new parameters in the code (or in a file)
  8. Then write the protocol initialization function - fn_NetSim_<protocol>_Init(). Through the protocol initialization function, NetSim's network stack passes all the relevant pointers to variables, paths, etc needed for the protocol. Inside this function: 
    • Local variables should be initialized, 
    • Initial events if any should be written, Eg: Hello packet in RIP, STP in Ethernet 
    • File pointers for reading & writing protocol_specific_IO files.
  9. fn_NetSim_<protocol>_Run(); This function is called by NetSim's network stack to run the protocol. In this function write the <Layer>_IN , <Layer>_OUT and Timer events for your protocol. 
    • The IN events represent what the protocol is supposed to do when it receives a packet from a lower layer.
    • The OUT events represent what a protocol is supposed to do when it receives a packet from a higher layer 
    • Define data structures for the protocol.
    • Add additional .h / .c files if required
  10. The other functions to be defined are
    • fn_NetSim_<protocol>_Finish(); To release all memory after completion
    • fn_NetSim_<protocol>_Configure(); - Optional. This is required if you are passing parameters through the config file. The stack calls this API when reading the config file. Upon reaching the appropriate protocol definition in the XML file, the stack calls this and passes all these pointers to the protocol
    • fn_NetSim_<protocol>_ConfigPacketTrace ();  — Optional. This is called by the stack to write the packet trace 
    • fn_NetSim__WriteEventTrace (); — Optional. This is called by the stack to write the event trace 
    • fn_NetSim_<protocol>_FreePacket(); The this to free the protocol-specific parameters/data in the packet
    • fn_NetSim_<protocol>_CopyPacket(); This is for copying protocol-specific parameters / data into the packet
    • fn_NetSim_<protocol>_Metrics (); - This is to write the metrics file upon completion of the simulation


Useful references