4

嗨,我是 NS3 的新手,我正在尝试修改 first.cc 以执行 TCP 而不是 UDP。我没有收到任何错误,但也没有发生数据交换。任何人都可以帮助我吗?〜〜非常感谢〜〜这是代码:主要是:

    NS_LOG_INFO ("Creating Topology");
    Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));

    Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
  NodeContainer nodes;
  nodes.Create (2);
//
  PointToPointHelper pointToPoint; 
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("20ms"));
//
  NetDeviceContainer devices;
  devices = pointToPoint.Install (nodes);
  InternetStackHelper stack;
  stack.Install (nodes);
    Ipv4AddressHelper address;
    address.SetBase ("109.11.12.0", "255.255.255.0");//address setting

    Ipv4InterfaceContainer interfaces = address.Assign (devices);

    OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address
                       (InetSocketAddress (Ipv4Address ("255.255.255.0"), 10)));
    onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
    onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));

    onOffHelper.SetAttribute ("DataRate",StringValue ("2Mbps"));
    onOffHelper.SetAttribute ("PacketSize",UintegerValue(2000));
    ApplicationContainer app = onOffHelper.Install (nodes.Get (0));

    // Start the application
    app.Start (Seconds (10.0));
    app.Stop (Seconds (100.0));

    // Create an optional packet sink to receive  packets

    PacketSinkHelper sink ("ns3::TcpSocketFactory",Address
                           (InetSocketAddress (Ipv4Address::GetAny (), 10)));
    app = sink.Install (nodes.Get(1));
    app.Start (Seconds (1.0));
    app.Stop (Seconds (100.0));

    pointToPoint.EnablePcapAll ("testtcp");
4

3 回答 3

3

ok,我想现在解决了,首先,onoff helper的IP不对,应该和Ipv4AddressHelper一样。那么app启动时间错误,不需要config onoff应用代码。这是现在的代码:它可能不是很正确,但至少我现在可以从中读取结果。

NodeContainer nodes;
  nodes.Create (2); //creat 2 nodes they are p2p

  PointToPointHelper pointToPoint; 
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("2Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("20ms"));

  NetDeviceContainer devices;// put nodes in ndc
  devices = pointToPoint.Install (nodes);
////give them an address 
  InternetStackHelper stack;
  stack.Install (nodes);
    Ipv4AddressHelper address;
    address.SetBase ("109.11.12.0", "255.255.255.0");//address setting

    Ipv4InterfaceContainer interfaces = address.Assign (devices);

    //sink for reciever????
    PacketSinkHelper sink ("ns3::TcpSocketFactory",Address
                           (InetSocketAddress (Ipv4Address::GetAny (), 10)));
    //set a node as reciever
    ApplicationContainer app = sink.Install (nodes.Get(0));

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

    OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address
                       (InetSocketAddress (Ipv4Address ("109.11.12.1"), 10)));
    onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
    onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));

    onOffHelper.SetAttribute ("DataRate",StringValue ("2Mbps"));
    onOffHelper.SetAttribute ("PacketSize",UintegerValue(1280));
   // ApplicationContainer
    app    = onOffHelper.Install (nodes.Get (1));
    // Start the application
    app.Start (Seconds (1.0));
    app.Stop (Seconds (10.0));




    pointToPoint.EnablePcapAll ("testtcp");
  Simulator::Run ();
于 2013-06-15T14:08:06.993 回答
0

您是否真的尝试将 TCP 流量发送到 ip 地址 255.255.255.0 ?这不太可能永远奏效。也许你应该试试 109.11.12.1

于 2013-06-11T07:17:56.483 回答
0

实际上 TCP 并不意味着支持广播,这就是为什么某些协议选择使用 UDP 而不是 TCP 来克服此类问题的原因。例如,由于 TCP 不支持协议的初始状态,因此 Bootp 在 UDP 上采用自己的方式。

于 2014-04-06T08:30:45.557 回答