title: NS-3: How to change node position during simulation?
body: <p>I am trying to model in NS-3 some nodes moving with constant vertical velocity inside a rectangle.</p>
  
  <p><strong>Problem</strong>: I have to add the feature that, when a node goes beyond y=2500, its x-position abruptly changes to its x-position + 257. This is what I have tried so far: </p>
  
  <pre><code>NodeContainer nodes;
  nodes.Create (25);
  MobilityHelper mobility;
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                               "MinX", DoubleValue (0.0),
                               "MinY", DoubleValue (0.0),
                               "DeltaX", DoubleValue (500),
                               "DeltaY", DoubleValue (500),
                               "GridWidth", UintegerValue (5),
                               "LayoutType", StringValue ("RowFirst"));
  
  mobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel");
  mobility.Install (nodes);
  for (uint n=0 ; n &lt; nodes.GetN() ; n++)
   {
      Ptr&lt;ConstantVelocityMobilityModel&gt; mob = nodes.Get(n)-&gt;GetObject&lt;ConstantVelocityMobilityModel&gt;();
      mob-&gt;SetVelocity(Vector(0, 10, 0));        
   }
  for (uint n=0 ; n &lt; satellites.GetN() ; n++)
   {
      Ptr&lt;ConstantVelocityMobilityModel&gt; cvMob = satellites.Get(n)-&gt;GetObject&lt;ConstantVelocityMobilityModel&gt;();
      Ptr&lt;MobilityModel&gt; mob = satellites.Get(n)-&gt;GetObject&lt;MobilityModel&gt;();
      Vector m_position = mob-&gt;GetPosition();
      Vector m_velocity = mob-&gt;GetVelocity();
      if (m_position.y &gt; 2500) 
          {
             m_position.x += 257;
             m_velocity.y *= -1;
             cvMob-&gt;SetVelocity(m_velocity);
             mob-&gt;SetPosition(m_position);
          }
   }
  </code></pre>
  
  <p>This last for loop is not working at all! How should I implement the feature into the current script?</p>
  
  <p>PS: Since I am new to NS-3, I do not want to risk modifying any NS-3 source file.</p>