Network Simulation Program

Network simulation Program code.

NS-3 is a new simulator, written from scratch but not really an evolution of NS-2.

Packet: tags in ns3 program:

  • A tag is a small chunk of information
  • New tag types are defined similarly to header types
  • Any number of tags can be attached a packet
  • Structure type of Tags is:
  • Ptr <Packet>p;
  • MyTag tag;
  • p-> AddTag(tag)
  • p->PeekTag(tag)

Uses of Tags:

  • convey additional information across layers
  • Attach context information to a packet for example NetDevice attaches destination MAC address when queuing, retrieves it when dequeuing for transmission.

Sample network simulation program:
This is the simple program for how to connect two nodes with each other. Each of which has unique network interface device.
int main(int argc, char *argv[]){
NodeContainer nodes;
Nodes.Create(2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“4Mbps”));
pointToPoint.SetChannelAttribute(“Delay”,StringValue(“3ms”));
NetDeviceContainer devices;
Devices = pointToPoint.Install (nodes);
InternetStackHelper stack;
Stack.Install (nodes);
Ipv4AddressHelper address;
Address.SetBase (“10.1.1.0”, “255.255.255.0”);
Address.Assign(devices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get(1));
serverApps.Start (Seconds(1.0));
serverApps.Stop (seconds(11.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1),9);
ApplicationContainer clientApps = echoClinet.Install (nodes.Get(0));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(11.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}