Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Simulation.addMote(..) and Simulation.removeMote(..) but crashed. #7

Open
iPAS opened this issue Jan 27, 2017 · 2 comments
Open

Comments

@iPAS
Copy link

iPAS commented Jan 27, 2017

Dear,
I used your Realsim code to study how to imitate death and rebirth of node in Cooja plugin.
In my plugin, I try Simulation.removeMote(..) and Simulation.addMote(..)
as same as being used in Realsim.
But, the Cooja always crashed after Simulation.addMote(..) was called.
The "illegalArguementException: Jumping to a time that is further than possible in LPM max cycles..."
was thrown.
If you have any clue or suggestion please guild me.
Thank you.

@cmorty
Copy link
Owner

cmorty commented Jan 30, 2017

Yea, I remember having those issues, too, but I can't remember whether I worked around them or fixed the issue. I do remember adding some patches to Cooja to solve issues with adding nodes using plugins. Especially having a list of uninitialized nodes. Yet unless you have a old (>2y) version of Cooja those should be fixed. Did you try stopping the simulation before adding the nodes?

@iPAS
Copy link
Author

iPAS commented Feb 19, 2017

Thanks @cmorty.
I have not tried to stop the simulation yet,
but already found the reason why crash occurred when adding a mote via Simulation.addMote()
after removing the mote.
It is because the logObserver is set to be null in the process of Simulation.removeMote().
So, I patched COOJA as the following code.

--- tools/cooja/java/org/contikios/cooja/interfaces/Mote2MoteRelations.java ---
index eb3a2f7..a28b27b 100644
@@ -135,7 +135,7 @@ public class Mote2MoteRelations extends MoteInterface {
         ((Log)mi).deleteObserver(logObserver);
       }
     }
-    logObserver = null;
+    //logObserver = null;  // [iPAS]: Why do we need to destroy it?
 
     /* Remove all relations to other motes */
     Mote[] relationsArr = relations.toArray(new Mote[0]);

----- tools/cooja/java/org/contikios/cooja/interfaces/MoteAttributes.java -----
index b2ff1b3..69c75d2 100644
@@ -114,7 +114,7 @@ public class MoteAttributes extends MoteInterface {
         ((Log)mi).deleteObserver(logObserver);
       }
     }
-    logObserver = null;
+    //logObserver = null;  // [iPAS]: Why do we need to destroy it? 
   }

The mote could be added correctly;
however, the other crash -- as I mentioned in my first post -- still occur.

java.lang.IllegalArgumentException: Jumping to a time that is further than possible in LPM maxCycles:231383624 cycles: 156073888 nextEventCycles: 156091473
	at se.sics.mspsim.core.MSP430.stepMicros(MSP430.java:236)
	at org.contikios.cooja.mspmote.MspMote.execute(MspMote.java:337)
	at org.contikios.cooja.mspmote.MspMoteTimeEvent.execute(MspMoteTimeEvent.java:53)
	at org.contikios.cooja.mspmote.interfaces.MspSerial$2.execute(MspSerial.java:82)
	at org.contikios.cooja.Simulation.run(Simulation.java:281)
	at java.lang.Thread.run(Thread.java:745)

Anyway, I will try stopping the simulation before removeMote() and addMote().
Thank you again, and hope you can share the patch of Real-Sim if it is not hard to find.

PS.
The Simulation.stopSimulation(...) and Simulation.startSimulation(...) functions don't help.

        /**
         * Rebirth of the node
         */
        } else if (wasDepleted) {  // Currently, it is not depleted. But it was.            
            String msg = "node " + nodeLabel + " was refilled!\n";
            senseh.showMessage(msg + " @" + simulation.getSimulationTime());            
            logger.debug(msg);
            
            wasDepleted = false;            

            simulation.stopSimulation(true);
            simulation.addMote(mote);
            simulation.startSimulation();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants