Network Simulator-3 (NS-3) Practical Lab Manual
ISBN 9788119221820

Highlights

Notes

  

Practical 6:: Experiment Specific Instructions

Create two nodes: an access point (AP) and a base station (BS). The BS will sends message to the AP, also the AP will sends a response back to the base station. Since the medium of communication is wireless (over air), the BS could send (or receive) messages to (or from) the AP only when ir is within a certain distance from the AP.

    1. Create the nodes and hold them in a container:

NodeContainer wifiStaNodes, wifiApNode;

wifiStaNodes.Create (nWifi);

wifiApNode = wifiStaNodes.Get (0);

    2. Create channel for communication:

YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();

YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();

wifi.SetRemoteStationManager (“ns3::AarfWifiManager”);

NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();

    3. Set up MAC for base station

Ssid ssid = Ssid (“ns-3-ssid”);

mac.SetType (“ns3::StaWifiMac”,”Ssid”, SsidValue (ssid),”ActiveProbing”, BooleanValue (false));

NetDeviceContainer staDevices;

staDevices = wifi.Install (phy, mac, wifiStaNodes.Get (1));

    4. Set up MAC for AP:

mac.SetType (“ns3::ApWifiMac”,”Ssid”,

SsidValue(ssid),”BeaconGeneration”,BooleanValue

(true),”BeaconInterval”,TimeValue (Seconds (5)));

NetDeviceContainer apDevice;

apDevice = wifi.Install (phy, mac, wifiApNode);

    5. Set mobility of the nodes:

MobilityHelper mobility;

mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,“MinX”, DoubleValue (0.0),

“MinY”, DoubleValue (0.0),”DeltaX”, DoubleValue (xDistance),”DeltaY”, DoubleValue

(10.0),”GridWidth”, UintegerValue (3),”LayoutType”,

StringValue”RowFirst”));

mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”); mobility.Install (wifiStaNodes);

    6. Add Internet layers stack:InternetStackHelper stack;stack.Install (wifiStaNodes);

    7. Assign IP address to each device:

Ipv4AddressHelper address;

Ipv4InterfaceContainer wifiInterfaces, wifiApInterface;

address.SetBase(10.1.1.0”,”255.255.255.0”);

wifiApInterface = address.Assign (apDevice);

wifiInterfaces = address.Assign (staDevices);

    8. Create and setup applications (traffic sink):

UdpEchoServerHelper echoServer (9);// Port # 9

ApplicationContainer serverApps = echoServer.Install (wifiApNode);

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (4.0));

    9. Create and setup applications (traffic source):

UdpEchoClientHelper echoClient (wifiApInterface.GetAddress (0), 9);

echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.)));

echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install (wifiStaNodes.Get (1));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (3.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

Simulator::Stop (Seconds (4.0));