EnergySourceContainer EnergySourceHelper::Install (NodeContainer c) const { EnergySourceContainer container; for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { Ptr<EnergySource> src = DoInstall (*i); container.Add (src); /* * Check if EnergySourceContainer is already aggregated to target node. If * not, create a new EnergySourceContainer and aggregate it to node. */ Ptr<EnergySourceContainer> EnergySourceContrainerOnNode = (*i)->GetObject<EnergySourceContainer> (); if (EnergySourceContrainerOnNode == NULL) { ObjectFactory fac; fac.SetTypeId ("ns3::EnergySourceContainer"); EnergySourceContrainerOnNode = fac.Create<EnergySourceContainer> (); EnergySourceContrainerOnNode->Add (src); (*i)->AggregateObject (EnergySourceContrainerOnNode); } else { EnergySourceContrainerOnNode->Add (src); // append new EnergySource } } return container; }
bool Ns3WimaxSimpleOFDMTestCase::DoRunOnce (double FrameDuration) { WimaxHelper::SchedulerType scheduler = WimaxHelper::SCHED_TYPE_SIMPLE; NodeContainer ssNodes; NodeContainer bsNodes; ssNodes.Create (3); bsNodes.Create (1); WimaxHelper wimax; NetDeviceContainer ssDevs, bsDevs; ssDevs = wimax.Install (ssNodes, WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler, FrameDuration); bsDevs = wimax.Install (bsNodes, WimaxHelper::DEVICE_TYPE_BASE_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler, FrameDuration); Simulator::Stop (Seconds (1)); Simulator::Run (); for (int i = 0; i < 3; i++) { if (ssDevs.Get (i)->GetObject<SubscriberStationNetDevice> ()->IsRegistered () == false) { NS_LOG_DEBUG ("SS[" << i << "] not registered"); return true; // Test fail because SS[i] is not registered } } Simulator::Destroy (); return (false); // Test was ok, all the SSs are registered }
void Writer::writeContainer(const NodeContainer& container) { XML::NodeContainer::const_iterator it = container.beginChild(); XML::NodeContainer::const_iterator end = container.endChild(); for (; it != end; ++it) { if ((*it)->type() == ELEMENT_NODE) { XML::ElementNodePtr child = Core::dynamic_ptr_cast<XML::ElementNode>(*it); writeElement(child); } else if ((*it)->type() == TEXT_NODE) { XML::TextNodePtr child = Core::dynamic_ptr_cast<XML::TextNode>(*it); m_buffer += child->text(); } else { ASSERT_FALSE(); } } }
void StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy) { for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { Install(*i, namePrefix, strategy); } }
void StackHelper::Update(const NodeContainer& c) { for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { Update(*i); } }
int main (int argc, char *argv[]) { NodeContainer nodes; nodes.Create (2); PointToPointHelper pointToPoint; NetDeviceContainer devices; devices = pointToPoint.Install (nodes); InternetStackHelper stack; stack.Install (nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.252"); Ipv4InterfaceContainer interfaces = address.Assign (devices); uint16_t sinkPort = 8080; Address sinkAddress (InetSocketAddress (interfaces.GetAddress (1), sinkPort)); Ptr<PacketSink> receiverApplication = CreateObject<PacketSink> (); receiverApplication->SetAttribute ("Local", AddressValue (InetSocketAddress (Ipv4Address::GetAny(), 8080))); receiverApplication->SetAttribute ("Protocol", TypeIdValue(TcpSocketFactory::GetTypeId())); receiverApplication->TraceConnectWithoutContext ("Rx", MakeCallback (&CountRx)); nodes.Get(1)->AddApplication(receiverApplication); Ptr<MyApp> app = CreateObject<MyApp> (nodes.Get (0), sinkAddress); nodes.Get (0)->AddApplication (app); Simulator::Stop (); Simulator::Run (); Simulator::Destroy (); return 0; }
int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); NodeContainer c; c.Create (10000); MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", "X", StringValue ("100.0"), "Y", StringValue ("100.0"), "Rho", StringValue ("ns3::UniformRandomVariable[Min=0|Max=30]")); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (c); Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&CourseChange)); Simulator::Stop (Seconds (100.0)); Simulator::Run (); Simulator::Destroy (); return 0; }
int main(int argc, char* argv[]) { // Setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(10)); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating 3x3 topology PointToPointHelper p2p; PointToPointGridHelper grid(3, 3, p2p); grid.BoundingBox(100, 100, 200, 200); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.InstallAll(); // Set BestRoute strategy ndn::StrategyChoiceHelper::InstallAll("/", "/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> producer = grid.GetNode(2, 2); NodeContainer consumerNodes; consumerNodes.Add(grid.GetNode(0, 0)); // Install NDN applications std::string prefix = "/prefix"; ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); consumerHelper.SetPrefix(prefix); consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second consumerHelper.Install(consumerNodes); ndn::AppHelper producerHelper("ns3::ndn::Producer"); producerHelper.SetPrefix(prefix); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(producer); // Add /prefix origins to ndn::GlobalRouter ndnGlobalRoutingHelper.AddOrigins(prefix, producer); // Calculate and install FIBs ndn::GlobalRoutingHelper::CalculateRoutes(); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); // // We are interacting with the outside, real, world. This means we have to // interact in real-time and therefore means we have to use the real-time // simulator and take the time to calculate checksums. // GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl")); GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true)); // // Create two ghost nodes. The first will represent the virtual machine host // on the left side of the network; and the second will represent the VM on // the right side. // NodeContainer nodes; nodes.Create (2); // // Use a CsmaHelper to get a CSMA channel created, and the needed net // devices installed on both of the nodes. The data rate and delay for the // channel can be set through the command-line parser. For example, // // ./waf --run "tap=csma-virtual-machine --ns3::CsmaChannel::DataRate=10000000" // CsmaHelper csma; NetDeviceContainer devices = csma.Install (nodes); // // Use the TapBridgeHelper to connect to the pre-configured tap devices for // the left side. We go with "UseBridge" mode since the CSMA devices support // promiscuous mode and can therefore make it appear that the bridge is // extended into ns-3. The install method essentially bridges the specified // tap to the specified CSMA device. // TapBridgeHelper tapBridge; tapBridge.SetAttribute ("Mode", StringValue ("UseBridge")); tapBridge.SetAttribute ("DeviceName", StringValue ("tap-left")); tapBridge.Install (nodes.Get (0), devices.Get (0)); // // Connect the right side tap to the right side CSMA device on the right-side // ghost node. // tapBridge.SetAttribute ("DeviceName", StringValue ("tap-right")); tapBridge.Install (nodes.Get (1), devices.Get (1)); // // Run the simulation for ten minutes to give the user time to play around // Simulator::Stop (Seconds (600.)); Simulator::Run (); Simulator::Destroy (); }
// // Network topology // // n0 n1 n2 n3 // | | | | // ===================== // // - Packet socket flow from n0 to n1 and from node n3 to n0 // -- We will test reception at node n0 // - Default 512 byte packets generated by traffic generator // void CsmaPacketSocketTestCase::DoRun (void) { // Here, we will explicitly create four nodes. NodeContainer nodes; nodes.Create (4); PacketSocketHelper packetSocket; packetSocket.Install (nodes); // create the shared medium used by all csma devices. Ptr<CsmaChannel> channel = CreateObjectWithAttributes<CsmaChannel> ( "DataRate", DataRateValue (DataRate (5000000)), "Delay", TimeValue (MilliSeconds (2))); // use a helper function to connect our nodes to the shared channel. CsmaHelper csma; csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc")); NetDeviceContainer devs = csma.Install (nodes, channel); // Create the OnOff application to send raw datagrams // // Make packets be sent about every DefaultPacketSize / DataRate = // 4096 bits / (5000 bits/second) = 0.82 second. PacketSocketAddress socket; socket.SetSingleDevice (devs.Get (0)->GetIfIndex ()); socket.SetPhysicalAddress (devs.Get (1)->GetAddress ()); socket.SetProtocol (2); OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); onoff.SetConstantRate (DataRate (5000)); ApplicationContainer apps = onoff.Install (nodes.Get (0)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); socket.SetSingleDevice (devs.Get (3)->GetIfIndex ()); socket.SetPhysicalAddress (devs.Get (0)->GetAddress ()); socket.SetProtocol (3); onoff.SetAttribute ("Remote", AddressValue (socket)); apps = onoff.Install (nodes.Get (3)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); PacketSinkHelper sink = PacketSinkHelper ("ns3::PacketSocketFactory", socket); apps = sink.Install (nodes.Get (0)); apps.Start (Seconds (0.0)); apps.Stop (Seconds (20.0)); // Trace receptions Config::Connect ("/NodeList/0/ApplicationList/*/$ns3::PacketSink/Rx", MakeCallback (&CsmaPacketSocketTestCase::SinkRx, this)); Simulator::Run (); Simulator::Destroy (); // We should have received 10 packets on node 0 NS_TEST_ASSERT_MSG_EQ (m_count, 10, "Node 0 should have received 10 packets"); }
Ptr<FaceContainer> StackHelper::Install(const NodeContainer& c) const { Ptr<FaceContainer> faces = Create<FaceContainer>(); for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { faces->AddAll(Install(*i)); } return faces; }
void EdgeContainer::buildNonboundaryEdgeList() { NodeContainer pContainer = m_triangleContainer.getPointContainer(); m_edgeToTriangleIndecesMap.clear(); m_edgeList.clear(); // Loop over all triangles and build a unique list of non-boundary edges. for (unsigned indexOuter = 0; indexOuter < m_triangleContainer.size() ; ++ indexOuter) { const Triangle& tOuter = m_triangleContainer.at(indexOuter); for (unsigned indexInner = indexOuter + 1; indexInner < m_triangleContainer.size() ; ++ indexInner) { if ( m_triangleContainer.hasCommonNode(indexInner, indexOuter) ) { const Triangle& tInner = m_triangleContainer.at(indexInner); // Find common nodes std::vector<NodeContainer::SizeType> edgePointList; for (unsigned ii = 0; ii < 3; ++ii) { for (unsigned jj = 0; jj < 3; ++jj) { if (tOuter.at(ii) == tInner.at(jj)) { edgePointList.push_back(pContainer.find(tOuter.at(ii))); } } } assert(edgePointList.size() < 3); // Three matching nodes = coincident triangle if (edgePointList.size() == 2) { // Found a common edge Edge e; std::sort(edgePointList.begin(), edgePointList.end()); e.set(pContainer.at(edgePointList.at(0)), pContainer.at(edgePointList.at(1))); // Add items in sorted order (smallest to largest - basis function direction) if (indexOuter < indexInner) { e.setSortedAssociatedTriangles({indexOuter, indexInner}); m_edgeToTriangleIndecesMap.push_back({indexOuter, indexInner}); } else { e.setSortedAssociatedTriangles({indexInner, indexOuter}); m_edgeToTriangleIndecesMap.push_back({indexInner, indexOuter}); } m_edgeList.push_back(e); } } } } buildTriangleToEdgeMap(); }
ApplicationContainer BulkSendHelper::Install (NodeContainer c) const { ApplicationContainer apps; for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { apps.Add (InstallPriv (*i)); } return apps; }
void DsrMainHelper::Install (DsrHelper &dsrHelper, NodeContainer nodes) { NS_LOG_DEBUG ("Passed node container"); delete m_dsrHelper; m_dsrHelper = dsrHelper.Copy (); for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i) { Install (*i); } }
Ptr<FlowMonitor> FlowMonitorHelper::Install (NodeContainer nodes) { for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i) { Ptr<Node> node = *i; if (node->GetObject<Ipv4L3Protocol> ()) { Install (node); } } return m_flowMonitor; }
// // 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"); }
int main(int argc, char* argv[]) { CommandLine cmd; cmd.Parse(argc, argv); AnnotatedTopologyReader topologyReader("", 25); topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-grid-3x3-red-queues.txt"); topologyReader.Read(); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.InstallAll(); ndn::StrategyChoiceHelper::InstallAll("/", "ndn:/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> producer = Names::Find<Node>("Node8"); NodeContainer consumerNodes; consumerNodes.Add(Names::Find<Node>("Node0")); // Install NDN applications std::string prefix = "/prefix"; ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); consumerHelper.SetPrefix(prefix); consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second consumerHelper.Install(consumerNodes); ndn::AppHelper producerHelper("ns3::ndn::Producer"); producerHelper.SetPrefix(prefix); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(producer); // Add /prefix origins to ndn::GlobalRouter ndnGlobalRoutingHelper.AddOrigins(prefix, producer); // Calculate and install FIBs ndn::GlobalRoutingHelper::CalculateRoutes(); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
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 }
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)); }
void XPathIterator::parse(QueryIterator begin, QueryIterator end, const NodePtr& context) { // Finished parsing? if (begin == end) { // Add to results, if valid node. if (context.get() != nullptr) m_results.push_back(context); return; } // Skip path separator. tstring::const_iterator it = begin; if (*it == TXT('/')) ++it; // Extract the node name. tstring::const_iterator nameFirst = it; while ( (it != end) && (*it != TXT('/')) ) ++it; tstring name(nameFirst, it); NodeType type = context->type(); NodeContainer* nodes = nullptr; // Has children? if (type == DOCUMENT_NODE) nodes = Core::static_ptr_cast<Document>(context).get(); else if (type == ELEMENT_NODE) nodes = Core::static_ptr_cast<ElementNode>(context).get(); // Find all children that match the name. for (NodeContainer::const_iterator nodeIter = nodes->beginChild(); nodeIter != nodes->endChild(); ++nodeIter) { const NodePtr& node = *nodeIter; // If a match, recurse... if ( (node->type() == ELEMENT_NODE) && (Core::static_ptr_cast<ElementNode>(node)->name() == name) ) { parse(it, end, *nodeIter); } } }
int main(int argc, char* argv[]) { // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::CsmaChannel::DataRate", StringValue("1Mbps")); Config::SetDefault("ns3::CsmaChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(20)); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links CsmaHelper csma; csma.Install(nodes); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.InstallAll(); // Installing applications // Consumer ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); // Consumer will request /prefix/0, /prefix/1, ... consumerHelper.SetPrefix("/prefix"); consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second consumerHelper.Install(nodes.Get(0)); // first node // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/prefix"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(nodes.Get(2)); // last node Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
InternedString uniqueHandle( const InternedString &handle ) { if( m_nodes.find( handle ) == m_nodes.end() ) { return handle; } string result; for( int i = 1; true; ++i ) { result = handle.string() + std::to_string( i ); if( m_nodes.find( result ) == m_nodes.end() ) { return result; } } }
void World::enemyProjectileCollision() { NodeContainer mCollidableNodes; for (const auto& node1 : mEnemyBulletNodes) { if (node1->isDestroyed()) continue; mCollidableNodes.clear(); mQuadTreeSecondary.getCloseObjects(node1->getBoundingRect(), mCollidableNodes); for (const auto& node2 : mCollidableNodes) { if (node2->isDestroyed()) continue; if (node2->getCategory() & Category::Shield) { auto& shield(static_cast<Shield&>(*node2)); auto& projectile(static_cast<Projectile&>(*node1)); if (!collision(shield, projectile)) continue; shield.onHit(projectile.getBoundingRect(), projectile.getPosition(), projectile.getCategory()); projectile.destroy(); } else if (node2->getCategory() & Category::PlayerSpaceship) { if (!collision(*node1, *node2)) continue; auto& player(static_cast<Player&>(*node2)); auto& projectile(static_cast<Projectile&>(*node1)); player.destroy(); projectile.destroy(); mLife->decrement(); mLivesCount--; } } } }
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; }
int64_t OnOffHelper::AssignStreams (NodeContainer c, int64_t stream) { int64_t currentStream = stream; Ptr<Node> node; for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { node = (*i); for (uint32_t j = 0; j < node->GetNApplications (); j++) { Ptr<OnOffApplication> onoff = DynamicCast<OnOffApplication> (node->GetApplication (j)); if (onoff) { currentStream += onoff->AssignStreams (currentStream); } } } return (currentStream - stream); }
inline void RandomizeProducers (Ptr<UniformRandomVariable> uniVar, std::string serverDatasetsPath, NodeContainer& nodes, PointToPointHelper& p2p){ RouterEndPointMap pr; pr.clear(); size_t prodIndex = 0; while (prodIndex < ns3::N_PRODUCERS){ size_t rtrID = uniVar->GetInteger (0, ns3::N_GEANT_ROUTERS-1); if(prodIndex==0){ pr[prodIndex] = rtrID; ++prodIndex; } else{ size_t rtrID1=0; do{ rtrID1 = uniVar->GetInteger (0, ns3::N_GEANT_ROUTERS-1); }while(pr.find(rtrID1)!= pr.end()); pr[prodIndex] = rtrID1; ++prodIndex; } }//while //////////////////////////////////////////////////////////////// //****HERE I ATTACH PRODUCERS TO SOME OF ROUTERS RANDOMLY*****// /////////////////////////////////////////////////////////////// ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /videos/myvideos/video1 producerHelper.SetPrefix("/"); producerHelper.SetAttribute("PayloadSize", StringValue(PAYLOAD_SIZE)); std::string strID="id"; //choose randomly the producers NS_LOG_UNCOND("from among "<<ns3::N_PRODUCERS<<" producers:"); for (RouterEndPointMap::iterator it= pr.begin(); it!=pr.end(); it++) { p2p.SetDeviceAttribute ("DataRate", StringValue (ns3::PROD_LINK_DATA_RATE)); p2p.SetChannelAttribute ("Delay", StringValue (ns3::PROD_LINK_DELAY)); NS_LOG_UNCOND("PRODUCER "<<it->first<<" was attached to id"<<it->second<<" lINK DataRate= "<<ns3::PROD_LINK_DATA_RATE<<" and LINK Delay = "<<ns3::PROD_LINK_DELAY); p2p.Install(nodes.Get(it->first + ns3::N_TotalClients), Names::Find<Node>(strID + std::to_string(it->second))); producerHelper.Install(nodes.Get(it->first + ns3::N_TotalClients)).Start (Seconds(ns3::PROD_START)); }//for }//FUNCTION: RandomizeProducers
void MobilityTraceTestCase::DoRun (void) { //*************************************************************************** // Create the new mobility trace. //*************************************************************************** NodeContainer sta; sta.Create (4); MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (1.0), "MinY", DoubleValue (1.0), "DeltaX", DoubleValue (5.0), "DeltaY", DoubleValue (5.0), "GridWidth", UintegerValue (3), "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", "Mode", StringValue ("Time"), "Time", StringValue ("2s"), "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), "Bounds", RectangleValue (Rectangle (0.0, 20.0, 0.0, 20.0))); mobility.Install (sta); // Set mobility random number streams to fixed values mobility.AssignStreams (sta, 0); SetDataDir (NS_TEST_SOURCEDIR); std::string referenceMobilityFilePath = CreateDataDirFilename ("mobility-trace-example.mob"); std::string testMobilityFilePath = CreateTempDirFilename ("mobility-trace-test.mob"); AsciiTraceHelper ascii; MobilityHelper::EnableAsciiAll (ascii.CreateFileStream (testMobilityFilePath)); Simulator::Stop (Seconds (5.0)); Simulator::Run (); Simulator::Destroy (); //*************************************************************************** // Test the new mobility trace against the reference mobility trace. //*************************************************************************** NS_ASCII_TEST_EXPECT_EQ (testMobilityFilePath, referenceMobilityFilePath); }
int main(int argc, char *argv[]) { // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes StackHelper ndnHelper; ndnHelper.InstallAll(); // Installing global routing interface on all nodes ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; ndnGlobalRoutingHelper.InstallAll(); // Installing applications // Consumer ndn::AppHelper consumerHelper("PingClientApp"); consumerHelper.SetAttribute("Prefix", StringValue("/ping")); consumerHelper.SetAttribute("nPings", StringValue("3")); consumerHelper.Install(nodes.Get(0)).Start(Seconds(2)); // Producer ndn::AppHelper producerHelper("PingServerApp"); producerHelper.SetAttribute("Prefix", StringValue("/ping")); producerHelper.SetAttribute("nMaxPings", StringValue("3")); producerHelper.Install(nodes.Get(2)).Start(Seconds(0.1)); ndnGlobalRoutingHelper.AddOrigins("/ping", nodes.Get(2)); // Calculate and install FIBs ndn::GlobalRoutingHelper::CalculateRoutes(); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
int64_t AodvHelper::AssignStreams (NodeContainer c, int64_t stream) { int64_t currentStream = stream; Ptr<Node> node; for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { node = (*i); Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); NS_ASSERT_MSG (ipv4, "Ipv4 not installed on node"); Ptr<Ipv4RoutingProtocol> proto = ipv4->GetRoutingProtocol (); NS_ASSERT_MSG (proto, "Ipv4 routing not installed on node"); Ptr<aodv::RoutingProtocol> aodv = DynamicCast<aodv::RoutingProtocol> (proto); if (aodv) { currentStream += aodv->AssignStreams (currentStream); continue; } // Aodv may also be in a list Ptr<Ipv4ListRouting> list = DynamicCast<Ipv4ListRouting> (proto); if (list) { int16_t priority; Ptr<Ipv4RoutingProtocol> listProto; Ptr<aodv::RoutingProtocol> listAodv; for (uint32_t i = 0; i < list->GetNRoutingProtocols (); i++) { listProto = list->GetRoutingProtocol (i, priority); listAodv = DynamicCast<aodv::RoutingProtocol> (listProto); if (listAodv) { currentStream += listAodv->AssignStreams (currentStream); break; } } } } return (currentStream - stream); }
int main(int argc, char* argv[]) { // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.SetOldContentStore( "ns3::ndn::cs::Freshness::Lru"); // don't set up max size here, will use default value = 100 ndnHelper.InstallAll(); // set up max sizes, after NDN stack is installed Config::Set("/NodeList/0/$ns3::ndn::ContentStore/MaxSize", UintegerValue( 1)); // number after nodeList is global ID of the node (= node->GetId ()) Config::Set("/NodeList/1/$ns3::ndn::ContentStore/MaxSize", UintegerValue(2)); Config::Set("/NodeList/2/$ns3::ndn::ContentStore/MaxSize", UintegerValue(200)); // Installing applications // Consumer ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); // Consumer will request /prefix/0, /prefix/1, ... consumerHelper.SetPrefix("/prefix"); consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second consumerHelper.Install(nodes.Get(0)); // first node // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/prefix"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(nodes.Get(2)); // last node Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }