examples/mesh.cc
changeset 4929 1689c94d7442
parent 4919 b8a0476c7e06
child 4930 fa5e570d56fa
equal deleted inserted replaced
4928:825037c2d7ab 4929:1689c94d7442
    36 NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
    36 NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
    37 
    37 
    38 int
    38 int
    39 main (int argc, char *argv[])
    39 main (int argc, char *argv[])
    40 {
    40 {
    41   // Creating square topology with nNodes x nNodes grid:
    41   // Creating square topology with nNodes x nNodes grid
    42   int      xSize       =6;
    42   int      xSize       = 6;
    43   int      ySize       = 6;
    43   int      ySize       = 6;
    44   double   step        = 100.0; //Grid with one-hop edge
    44   double   step        = 100.0; //Grid with one-hop edge
    45   double   randomStart = 0.1; //One beacon interval
    45   double   randomStart = 0.1;   //One beacon interval
    46   NodeContainer      nodes;
    46   
    47   CommandLine        cmd;
    47   // Defining a size of our network
    48   MobilityHelper     mobility;
    48   CommandLine cmd;
    49   MeshWifiHelper     wifi;
       
    50   NetDeviceContainer meshDevices;
       
    51   // Defining a size of our network:
       
    52   cmd.AddValue ("x-size", "Number of nodes in a row grid", xSize);
    49   cmd.AddValue ("x-size", "Number of nodes in a row grid", xSize);
    53   cmd.AddValue ("y-size", "Number of rows in a grid", ySize);
    50   cmd.AddValue ("y-size", "Number of rows in a grid", ySize);
    54   cmd.AddValue ("step", "Size of edge in our grid", step);
    51   cmd.AddValue ("step", "Size of edge in our grid", step);
    55   cmd.AddValue ("start", "Random start parameter", randomStart);
    52   cmd.AddValue ("start", "Random start parameter", randomStart);
    56   cmd.Parse (argc, argv);
    53   cmd.Parse (argc, argv);
    57   NS_LOG_DEBUG ("Grid:"<<xSize<<"*"<<ySize);
    54   NS_LOG_DEBUG ("Grid:" << xSize << "*" << ySize);
    58   // Creating nodes:
    55   
       
    56   // Creating nodes
       
    57   NodeContainer nodes;
    59   nodes.Create (ySize*xSize);
    58   nodes.Create (ySize*xSize);
    60 
    59 
    61   // Setting channel:
    60   // Setting channel
    62   YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
    61   YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
    63   YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
    62   YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
    64   wifiPhy.SetChannel (wifiChannel.Create ());
    63   wifiPhy.SetChannel (wifiChannel.Create ());
    65   // Setting Wifi:
    64   
    66   //wifi.SetPhy ("ns3::WifiPhy");
    65   // Install mesh point devices & protocols
    67   wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
    66   MeshWifiHelper mesh;
    68   Ssid ssid = Ssid ("MyMeSH");
    67   NetDeviceContainer meshDevices = mesh.Install (wifiPhy, nodes);
    69   wifi.SetMac ("ns3::MeshWifiInterfaceMac",
    68   
    70                "Ssid", SsidValue (ssid),
    69   // Setup mobility
    71                "RandomStart", TimeValue (Seconds (randomStart))
    70   MobilityHelper mobility;
    72               );
       
    73   wifi.SetRouting("ns3::dot11s::HwmpProtocol");
       
    74   wifi.SetPeerManager("ns3::dot11s::PeerManagementProtocol");
       
    75   wifi.SetL2RoutingNetDevice ("ns3::MeshPointDevice");
       
    76   meshDevices = wifi.Install (wifiPhy,nodes);
       
    77   // Installing Mobility.
       
    78   mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
    71   mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
    79                                  "MinX", DoubleValue (0.0),
    72                                  "MinX", DoubleValue (0.0),
    80                                  "MinY", DoubleValue (0.0),
    73                                  "MinY", DoubleValue (0.0),
    81                                  "DeltaX", DoubleValue (step),
    74                                  "DeltaX", DoubleValue (step),
    82                                  "DeltaY", DoubleValue (step),
    75                                  "DeltaY", DoubleValue (step),
    83                                  "GridWidth", UintegerValue (xSize),
    76                                  "GridWidth", UintegerValue (xSize),
    84                                  "LayoutType", StringValue ("RowFirst"));
    77                                  "LayoutType", StringValue ("RowFirst"));
    85   mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
    78   mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
    86   mobility.Install (nodes);
    79   mobility.Install (nodes);
       
    80   
    87   NS_LOG_UNCOND("start");
    81   NS_LOG_UNCOND("start");
    88   // Setting Internet Stack:
    82   
       
    83   // Install internet stack
    89   InternetStackHelper stack;
    84   InternetStackHelper stack;
    90   stack.Install (nodes);
    85   stack.Install (nodes);
    91   Ipv4AddressHelper address;
    86   Ipv4AddressHelper address;
    92   address.SetBase ("10.1.1.0", "255.255.255.0");
    87   address.SetBase ("10.1.1.0", "255.255.255.0");
    93   Ipv4InterfaceContainer interfaces = address.Assign (meshDevices);
    88   Ipv4InterfaceContainer interfaces = address.Assign (meshDevices);
       
    89   
       
    90   // Install applications
    94   UdpEchoServerHelper echoServer (9);
    91   UdpEchoServerHelper echoServer (9);
    95   ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
    92   ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
    96   serverApps.Start (Seconds (1.0));
    93   serverApps.Start (Seconds (1.0));
    97   serverApps.Stop (Seconds (10.0));
    94   serverApps.Stop (Seconds (10.0));
    98   UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
    95   UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
   100   echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.001)));
    97   echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.001)));
   101   echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
    98   echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
   102   ApplicationContainer clientApps = echoClient.Install (nodes.Get (1));
    99   ApplicationContainer clientApps = echoClient.Install (nodes.Get (1));
   103   clientApps.Start (Seconds (2.0));
   100   clientApps.Start (Seconds (2.0));
   104   clientApps.Stop (Seconds (10.0));
   101   clientApps.Stop (Seconds (10.0));
   105   //end
   102   
       
   103   // Happy end
   106   Simulator::Stop (Seconds (10.0));
   104   Simulator::Stop (Seconds (10.0));
   107   Simulator::Run ();
   105   Simulator::Run ();
   108   Simulator::Destroy ();
   106   Simulator::Destroy ();
   109   return 0;
   107   return 0;
   110 }
   108 }