本文整理汇总了C++中ApplicationContainer::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ ApplicationContainer::Add方法的具体用法?C++ ApplicationContainer::Add怎么用?C++ ApplicationContainer::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationContainer
的用法示例。
在下文中一共展示了ApplicationContainer::Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char *argv[])
{
#ifdef NS3_CLICK
NodeContainer csmaNodes;
csmaNodes.Create (2);
// Setup CSMA channel between the nodes
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
NetDeviceContainer csmaDevices = csma.Install (csmaNodes);
// Install normal internet stack on node B
InternetStackHelper internet;
internet.Install (csmaNodes.Get (1));
// Install Click on node A
ClickInternetStackHelper clickinternet;
clickinternet.SetClickFile (csmaNodes.Get (0), "src/click/examples/nsclick-lan-single-interface.click");
clickinternet.SetRoutingTableElement (csmaNodes.Get (0), "rt");
clickinternet.Install (csmaNodes.Get (0));
// Configure IP addresses for the nodes
Ipv4AddressHelper ipv4;
ipv4.SetBase ("172.16.1.0", "255.255.255.0");
ipv4.Assign (csmaDevices);
// Configure traffic application and sockets
Address LocalAddress (InetSocketAddress (Ipv4Address::GetAny (), 50000));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", LocalAddress);
ApplicationContainer recvapp = packetSinkHelper.Install (csmaNodes.Get (1));
recvapp.Start (Seconds (5.0));
recvapp.Stop (Seconds (10.0));
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
ApplicationContainer appcont;
AddressValue remoteAddress (InetSocketAddress (Ipv4Address ("172.16.1.2"), 50000));
onOffHelper.SetAttribute ("Remote", remoteAddress);
appcont.Add (onOffHelper.Install (csmaNodes.Get (0)));
appcont.Start (Seconds (5.0));
appcont.Stop (Seconds (10.0));
// For tracing
csma.EnablePcap ("nsclick-simple-lan", csmaDevices, false);
Simulator::Stop (Seconds (20.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
#else
NS_FATAL_ERROR ("Can't use ns-3-click without NSCLICK compiled in");
#endif
}
示例2:
ApplicationContainer
BulkSendHelper::Install (NodeContainer c) const
{
ApplicationContainer apps;
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
apps.Add (InstallPriv (*i));
}
return apps;
}
示例3: Install
ApplicationContainer RadvdHelper::Install (Ptr<Node> node)
{
ApplicationContainer apps;
Ptr<Radvd> radvd = m_factory.Create<Radvd> ();
for (RadvdInterfaceMapI iter = m_radvdInterfaces.begin(); iter != m_radvdInterfaces.end(); iter ++)
{
if (!iter->second->GetPrefixes().empty())
{
radvd->AddConfiguration(iter->second);
}
}
node->AddApplication (radvd);
apps.Add (radvd);
return apps;
}
示例4: bearer
void
LenaPssFfMacSchedulerTestCase2::DoRun (void)
{
if (!m_errorModelEnabled)
{
Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
}
Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
lteHelper->SetEpcHelper (epcHelper);
Ptr<Node> pgw = epcHelper->GetPgwNode ();
// Create a single RemoteHost
NodeContainer remoteHostContainer;
remoteHostContainer.Create (1);
Ptr<Node> remoteHost = remoteHostContainer.Get (0);
InternetStackHelper internet;
internet.Install (remoteHostContainer);
// Create the Internet
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.001)));
NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
Ipv4AddressHelper ipv4h;
ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
// interface 0 is localhost, 1 is the p2p device
Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
// LogComponentDisableAll (LOG_LEVEL_ALL);
//LogComponentEnable ("LenaTestPssFfMacCheduler", LOG_LEVEL_ALL);
lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
// Create Nodes: eNodeB and UE
NodeContainer enbNodes;
NodeContainer ueNodes;
enbNodes.Create (1);
ueNodes.Create (m_nUser);
// Install Mobility Model
MobilityHelper mobility;
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (enbNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (ueNodes);
// Create Devices and install them in the Nodes (eNB and UE)
NetDeviceContainer enbDevs;
NetDeviceContainer ueDevs;
lteHelper->SetSchedulerType ("ns3::PssFfMacScheduler");
enbDevs = lteHelper->InstallEnbDevice (enbNodes);
ueDevs = lteHelper->InstallUeDevice (ueNodes);
Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
// Set UEs' position and power
for (int i = 0; i < m_nUser; i++)
{
Ptr<ConstantPositionMobilityModel> mm = ueNodes.Get (i)->GetObject<ConstantPositionMobilityModel> ();
mm->SetPosition (Vector (m_dist.at (i), 0.0, 0.0));
Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
}
// Install the IP stack on the UEs
internet.Install (ueNodes);
Ipv4InterfaceContainer ueIpIface;
ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
// Assign IP address to UEs
for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
{
Ptr<Node> ueNode = ueNodes.Get (u);
// Set the default gateway for the UE
Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
}
// Attach a UE to a eNB
lteHelper->Attach (ueDevs, enbDevs.Get (0));
//.........这里部分代码省略.........
示例5: star
// Network topology (default)
//
// n2 + + n3 .
// | ... |\ /| ... | .
// ======= \ / ======= .
// CSMA \ / CSMA .
// \ / .
// n1 +--- n0 ---+ n4 .
// | ... | / \ | ... | .
// ======= / \ ======= .
// CSMA / \ CSMA .
// / \ .
// n6 + + n5 .
// | ... | | ... | .
// ======= ======= .
// CSMA CSMA .
//
void
CsmaStarTestCase::DoRun (void)
{
//
// Default number of nodes in the star.
//
uint32_t nSpokes = 7;
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", StringValue ("1ms"));
CsmaStarHelper star (nSpokes, csma);
NodeContainer fillNodes;
//
// Just to be nasy, hang some more nodes off of the CSMA channel for each
// spoke, so that there are a total of 16 nodes on each channel. Stash
// all of these new devices into a container.
//
NetDeviceContainer fillDevices;
uint32_t nFill = 14;
for (uint32_t i = 0; i < star.GetSpokeDevices ().GetN (); ++i)
{
Ptr<Channel> channel = star.GetSpokeDevices ().Get (i)->GetChannel ();
Ptr<CsmaChannel> csmaChannel = channel->GetObject<CsmaChannel> ();
NodeContainer newNodes;
newNodes.Create (nFill);
fillNodes.Add (newNodes);
fillDevices.Add (csma.Install (newNodes, csmaChannel));
}
InternetStackHelper internet;
star.InstallStack (internet);
internet.Install (fillNodes);
star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.0.0", "255.255.255.0"));
//
// We assigned addresses to the logical hub and the first "drop" of the
// CSMA network that acts as the spoke, but we also have a number of fill
// devices (nFill) also hanging off the CSMA network. We have got to
// assign addresses to them as well. We put all of the fill devices into
// a single device container, so the first nFill devices are associated
// with the channel connected to spokeDevices.Get (0), the second nFill
// devices afe associated with the channel connected to spokeDevices.Get (1)
// etc.
//
Ipv4AddressHelper address;
for(uint32_t i = 0; i < star.SpokeCount (); ++i)
{
std::ostringstream subnet;
subnet << "10.1." << i << ".0";
address.SetBase (subnet.str ().c_str (), "255.255.255.0", "0.0.0.3");
for (uint32_t j = 0; j < nFill; ++j)
{
address.Assign (fillDevices.Get (i * nFill + j));
}
}
//
// Create a packet sink on the star "hub" to receive packets.
//
uint16_t port = 50000;
Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
hubApp.Start (Seconds (1.0));
hubApp.Stop (Seconds (10.0));
//
// Create OnOff applications to send TCP to the hub, one on each spoke node.
//
// Make packets be sent about every DefaultPacketSize / DataRate =
// 4096 bits / (5000 bits/second) = 0.82 second.
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
onOffHelper.SetConstantRate (DataRate (5000));
ApplicationContainer spokeApps;
for (uint32_t i = 0; i < star.SpokeCount (); ++i)
//.........这里部分代码省略.........
示例6: onoff
//
// Example of the sending of a datagram to a broadcast address
//
// Network topology
// ==============
// | |
// n0 n1 n2
// | |
// ==========
//
// n0 originates UDP broadcast to 255.255.255.255/discard port, which
// is replicated and received on both n1 and n2
//
void
CsmaBroadcastTestCase::DoRun (void)
{
NodeContainer c;
c.Create (3);
NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1));
NodeContainer c1 = NodeContainer (c.Get (0), c.Get (2));
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
NetDeviceContainer n0 = csma.Install (c0);
NetDeviceContainer n1 = csma.Install (c1);
InternetStackHelper internet;
internet.Install (c);
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.0.0", "255.255.255.0");
ipv4.Assign (n0);
ipv4.SetBase ("192.168.1.0", "255.255.255.0");
ipv4.Assign (n1);
// RFC 863 discard port ("9") indicates packet should be thrown away
// by the system. We allow this silent discard to be overridden
// by the PacketSink application.
uint16_t port = 9;
// Create the OnOff application to send UDP datagrams from n0.
//
// Make packets be sent about every DefaultPacketSize / DataRate =
// 4096 bits / (5000 bits/second) = 0.82 second.
OnOffHelper onoff ("ns3::UdpSocketFactory",
Address (InetSocketAddress (Ipv4Address ("255.255.255.255"), port)));
onoff.SetConstantRate (DataRate (5000));
ApplicationContainer app = onoff.Install (c0.Get (0));
// Start the application
app.Start (Seconds (1.0));
app.Stop (Seconds (10.0));
// Create an optional packet sink to receive these packets
PacketSinkHelper sink ("ns3::UdpSocketFactory",
Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
app = sink.Install (c0.Get (1));
app.Add (sink.Install (c1.Get (1)));
app.Start (Seconds (1.0));
app.Stop (Seconds (10.0));
// Trace receptions
Config::ConnectWithoutContext ("/NodeList/1/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaBroadcastTestCase::SinkRxNode1, this));
Config::ConnectWithoutContext ("/NodeList/2/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaBroadcastTestCase::SinkRxNode2, this));
Simulator::Run ();
Simulator::Destroy ();
// We should have sent and received 10 packets
NS_TEST_ASSERT_MSG_EQ (m_countNode1, 10, "Node 1 should have received 10 packets");
NS_TEST_ASSERT_MSG_EQ (m_countNode2, 10, "Node 2 should have received 10 packets");
}
示例7: bth
int
main (int argc, char *argv[])
{
#ifdef NS3_MPI
// Distributed simulation setup
MpiInterface::Enable (&argc, &argv);
GlobalValue::Bind ("SimulatorImplementationType",
StringValue ("ns3::DistributedSimulatorImpl"));
LogComponentEnable ("BriteMPITest", LOG_LEVEL_ALL);
LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO);
uint32_t systemId = MpiInterface::GetSystemId ();
uint32_t systemCount = MpiInterface::GetSize ();
// Check for valid distributed parameters.
// For just this particular example, must have 2 and only 2 Logical Processors (LPs)
NS_ASSERT_MSG (systemCount == 2, "This demonstration requires 2 and only 2 logical processors.");
// BRITE needs a configuration file to build its graph. By default, this
// example will use the TD_ASBarabasi_RTWaxman.conf file. There are many others
// which can be found in the BRITE/conf_files directory
std::string confFile = "src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf";
bool tracing = false;
bool nix = false;
CommandLine cmd;
cmd.AddValue ("confFile", "BRITE conf file", confFile);
cmd.AddValue ("tracing", "Enable or disable ascii tracing", tracing);
cmd.AddValue ("nix", "Enable or disable nix-vector routing", nix);
cmd.Parse (argc,argv);
// Invoke the BriteTopologyHelper and pass in a BRITE
// configuration file and a seed file. This will use
// BRITE to build a graph from which we can build the ns-3 topology
BriteTopologyHelper bth (confFile);
PointToPointHelper p2p;
Ipv4StaticRoutingHelper staticRouting;
Ipv4GlobalRoutingHelper globalRouting;
Ipv4ListRoutingHelper listRouting;
Ipv4NixVectorHelper nixRouting;
InternetStackHelper stack;
if (nix)
{
listRouting.Add (staticRouting, 0);
listRouting.Add (nixRouting, 10);
}
else
{
listRouting.Add (staticRouting, 0);
listRouting.Add (globalRouting, 10);
}
stack.SetRoutingHelper (listRouting);
Ipv4AddressHelper address;
address.SetBase ("10.0.0.0", "255.255.255.252");
//build topology as normal but also pass systemCount
bth.BuildBriteTopology (stack, systemCount);
bth.AssignIpv4Addresses (address);
NS_LOG_LOGIC ("Number of AS created " << bth.GetNAs ());
uint16_t port = 5001;
NodeContainer client;
NodeContainer server;
//For this example will use AS 0 and AS 1 which will be on seperate systems
//due to the mod divide used to assign AS to system.
//GetSystemNumberForAs (uint32_t) can be used to determine which system an
//AS is assigned to
NS_LOG_LOGIC ("AS 0 has been assigned to system " << bth.GetSystemNumberForAs (0));
NS_LOG_LOGIC ("As 1 has been assigned to system " << bth.GetSystemNumberForAs (1));
//install client node on last leaf node of AS 0
client.Add (CreateObject<Node> (0));
stack.Install (client);
int numLeafNodesInAsZero = bth.GetNLeafNodesForAs (0);
client.Add (bth.GetLeafNodeForAs (0, numLeafNodesInAsZero - 1));
//install server node on last leaf node on AS 1
server.Add (CreateObject<Node> (1));
stack.Install (server);
int numLeafNodesInAsOne = bth.GetNLeafNodesForAs (1);
server.Add (bth.GetLeafNodeForAs (1, numLeafNodesInAsOne - 1));
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer p2pClientDevices;
NetDeviceContainer p2pServerDevices;
//.........这里部分代码省略.........
示例8: star
int
main (int argc, char *argv[])
{
//
// Set up some default values for the simulation.
//
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
// ??? try and stick 15kb/s into the data rate
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
//
// Default number of nodes in the star. Overridable by command line argument.
//
uint32_t nSpokes = 8;
CommandLine cmd;
cmd.AddValue ("nSpokes", "Number of nodes to place in the star", nSpokes);
cmd.Parse (argc, argv);
NS_LOG_INFO ("Build star topology.");
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointStarHelper star (nSpokes, pointToPoint);
NS_LOG_INFO ("Install internet stack on all nodes.");
InternetStackHelper internet;
star.InstallStack (internet);
NS_LOG_INFO ("Assign IP Addresses.");
star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"));
NS_LOG_INFO ("Create applications.");
//
// Create a packet sink on the star "hub" to receive packets.
//
uint16_t port = 50000;
Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
hubApp.Start (Seconds (1.0));
hubApp.Stop (Seconds (10.0));
//
// Create OnOff applications to send TCP to the hub, one on each spoke node.
//
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
ApplicationContainer spokeApps;
for (uint32_t i = 0; i < star.SpokeCount (); ++i)
{
AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port));
onOffHelper.SetAttribute ("Remote", remoteAddress);
spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i)));
}
spokeApps.Start (Seconds (1.0));
spokeApps.Stop (Seconds (10.0));
NS_LOG_INFO ("Enable static global routing.");
//
// Turn on global static routing so we can actually be routed across the star.
//
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
NS_LOG_INFO ("Enable pcap tracing.");
//
// Do pcap tracing on all point-to-point devices on all nodes.
//
pointToPoint.EnablePcapAll ("star");
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
return 0;
}