saleh refaai
unread,May 21, 2024, 11:48:47 AMMay 21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ns-3-users
hello
I have the attached topology. I am trying to to apply it in NS3 but the results are zeros. Can you help me to know what is missing about the code or if the code even meets the topology. I want it to be somehow similar to the implementation of second.cc code :
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/csma-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/flow-monitor-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("NetworkTopologyExample");
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer ethernetNodes;
ethernetNodes.Create (3);
NodeContainer csmaNodes;
csmaNodes.Create (3);
NodeContainer routerNode;
routerNode.Create (1);
NodeContainer allNodes = NodeContainer (ethernetNodes, csmaNodes, routerNode);
// Install internet stack
InternetStackHelper stack;
stack.Install (allNodes);
// Create and configure Ethernet LAN
CsmaHelper csmaEthernet;
csmaEthernet.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csmaEthernet.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer ethernetDevices;
ethernetDevices = csmaEthernet.Install (ethernetNodes);
// Create and configure CSMA LAN
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("10Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
// Create and configure point-to-point link between router and LANs
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
NetDeviceContainer p2pDevices1;
p2pDevices1 = p2p.Install (routerNode.Get (0), ethernetNodes.Get (0));
NetDeviceContainer p2pDevices2;
p2pDevices2 = p2p.Install (routerNode.Get (0), csmaNodes.Get (0));
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer ethernetInterfaces;
ethernetInterfaces = address.Assign (ethernetDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
address.SetBase ("10.1.3.0", "255.255.255.252");
Ipv4InterfaceContainer routerInterfaces1;
routerInterfaces1 = address.Assign (p2pDevices1);
address.SetBase ("10.1.4.0", "255.255.255.252");
Ipv4InterfaceContainer routerInterfaces2;
routerInterfaces2 = address.Assign (p2pDevices2);
// Populate routing tables
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
// Create applications
uint16_t port = 9;
// Create and install UdpEchoServer application
uint16_t port = 9;
UdpEchoServerHelper echoServer(port);
ApplicationContainer serverApps = echoServer.Install(ethernetNodes.Get(1));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
// Create and install UdpEchoClient application
UdpEchoClientHelper echoClient(ethernetInterfaces.GetAddress(1), port);
echoClient.SetAttribute("MaxPackets", UintegerValue(1000));
echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
echoClient.SetAttribute("PacketSize", UintegerValue(1024));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}