void LinkControlHelper::setErrorRate(Ptr<Node> node1, Ptr<Node> node2, double errorRate) { NS_LOG_FUNCTION(node1 << node2 << errorRate); NS_ASSERT(node1 != nullptr && node2 != nullptr); NS_ASSERT(errorRate <= 1.0); Ptr<ndn::L3Protocol> ndn1 = node1->GetObject<ndn::L3Protocol>(); Ptr<ndn::L3Protocol> ndn2 = node2->GetObject<ndn::L3Protocol>(); NS_ASSERT(ndn1 != nullptr && ndn2 != nullptr); // iterate over all faces to find the right one for (const auto& face : ndn1->getForwarder()->getFaceTable()) { auto transport = dynamic_cast<NetDeviceTransport*>(face.getTransport()); if (transport == nullptr) continue; Ptr<PointToPointNetDevice> nd1 = transport->GetNetDevice()->GetObject<PointToPointNetDevice>(); if (nd1 == nullptr) continue; Ptr<Channel> channel = nd1->GetChannel(); if (channel == nullptr) continue; Ptr<PointToPointChannel> ppChannel = DynamicCast<PointToPointChannel>(channel); Ptr<NetDevice> nd2 = ppChannel->GetDevice(0); if (nd2->GetNode() == node1) nd2 = ppChannel->GetDevice(1); if (nd2->GetNode() == node2) { ObjectFactory errorFactory("ns3::RateErrorModel"); errorFactory.Set("ErrorUnit", StringValue("ERROR_UNIT_PACKET")); errorFactory.Set("ErrorRate", DoubleValue(errorRate)); if (errorRate <= 0) { errorFactory.Set("IsEnabled", BooleanValue(false)); } nd1->SetAttribute("ReceiveErrorModel", PointerValue(errorFactory.Create<ErrorModel>())); nd2->SetAttribute("ReceiveErrorModel", PointerValue(errorFactory.Create<ErrorModel>())); return; } } NS_FATAL_ERROR("There is no link to fail between the requested nodes"); }
TypeId WimaxPhy::GetTypeId (void) { static TypeId tid = TypeId ("ns3::WimaxPhy").SetParent<Object> () .AddAttribute ("Channel", "Wimax channel", PointerValue (), MakePointerAccessor (&WimaxPhy::GetChannel, &WimaxPhy::Attach), MakePointerChecker<WimaxChannel> ()) .AddAttribute ("FrameDuration", "The frame duration in seconds.", TimeValue (Seconds (0.01)), MakeTimeAccessor (&WimaxPhy::SetFrameDuration, &WimaxPhy::GetFrameDurationSec), MakeTimeChecker ()) .AddAttribute ("Frequency", "The central frequency in KHz.", UintegerValue (5000000), MakeUintegerAccessor (&WimaxPhy::SetFrequency, &WimaxPhy::GetFrequency), MakeUintegerChecker<uint32_t> (1000000, 11000000)) .AddAttribute ("Bandwidth", "The channel bandwidth in Hz.", UintegerValue (10000000), MakeUintegerAccessor (&WimaxPhy::SetChannelBandwidth, &WimaxPhy::GetChannelBandwidth), MakeUintegerChecker<uint32_t> (5000000, 30000000)) ; return tid; }
DynamicType * DynamicObjectPropertyEnumerator::GetTypeToEnumerate() const { return GetSnapShotSemantics() && initialType->GetIsLocked() && CONFIG_FLAG(TypeSnapshotEnumeration) ? PointerValue(initialType) : object->GetDynamicType(); }
TypeId UanChannel::GetTypeId () { static TypeId tid = TypeId ("ns3::UanChannel") .SetParent<Channel> () .AddConstructor<UanChannel> () .AddAttribute ("PropagationModel", "A pointer to the propagation model.", PointerValue (CreateObject<UanPropModelIdeal> ()), MakePointerAccessor (&UanChannel::m_prop), MakePointerChecker<UanPropModel> ()) .AddAttribute ("NoiseModel", "A pointer to the model of the channel ambient noise.", PointerValue (CreateObject<UanNoiseModelDefault> ()), MakePointerAccessor (&UanChannel::m_noise), MakePointerChecker<UanNoiseModel> ()) ; return tid; }
void TextbookBoyerMoore<C>::FreeBody(ArenaAllocator* allocator, CharCount patLen) { if(goodSuffix) { AdeleteArray(allocator, patLen + 1, PointerValue(goodSuffix)); #if DBG goodSuffix = nullptr; #endif } lastOccurrence.FreeBody(allocator); }
TypeId NonCommunicatingNetDevice::GetTypeId (void) { static TypeId tid = TypeId ("ns3::NonCommunicatingNetDevice") .SetParent<NetDevice> () .AddConstructor<NonCommunicatingNetDevice> () .AddAttribute ("Phy", "The PHY layer attached to this device.", PointerValue (), MakePointerAccessor (&NonCommunicatingNetDevice::GetPhy, &NonCommunicatingNetDevice::SetPhy), MakePointerChecker<Object> ()) ; return tid; }
Clip * TypedValue::ClipValue(QuasiStack *stack) { return (type == S_CLIP)? (Clip *)PointerValue(stack):nullptr; }
int main(int argc, char* argv[]) { // setting default parameters for Wifi // enable rts cts all the time. Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0")); // disable fragmentation Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue("OfdmRate24Mbps")); // 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")); std::uint32_t max_routers = 1; std::string cSize = "100"; std::string cSplit = "75"; // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.AddValue("cSize", "Cache Size", cSize); cmd.AddValue("cSplit", "Cache Split", cSplit); cmd.AddValue("routers", "number of routers", max_routers); cmd.Parse(argc, argv); Packet::EnablePrinting (); // Wifi config WifiHelper wifi = WifiHelper::Default (); // Nodes NodeContainer sta_consumers; NodeContainer sta_mobile_consumers; NodeContainer ap; NodeContainer routers; NodeContainer producers; // ?? NetDeviceContainer staDevs; PacketSocketHelper packetSocket; // 5 stationary consumers, 5 mobile, 4 APs and 1 router sta_consumers.Create(3*max_routers); sta_mobile_consumers.Create(7*max_routers); ap.Create (5*max_routers); routers.Create(max_routers); producers.Create(1); // give packet socket powers to nodes. packetSocket.Install(sta_mobile_consumers); packetSocket.Install(sta_consumers); packetSocket.Install (ap); // Wifi Config NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ()); wifiPhy.Set("TxPowerStart", DoubleValue(5)); wifiPhy.Set("TxPowerEnd", DoubleValue(5)); Ssid ssid = Ssid ("wifi-default"); wifi.SetRemoteStationManager ("ns3::ArfWifiManager"); // setup stas. wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false)); // install wifi wifi.Install(wifiPhy, wifiMac, sta_mobile_consumers); wifi.Install(wifiPhy, wifiMac, sta_consumers); // setup ap. wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid)); wifi.Install (wifiPhy, wifiMac, ap); // Mobility config -- Change max_routers value to change size of sim int number_rows = sqrt(max_routers); int x = 0; int y = 0; int pos_counter = 0; Ptr<UniformRandomVariable> randomizerX = CreateObject<UniformRandomVariable>(); Ptr<UniformRandomVariable> randomizerY = CreateObject<UniformRandomVariable>(); MobilityHelper stationary_mobility; stationary_mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); MobilityHelper mobility; mobility.SetMobilityModel("ns3::GaussMarkovMobilityModel", "Bounds", BoxValue(Box (0, number_rows*10, 0, number_rows*10, 0, 0)), "TimeStep", TimeValue(Seconds(1))); // Place router in center of box randomizerX->SetAttribute("Min", DoubleValue(5)); randomizerX->SetAttribute("Max", DoubleValue(5)); randomizerY->SetAttribute("Min", DoubleValue(5)); randomizerY->SetAttribute("Max", DoubleValue(5)); stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); // Install on routers stationary_mobility.Install(producers.Get(0)); // p2p helper PointToPointHelper p2p; // for each row for (int i=0; i < number_rows; i++) { x = i * 10 + 5; // for each column for (int j=0; j < number_rows; j++) { y = j * 10 + 5; // Place router in center of box randomizerX->SetAttribute("Min", DoubleValue(x)); randomizerX->SetAttribute("Max", DoubleValue(x)); randomizerY->SetAttribute("Min", DoubleValue(y)); randomizerY->SetAttribute("Max", DoubleValue(y)); stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); // Install on routers stationary_mobility.Install(routers.Get(pos_counter)); // Set box (center +/-5) randomizerX->SetAttribute("Min", DoubleValue(x-5)); randomizerX->SetAttribute("Max", DoubleValue(x+5)); randomizerY->SetAttribute("Min", DoubleValue(y-5)); randomizerY->SetAttribute("Max", DoubleValue(y+5)); // Connect router to previous if not 1 if (pos_counter == 0) { p2p.Install(routers.Get(0), producers.Get(0)); } else // Otherwise connect to router behind you { p2p.Install(routers.Get(pos_counter), routers.Get(pos_counter-1)); } // APs for (int k=0; k < 5; k++) { stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); stationary_mobility.Install(ap.Get(pos_counter * 5 + k)); p2p.Install(routers.Get(pos_counter), ap.Get(pos_counter * 5 + k)); } // Consumers (stationary) for (int l=0; l < 3; l++) { stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); stationary_mobility.Install(sta_consumers.Get(pos_counter * 3 + l)); } // Consumers (Mobile) for (int m=0; m < 7; m++) { mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); mobility.Install(sta_mobile_consumers.Get(pos_counter * 7 + m)); } // Keep track of overall position pos_counter++; } } // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.SetOldContentStore("ns3::ndn::cs::Splitcache", "NormalPolicy", "ns3::ndn::cs::Lru", "SpecialPolicy", "ns3::ndn::cs::Lfu", "TotalCacheSize", cSize, "Configure", cSplit); // Percentage Special^ //ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru"); ndnHelper.Install(ap); ndnHelper.Install(routers); ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache"); ndnHelper.Install(sta_consumers); ndnHelper.Install(sta_mobile_consumers); ndnHelper.Install(producers); // Choosing forwarding strategy ndn::StrategyChoiceHelper::Install(sta_consumers, "/", "/localhost/nfd/strategy/best-route"); ndn::StrategyChoiceHelper::Install(sta_mobile_consumers, "/", "/localhost/nfd/strategy/best-route"); ndn::StrategyChoiceHelper::Install(ap, "/", "/localhost/nfd/strategy/best-route"); ndn::StrategyChoiceHelper::Install(routers, "/", "/localhost/nfd/strategy/best-route"); ndn::StrategyChoiceHelper::Install(producers, "/", "/localhost/nfd/strategy/best-route"); // Installing applications // Consumer (basic and special data) ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot"); consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents // Consumer will request /prefix/0, /prefix/1, ... // Basic consumers request basic data (and pumpkin spice coffee) consumerHelper.SetPrefix("data/basic"); consumerHelper.SetAttribute("Frequency", StringValue("10")); // 1 interests a second consumerHelper.Install(sta_consumers); // Mobile consumers request special data only consumerHelper.SetPrefix("data/special"); consumerHelper.SetAttribute("Frequency", StringValue("10")); // 2 interests a second consumerHelper.Install(sta_mobile_consumers); // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/data"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.SetAttribute("Freshness", TimeValue(Seconds(-1.0))); // unlimited freshness producerHelper.Install(producers); // Tracers 'n stuff //AthstatsHelper athstats; //athstats.EnableAthstats("athstats-sta", sta_mobile_consumers); //athstats.EnableAthstats("athstats-sta", sta_consumers); //athstats.EnableAthstats ("athstats-ap", ap); ndn::AppDelayTracer::Install(sta_consumers, "app-delays-trace-stationary-03.txt"); ndn::AppDelayTracer::Install(sta_mobile_consumers, "app-delays-trace-mobile-03.txt"); ndn::CsTracer::Install(ap, "cs-trace-ap-03.txt", Seconds(1)); ndn::CsTracer::Install(routers, "cs-trace-routers-03.txt", Seconds(1)); // 10 min Simulator::Stop(Seconds(600.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
TypePath * TypePath::Branch(Recycler * recycler, int pathLength, bool couldSeeProto) { AssertMsg(pathLength < this->GetPathLength(), "Why are we branching at the tip of the type path?"); // Ensure there is at least one free entry in the new path, so we can extend it. // TypePath::New will take care of aligning this appropriately. TypePath * branchedPath = TypePath::New(recycler, pathLength + 1); for (PropertyIndex i = 0; i < pathLength; i++) { branchedPath->AddInternal(assignments[i]); #ifdef SUPPORT_FIXED_FIELDS_ON_PATH_TYPES if (couldSeeProto) { if (this->GetData()->usedFixedFields.Test(i)) { // We must conservatively copy all used as fixed bits if some prototype instance could also take // this transition. See comment in PathTypeHandlerBase::ConvertToSimpleDictionaryType. // Yes, we could devise a more efficient way of copying bits 1 through pathLength, if performance of this // code path proves important enough. branchedPath->GetData()->usedFixedFields.Set(i); } else if (this->GetData()->fixedFields.Test(i)) { // We must clear any fixed fields that are not also used as fixed if some prototype instance could also take // this transition. See comment in PathTypeHandlerBase::ConvertToSimpleDictionaryType. this->GetData()->fixedFields.Clear(i); } } #endif } #ifdef SUPPORT_FIXED_FIELDS_ON_PATH_TYPES // When branching, we must ensure that fixed field values on the prefix shared by the two branches are always // consistent. Hence, we can't leave any of them uninitialized, because they could later get initialized to // different values, by two different instances (one on the old branch and one on the new branch). If that happened // and the instance from the old branch later switched to the new branch, it would magically gain a different set // of fixed properties! if (this->GetMaxInitializedLength() < pathLength) { this->SetMaxInitializedLength(pathLength); } branchedPath->SetMaxInitializedLength(pathLength); #endif #ifdef SUPPORT_FIXED_FIELDS_ON_PATH_TYPES if (PHASE_VERBOSE_TRACE1(FixMethodPropsPhase)) { Output::Print(_u("FixedFields: TypePath::Branch: singleton: 0x%p(0x%p)\n"), PointerValue(this->singletonInstance), this->singletonInstance->Get()); Output::Print(_u(" fixed fields:")); for (PropertyIndex i = 0; i < GetPathLength(); i++) { Output::Print(_u(" %s %d%d%d,"), GetPropertyId(i)->GetBuffer(), i < GetMaxInitializedLength() ? 1 : 0, GetIsFixedFieldAt(i, GetPathLength()) ? 1 : 0, GetIsUsedFixedFieldAt(i, GetPathLength()) ? 1 : 0); } Output::Print(_u("\n")); } #endif return branchedPath; }