SoonyangZhang / quic-on-ns3

running quic on ns3
Apache License 2.0
21 stars 8 forks source link

和tap-bridge一起用 #10

Closed MikeLee9527 closed 1 year ago

MikeLee9527 commented 1 year ago

我试着通过tap-brige,让在docker的真实quic和您的ns3 quic进行通信,但是修改完BuildP2PTopo()和test_app_on_p2p(),ns3程序总是直接就结束了(大概几十ms),而我还没来得及启动docker里的quic程序。这是为什么呢

`#include

include

include

include

include

include "ns3/core-module.h"

include "ns3/applications-module.h"

include "ns3/internet-module.h"

include "ns3/network-module.h"

include "ns3/point-to-point-module.h"

include "ns3/ipv4-global-routing-helper.h"

include "ns3/traffic-control-module.h"

include "ns3/quic-module.h"

include "ns3/nstime.h"

include "ns3/csma-module.h"

include "ns3/tap-bridge-module.h"

using namespace ns3; using namespace quic; using namespace std; NS_LOG_COMPONENT_DEFINE ("quic-main"); const uint32_t DEFAULT_PACKET_SIZE = 1500; const uint32_t kBwUnit=1000000; class TriggerRandomLoss{ public: TriggerRandomLoss(){} ~TriggerRandomLoss(){ if(m_timer.IsRunning()){ m_timer.Cancel(); } } void RegisterDevice(Ptr dev){ m_dev=dev; } void Start(){ Time next=Seconds(2); m_timer=Simulator::Schedule(next,&TriggerRandomLoss::ConfigureRandomLoss,this); } void ConfigureRandomLoss(){ if(m_timer.IsExpired()){ std::string errorModelType = "ns3::RateErrorModel"; ObjectFactory factory; factory.SetTypeId (errorModelType); Ptr em = factory.Create (); m_dev->SetAttribute ("ReceiveErrorModel", PointerValue (em));
m_timer.Cancel(); } } private: Ptr m_dev; EventId m_timer; };

// ./waf --run "scratch/quic-test --cc1=bbr --cc2=bbr --folder=no" int main(int argc, char argv[]){ //LogComponentEnable("Ns3QuicBackendBase",LOG_LEVEL_ALL); //LogComponentEnable("Ns3QuicAlarmEngine",LOG_LEVEL_ALL); //LogComponentEnable("Ns3QuicChannelBase",LOG_LEVEL_ALL); LogComponentEnable("QuicClientApp",LOG_LEVEL_ALL); LogComponentEnable("QuicServerApp",LOG_LEVEL_ALL); std::string topo("p2p"); std::string instance=std::string("1"); std::string loss_str("0"); //config random loss std::string cc1("cubic"); std::string cc2("cubic"); std::string data_folder("no-one"); CommandLine cmd; cmd.AddValue ("topo", "topology", topo); cmd.AddValue ("it", "instacne", instance); cmd.AddValue ("folder", "folder name to collect data", data_folder); cmd.AddValue ("lo", "loss",loss_str); // 10 means the dev will introduce 10/1000 % random loss cmd.AddValue ("cc1", "congestion algorithm1",cc1); cmd.AddValue ("cc2", "congestion algorithm2",cc2); cmd.Parse (argc, argv); int loss_integer=std::stoi(loss_str); double random_loss=loss_integer1.0/1000; std::unique_ptr triggerloss=nullptr; if(loss_integer>0){ Config::SetDefault ("ns3::RateErrorModel::ErrorRate", DoubleValue (random_loss)); Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("ERROR_UNIT_PACKET")); Config::SetDefault ("ns3::BurstErrorModel::ErrorRate", DoubleValue (random_loss)); Config::SetDefault ("ns3::BurstErrorModel::BurstSize", StringValue ("ns3::UniformRandomVariable[Min=1|Max=3]")); triggerloss.reset(new TriggerRandomLoss()); triggerloss->Start(); } const char envKey="QUICHE_SRC_DIR"; char envValue=getenv(envKey); if(envValue){ std::cout<<envValue<<std::endl; }

set_quic_log_error_level(); //print quiche lib error
quic::ContentInit('a');

std::string quic_cert_path=std::string(envValue)+"utils/data/quic-cert/";
if(ns3::set_quic_cert_key(quic_cert_path)){
    //HELLO_UNIDI
    //HELLO_BIDI
    //BANDWIDTH

    quic::BackendType type=quic::BackendType::BANDWIDTH;
    //QuicClientTraceType client_log_flag=E_QC_IN_FLIGHT|E_QC_SEND_RATE;
    //QuicServerTraceType server_log_flag=E_QS_OWD|E_QS_LOST|E_QS_GOODPUT;
    RegisterExternalCongestionFactory();

uint64_t bps=5*kBwUnit; uint32_t link_delay=100;//milliseconds; uint32_t buffer_delay=300;//ms

        std::string mode = "UseBridge";    

std::string tapName ="tap-test1";

NodeContainer nodesLeft;

nodesLeft.Create (2);

CsmaHelper csmaSN0; csmaSN0.SetChannelAttribute ("DataRate", StringValue ("100Mbps")); csmaSN0.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560))); NetDeviceContainer devicesLeft = csmaSN0.Install (nodesLeft);

NodeContainer nodes; nodes.Add(nodesLeft.Get(1)); nodes.Create(1);

PointToPointHelper p2p; p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (bps))); p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (link_delay))); p2p.SetQueue ("ns3::DropTailQueue", "MaxSize", StringValue (std::to_string(5)+"p")); NetDeviceContainer devices = p2p.Install (nodes);

InternetStackHelper internet;

internet.Install (nodesLeft.Get(0)); internet.Install (nodes);

Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfacesLeft = ipv4.Assign (devicesLeft);

ipv4.SetBase ("10.1.2.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);

TapBridgeHelper tapBridge (interfacesLeft.GetAddress (0)); tapBridge.SetAttribute ("Mode", StringValue (mode)); tapBridge.SetAttribute ("DeviceName", StringValue (tapName)); tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0));

//install server
uint16_t server_port=1234;
InetSocketAddress server_addr(server_port);
{
    Ptr<QuicServerApp> server_app=CreateObject<QuicServerApp>(type);
    nodes.Get(1)->AddApplication(server_app);
    server_app->Bind(server_port);
    server_addr=server_app->GetLocalAddress();
    server_app->SetStartTime (Seconds(0.01));
    server_app->SetStopTime (Seconds(200)+Seconds(10));

}

//int last_time=WallTimeMillis();
Simulator::Stop (Seconds(200)+Seconds(20));
Simulator::Run ();
Simulator::Destroy();

/int delta=WallTimeMillis()-last_time; std::cout<<"run time ms: "<<delta<<std::endl;/

}
return 0;

} `

