<?xml version='1.0' encoding='UTF-8'?>
<simconf version="2022112801">
  <simulation>
    <title>RPL sink restart: sequence gap over three-link path</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>Relays 2-3 and sequence sender 4</description>
      <source>[CONFIG_DIR]/firmware/sequence-client.c</source>
      <commands>make TARGET=cooja clean
make -j4 sequence-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="40" y="0" />
        </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="80" y="0" />
        </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="120" y="0" />
        </interface_config>
        <interface_config>org.contikios.cooja.contikimote.interfaces.ContikiMoteID<id>4</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>SEQ_|Received request|Forwarding packet|Preferred parent|Rank|DIO|DIS|DAO|Starting Contiki</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>Seed 1. Four-mote 40 m chain, 50 m UDGM range. Synthetic sequence sender 4 sends every 5 s. Root mote 1 is removed at 95 s and freshly instantiated with the same ID and position at 125 s; only the sink restarts. Observe the delivery sequence gap and RPL control traffic. Simulated radio, not field reliability.</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>sent=[]; received=[]; rootAbsent=false; rootRestarted=false; rootSnapshot=null; rootType=null; rebootAt=0; restartAt=0; lastBefore=-1; firstAfter=-1; firstAfterTime=0; controlAfter=0;
TIMEOUT(500000, log.log("REBOOT_SUMMARY last_before="+lastBefore+" first_after="+firstAfter+" missing_seq="+(firstAfter-lastBefore-1)+" reboot_us="+rebootAt+" restart_us="+restartAt+" first_delivery_us="+firstAfterTime+" recovery_from_reboot_ms="+((firstAfterTime-rebootAt)/1000)+" recovery_after_restart_ms="+((firstAfterTime-restartAt)/1000)+" control_after="+controlAfter+" sent="+sent.length+" delivered="+received.length+"\n"); if(rootAbsent &amp;&amp; rootRestarted &amp;&amp; lastBefore&gt;=0 &amp;&amp; firstAfter&gt;lastBefore+1 &amp;&amp; controlAfter&gt;0)log.testOK();else log.testFailed());
GENERATE_MSG(75000,"PAUSE 1"); GENERATE_MSG(95000,"EVENT remove-root"); GENERATE_MSG(100000,"PAUSE 2"); GENERATE_MSG(120000,"PAUSE 3"); GENERATE_MSG(125000,"EVENT restart-root"); GENERATE_MSG(200000,"PAUSE 4"); GENERATE_MSG(470000,"PAUSE 5"); GENERATE_MSG(490000,"PAUSE 6");
while(true) {
 YIELD(); msg=String(msg); log.log(time+" ID:"+id+" "+msg+"\n");
 if(msg=="EVENT remove-root") { var old=sim.getMoteWithID(1); rootSnapshot=old.getConfigXML(); rootType=old.getType(); sim.removeMote(old); rootAbsent=true; rebootAt=time; log.log("SINK_REBOOT phase=down node=1 removed_instance=true at_us="+time+"\n"); }
 if(msg=="EVENT restart-root") { var fresh=rootType.generateMote(sim); fresh.setConfigXML(sim,rootSnapshot,false); sim.addMote(fresh); rootRestarted=true; restartAt=time; log.log("SINK_REBOOT phase=up node=1 fresh_instance=true at_us="+time+"\n"); }
 var s=msg.match(/SEQ_SEND node=4 seq=(\d+)/); if(s)sent.push(Number(s[1]));
 var r=msg.match(/Received request 'SEQ:(\d+)'/); if(id==1 &amp;&amp; r) {var n=Number(r[1]);received.push(n);if(!rootAbsent)lastBefore=n;else if(rootRestarted &amp;&amp; firstAfter&lt;0){firstAfter=n;firstAfterTime=time;log.log("FIRST_RECOVERED seq="+n+" at_us="+time+"\n");}}
 if(rootAbsent &amp;&amp; (msg.indexOf("DIO")&gt;=0 || msg.indexOf("DIS")&gt;=0 || msg.indexOf("DAO")&gt;=0 || msg.indexOf("Preferred parent")&gt;=0))controlAfter++;
 if(msg.indexOf("PAUSE ")==0 &amp;&amp; Java.type("org.contikios.cooja.Cooja").isVisualized())sim.stopSimulation();
}</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="1005" y="0" width="575" height="475" z="5" />
  </plugin>
</simconf>