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");
}
void
PeerLinkFrameStart::Serialize (Buffer::Iterator start) const
{
  Buffer::Iterator i = start;
  NS_ASSERT (m_subtype < 3);
  i = m_protocol.Serialize (i);
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      i.WriteHtolsbU16 (m_capability);
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) == m_subtype)
    {
      i.WriteHtolsbU16 (m_aid);
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      i = m_rates.Serialize (i);
      i = m_rates.extended.Serialize (i);
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) != m_subtype)
    {
      i = m_meshId.Serialize (i);
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      i = m_config.Serialize (i);
    }
  else
    {
      i.WriteHtolsbU16 (m_reasonCode);
    }
}
void
EnergySource::SetNode (Ptr<Node> node)
{
  NS_LOG_FUNCTION (this);
  NS_ASSERT (node != NULL);
  m_node = node;
}
TagBuffer
ByteTagList::Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
{
  NS_LOG_FUNCTION (this << tid << bufferSize << start << end);
  uint32_t spaceNeeded = m_used + bufferSize + 4 + 4 + 4 + 4;
  NS_ASSERT (m_used <= spaceNeeded);
  if (m_data == 0)
    {
      m_data = Allocate (spaceNeeded);
      m_used = 0;
    } 
  else if (m_data->size < spaceNeeded ||
           (m_data->count != 1 && m_data->dirty != m_used))
    {
      struct ByteTagListData *newData = Allocate (spaceNeeded);
      std::memcpy (&newData->data, &m_data->data, m_used);
      Deallocate (m_data);
      m_data = newData;
    }
  TagBuffer tag = TagBuffer (&m_data->data[m_used], 
                             &m_data->data[spaceNeeded]);
  tag.WriteU32 (tid.GetUid ());
  tag.WriteU32 (bufferSize);
  tag.WriteU32 (start);
  tag.WriteU32 (end);
  m_used = spaceNeeded;
  m_data->dirty = m_used;
  return tag;
}
void
EnergySource::AppendDeviceEnergyModel (Ptr<DeviceEnergyModel> deviceEnergyModelPtr)
{
  NS_LOG_FUNCTION (this << deviceEnergyModelPtr);
  NS_ASSERT (deviceEnergyModelPtr != NULL); // model must exist
  m_models.Add (deviceEnergyModelPtr);
}
void
BlockAckManager::NotifyMpduTransmission (Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber)
{
  NS_LOG_FUNCTION (this << recipient << static_cast<uint32_t> (tid) << nextSeqNumber);
  Ptr<Packet> bar = 0;
  AgreementsI it = m_agreements.find (std::make_pair (recipient, tid));
  NS_ASSERT (it != m_agreements.end ());

  uint16_t nextSeq;
  if (GetNRetryNeededPackets (recipient, tid) > 0)
    {
      nextSeq = GetSeqNumOfNextRetryPacket (recipient, tid);
    }
  else
    {
      nextSeq = nextSeqNumber;
    }
  it->second.first.NotifyMpduTransmission (nextSeq);
  bar = ScheduleBlockAckReqIfNeeded (recipient, tid);
  if (bar != 0)
    {
      Bar request (bar, recipient, tid, it->second.first.IsImmediateBlockAck ());
      m_bars.push_back (request);
    }
}
/* cache_service_debug()
 * To force the creation of good debugging tools, all known caches must
 * have a debugging routine.  The cache_service_debug() routine is a common
 * routine that can be inserted via NSAPI to view the status of all
 * known caches.  This is a hidden entry point which can be enabled when
 * debugging is needed.
 *
 */