SoonyangZhang commented 1 year ago

你需要用现实的时钟,而不是仿真时钟。

GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl")); 

还有就是为啥非要在让数据包在ns3中跑一遍,直接跑原生的quic程序,测试性能,不更方便。

MikeLee9527 commented 1 year ago

感谢您的回复,我在做老师给的毕设,要求了使用docker和ns3,所以想让数据包进来ns3。原先想docker ns3 to docker ns3 但是发现模拟不了csma p2p wifi链路,就选择了docker to ns3。 我发包程序用的quic-go,请问需要用quiche/util里的生成cert脚本生成发包和接收方的cert吗?他们的IP不一样,对QUIC这块儿不太了解。

SoonyangZhang commented 1 year ago

这里面就有quic的客户端程序,你全部在ns3环境里仿真不就完事了。有能力了,怎么折腾都行,能力不足时候,不要瞎折腾。或者让你的指导老师折腾。

MikeLee9527 commented 1 year ago

谢谢您的回复,我确实能力和时间都不足以在设想的方向上折腾,老师也没提供技术支持,可能还是得留给以后的人在这方面尝试了

SoonyangZhang commented 1 year ago

我的意思是,找个最简的方案,快速demo出来,拿到数据。多引入一个依赖,就需要更多时间学习,调试,理解。

MikeLee9527 commented 1 year ago

谢谢您的建议