我在ns3
添加了一个类,在使用它时,我不断收到错误:
../scratch/seven.cc: In function ‘int main(int, char**)’:
../scratch/seven.cc:102:3: error: ‘RandomAppHelper’ was not declared in this scope
RandomAppHelper source = RandomAppHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address ("192.168.1.10"), 10));
^
../scratch/seven.cc:103:3: error: ‘source’ was not declared in this scope
source.SetAttribute ("Delay", StringValue ("Constant:2.5"));
^
此处的代码位于:https://www.nsnam.org/docs/release/3.3/doxygen/application.html
我无法解决错误。我在代码中使用了正确的namespace
ns3
。由于错误是“未在范围内声明”,我不确定如何纠正它。
这是我的助手类(我正在使用)的实现:
#include "ns3/log.h"
#include "ns3/address.h"
#include "ns3/node.h"
#include "ns3/nstime.h"
#include "ns3/socket.h"
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/packet.h"
#include "ns3/uinteger.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/tcp-socket-factory.h"
#include "random-helper.h"
namespace ns3{
RandomAppHelper::RandomAppHelper (std::string protocol, Address remote)
{
m_factory.SetTypeId ("ns3::MpTcpBulkSendApplication");
m_factory.Set ("Protocol", StringValue (protocol));
m_factory.Set ("Remote", AddressValue (remote));
}
void
RandomAppHelper::SetAttribute (std::string name, const AttributeValue &value)
{
m_factory.Set (name, value);
}
ApplicationContainer
RandomAppHelper::Install (Ptr<Node> node) const
{
return ApplicationContainer (InstallPriv (node));
}
ApplicationContainer
RandomAppHelper::Install (std::string nodeName) const
{
Ptr<Node> node = Names::Find<Node> (nodeName);
return ApplicationContainer (InstallPriv (node));
}
ApplicationContainer
RandomAppHelper::Install (NodeContainer c) const
{
ApplicationContainer apps;
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
apps.Add (InstallPriv (*i));
}
return apps;
}
Ptr<Application>
RandomAppHelper::InstallPriv (Ptr<Node> node) const
{
Ptr<Application> app = m_factory.Create<Application> ();
node->AddApplication (app);
return app;
}
}
此类在ns3的applications文件夹中定义,该文件夹包含在 applications-module.h include中。在我的代码中,我将它包含在我使用RandomAppHelper的地方。
答案 0 :(得分:0)
我猜你忘了在应用程序文件夹中的wscript.py文件中添加你的文件名(我猜你创建了RandomAppHelper)。 希望它有效。 再见