Search code examples
intellij-ideaunetstack

Configuring a 2-node simulation in IntelliJ IDEA


I'd like to set up a network simulation in IntelliJ IDEA. To do this I'm trying configure the IDE to use the 2-node-network.groovy script included in the package. I can run the simulation script and access the modems through the web interface but some shell commands such as 'tell', 'host' etcetera will not work.

The steps I've taken so far:

  1. Configure an environment variable in the IDE to point to the Unetstack home directory (unet_home=.../unet-3.0.0/)

  2. Made a new run configuration in the IDE with code copied from the 2-node-network.groovy script but changed the home variable:

    import org.arl.fjage.RealTimePlatform

    def unet_home = System.getenv("unet_home");
    println(unet_home)

    println '''
    2-node network
    --------------
    Stack:
    Node A: tcp://localhost:1101, http://localhost:8081/
    Node B: tcp://localhost:1102, http://localhost:8082/
    '''

    platform = RealTimePlatform   // use real-time mode

    // run the simulation forever
    simulate {
        node 'A', location: [ 0.km, 0.km, -15.m], web: 8081, api: 1101, stack: "$unet_home/etc/setup"
        node 'B', location: [ 1.km, 0.km, -15.m], web: 8082, api: 1102, stack: "$unet_home/etc/setup"
    }

Web shell output:

> mac
<<< CSMA >>>

[org.arl.unet.mac.CSMAParam]
  maxBackoff = 30.0
  minBackoff = 0.5
  phy = phy
  reservationsPending = 0

[org.arl.unet.mac.MacParam]
  ackPayloadSize = 0
  channelBusy = false
  maxReservationDuration = 600.0
  recommendedReservationDuration = 15.0
  reservationPayloadSize = 0
> tell host('A'), "Hello"
Unknown method: host(...)
> tell
Unknown command or property: tell
>

Solution

  • During the shell startup process, the commands are loaded from etc/fshrc.groovy file. It seems that this file execution failed, probably because it could not be found.

    The system property that is used by the initialization script for finding etc is unet.home (not unet_home). That is usually set in the bin/unet shell script from the environment variable UNET_HOME when starting up Java:

    java -Dunet.home="$UNET_HOME" ...
    

    If you use the shell script to run your simulation, you should set the environment variable UNET_HOME (case sensitive) to point to your unet-3.0.0 folder, which contains the etc/ folder. If you directly run java yourself, you should set the system property unet.home like shown above.

    In your simulation script, you can check if this is correctly set:

    println(System.getProperty('unet.home'))
    

    to help you debug.