本文整理汇总了C++中ApplicationContainer类的典型用法代码示例。如果您正苦于以下问题:C++ ApplicationContainer类的具体用法?C++ ApplicationContainer怎么用?C++ ApplicationContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ApplicationContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main(int argc, char* argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
AnnotatedTopologyReader topologyReader("", 1);
topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-tree.txt");
topologyReader.Read();
// Install NDN stack on all nodes
ndn::StackHelper ndnHelper;
ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize",
"100"); // default ContentStore parameters
ndnHelper.InstallAll();
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
// Installing global routing interface on all nodes
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
ndnGlobalRoutingHelper.InstallAll();
// Getting containers for the consumer/producer
Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"),
Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")};
Ptr<Node> producer = Names::Find<Node>("root");
for (int i = 0; i < 4; i++) {
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
consumerHelper.SetAttribute("Frequency", StringValue("10")); // 100 interests a second
// Each consumer will express the same data /root/<seq-no>
consumerHelper.SetPrefix("/root");
ApplicationContainer app = consumerHelper.Install(consumers[i]);
app.Start(Seconds(0.01 * i));
}
ndn::AppHelper producerHelper("ns3::ndn::Producer");
producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
// Register /root prefix with global routing controller and
// install producer that will satisfy Interests in /root namespace
ndnGlobalRoutingHelper.AddOrigins("/root", producer);
producerHelper.SetPrefix("/root");
producerHelper.Install(producer);
// Calculate and install FIBs
ndn::GlobalRoutingHelper::CalculateRoutes();
Simulator::Stop(Seconds(20.0));
ndn::CsTracer::InstallAll("cs-trace.txt", Seconds(1));
Simulator::Run();
Simulator::Destroy();
return 0;
}
示例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: DataRateValue
//
// Network topology
// (sender) (receiver)
// n0 n1 n2 n3
// | | | |
// =====================
//
// Node n0 sends data to node n3 over a raw IP socket. The protocol
// number used is 2.
//
void
CsmaRawIpSocketTestCase::DoRun (void)
{
// Here, we will explicitly create four nodes.
NodeContainer c;
c.Create (4);
// connect all our nodes to a shared channel.
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
NetDeviceContainer devs = csma.Install (c);
// add an ip stack to all nodes.
InternetStackHelper ipStack;
ipStack.Install (c);
// assign ip addresses
Ipv4AddressHelper ip;
ip.SetBase ("192.168.1.0", "255.255.255.0");
Ipv4InterfaceContainer addresses = ip.Assign (devs);
// IP protocol configuration
//
// Make packets be sent about every DefaultPacketSize / DataRate =
// 4096 bits / (5000 bits/second) = 0.82 second.
Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
onoff.SetConstantRate (DataRate (5000));
ApplicationContainer apps = onoff.Install (c.Get (0));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
apps = sink.Install (c.Get (3));
apps.Start (Seconds (0.0));
apps.Stop (Seconds (12.0));
// Trace receptions
Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
MakeCallback (&CsmaRawIpSocketTestCase::SinkRx, this));
Simulator::Run ();
Simulator::Destroy ();
// We should have sent and received 10 packets
NS_TEST_ASSERT_MSG_EQ (m_count, 10, "Node 3 should have received 10 packets");
}
示例4: 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;
}
示例5: ping
void
AodvExample::InstallApplications ()
{
V4PingHelper ping (interfaces.GetAddress (size - 1));
ping.SetAttribute ("Verbose", BooleanValue (true));
ApplicationContainer p = ping.Install (nodes.Get (0));
p.Start (Seconds (0));
p.Stop (Seconds (totalTime) - Seconds (0.001));
// move node away
Ptr<Node> node = nodes.Get (size/2);
Ptr<MobilityModel> mob = node->GetObject<MobilityModel> ();
Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector (1e5, 1e5, 1e5));
}
示例6: uniFlow
Ptr<Socket> uniFlow(Address sinkAddress,
uint32_t sinkPort,
string tcpVariant,
Ptr<Node> hostNode,
Ptr<Node> sinkNode,
double startTime,
double stopTime,
uint32_t packetSize,
uint32_t numPackets,
std::string dataRate,
double appStartTime,
double appStopTime)
{
//if tcp socket is Reno set it to default and so on for Tahoe and Westwood
if(tcpVariant.compare("TcpReno") == 0)
Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue(TcpReno::GetTypeId()));
else if(tcpVariant.compare("TcpTahoe") == 0)
Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue(TcpTahoe::GetTypeId()));
else if(tcpVariant.compare("TcpWestwood") == 0)
Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue(TcpWestwood::GetTypeId()));
else
{
fprintf(stderr, "Invalid TCP version\n");
exit(EXIT_FAILURE);
}
//setup the sink
PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", InetSocketAddress(Ipv4Address::GetAny(), sinkPort));
ApplicationContainer sinkApps = packetSinkHelper.Install(sinkNode);
sinkApps.Start(Seconds(startTime));
sinkApps.Stop(Seconds(stopTime));
Ptr<Socket> ns3TcpSocket = Socket::CreateSocket(hostNode, TcpSocketFactory::GetTypeId());
//setup the source
Ptr<MyApp> app = CreateObject<MyApp>();
app->Setup(ns3TcpSocket, sinkAddress, packetSize, numPackets, DataRate(dataRate));
hostNode->AddApplication(app);
app->SetStartTime(Seconds(appStartTime));
app->SetStopTime(Seconds(appStopTime));
return ns3TcpSocket;
}
示例7: 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
}
示例8: echoServer
void
FlameRegressionTest::InstallApplications ()
{
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (m_nodes->Get (0));
serverApps.Start (Seconds (0.0));
serverApps.Stop (m_time);
UdpEchoClientHelper echoClient (m_interfaces.GetAddress (0), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (300));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.1)));
echoClient.SetAttribute ("PacketSize", UintegerValue (20));
ApplicationContainer clientApps = echoClient.Install (m_nodes->Get (2));
clientApps.Start (Seconds (1.0));
clientApps.Stop (m_time);
}
示例9: main
int
main (int argc, char *argv[])
{
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
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);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
示例10: Seconds
void
Ns3TcpNoDelayTestCase::DoRun (void)
{
uint16_t sinkPort = 50000;
double sinkStopTime = 8; // sec; will trigger Socket::Close
double writerStopTime = 5; // sec; will trigger Socket::Close
double simStopTime = 10; // sec
Time sinkStopTimeObj = Seconds (sinkStopTime);
Time writerStopTimeObj = Seconds (writerStopTime);
Time simStopTimeObj= Seconds (simStopTime);
Ptr<Node> n0 = CreateObject<Node> ();
Ptr<Node> n1 = CreateObject<Node> ();
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (n0, n1);
InternetStackHelper internet;
internet.InstallAll ();
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.252");
Ipv4InterfaceContainer ifContainer = address.Assign (devices);
Ptr<SocketWriter> socketWriter = CreateObject<SocketWriter> ();
Address sinkAddress (InetSocketAddress (ifContainer.GetAddress (1), sinkPort));
socketWriter->Setup (n0, sinkAddress);
n0->AddApplication (socketWriter);
socketWriter->SetStartTime (Seconds (0.));
socketWriter->SetStopTime (writerStopTimeObj);
PacketSinkHelper sink ("ns3::TcpSocketFactory",
InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
ApplicationContainer apps = sink.Install (n1);
// Start the sink application at time zero, and stop it at sinkStopTime
apps.Start (Seconds (0.0));
apps.Stop (sinkStopTimeObj);
Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
MakeCallback (&Ns3TcpNoDelayTestCase::SinkRx, this));
// Enable or disable TCP no delay option
Config::SetDefault ("ns3::TcpSocket::TcpNoDelay", BooleanValue (m_noDelay));
// Connect the socket writer
Simulator::Schedule (Seconds (1), &SocketWriter::Connect, socketWriter);
// Write 5 packets to get some bytes in flight and some acks going
Simulator::Schedule (Seconds (2), &SocketWriter::Write, socketWriter, 2680);
m_inputs.Add (536);
m_inputs.Add (536);
m_inputs.Add (536);
m_inputs.Add (536);
m_inputs.Add (536);
// Write one byte after 10 ms to ensure that some data is outstanding
// and the window is big enough
Simulator::Schedule (Seconds (2.010), &SocketWriter::Write, socketWriter, 1);
// If Nagle is not enabled, i.e. no delay is on, add an input for a 1-byte
// packet to be received
if (m_noDelay)
{
m_inputs.Add (1);
}
// One ms later, write 535 bytes, i.e. one segment size - 1
Simulator::Schedule (Seconds (2.012), &SocketWriter::Write, socketWriter, 535);
// If Nagle is not enabled, add an input for a 535 byte packet,
// otherwise, we should get a single "full" packet of 536 bytes
if (m_noDelay)
{
m_inputs.Add (535);
}
else
{
m_inputs.Add (536);
}
// Close down the socket
Simulator::Schedule (writerStopTimeObj, &SocketWriter::Close, socketWriter);
if (m_writeResults)
{
std::ostringstream oss;
if (m_noDelay)
{
oss << "tcp-no-delay-on-test-case";
pointToPoint.EnablePcapAll (oss.str ());
}
else
{
oss << "tcp-no-delay-off-test-case";
pointToPoint.EnablePcapAll (oss.str ());
}
//.........这里部分代码省略.........
示例11: main
int
main (int argc, char *argv[])
{
std::string mode = "ConfigureLocal";
std::string tapName = "thetap";
CommandLine cmd;
cmd.AddValue ("mode", "Mode setting of TapBridge", mode);
cmd.AddValue ("tapName", "Name of the OS tap device", tapName);
cmd.Parse (argc, argv);
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
//
// The topology has a Wifi network of four nodes on the left side. We'll make
// node zero the AP and have the other three will be the STAs.
//
NodeContainer nodesLeft;
nodesLeft.Create (4);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
Ssid ssid = Ssid ("left");
WifiHelper wifi = WifiHelper::Default ();
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
wifiMac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer devicesLeft = wifi.Install (wifiPhy, wifiMac, nodesLeft.Get (0));
wifiMac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
devicesLeft.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodesLeft.Get (1), nodesLeft.Get (2), nodesLeft.Get (3))));
MobilityHelper mobility;
mobility.Install (nodesLeft);
InternetStackHelper internetLeft;
internetLeft.Install (nodesLeft);
Ipv4AddressHelper ipv4Left;
ipv4Left.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft);
TapBridgeHelper tapBridge (interfacesLeft.GetAddress (1));
tapBridge.SetAttribute ("Mode", StringValue (mode));
tapBridge.SetAttribute ("DeviceName", StringValue (tapName));
tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0));
//
// Now, create the right side.
//
NodeContainer nodesRight;
nodesRight.Create (4);
CsmaHelper csmaRight;
csmaRight.SetChannelAttribute ("DataRate", DataRateValue (5000000));
csmaRight.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
NetDeviceContainer devicesRight = csmaRight.Install (nodesRight);
InternetStackHelper internetRight;
internetRight.Install (nodesRight);
Ipv4AddressHelper ipv4Right;
ipv4Right.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesRight = ipv4Right.Assign (devicesRight);
//
// Stick in the point-to-point line between the sides.
//
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("512kbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
NodeContainer nodes = NodeContainer (nodesLeft.Get (3), nodesRight.Get (0));
NetDeviceContainer devices = p2p.Install (nodes);
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.2.0", "255.255.255.192");
Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
//
// Simulate some CBR traffic over the point-to-point link
//
uint16_t port = 9; // Discard port (RFC 863)
OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (interfaces.GetAddress (1), port));
onoff.SetConstantRate (DataRate ("500kb/s"));
ApplicationContainer apps = onoff.Install (nodesLeft.Get (3));
apps.Start (Seconds (1.0));
// Create a packet sink to receive these packets
PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
//.........这里部分代码省略.........
示例12: main
int
main (int argc, char *argv[])
{
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
#if 0
LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
#endif
// Set up some default values for the simulation. Use the
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
// Allow the user to override any of the defaults and the above
// DefaultValue::Bind ()s at run-time, via command-line arguments
CommandLine cmd;
cmd.Parse (argc, argv);
// Here, we will explicitly create four nodes. In more sophisticated
// topologies, we could configure a node factory.
NS_LOG_INFO ("Create nodes.");
NodeContainer c;
c.Create (5);
NodeContainer n02 = NodeContainer (c.Get (0), c.Get (2));
NodeContainer n12 = NodeContainer (c.Get (1), c.Get (2));
NodeContainer n32 = NodeContainer (c.Get (3), c.Get (2));
NodeContainer n34 = NodeContainer (c.Get (3), c.Get (4));
// Enable OLSR
NS_LOG_INFO ("Enabling OLSR Routing.");
OlsrHelper olsr;
Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
list.Add (staticRouting, 0);
list.Add (olsr, 10);
InternetStackHelper internet;
internet.SetRoutingHelper (list); // has effect on the next Install ()
internet.Install (c);
// We create the channels first without any IP addressing information
NS_LOG_INFO ("Create channels.");
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer nd02 = p2p.Install (n02);
NetDeviceContainer nd12 = p2p.Install (n12);
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
NetDeviceContainer nd32 = p2p.Install (n32);
NetDeviceContainer nd34 = p2p.Install (n34);
// Later, we add IP addresses.
NS_LOG_INFO ("Assign IP Addresses.");
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i02 = ipv4.Assign (nd02);
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer i12 = ipv4.Assign (nd12);
ipv4.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer i32 = ipv4.Assign (nd32);
ipv4.SetBase ("10.1.4.0", "255.255.255.0");
Ipv4InterfaceContainer i34 = ipv4.Assign (nd34);
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s from n0 to n4
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
OnOffHelper onoff ("ns3::UdpSocketFactory",
InetSocketAddress (i34.GetAddress (1), port));
onoff.SetConstantRate (DataRate ("448kb/s"));
ApplicationContainer apps = onoff.Install (c.Get (0));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
// Create a packet sink to receive these packets
PacketSinkHelper sink ("ns3::UdpSocketFactory",
InetSocketAddress (Ipv4Address::GetAny (), port));
apps = sink.Install (c.Get (3));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
onoff.SetAttribute ("Remote",
AddressValue (InetSocketAddress (i12.GetAddress (0), port)));
apps = onoff.Install (c.Get (3));
apps.Start (Seconds (1.1));
apps.Stop (Seconds (10.0));
//.........这里部分代码省略.........
示例13: StringValue
// 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)
//.........这里部分代码省略.........
示例14: main
int
main (int argc, char *argv[])
{
//
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
//
#if 0
LogComponentEnable ("UdpEchoExample", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_ALL);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_ALL);
#endif
//
// Allow the user to override any of the defaults and the above Bind() at
// run-time, via command-line arguments
//
bool useV6 = false;
Address serverAddress;
CommandLine cmd;
cmd.AddValue ("useIpv6", "Use Ipv6", useV6);
cmd.Parse (argc, argv);
//
// Explicitly create the nodes required by the topology (shown above).
//
NS_LOG_INFO ("Create nodes.");
NodeContainer n;
n.Create (4);
InternetStackHelper internet;
internet.Install (n);
NS_LOG_INFO ("Create channels.");
//
// Explicitly create the channels required by the topology (shown above).
//
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
NetDeviceContainer d = csma.Install (n);
//
// We've got the "hardware" in place. Now we need to add IP addresses.
//
NS_LOG_INFO ("Assign IP Addresses.");
if (useV6 == false)
{
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (d);
serverAddress = Address(i.GetAddress (1));
}
else
{
Ipv6AddressHelper ipv6;
ipv6.SetBase ("2001:0000:f00d:cafe::", Ipv6Prefix (64));
Ipv6InterfaceContainer i6 = ipv6.Assign (d);
serverAddress = Address(i6.GetAddress (1,1));
}
NS_LOG_INFO ("Create Applications.");
//
// Create a UdpEchoServer application on node one.
//
uint16_t port = 9; // well-known echo port number
UdpEchoServerHelper server (port);
ApplicationContainer apps = server.Install (n.Get (1));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
//
// Create a UdpEchoClient application to send UDP datagrams from node zero to
// node one.
//
uint32_t packetSize = 1024;
uint32_t maxPacketCount = 1;
Time interPacketInterval = Seconds (1.);
UdpEchoClientHelper client (serverAddress, port);
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
client.SetAttribute ("Interval", TimeValue (interPacketInterval));
client.SetAttribute ("PacketSize", UintegerValue (packetSize));
apps = client.Install (n.Get (0));
apps.Start (Seconds (2.0));
apps.Stop (Seconds (10.0));
#if 0
//
// Users may find it convenient to initialize echo packets with actual data;
// the below lines suggest how to do this
//
client.SetFill (apps.Get (0), "Hello World");
client.SetFill (apps.Get (0), 0xa5, 1024);
uint8_t fill[] = { 0, 1, 2, 3, 4, 5, 6};
client.SetFill (apps.Get (0), fill, sizeof(fill), 1024);
#endif
AsciiTraceHelper ascii;
//.........这里部分代码省略.........
示例15: main
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;
}