<?xml version='1.0' encoding='UTF-8'?>
<simconf version="2022112801">
  <simulation>
    <title>WSN collection: per-source delivery and measured hop RTT</title>
    <randomseed>1</randomseed>
    <motedelay_us>1000000</motedelay_us>
    <radiomedium>
      org.contikios.cooja.radiomediums.UDGM
      <transmitting_range>50.0</transmitting_range>
      <interference_range>50.0</interference_range>
      <success_ratio_tx>1.0</success_ratio_tx>
      <success_ratio_rx>1.0</success_ratio_rx>
    </radiomedium>
    <events>
      <logoutput>40000</logoutput>
    </events>
    <motetype>
      org.contikios.cooja.contikimote.ContikiMoteType
      <description>Collection sink 1</description>
      <source>[CONFIG_DIR]/firmware/udp-server.c</source>
      <commands>make TARGET=cooja clean
make -j4 udp-server.cooja TARGET=cooja</commands>
      <moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiMoteID</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRS232</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiBeeper</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRadio</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiButton</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiPIR</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiClock</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiLED</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiCFS</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
      <mote>
        <interface_config>org.contikios.cooja.interfaces.Position<pos x="0" y="0" />
        </interface_config>
        <interface_config>org.contikios.cooja.contikimote.interfaces.ContikiMoteID<id>1</id>
        </interface_config>
      </mote>
    </motetype>
    <motetype>
      org.contikios.cooja.contikimote.ContikiMoteType
      <description>Sampling clients 2-6</description>
      <source>[CONFIG_DIR]/firmware/udp-client.c</source>
      <commands>make TARGET=cooja clean
make -j4 udp-client.cooja TARGET=cooja</commands>
      <moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiMoteID</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRS232</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiBeeper</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRadio</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiButton</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiPIR</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiClock</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiLED</moteinterface>
      <moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiCFS</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
      <moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
      <mote>
        <interface_config>org.contikios.cooja.interfaces.Position<pos x="-30" y="25" />
        </interface_config>
        <interface_config>org.contikios.cooja.contikimote.interfaces.ContikiMoteID<id>2</id>
        </interface_config>
      </mote>
      <mote>
        <interface_config>org.contikios.cooja.interfaces.Position<pos x="30" y="25" />
        </interface_config>
        <interface_config>org.contikios.cooja.contikimote.interfaces.ContikiMoteID<id>3</id>
        </interface_config>
      </mote>
      <mote>
        <interface_config>org.contikios.cooja.interfaces.Position<pos x="-60" y="55" />
        </interface_config>
        <interface_config>org.contikios.cooja.contikimote.interfaces.ContikiMoteID<id>4</id>
        </interface_config>
      </mote>
      <mote>
        <interface_config>org.contikios.cooja.interfaces.Position<pos x="0" y="55" />
        </interface_config>
        <interface_config>org.contikios.cooja.contikimote.interfaces.ContikiMoteID<id>5</id>
        </interface_config>
      </mote>
      <mote>
        <interface_config>org.contikios.cooja.interfaces.Position<pos x="60" y="55" />
        </interface_config>
        <interface_config>org.contikios.cooja.contikimote.interfaces.ContikiMoteID<id>6</id>
        </interface_config>
      </mote>
    </motetype>
  </simulation>
  <plugin>org.contikios.cooja.plugins.Visualizer<plugin_config>
      <skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
      <skin>org.contikios.cooja.plugins.skins.MoteTypeVisualizerSkin</skin>
      <skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
      <skin>org.contikios.cooja.plugins.skins.GridVisualizerSkin</skin>
      <viewport>4.0 0.0 0.0 4.0 490.0 80.0</viewport>
      <moterelations />
    </plugin_config>
    <bounds x="0" y="0" width="1000" height="475" z="1" />
  </plugin>
  <plugin>org.contikios.cooja.plugins.LogListener<plugin_config>
      <filter>Received request|Received response|#L</filter>
      <formatted_time />
      <coloring />
    </plugin_config>
    <bounds x="0" y="480" width="1580" height="430" z="0" />
  </plugin>
  <plugin>org.contikios.cooja.plugins.Notes<plugin_config>
      <notes>WSN collection, seed 1. Sink 1; leaf 4 uses relay 2.
