1

我正在努力掌握 ns3 的窍门并进行完整性检查,但结果是错误的。

我想通过交换机以 10MB/s 的速率在 TCP 上发送 10MB,我希望它需要 1.x 秒,但由于一些明显的错误,它需要高达 17.x 秒。在谷歌搜索和检查用户 ns-3 组后,我似乎无法弄清楚出了什么问题。如果有人能指出我如何有效地调试它的正确方向,我会把它作为答案。顺便说一句,如果我将延迟设置为零,它的工作速度大约快十倍,我无法理解,只需要 1.7 倍秒。

这里有足够的代码来重现该行为:

#include <iostream>
#include <fstream>

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/bridge-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"

using namespace ns3;

int
main (int argc, char *argv[])
{ 
  uint32_t burstSize  = 10000000;
  uint32_t packetSize = 1000;

  Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue (packetSize)); 


  // Create the topology's nodes.

  NodeContainer nodes;
  nodes.Create (2);

  NodeContainer csmaSwitch;
  csmaSwitch.Create (1);

  NetDeviceContainer nodeDevices;
  NetDeviceContainer switchDevices;

  // Setting up csma attributes                      
  CsmaHelper csma;

  // Setting up node's channels
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate ("10MB/s")));
  csma.SetChannelAttribute ("Delay", StringValue ("10ms"));
  for (int i = 0; i < 2; i++)
    {
      NetDeviceContainer link = csma.Install (NodeContainer (nodes.Get (i), csmaSwitch));
      nodeDevices.Add (link.Get (0));
      switchDevices.Add (link.Get (1));
    }

  // Create the bridge netdevice, which will do the packet switching
  Ptr<Node> switchNode = csmaSwitch.Get (0);
  BridgeHelper bridge;
  bridge.Install (switchNode, switchDevices);

  // Add internet protocol stack to nodes
  Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue ("ns3::TcpReno"));
  InternetStackHelper internet;
  internet.Install (nodes);
  internet.Install (csmaSwitch);

  // Add IP addresses
  Ipv4AddressHelper ipv4;
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer nodeInterfaces;
  nodeInterfaces = ipv4.Assign (nodeDevices);

  uint16_t port = 10100;
  BulkSendHelper source ("ns3::TcpSocketFactory",
                        InetSocketAddress (nodeInterfaces.GetAddress (0), port));

  source.SetAttribute ("MaxBytes", UintegerValue (burstSize));
  source.SetAttribute ("SendSize", UintegerValue (packetSize));

  ApplicationContainer sourceApps = source.Install (nodes.Get (1));

  sourceApps.Start (Seconds (0.0));
  sourceApps.Stop (Seconds (1000.0));

  //
  // Create a PacketSinkApplication and install it on node 0
  //
  PacketSinkHelper sink ("ns3::TcpSocketFactory",
                        InetSocketAddress (Ipv4Address::GetAny (), port));
  ApplicationContainer sinkApps = sink.Install (nodes.Get (0));
  sinkApps.Start (Seconds (0.0));
  sinkApps.Stop (Seconds (1000.0));

  csma.EnablePcapAll ("results/pcap/data", false);

  Simulator::Run ();
  Simulator::Destroy ();
}
4

1 回答 1

1

csma 桥接器的实现是半双工的,这就是性能很糟糕的原因。

于 2014-03-25T06:17:54.737 回答