NSAPI_PUBLIC int 
cache_service_debug(pblock *pb, Session *sn, Request *rq)
{
	cache_t *ptr;
	char buf[MAX_DEBUG_LINE];
	int len;

	NS_ASSERT(cache_crit);

	param_free(pblock_removekey(pb_key_content_type, rq->srvhdrs));
	pblock_nvinsert("content-type", "text/html", rq->srvhdrs);

	len = util_sprintf(buf, XP_GetClientStr(DBT_http10200OkNcontentTypeTextHtmlN_));
	net_write(sn->csd, buf, len);

	len = util_sprintf(buf, XP_GetClientStr(DBT_H2NetscapeCacheStatusReportH2N_));
	net_write(sn->csd, buf, len);

	crit_enter(cache_crit);
	if (cache_list) {
		len = util_sprintf(buf, "<HR>");
		net_write(sn->csd, buf, len);
		for (ptr = cache_list; ptr; ptr = ptr->next) {
			if (ptr->virtual_fn->debug_fn)
				if ( ptr->virtual_fn->debug_fn(pb, sn, rq) == REQ_ABORTED ) 
					return REQ_ABORTED;
		}
	} else {
		len = util_sprintf(buf, XP_GetClientStr(DBT_noCachesOnSystemP_));
		net_write(sn->csd, buf, len);
	}
	crit_exit(cache_crit);

	return REQ_PROCEED;
}
//
// ACL_ListDecrement - decrement the ACLList's refcount safely
//
NSAPI_PUBLIC int
ACL_ListDecrement(NSErr_t *errp, ACLListHandle_t *acllist)
{
    if (!acllist  ||  acllist == ACL_LIST_NO_ACLS)
	return 0;

    NS_ASSERT(ACL_AssertAcllist(acllist));

    ACL_CritEnter();
    NS_ASSERT(ACL_CritHeld());
    if (--acllist->ref_count == 0)
        ACL_ListDestroy(errp, acllist);
    ACL_CritExit();

    return 0;
}
struct ByteTagListData *
ByteTagList::Allocate (uint32_t size)
{
  NS_LOG_FUNCTION (this << size);
  while (!g_freeList.empty ())
    {
      struct ByteTagListData *data = g_freeList.back ();
      g_freeList.pop_back ();
      NS_ASSERT (data != 0);
      if (data->size >= size)
        {
          data->count = 1;
          data->dirty = 0;
          return data;
        }
      uint8_t *buffer = (uint8_t *)data;
      delete [] buffer;
    }
  uint8_t *buffer = new uint8_t [std::max (size, g_maxSize) + sizeof (struct ByteTagListData) - 4];
  struct ByteTagListData *data = (struct ByteTagListData *)buffer;
  data->count = 1;
  data->size = size;
  data->dirty = 0;
  return data;
}
uint32_t
PeerLinkFrameStart::GetSerializedSize () const
{
  uint32_t size = 3; //Peering protocol
  NS_ASSERT (m_subtype < 3);
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      size += 2; //capability
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) == m_subtype)
    {
      size += 2; //AID of remote peer
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      size += m_rates.GetSerializedSize ();
      size += m_rates.extended.GetSerializedSize ();
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) != m_subtype)
    {
      size += m_meshId.GetInformationFieldSize () + 2;
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      size += m_config.GetInformationFieldSize () + 2;
    }
  else
    {
      size += 2; //reasonCode
    }
  return size;
}
Example #11
0
double
UanChannel::GetNoiseDbHz (double fKhz)
{
  NS_ASSERT (m_noise);
  double noise = m_noise->GetNoiseDbHz (fKhz);
  return noise;
}
Example #12
0
void
AsciiFile::Read (std::string& line)
{
  NS_ASSERT (m_file.good ());

  // Read the next line.
  getline (m_file, line);
}
Example #13
0
void
RedQueue::SetTh (double minTh, double maxTh)
{
  NS_LOG_FUNCTION (this << minTh << maxTh);
  NS_ASSERT (minTh <= maxTh);
  m_minTh = minTh;
  m_maxTh = maxTh;
}
NSAPI_PUBLIC void
cache_collect_garbage(cache_t *cache)
{
  unsigned int now;
  cache_entry_t	*ptr, *last;

  NS_ASSERT(cache_crit);
  NS_ASSERT(cache);
#ifdef CACHE_DEBUG
  NS_ASSERT(cache->magic == CACHE_MAGIC);
#endif

  if(!cache->fast_mode)
    return;

  now = ft_time();
  if(now - cache->gc_time < GC_INTERVAL)
    return;

  crit_enter(cache->lock);

  last = NULL;
  ptr = cache->garbage_list_head;
  while(ptr) {
    NS_ASSERT(ptr->delete_pending);
    if((ptr->delete_time + SAFE_INTERVAL < now) && (ptr->access_count == 0)) {
      if(last)
	last->next_deleted = ptr->next_deleted;
      else
	cache->garbage_list_head = ptr->next_deleted;

      ptr->fn_list->cleanup_fn(ptr->data);
      PERM_FREE(ptr);

      ptr = (last) ? (last->next_deleted) : (cache->garbage_list_head);

    } else {
      last = ptr;
      ptr = ptr->next_deleted;
    }
  }

  crit_exit(cache->lock);
  cache->gc_time = now;
}
Example #15
0
void
CsmaChannel::PropagationCompleteEvent ()
{
  NS_LOG_FUNCTION (this << m_currentPkt);
  NS_LOG_INFO ("UID is " << m_currentPkt->GetUid () << ")");

  NS_ASSERT (m_state == PROPAGATING);
  m_state = IDLE;
}
Example #16
0
AppFace::AppFace(Ptr<App> app)
  : LocalFace(FaceUri("appFace://"), FaceUri("appFace://"))
  , m_node(app->GetNode())
  , m_app(app)
{
  NS_LOG_FUNCTION(this << app);

  NS_ASSERT(m_app != 0);
}
Example #17
0
 uint32_t
 RrepAckHeader::Deserialize (Buffer::Iterator start )
 {
     Buffer::Iterator i = start;
     m_reserved = i.ReadU8 ();
     uint32_t dist = i.GetDistanceFrom (start);
     NS_ASSERT (dist == GetSerializedSize ());
     return dist;
 }
