Home > other >  Ns3 lozenge network topology is established
Ns3 lozenge network topology is established

Time:09-20

I hope to establish a lozenge network topology
But ran out of the results only left side have the data transmission, routing problem or what problem?
And a big answer next


/* - * - Mode: c + +; C - file - style: "gnu"; Indent - tabs - mode: nil; - * - */
/*
* This program is free software; You can redistribute it and/or modify the
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY giant; Without even the implied giant of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; If not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA, USA, 02111-1307
*/

#include
#include
#include
#include

# include "ns3/core - module. H"
# include "ns3/network - module. H"
# include "ns3/Internet - module. H"
# include "ns3/point - to - point - the module. H"
# include "ns3/applications - module. H"
# include "ns3/ipv4 - global - routing - helper. H"
# include "ns3/netanim - module. H"

Using the namespace ns3;
using namespace std;

BottleNeckTcpScriptExample NS_LOG_COMPONENT_DEFINE (" ");

Int
The main (int arg c, char * argv [])
{
Time: : SetResolution (Time: : NS);//set the unit of time for a nanosecond
LogComponentEnable (" BottleNeckTcpScriptExample LOG_LEVEL_INFO);
LogComponentEnable (" TcpL4Protocol LOG_LEVEL_INFO);
//LogComponentEnable (" TcpSocketImpl, "LOG_LEVEL_ALL);
LogComponentEnable (" PacketSink LOG_LEVEL_INFO);

Config: : SetDefault (" ns3: : OnOffApplication: : PacketSize UintegerValue (1024));
Config: : SetDefault (" ns3: : OnOffApplication: : DataRate ", StringValue (" 50 MB/s) ");
CommandLine CMD.
CMD. Parse (arg c, argv);

NodeContainer nodes;
Nodes. The Create (4);//create a four node

//every edge node
Vector NodeAdjacencyList (4);
NodeAdjacencyList [0]=NodeContainer (nodes) Get (0), the nodes, the Get (1));
NodeAdjacencyList [1]=NodeContainer (nodes) Get (0), the nodes, the Get (2));
NodeAdjacencyList [2]=NodeContainer (nodes) Get (1), nodes. The Get (3));
NodeAdjacencyList [3]=NodeContainer (nodes) Get (2), the nodes, the Get (3));

Vector PointToPoint (4);
PointToPoint [0]. SetDeviceAttribute (" DataRate ", StringValue (" 20 MBPS "));//nic maximum rate
PointToPoint [0]. SetChannelAttribute (" Delay ", StringValue (" ms "));

PointToPoint [1]. SetDeviceAttribute (" DataRate ", StringValue (" 20 MBPS "));//nic maximum rate
PointToPoint [1]. SetChannelAttribute (" Delay ", StringValue (" ms "));

PointToPoint [2]. SetDeviceAttribute (" DataRate ", StringValue (" 20 MBPS "));//nic maximum rate
PointToPoint [2]. SetChannelAttribute (" Delay ", StringValue (" ms "));

PointToPoint [3]. SetDeviceAttribute (" DataRate ", StringValue (" 20 MBPS "));//nic maximum rate
PointToPoint [3]. SetChannelAttribute (" Delay ", StringValue (" ms "));


Vector Devices (4);
For (uint32_t I=0; i<4. I++)
{
Devices [I]=pointToPoint [I]. Install (nodeAdjacencyList [I]);
}

InternetStackHelper stack;
Stack. The Install (nodes);//install protocol stack, TCP, udp, IP, etc.

Ipv4AddressHelper address;
VectorFor (uint32_t I=0; i<4. I++)
{
Ostringstream subset.
Subset<& lt;" 10.1. "& lt; Address. SetBase (subset. STR () c_str (), "255.255.255.0");//set the base address (the default gateway), subnet mask
Interfaces [I]=address. Assign (devices [I]);//the IP address assigned to the network card
}

//Create a packet sink on the star "hub" to receive these packets
Uint16_t port=50000;
ApplicationContainer sinkApp;
Address sinkLocalAddress (InetSocketAddress (Ipv4Address: : GetAny (), port));
PacketSinkHelper sinkHelper (" ns3: : TcpSocketFactory, "sinkLocalAddress);
SinkApp. Add (sinkHelper. Install (nodeAdjacencyList [0]. Get (0)));
SinkApp. Start (Seconds (0.0));
SinkApp. Stop (Seconds (30.0));

OnOffHelper clientHelper (" ns3: : TcpSocketFactory ", the Address ());
ClientHelper. SetAttribute (" OnTime ", StringValue (" ns3: : ConstantRandomVariable/Constant=1 "));
ClientHelper. SetAttribute (" OffTime ", StringValue (" ns3: : ConstantRandomVariable [Constant=0] "));

ApplicationContainer clientApps;
//0 - & gt; 3
AddressValue remoteAddress
(InetSocketAddress (interfaces [0]. GetAddress (0), port));
ClientHelper. SetAttribute (" Remote ", remoteAddress);
ClientApps. Add (clientHelper. Install (nodeAdjacencyList [2], the Get (1)));

ClientApps. Start (Seconds (1.0));
ClientApps. Stop (Seconds (10.0));

Ipv4GlobalRoutingHelper: : PopulateRoutingTables ();
//sniffer, record all nodes related packets

AnimationInterface anim (" t1. XML "); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related