// testptx - Demonstrate transmitter power and transmission power range // George F. Riley, Georgia Tech, Fall 2009 #include "simulator.h" #include "node.h" #include "wlan.h" #include "ratetimeparse.h" #include "application-cbr.h" #include "udp.h" #include "routing-dsr.h" #include "routing-nvr.h" #include "routing-aodv.h" #include "application-aodv.h" #include "wireless-grid-rectangular.h" #include "priqueue.h" #include "trace.h" #include "propagation.h" #define ANIMATION_ON #define XWIDTH 1000 #define YWIDTH 1000 #define NO_NODE 100 #define NO_SRC 1 #define SIM_TIME 500 using namespace std; void NodeSelected(Node* n) { cout << "Hello from NodeSelected, node " << n->Id() << endl; } int main(int argc, char** argv) { // For illustration, we use a global seed and thus the simulatino // does exactly the same thing every time. double ptx = 0; // milliwatts, 0 = use default Meters_t radioRange = 0; // meters, 0 = use default if (argc > 1) ptx = atol(argv[1]); if (argc > 2) radioRange = atol(argv[2]); Random::GlobalSeed(31731,44543,425345,19367,48201,72333); Simulator s; if (ptx > 0) Propagation::DefaultPtx(ptx); // Set default transmit power // This is wrong; the WirelessGridRectangular creates the wireless // link object internally //WirelessLink wlink(NO_NODE, IPAddr("192.168.0.1"), MASK_ALL); Uniform urvx(0, XWIDTH), urvy(0, YWIDTH); WirelessGridRectangular g(Location(0,0), Constant(NO_NODE), urvx, urvy, IPADDR_NONE); WirelessLink* wlink = g.GetWLink(); Node* n[NO_NODE]; for (int i = 0; i < NO_NODE; i++) { n[i] = wlink->GetNode(i); if (radioRange > 0) n[i]->SetRadioRange(radioRange); else n[i]->SetRadioRange(500); // set default of 100 meters n[i]->SetLocation(urvx.Value(), urvy.Value()); if (i == 0) { // Put zero right in the middle n[i]->SetLocation(XWIDTH/2, YWIDTH/2); } } Rate_t rate = (Rate_t)Rate("512Kb"); Application* cbr; cbr = n[0]->AddApplication( CBRApplication(IPAddrBroadcast, 1001, 1000, rate, 512, UDP())); cbr->Start(0); cbr->Stop(SIM_TIME); s.StopAt(SIM_TIME); #ifdef ANIMATION_ON s.AnimateWirelessTx(true); s.PauseOnWirelessTx(false); s.StartAnimation(0, true); s.AnimationUpdateInterval(Time("1ms")); s.NodeSelectedCallback(NodeSelected); #endif s.Run(); cout << "Simulation complete" << endl; }