<?xml version='1.0' encoding='UTF-8'?>
<simconf version="2022112801">
  <simulation>
    <title>WSN delivery and radio-transmission ledger with one directed loss edge</title>
    <randomseed>1</randomseed>
    <motedelay_us>1000000</motedelay_us>
    <radiomedium>org.contikios.cooja.radiomediums.DirectedGraphMedium<edge>
        <source>1</source>
        <dest>org.contikios.cooja.radiomediums.DGRMDestinationRadio<radio>2</radio>
          <ratio>1.0</ratio>
        </dest>
      </edge>
      <edge>
        <source>2</source>
        <dest>org.contikios.cooja.radiomediums.DGRMDestinationRadio<radio>1</radio>
          <ratio>1.0</ratio>
        </dest>
      </edge>
      <edge>
        <source>1</source>
        <dest>org.contikios.cooja.radiomediums.DGRMDestinationRadio<radio>3</radio>
          <ratio>1.0</ratio>
        </dest>
      </edge>
      <edge>
        <source>3</source>
        <dest>org.contikios.cooja.radiomediums.DGRMDestinationRadio<radio>1</radio>
          <ratio>1.0</ratio>
        </dest>
      </edge>
      <edge>
        <source>1</source>
        <dest>org.contikios.cooja.radiomediums.DGRMDestinationRadio<radio>4</radio>
          <ratio>1.0</ratio>
        </dest>
      </edge>
      <edge>
        <source>4</source>
        <dest>org.contikios.cooja.radiomediums.DGRMDestinationRadio<radio>1</radio>
          <ratio>1.0</ratio>
        </dest>
      </edge>
    </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>Synthetic samplers 2-4</description>
      <source>[CONFIG_DIR]/firmware/sample-client.c</source>
      <commands>make TARGET=cooja clean
make -j4 sample-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="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="40" 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="0" y="45" />
        </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.DGRMVisualizerSkin</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>SAMPLE_|Received request|packet sent to</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. Three synthetic sample sources 2-4, DGRM star links. At 90 s only directed 4-&gt;1 reception ratio changes from 1.0 to 0.5; at 120 s it returns to 1.0. Count radio transmissions separately from application delivery. Simulated radio, not field energy.</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={BASE:0,FAST:0,LOSS:0,RESTORE:0}; received={BASE:0,FAST:0,LOSS:0,RESTORE:0}; receivedFrom4={BASE:0,FAST:0,LOSS:0,RESTORE:0}; radioTx={BASE:0,FAST:0,LOSS:0,RESTORE:0}; seenConn={}; medium=sim.getRadioMedium();
medium.getRadioTransmissionTriggers().addTrigger("ledger",function(event,object){ var conn=medium.getLastConnection(); if(conn==null || conn.getSource().getLastPacketTransmitted()==null)return; var t=Number(conn.getStartTime()); var id=conn.getSource().getMote().getID(); var key=t+":"+id; if(seenConn[key])return; seenConn[key]=true; var phase=t&lt;60000000?"BASE":t&lt;90000000?"FAST":t&lt;120000000?"LOSS":"RESTORE"; if(t&gt;=35000000 &amp;&amp; t&lt;150000000)radioTx[phase]++; });
TIMEOUT(155000, log.log("LEDGER sent="+JSON.stringify(sent)+" delivered="+JSON.stringify(received)+" source4="+JSON.stringify(receivedFrom4)+" radio_tx="+JSON.stringify(radioTx)+"\n"); if(sent.BASE==3 &amp;&amp; sent.FAST==18 &amp;&amp; sent.LOSS==18 &amp;&amp; sent.RESTORE==18 &amp;&amp; received.BASE==3 &amp;&amp; received.FAST==18 &amp;&amp; received.LOSS==18 &amp;&amp; received.RESTORE==18 &amp;&amp; radioTx.FAST&gt;radioTx.BASE &amp;&amp; radioTx.LOSS&gt;radioTx.FAST &amp;&amp; radioTx.RESTORE&lt;radioTx.LOSS) log.testOK(); else log.testFailed());
GENERATE_MSG(35000,"PAUSE 1"); GENERATE_MSG(50000,"PAUSE 2"); GENERATE_MSG(75000,"PAUSE 3"); GENERATE_MSG(90000,"EVENT loss-edge"); GENERATE_MSG(95000,"PAUSE 4"); GENERATE_MSG(120000,"EVENT restore-edge"); GENERATE_MSG(125000,"PAUSE 5"); GENERATE_MSG(150000,"PAUSE 6");
while(true) {
 YIELD(); msg=String(msg); log.log(time+" ID:"+id+" "+msg+"\n");
 var s=msg.match(/SAMPLE_SEND phase=(BASE|FAST|LOSS|RESTORE) node=([234]) seq=(\d+)/);if(s)sent[s[1]]++;
 var r=msg.match(/Received request '(BASE|FAST|LOSS|RESTORE):([234]):(\d+)'/);if(id==1 &amp;&amp; r){received[r[1]]++;if(r[2]=="4")receivedFrom4[r[1]]++;}
 if(msg=="EVENT loss-edge" || msg=="EVENT restore-edge") { var ratio=msg=="EVENT loss-edge"?0.5:1.0; var edges=medium.getEdges(); for(var i=0;i&lt;edges.length;i++){var e=edges[i];if(e.source.getMote().getID()==4 &amp;&amp; e.superDest.radio.getMote().getID()==1){e.superDest.ratio=ratio;medium.requestEdgeAnalysis();log.log("EDGE source=4 dest=1 ratio="+ratio+" at_us="+time+"\n");}} }
 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>