UDP hello sequence is a synthetic sample, not a physical sensor.
Script measures send-to-sink delay and per-link ping RTT.
RTT is not one-way hop delay; do not divide by two.
UDGM 50 m / 100 m, no hardware energy or field RF claim.</notes>
      <decorations>true</decorations>
    </plugin_config>
    <bounds x="1005" y="0" width="575" height="215" z="3" />
  </plugin>
  <plugin>org.contikios.cooja.plugins.ScriptRunner<plugin_config>
      <script>sources={}; replies={}; sent=0; received=0; parents={}; measurements={};
TIMEOUT(120000, log.log("SUMMARY duration_us="+sim.getSimulationTime()+" sent="+sent+" root_received="+received+" clients="+Object.keys(sources).length+" reply_clients="+Object.keys(replies).length+" parents="+JSON.stringify(parents)+" measurements="+JSON.stringify(measurements)+"\n"); if(Object.keys(sources).length==5 &amp;&amp; Object.keys(replies).length==5 &amp;&amp; measurements.latencies_us.length==received &amp;&amp; Object.keys(measurements).length&gt;=4) log.testOK(); else log.testFailed());
GENERATE_MSG(60000, "EVENT leaf-path");
GENERATE_MSG(61000, "EVENT relay-path");
GENERATE_MSG(65000, "EVENT hop-one-rtt");
GENERATE_MSG(72000, "EVENT hop-two-rtt");
GENERATE_MSG(80000, "EVENT end-to-end-rtt");
while(true) {
 YIELD(); msg=String(msg); log.log(time+" ID:"+id+" "+msg+"\n");
 if(msg.indexOf("Sending request")&gt;=0) sent++;
 if(id==1 &amp;&amp; msg.indexOf("Received request")&gt;=0) { received++; sources[msg.split(" from ")[1]]=true; }
 if(id!=1 &amp;&amp; msg.indexOf("Received response")&gt;=0) replies[id]=true;
 var match=msg.match(/#L (\d+) 1/); if(match) parents[id]=Number(match[1]);
 if(msg=="EVENT leaf-path") { write(sim.getMoteWithID(4),"rpl-status"); }
 if(msg=="EVENT relay-path") { write(sim.getMoteWithID(2),"rpl-status"); }
 if(msg=="EVENT hop-one-rtt") { write(sim.getMoteWithID(4),"ping fe80::202:2:2:2"); }
 if(msg=="EVENT hop-two-rtt") { write(sim.getMoteWithID(2),"ping fe80::201:1:1:1"); }
 if(msg=="EVENT end-to-end-rtt") { write(sim.getMoteWithID(4),"ping fd00::201:1:1:1"); }

if(typeof starts=="undefined") { starts={}; counts={}; }
var tx=msg.match(/Sending request (\d+) to/);
if(tx) { starts[id+":"+tx[1]]=time; counts[id]=(counts[id]||0)+1; }
var rx=msg.match(/Received request 'hello (\d+)' from fd00::20([2-6]):/);
if(id==1 &amp;&amp; rx) { var key=rx[2]+":"+rx[1]; if(starts[key]!==undefined) { var latency=time-starts[key]; measurements.latencies_us=measurements.latencies_us||[]; measurements.latencies_us.push(latency); log.log("COLLECTION source="+rx[2]+" sequence="+rx[1]+" latency_us="+latency+"\n"); } }
if(msg.indexOf("Received ping reply")&gt;=0) { measurements["ping"+id+"_"+Math.floor(time/10000000)]=msg; log.log("HOP_RTT node="+id+" "+msg+"\n"); }

}
</script>
      <active>true</active>
    </plugin_config>
    <bounds x="1005" y="220" width="575" height="255" z="4" />
  </plugin>
  <plugin>org.contikios.cooja.plugins.RadioLogger<plugin_config>
      <split>150</split>
      <analyzers>6lowpan</analyzers>
    </plugin_config>
    <bounds x="0" y="0" width="1580" height="475" z="5" />
  </plugin>
</simconf>