uint32_t
PeerLinkFrameStart::Deserialize (Buffer::Iterator start)
{
  Buffer::Iterator i = start;
  NS_ASSERT (m_subtype < 3);
  {
    uint8_t id = i.ReadU8 ();
    uint8_t length = i.ReadU8 ();
    m_protocol.DeserializeInformationField (i, length);
    if ((m_protocol.ElementId () != (WifiInformationElementId) id) || (m_protocol.GetInformationFieldSize () != length))
      {
        NS_FATAL_ERROR ("Broken frame: Element ID does not match IE itself!");
      }
    i.Next (m_protocol.GetInformationFieldSize ());
  }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      m_capability = i.ReadLsbtohU16 ();
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) == m_subtype)
    {
      m_aid = i.ReadLsbtohU16 ();
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      i = m_rates.Deserialize (i);
      i = m_rates.extended.DeserializeIfPresent (i);
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) != m_subtype)
    {
      uint8_t id = i.ReadU8 ();
      uint8_t length = i.ReadU8 ();
      m_meshId.DeserializeInformationField (i, length);
      if ((m_meshId.ElementId () != (WifiInformationElementId) id) || (m_meshId.GetInformationFieldSize () != length))
        {
          NS_FATAL_ERROR ("Broken frame: Element ID does not match IE itself!");
        }
      i.Next (m_meshId.GetInformationFieldSize ());
    }
  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
    {
      uint8_t id = i.ReadU8 ();
      uint8_t length = i.ReadU8 ();
      m_config.DeserializeInformationField (i, length);
      if ((m_config.ElementId () != (WifiInformationElementId) id) || (m_config.GetInformationFieldSize () != length))
        {
          NS_FATAL_ERROR ("Broken frame: Element ID does not match IE itself!");
        }
      i.Next (m_config.GetInformationFieldSize ());
    }
  else
    {
      m_reasonCode = i.ReadLsbtohU16 ();
    }
  return i.GetDistanceFrom (start);
}
void
DcfManagerTest::AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime,
                                                    uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from)
{
  NS_ASSERT (ackDelay < m_ackTimeoutValue);
  Simulator::Schedule (MicroSeconds (at) - Now (),
                       &DcfManagerTest::DoAccessRequest, this,
                       txTime, expectedGrantTime, m_dcfStates[from]);
  AddAckTimeoutReset (expectedGrantTime + txTime + ackDelay);
}
Example #20
0
NdiscCache::Entry* NdiscCache::Add (Ipv6Address to)
{
  NS_LOG_FUNCTION (this << to);
  NS_ASSERT (m_ndCache.find (to) == m_ndCache.end ());

  NdiscCache::Entry* entry = new NdiscCache::Entry (this);
  entry->SetIpv6Address (to);
  m_ndCache[to] = entry;
  return entry;
}
void
BlockAckManager::NotifyAgreementEstablished (Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
{
  NS_LOG_FUNCTION (this << recipient << static_cast<uint32_t> (tid) << startingSeq);
  AgreementsI it = m_agreements.find (std::make_pair (recipient, tid));
  NS_ASSERT (it != m_agreements.end ());

  it->second.first.SetState (OriginatorBlockAckAgreement::ESTABLISHED);
  it->second.first.SetStartingSequence (startingSeq);
}
DeviceEnergyModelContainer
DeviceEnergyModelHelper::Install (NetDeviceContainer deviceContainer,
                                  EnergySourceContainer sourceContainer) const
{
  NS_ASSERT (deviceContainer.GetN () <= sourceContainer.GetN ());
  DeviceEnergyModelContainer container;
  NetDeviceContainer::Iterator dev = deviceContainer.Begin ();
  EnergySourceContainer::Iterator src = sourceContainer.Begin ();
  while (dev != deviceContainer.End ())
    {
      // check to make sure source and net device are on the same node
      NS_ASSERT ((*dev)->GetNode () == (*src)->GetNode ());
      Ptr<DeviceEnergyModel> model = DoInstall (*dev, *src);
      container.Add (model);
      dev++;
      src++;
    }
  return container;
}
Example #23
0
        bool
        RerrHeader::AddUnDestination (Ipv4Address dst, uint32_t seqNo )
        {
            if (m_unreachableDstSeqNo.find (dst) != m_unreachableDstSeqNo.end ())
                return true;

            NS_ASSERT (GetDestCount () < 255); // can't support more than 255 destinations in single RERR
            m_unreachableDstSeqNo.insert (std::make_pair (dst, seqNo));
            return true;
        }
void
A2A4RsrqHandoverAlgorithm::UpdateNeighbourMeasurements (uint16_t rnti,
                                                        uint16_t cellId,
                                                        uint8_t rsrq)
{
  NS_LOG_FUNCTION (this << rnti << cellId << (uint16_t) rsrq);
  MeasurementTable_t::iterator it1;
  it1 = m_neighbourCellMeasures.find (rnti);

  if (it1 == m_neighbourCellMeasures.end ())
    {
      // insert a new UE entry
      MeasurementRow_t row;
      std::pair<MeasurementTable_t::iterator, bool> ret;
      ret = m_neighbourCellMeasures.insert (std::pair<uint16_t, MeasurementRow_t> (rnti, row));
      NS_ASSERT (ret.second);
      it1 = ret.first;
    }

  NS_ASSERT (it1 != m_neighbourCellMeasures.end ());
  Ptr<UeMeasure> neighbourCellMeasures;
  std::map<uint16_t, Ptr<UeMeasure> >::iterator it2;
  it2 = it1->second.find (cellId);

  if (it2 != it1->second.end ())
    {
      neighbourCellMeasures = it2->second;
      neighbourCellMeasures->m_cellId = cellId;
      neighbourCellMeasures->m_rsrp = 0;
      neighbourCellMeasures->m_rsrq = rsrq;
    }
  else
    {
      // insert a new cell entry
      neighbourCellMeasures = Create<UeMeasure> ();
      neighbourCellMeasures->m_cellId = cellId;
      neighbourCellMeasures->m_rsrp = 0;
      neighbourCellMeasures->m_rsrq = rsrq;
      it1->second[cellId] = neighbourCellMeasures;
    }

} // end of UpdateNeighbourMeasurements
NSAPI_PUBLIC void
ACL_AttrGetterRegisterInit()
{
    ACLAttrGetterHash = PR_NewHashTable(256,
				     ACLPR_HashCaseString,
				     ACLPR_CompareCaseStrings,
				     PR_CompareValues,
				     &ACLPermAllocOps,
				     NULL);
    NS_ASSERT(ACLAttrGetterHash);
}
double
FriisSpectrumPropagationLossModel::CalculateLoss (double f, double d) const
{
  NS_ASSERT (d >= 0);

  if (d == 0)
    {
      return 1;
    }

  NS_ASSERT (f > 0);
  double loss_sqrt = (4 * M_PI * f * d) / 3e8;
  double loss = loss_sqrt * loss_sqrt;

  if (loss < 1)
    {
      loss = 1;
    }
  return loss;
}
Example #27
0
int32_t
CsmaChannel::Attach (Ptr<CsmaNetDevice> device)
{
  NS_LOG_FUNCTION (this << device);
  NS_ASSERT (device != 0);

  CsmaDeviceRec rec (device);

  m_deviceList.push_back (rec);
  return (m_deviceList.size () - 1);
}
void
BlockAckManager::NotifyAgreementUnsuccessful (Mac48Address recipient, uint8_t tid)
{
  NS_LOG_FUNCTION (this << recipient << static_cast<uint32_t> (tid));
  AgreementsI it = m_agreements.find (std::make_pair (recipient, tid));
  NS_ASSERT (it != m_agreements.end ());
  if (it != m_agreements.end ())
    {
      it->second.first.SetState (OriginatorBlockAckAgreement::UNSUCCESSFUL);
    }
}
NSAPI_PUBLIC void *
cache_do_lookup(cache_t *cache, void *key)
{
	cache_entry_t *ptr;
        int rcs = NSCACHESTATUS_OK;

SOLARIS_PROBE(cache_do_lookup_start, "cache");
	NS_ASSERT(cache_crit);
	NS_ASSERT(cache);
#ifdef CACHE_DEBUG
	NS_ASSERT(cache->magic == CACHE_MAGIC);
#endif

	ptr = _cache_entry_lookup(cache, key, &rcs);

SOLARIS_PROBE(cache_do_lookup_end, "cache");
	if (ptr) 
		return ptr->data;
	else
		return NULL;
    
}
double
IdealWifiManager::GetSnrThreshold (WifiMode mode) const
{
  for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++)
    {
      if (mode == i->second)
        {
          return i->first;
        }
    }
  NS_ASSERT (false);
  return 0.0;
}