我希望建立一個菱形網路拓撲

但是跑出來結果只有左半邊有資料傳輸,是路由的問題還是什么問題?
求個大佬解答一下下
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* 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 WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 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 02111-1307 USA
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/netanim-module.h"
using namespace ns3;
using namespace std;
NS_LOG_COMPONENT_DEFINE ("BottleNeckTcpScriptExample");
int
main (int argc, char *argv[])
{
Time::SetResolution (Time::NS);//設定時間單位為納秒
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 ("50Mb/s"));
CommandLine cmd;
cmd.Parse (argc,argv);
NodeContainer nodes;
nodes.Create (4);//創建四個節點
//各條邊的節點組合
vector<NodeContainer> nodeAdjacencyList(4);
nodeAdjacencyList[0]=NodeContainer(nodes.Get(0),nodes.Get(1));
nodeAdjacencyList[1]=NodeContainer(nodes.Get(0),nodes.Get(2));
nodeAdjacencyList[2]=NodeContainer(nodes.Get(1),nodes.Get(3));
nodeAdjacencyList[3]=NodeContainer(nodes.Get(2),nodes.Get(3));
vector<PointToPointHelper> pointToPoint(4);
pointToPoint[0].SetDeviceAttribute ("DataRate", StringValue ("20Mbps"));//網卡最大速率
pointToPoint[0].SetChannelAttribute ("Delay", StringValue ("2ms"));
pointToPoint[1].SetDeviceAttribute ("DataRate", StringValue ("20Mbps"));//網卡最大速率
pointToPoint[1].SetChannelAttribute ("Delay", StringValue ("2ms"));
pointToPoint[2].SetDeviceAttribute ("DataRate", StringValue ("20Mbps"));//網卡最大速率
pointToPoint[2].SetChannelAttribute ("Delay", StringValue ("2ms"));
pointToPoint[3].SetDeviceAttribute ("DataRate", StringValue ("20Mbps"));//網卡最大速率
pointToPoint[3].SetChannelAttribute ("Delay", StringValue ("2ms"));
vector<NetDeviceContainer> devices(4);
for(uint32_t i=0; i<4; i++)
{
devices[i] = pointToPoint[i].Install (nodeAdjacencyList[i]);
}
InternetStackHelper stack;
stack.Install (nodes);//安裝協議堆疊,tcp、udp、ip等
Ipv4AddressHelper address;
vector<Ipv4InterfaceContainer> interfaces(4);
for(uint32_t i=0; i<4; i++)
{
ostringstream subset;
subset<<"10.1."<<i+1<<".0";
address.SetBase(subset.str().c_str (),"255.255.255.0");//設定基地址(默認網關)、子網掩碼
interfaces[i]=address.Assign(devices[i]);//把IP地址分配給網卡
}
// 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", Address ());
clientHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
ApplicationContainer clientApps;
//0->3
AddressValue remoteAddress
(InetSocketAddress (interfaces[0].GetAddress (0), port));
clientHelper.SetAttribute("Remote",remoteAddress);
clientApps.Add(clientHelper.Install(nodeAdjacencyList[2].Get(1)));
clientApps.Start(Seconds(1.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
//嗅探,記錄所有節點相關的資料包
AnimationInterface anim("t1.xml");
anim.SetConstantPosition(nodes.Get(0),50.0,99.0);
anim.SetConstantPosition(nodes.Get(3),50.0,1.0);
anim.SetConstantPosition(nodes.Get(1),1.0,50.0);
anim.SetConstantPosition(nodes.Get(2),99.0,50.0);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
uj5u.com熱心網友回復:
............轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/53035.html
標籤:網絡通信
上一篇:RIP動態路由協議
