点对点 多tcp流 设置

按照工作要求,实现两个IP地址之间,多个TCP流的数据传输。每个TCP流发总字节数给定(数据存储在数组中),TCP流之间的时间间隔给定(数据存储在数组中)
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/netanim-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/point-to-point-layout-module.h"
#include "ns3/netanim-module.h"
#include "iostream"
#include "fstream"
#include "cstdlib"
// Network topology
//     n0--- -----n1
using namespace ns3;
using namespace std;
NS_LOG_COMPONENT_DEFINE ("duo-tcp-one-point2one-point");
//string name1="shujubao.txt";

int
  main (int argc, char *argv[])
{ 
  //string name1="shujubao.txt";

  //ifstream inFile1;
  //inFile1.open(name1);
  /*if (!inFile1.is_open())
  {
   cout<<"could not open the file"<<name1<<endl;


  }
  */
  double shuju_1[1000]={3720,2656,8959,7528,4926,2885,9573,7928,2251,7844,6253,967,8417,5165,619,9078,1363,8909,5411,4192,7155,8997,4791,3314,4662,7454,8616,3978,3339,3780,3493,7526,421,5575,9042,1985,4487,2522,6646,9435,4067,1146,9050,4636,3735,9559,7008,3827,3094,891,3982,9197,4768,6819,5299,9113,6871,4398,6596,13,2465,4958,957,223,8749,9229,3987,7671,2183,4952,334,6995,7365,387,6490,1951,9052,5290,9654,508,9668,6432,252,5256,6122,8919,866,9348,4481,1425,232,2257,1498,8081,233,4901,1414,6500,9674,1330,6393,7771,567,7549,6358,6318,2735,2158,7443,8564,5806,1801,815,700,6063,148,993,2622,8142,5612,1046,4188,300,3150,1127,9936,2190,5057,4752,7998,5806,3185,618,9034,4338,3539,1504,5514,588,4090,4206,1416,5762,7485,3055,3277,356,6844,7217,4328,9640,2850,7838,613,7809,4644,4039,2266,4774,7705,7866,5447,5785,1789,7179,7880,364,8435,5783,6607,9662,1166,3523,6088,4261,3143,1204,4567,2689,639,7567,9178,6772,5226,8360,5241,2006,7079,8565,5551,8470,5913,7997,8670,2204,8904,3579,5009,5355,2940,6769,3584,533,2532,6043,4566,5113,5460,2773,7737,7106,5609,5336,3321,484,357,8758,5786,3475,8388,365,1537,3378,7921,5202,5961,2773,5922,5542,8129,7035,268,1444,5028,4590,9462,9720,1007,6388,1737,5082,3499,5232,2456,8332,4951,8678,5020,3880,1695,5827,2504,2533,10041,5603,8426,2128,4917,3624,8854,6575,6233,6179,6714,9,9485,908,7534,5821,4412,5666,6571,5581,1924,5148,9912,4518,1309,7717,5656,5680,3304,6095,2243,4939,89,6077,9630,2295,4823,4963,4195,433,5568,6411,2071,7083,2879,7874,8245,3050,7502,3607,10185,3345,7240,5767,8471,588,1954,2532,546,3633,2067,1270,9421,5997,7490,633,7835,5916,3964,5060,6563,8327,632,4783,417,8011,3058,10004,8082,9956,8143,5961,3271,5186,5977,3132,443,7372,8766,5263,1194,6022,2146,3855,9796,7605,2474,9428,5933,6942,1001,639,2467,9621,10018,5735,2478,7326,4249,2959,2837,4883,10100,2245,7937,5834,3991,7004,3006,2249,6024,2023,8187,8915,64,821,4858,7241,9035,1559,1766,4660,6903,2958,9156,7020,8757,8452,8587,6115,10115,3018,6388,7242,6544,3324,717,7246,1962,4999,6583,8155,7580,7645,10018,95,10008,3059,1423,9473,4860,5552,6905,7664,8242,7610,1234,5852,9956,8153,4386,7755,55,9064,50,8991,2563,5757,6816,4225,1609,8631,2063,8913,8025,6146,8685,4790,3982,1500,743,6648,2895,1335,7960,5900,10002,5982,3145,173,5598,5598,3517,2116,5106,6482,2251,8734,9123,80,2814,4911,8674,957,2917,3275,479,4452,6667,5504,8219,8260,9636,4116,2818,8935,7403,697,5974,1848,6978,6133,5428,9488,6344,5905,7860,8970,8935,6041,2853,189,3014,1105,1521,508,3190,6059,5756,4664,758,4990,3951,6138,2936,7660,1351,5694,8773,6296,9668,365,8584,2500,1509,7874,2642,3094,6232,1876,3396,4264,5119,9312,3127,5343,9728,2662,6018,1316,3922,2319,5237,4765,5476,3223,7168,6307,6459,2585,10088,7157,4465,5436,7086,7375,5002,5467,9793,388,239,4710,7647,8998,214,6661,1709,7535,3874,6511,2186,283,403,3286,2141,755,1419,5834,2671,1142,10084,5840,1543,10091,8864,4534,4732,1690,8226,8411,8517,2056,7951,3334,6344,8503,4080,7039,9300,2856,9129,7787,7301,4650,7854,4430,7444,7978,4010,748,10182,696,9692,2049,1414,5156,9555,640,4801,2834,8063,6394,3207,4888,7938,3414,8752,8821,871,7135,9428,9847,5863,3012,228,7184,1148,4149,7861,4151,5390,2972,1226,7163,5927,867,9762,4959,6694,2131,5245,8553,1599,34,6580,8908,5166,1230,8422,10180,4850,3980,551,3063,3911,10053,3264,809,7704,1640,3221,4039,3890,5214,9527,7429,6581,5153,6140,501,4626,5830,2099,8283,8870,9914,3266,9883,6784,4976,442,5803,7141,706,5881,212,4792,5860,9281,4552,2787,9949,8950,7138,7432,6972,5454,534,6892,9365,177,6890,148,1840,4567,9500,7936,5156,4713,253,7868,6868,3555,5149,6594,6948,7334,7167,246,8779,8427,9754,9159,1580,6791,9523,3169,2929,6574,9696,7050,2360,4990,4147,4890,2563,10086,5763,5130,8884,1579,2677,4271,9240,2244,6722,950,3980,1670,4424,5899,2227,8448,1894,6127,8833,7836,2941,136,3533,5894,706,5409,3422,6952,4904,9285,1700,9251,915,8452,9331,3863,1289,4701,2921,3601,1505,5152,4316,1635,2602,6076,4575,4234,1718,2417,1348,6448,7823,1994,547,3163,7354,6385,9768,85,9036244,2338033,2830556,4269901,7980319,2634513,2102991,9191640,3161494,3078948,10320751,10464307,3816661,2175626,3197273,3808645,7227443,5720426,6988706,8403509,3789201,5743075,5466889,4026926,6823382,7600311,5918762,2580590,5423207,1604048,8137535,9710776,3930945,6457159,8373852,2727753,3779961,6977431,3734285,589617,2255595,9848703,1152446,3776375,3701965,7523840,7621475,185233,5890232,8918861,6784976,9962480,6731436,1723576,2686949,9097984,7576897,8084692,1329679,7666139,182339,4830252,5622209,9218505,10387718,2750614,3258672,5230876,2361964,10226389,5408003,2184805,9080318,1080661,165100,1545576,10118853,3699323,4538786,1229132,6613366,2840148,8292026,5465877,1998920,2391790,4231314,8772047,1391606,4541742,8463637,3982947,6742772,850529,311909,4094423,2151737,9079500,1747305,389484,9023976,8625489,7656427,843219,10425573,1582790,5580010,7021230,3485620,3013952,1256067,1436970,10420388,9964092,9184052,5543541,4841116,1714294,4671597,2216334,4097870,7887648,4197018,743696,1114332,8015206,257974,4830999,7585973,4788901,1765291,2456245,2504226,1731947,1902673,6358586,11846,6155261,9657416,5071365,6848331,10381779,9919888,7398394,408792,7419543,5163508,523843,8269317,9490590,19299625,17717033,17991726,13373054,18183977,15039448,18959472,16906196,17700409,13593373,18062377,14186834,14946970,14599270,12742993,20737850,14207324,15601480,17657526,11382205,18501838,13671305,17613017,19958666,20128118,15869440,18569759,17067151,20212469,17386726,17902345,13861338,12064879,10978389,12162687,15715846,19644306,13241996,19846070,13498917,17587920,19099635,11573429,19237331,11015871,13836619,18763331,18507222,12965763,15855066};

  double shuju_2[1000]={436827,2377586,414365,5842178,4072837,2289984,2047126,418425,4907093,1304412,2169021,655701,3238508,3831900,5294638,3113111,1881973,5828530,1024449,2172457,3661121,4400262,2646945,5021090,3014602,5250339,807015,2357800,3199198,1359682,3087528,5808047,280391,3828726,3689688,3722955,2109412,712853,3015128,1392774,1514465,2808840,2575284,2051029,2113824,2907847,2126623,4424803,5050502,1116115,4109704,1184760,4343111,487265,5063025,4265980,4052805,4585503,1969020,70527,1095797,2902004,4428593,369365,5618861,2898569,3442311,3023312,1513313,5856946,2170598,3709560,2413908,4463117,410760,3743570,4469954,1441354,4065262,5547957,2643127,5629874,1526648,2612738,4446744,911535,857783,4593619,1095558,5273886,2547353,3403896,2208376,3612851,1385208,5862591,4518615,732488,3863277,2089662,5313665,2244170,2297140,488210,5237523,2066802,4091716,2368827,179635,4696719,561333,222260,4803150,3294571,374760,4577692,4326182,1254824,1084528,4320005,2424102,4496437,5001059,4005935,2402396,1255883,1200970,237048,362094,5629778,3777862,1878954,2804441,3289573,3833914,2459139,864611,281458,4290402,77463,1544404,5404027,5138406,5715882,3016588,4481337,292064,2939822,4201916,3933324,4221334,2849516,4422001,1922417,3668434,273414,5521187,3118679,2811400,5440018,3156767,2756434,1466209,2586178,4171000,418809,5979168,2849900,1880805,4551813,2458068,1506752,5917313,4091528,5661466,4125991,2786805,1108819,3399151,4793368,3756408,2829544,2389106,4738588,4172462,5567618,4892525,3312227,4344788,5135605,4976259,2187000,3243860,5088165,5853297,2992507,727725,3933549,1440693,1174341,4021252,1674342,4099287,374718,918614,3085212,2434755,232658,4949347,3395739,3317403,5256244,2434712,4270045,407432,2916853,879372,1713649,1688687,5492431,769420,1212806,5894808,865395,3428213,4503319,2954735,5983157,2013493,1672680,3177467,2623050,5385065,4583845,3398508,2696886,5498726,4011908,4944016,2603150,4519542,4906803,3745443,5609419,475850,2039309,5788897,411462,4270965,2825096,1826265,5734306,1919089,879272,450762,2845517,1039462,4370331,688736,1169429,4657409,4489221,2861443,5006653,1005767,673620,1236961,4646552,2977790,2615079,3361377,2593584,606845,3084647,4376219,2243219,1543703,1816446,5786539,2766783,3145240,5132263,5551,1379518,3537544,260149,2751998,2747623,4038510,1179702,5968157,1728954,4842887,5380916,235562,5243467,4494525,5607785,4725947,638156,4581622,5173274,5526351,4035971,4596515,5972531,4668947,2103949,2640780,3458246,1607155,3215781,1591257,288266,5687700,443589,3319742,792638,3592542,2918581,4813726,3935216,2089226,2350550,501398,3622030,1349260,4107229,3536010,215357,2252007,2025271,4527616,548695,4012777,3311877,402447,1112004,3960821,17159,3899290,3093594,2095896,4006564,2807191,77714,5203820,3491941,33993,997260,960561,4006471,1719423,3475464,1275318,5634796,2323517,5154912,369445,4764009,3527606,1770364,158892,1218887,5063249,5014405,5691201,1922338,2986596,865729,4199630,2702693,3185038,1636730,511590,4593629,4368464,4944106,523050,4261361,5434396,3504333,4897444,1919779,5219562,2295961,1281353,5676558,1956082,1875284,584580,5745908,1209361,4454011,9994,2000631,2444804,573175,2140228,919549,1863116,2910147,3383098,5654018,3254609,3657729,5548445,400970,4804519,5117099,2962895,1526318,3574505,3185424,2803896,2304494,2374783,419641,5816326,185227,3557845,4145728,857912,724141,3905983,5603435,5386805,2308472,888297,1411887,246112,2377270,4220128,91707,909004,3243241,4758453,265055,4234245,3341166,4712740,2580745,5368451,1313098,2219028,1536037,5127041,3203315,5107396,4018692,5872735,4253862,3670158,648062,4660193,4925377,2195424,3824144,5925165,3334053,2896260,352319,734066,4977896,3729510,1104857,3030640,2007635,5565908,1650300,1105556,4941181,4968668,2819440,2195743,3010191,822870,3618506,399616,2283082,5921468,3863070,971961,1228934,2938295,5547831,2298263,5206850,4336443,3922052,4950797,2928677,1635502,4333675,3858785,354265,3422873,5580319,2777529,3813246,4038292,36643,5512878,284008,3864687,4989616,4980017,1642708,1817659,4981762,3183796,3501318,1277730,332163,3946629,1629684,1634989,725371,1255172,1909790,5676574,3394312,243873,5263388,4180897,1279603,405797,3817548,4538847,136441,2173290,927667,3144539,3693029,854175,5244879,1272232,2980423,4031233,4589394,2564774,2484234,4232723,3779934,112385,1768424,5633757,5958214,3143886,4536489,5740162,3385970,2697233,1705735,3216056,5260512,2765758,4724264,2902806,4764142,5222565,4755991,2087012,2505387,820811,576628,5302934,5957444,1294370,1218852,1124344,1613103,1646122,4428014,291587,12541,3618198,1495372,3929474,5210439,3122972,1364316,782588,2948611,4285916,2576231,5832690,2968699,445280,520170,3943138,5710385,5513677,4931375,3209301,2161499,1721221,4579451,1044302,2521939,1708009,5925631,5670947,4008869,2623626,3210742,1708947,268073,466613,5811020,2383323,717346,626754,973500,1644361,1453697,4123509,4192788,3801190,1961695,2384662,637464,165404,3554620,1336567,3816515,4713845,1162002,4903782,756322,64500,2997771,866136,5898304,5947191,5204695,1765169,124249,4248858,2719326,1843065,2204804,3729554,1113145,2322043,1149751,3418197,3326428,1534151,1471969,4222291,3327710,1664068,833458,98154,601336,1340019,1993068,3396254,427501,3197974,5753392,64791,893897,3448172,3990317,3794957,2330832,2810057,2026729,2893563,1206198,3414735,1593417,3526172,2070673,3179667,2889196,5374165,5361827,5290594,2453774,2657829,2746010,373576,3568494,3418038,4483581,2778782,4609107,5381624,876171,985636,1776620,1399532,2293591,164896,1648107,2880260,1430318,4603474,244295,4365390,1372516,3876628,5708641,2677929,1668084,2350318,1654260,4871950,3287567,3347310,4173466,3588295,4022862,2648330,195518,123723,3025691,3331964,3842172,5266089,3181390,5709172,339126,2905179,1531989,1991945,5359211,5315243,62546,3758256,3566729,4868240,4810347,421280,1739452,4572618,1509603,183123,3530290,5202612,5250124,5149398,612517,2394320,4658049,4700829,2745235,2012085,977404,91933,4406764,1542313,3924251,1590118,2358178,5112716,1419921,4347838,2464462,684848,1903195,5465825,4274801,3673338,2646680,5130369,393325,639204,2586871,2999621,2605928,1236728,5838384,5817979,976172,2055289,5012484,4802007,4932547,4972920,4575674,5591665,5637429,1647709,2412210,772289,643487,2833110,906999,5410524,1479084,2819097,2128960,5767860,1051759,342804,74378,2185698,1700446,117956,3853341,2835057,3482397,3727926,58794,2150760,2880421,3111161,5497793,4235630,3861154,3102681,5217709,2613763,2040855,651093,3104995,3855088,5193813,4139105,4953930,5428907,948412,738207,2523785,3457611,15116,5882353,3231058,145265,2053470,5484078,801214,2399144,5297448,1671520,2807868,257990,1347673,954987,2928361,4807711,1736003,5032943,2304894,1863519,113435,5541606,5738095,1731002,3731641,5866715,4329131,4403369,2523529,4798058,1822858,2044100,5713293,4100136,5143365,61153,1684833,4627732,4193766,3938900,263793,141213,1189966,5319801,5038993,4325828,1025003,4164907,4310541,5763966,3358330,298446,4738465,1585441,2367127,3108410,32903,2302769,2792826,3481255,2143948,5055942,4742662,3819432,2517331,1868150,2115899,1071537,3923520,1111677,1907622,2601901,1322955,3151780,5983682,2541808,4289381,4295333,3701976,3530249,942589,3781679,5820361,3065640,1379852,1826045,925179,1506398,291303,549329,120799,653756,602388,2802801,4449028,3993724,3865339,5209414,638088,3818539,1312569,3491038,3891327,3338795,737983,4281080,3618958,3010963,4424589,1454736,5134410,3868370,4084300,518663,2196592,3274592,3327553,605938,3478705,74188,4376895,4935570,3504967,3849886,5607655,913556,3554277,4931254,4771039,3094776,3832589,1131388,5476270,2891820,1423842,1433585,5312380,1661155,5161107,3771834,2945436,2784043,2969774,5384377,726714,2173035,4893170,2835301,1338512,728004,4914484,3620349,4093785,5591709,4841129,4387878,1560461,2989325,4101458,4998447,4700795,2674974,243683,5199754,3242221,5013787,1013306,946948,2069647,2794822,3481378};
  uint32_t nFlows = 1000;
  uint16_t port = 40000;
  CommandLine cmd;
  cmd.AddValue("nFlows", "Number of parallel flows", nFlows);
  cmd.Parse(argc, argv);

  LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
  LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);

  NodeContainer nodes;
  nodes.Create (2);
  PointToPointHelper pointToPoint;
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("10ms"));

  NetDeviceContainer devices;
  devices = pointToPoint.Install (nodes);

  InternetStackHelper stack;
  stack.Install (nodes);

  Ipv4AddressHelper address;
  address.SetBase ("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer interfaces = address.Assign (devices);                                                                             

  ApplicationContainer clientApp[nFlows];
  ApplicationContainer sinkApp[nFlows];

  for(unsigned int i = 0; i < nFlows; i++)
  {
      PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", InetSocketAddress(interfaces.GetAddress (1), port + i));
      sinkApp[i] = packetSinkHelper.Install (nodes.Get (1));
      sinkApp[i].Start(Seconds (0.0));
      sinkApp[i].Stop(Seconds (60000.0));
  }

  double start_time=10;
  for(unsigned int i = 0; i < nFlows; i++)
  {
    OnOffHelper client("ns3::TcpSocketFactory", InetSocketAddress(interfaces.GetAddress (1), port + i));
    client.SetAttribute ("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=50000]"));
    client.SetAttribute ("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
    client.SetAttribute ("DataRate", DataRateValue (DataRate ("1.5Mbps")));
    client.SetAttribute ("PacketSize", UintegerValue (50));

    //client.SetAttribute("MaxBytes",UintegerValue (5000));   
    client.SetAttribute("MaxBytes",UintegerValue (shuju_1[i]));
    // client.SetAttribute ("")   
    clientApp[i] = client.Install (nodes.Get (0));
   // clientApp[i].Start(Seconds (1.0 + (i * 8)));
   // start_time+=shuju_2[i];
   // clientApp[i].Start(MicroSeconds (1000000.0 + (i * 8000000)));
    clientApp[i].Start(MicroSeconds (start_time)); 
    clientApp[i].Stop (Seconds (51000));
    start_time+=shuju_2[i];
  }


  pointToPoint.EnablePcapAll ("nflow");

  Simulator::Stop (Seconds(50000));
  Simulator::Run ();
  Simulator::Destroy ();


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值