ns-3でボトルネックリンク帯域幅を動的に調整する方法

2373 ワード

ns-3のtutorialとns-3のインストール後、ディレクトリexampleで与えられた例は、channelのbandwidthとdelayを予め設定しておきますが、trace drivenベースのsimulationを作りたい場合は、channelのbandwidthやdelayを一定時間ごとに動的に変更するにはどうすればいいですか?このブログはns-3ディレクトリexample/tcp/下のtcp-variants-comparison.ccを例として、修正されたソースファイルは私のgithubで見ることができます.ここではgithubアドレスgithubを示します.

静的設定bandwidthとdelay

...
int main (int args, char *argv[])
...
std::string bandwidth = "2Mbps"
std::string delay = "0.01ms"
...
PointToPointHelper UnReLink;
UnReLink.SetDeviceAttribute ("Datarate", StringValue (bandwidth));
UnReLink.SetChannelAttribute ("Delay", StringValue (delay));
...

動的調整bandwidthとdelay


ダイナミックにbandwidthとdelayを調整するには、まずbandwidth traceを作る必要があります.このtraceはどうすればいいか、言わないでください.私に聞いても言わないと思います.

BandwidthTrace()関数の書き込み


ここではdownlinkにtraceを追加します.downlinkと申します.txtファイル読み込みファイル
#include 
using namespace std;
...
void BandwidthTrace (void);
void ScheduleBw (void);
string bandwidth = "2Mbps";
uint32_t m_timer_value = 100;
...
ifstream bwfile ("downlink.txt");
PointToPoint UnReLink;
...

ifstreamが何者かと聞かれたら、何者かは教えてくれません.使用時にヘッダファイル「fstream」を含むことを覚えておくだけです.また、なぜここでこの表現「PointToPoint UnReLink」を使うのか、後で言います.書く関数BandwidthTrace()ここでまず1種の誤ったやり方を与えて、私は以前このようにして、ああ、生命を浪費します!
void
BandwidthTrace (void)
{   
    // trace ,bwfile ,getline 
    getline (bwfile, bandwidth);
    // bandwidth
    UnReLink.SetDeviceAttribute ("Datarate", StringValue (bandwidth));
    // 
    if (!bwfile.eof ())
    {
        //trace , ScheduleBw , 
        ScheduleBw ();
    }
    else 
    {
        cout <

今問題が来ました.間違いはどこですか.質問はここです.SetDeviceAttribute ("Datarate", StringValue (bandwidth)); この文は一度しか実行されず、後で再度呼び出された場合、エラーは報告されないが、何も変更されないので、attributeを動的に変更するには、Config::Set(「NodeList/[i]/DeviceList/[i]/$ns 3::PointToPointNet/DataRate」,StringValue)を使用します.NodeList/[i]はi番目のノードを表し、DeviceList/[i]はi番目のノードのi番目のデバイスを表す.BandwidthTrace()関数の書き方は次のようになります.
void
BandwidthTrace (void)
{   
    // trace ,bwfile ,getline 
    getline (bwfile, bandwidth);
    Config::Set("/NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/DataRate", StringValue(bandwidth));
    if (!bwfile.eof())
    {
        ScheduleBw();
    }
    else 
    {
        cout <