Beispiel #1
0
void
FibHelper::RemoveRoute(Ptr<Node> node, const Name& prefix, Ptr<Node> otherNode)
{
  for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
    Ptr<PointToPointNetDevice> netDevice =
      DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
    if (netDevice == 0)
      continue;

    Ptr<Channel> channel = netDevice->GetChannel();
    if (channel == 0)
      continue;

    if (channel->GetDevice(0)->GetNode() == otherNode
        || channel->GetDevice(1)->GetNode() == otherNode) {
      Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>();
      NS_ASSERT_MSG(ndn != 0, "Ndn stack should be installed on the node");

      shared_ptr<Face> face = ndn->getFaceByNetDevice(netDevice);
      NS_ASSERT_MSG(face != 0, "There is no face associated with the p2p link");

      RemoveRoute(node, prefix, face);

      return;
    }
  }

  NS_FATAL_ERROR("Cannot remove route: Node# " << node->GetId() << " and Node# " << otherNode->GetId()
                                            << " are not connected");
}
Ipv4InterfaceContainer
Ipv4AddressHelper::Assign (const NetDeviceContainer &c)
{
  NS_LOG_FUNCTION_NOARGS ();
  Ipv4InterfaceContainer retval;
  for (uint32_t i = 0; i < c.GetN (); ++i) {
      Ptr<NetDevice> device = c.Get (i);

      Ptr<Node> node = device->GetNode ();
      NS_ASSERT_MSG (node, "Ipv4AddressHelper::Assign(): NetDevice is not not associated "
                     "with any node -> fail");

      Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
      NS_ASSERT_MSG (ipv4, "Ipv4AddressHelper::Assign(): NetDevice is associated"
                     " with a node without IPv4 stack installed -> fail "
                     "(maybe need to use InternetStackHelper?)");

      int32_t interface = ipv4->GetInterfaceForDevice (device);
      if (interface == -1)
        {
          interface = ipv4->AddInterface (device);
        }
      NS_ASSERT_MSG (interface >= 0, "Ipv4AddressHelper::Assign(): "
                     "Interface index not found");

      Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (NewAddress (), m_mask);
      ipv4->AddAddress (interface, ipv4Addr);
      ipv4->SetMetric (interface, 1);
      ipv4->SetUp (interface);
      retval.Add (ipv4, interface);
    }
  return retval;
}
void
SSLinkManager::SendRangingRequest (uint8_t uiuc, uint16_t allocationSize)
{
  NS_ASSERT_MSG (
    m_ss->GetState ()
    == SubscriberStationNetDevice::SS_STATE_WAITING_REG_RANG_INTRVL
    || m_ss->GetState ()
    == SubscriberStationNetDevice::SS_STATE_WAITING_INV_RANG_INTRVL,
    "SS: Error while sending a ranging request: the ss state should be SS_STATE_WAITING_REG_RANG_INTRVL or SS_STATE_WAITING_INV_RANG_INTRVL");

  if (m_nrRngReqsSent == 0) // sending the first time
    {
      m_pTxIrMax = CalculateMaxIRSignalStrength ();
      m_rngreq.SetReqDlBurstProfile (
        m_ss->GetBurstProfileManager ()->GetBurstProfileToRequest ());
      m_rngreq.SetMacAddress (m_ss->GetMacAddress ());
    }
  else
    {
      m_pTxIrMax++;
      if (m_nrRngRspsRecvd > 0)
        {
          m_rngreq.SetRangingAnomalies (m_rangingAnomalies);
        }
    }

  Ptr<Packet> packet = Create<Packet> ();
  Ptr<PacketBurst> burst = Create<PacketBurst> ();

  packet->AddHeader (m_rngreq);
  packet->AddHeader (ManagementMessageType (
                       ManagementMessageType::MESSAGE_TYPE_RNG_REQ));

  Ptr<WimaxConnection> connection;

  if (m_rangingStatus == WimaxNetDevice::RANGING_STATUS_CONTINUE)
    {
      connection = m_ss->GetBasicConnection ();
    }
  else     // have been assigned BCID, means currently adjusting parameters
    {
      connection = m_ss->GetInitialRangingConnection ();
    }

  m_ss->Enqueue (packet, MacHeaderType (), connection);

  m_ss->SetState (SubscriberStationNetDevice::SS_STATE_WAITING_RNG_RSP);
  m_ss->SetTimer (Simulator::Schedule (m_ss->GetIntervalT3 (),
                                       &SSLinkManager::StartContentionResolution, this), m_waitForRngRspEvent);
  m_nrRngReqsSent++;

  NS_ASSERT_MSG (allocationSize
                 == m_ss->GetCurrentUcd ().GetChannelEncodings ().GetRangReqOppSize ()
                 / m_ss->GetPhy ()->GetPsPerSymbol (),
                 "SS: Error while sending a ranging request: the allocation size is not correct");

  // will work even if connection is not passed (i.e. null is passed) as scheduler will automatically select the same connection
  m_ss->SendBurst (uiuc, allocationSize, connection);
}
Beispiel #4
0
void
FibHelper::AddRoute(const std::string& nodeName, const Name& prefix,
                    const std::string& otherNodeName, int32_t metric)
{
  Ptr<Node> node = Names::Find<Node>(nodeName);
  NS_ASSERT_MSG(node != 0, "Node [" << nodeName << "] does not exist");

  Ptr<Node> otherNode = Names::Find<Node>(otherNodeName);
  NS_ASSERT_MSG(otherNode != 0, "Node [" << otherNodeName << "] does not exist");

  AddRoute(node, prefix, otherNode, metric);
}
Beispiel #5
0
void
FibHelper::AddRoute(Ptr<Node> node, const Name& prefix, uint32_t faceId, int32_t metric)
{
  Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>();
  NS_ASSERT_MSG(ndn != 0, "Ndn stack should be installed on the node");

  shared_ptr<Face> face = ndn->getFaceById(faceId);
  NS_ASSERT_MSG(face != 0, "Face with ID [" << faceId << "] does not exist on node ["
                                            << node->GetId() << "]");

  AddRoute(node, prefix, face, metric);
}
Beispiel #6
0
void
FibHelper::RemoveRoute(const std::string& nodeName, const Name& prefix, uint32_t faceId)
{
  Ptr<Node> node = Names::Find<Node>(nodeName);
  Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>();
  NS_ASSERT_MSG(ndn != 0, "Ndn stack should be installed on the node");

  shared_ptr<Face> face = ndn->getFaceById(faceId);
  NS_ASSERT_MSG(face != 0, "Face with ID [" << faceId << "] does not exist on node ["
                                            << node->GetId() << "]");

  RemoveRoute(node, prefix, face);
}
Ptr<Building>
BuildingListPriv::GetBuilding (uint32_t n)
{
  NS_ASSERT_MSG (n < m_buildings.size (), "Building index " << n <<
                 " is out of range (only have " << m_buildings.size () << " buildings).");
  return m_buildings.at (n);
}
void
SSLinkManager::StartScanning (
  SubscriberStationNetDevice::EventType type, bool deleteParameters)
{
  // temp parameter "type" just to check on expiry of which event the function was called

  if (deleteParameters)
    {
      DeleteUplinkParameters ();
    }

  NS_ASSERT_MSG (!m_ss->IsRegistered (),
                 "Subscriber Station: Error while scanning: Already registered with a BS");

  if (m_ss->GetState () != SubscriberStationNetDevice::SS_STATE_IDLE)
    {
      m_dlChnlNr++;
    }

  // using max number of channel according to according to Section 8.5.1 of IEEE 802.16-2004 standard.
  if (m_dlChnlNr >= 200)
    {
      m_dlChnlNr = 0;
    }

  uint64_t dlChannel = m_ss->GetChannel (m_dlChnlNr);

  m_ss->SetState (SubscriberStationNetDevice::SS_STATE_SCANNING);
  m_ss->GetPhy ()->StartScanning (dlChannel, m_ss->GetIntervalT20 (),
                                  MakeCallback (&SSLinkManager::EndScanning, this));
}
uint32_t
PendingData::RemoveToSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset)
{
  NS_LOG_FUNCTION (this << seqFront << seqOffset);
  uint32_t count = OffsetFromSeq (seqFront, seqOffset);
  NS_ASSERT_MSG (count <= size, "Trying to remove more data than in the buffer"); 
  if (count == size)
    {
      Clear ();
      return size;
    }
  // Remove whole packets, if possible, from the front of the data
  // Do not perform buffer manipulations within packet; if a whole packet
  // cannot be removed, leave it alone
  std::vector<Ptr<Packet> >::iterator endI = data.begin ();
  uint32_t current = 0;
  // Any packet whose data has been completely acked can be removed
  for (std::vector<Ptr<Packet> >::iterator dataI = data.begin (); dataI < data.end (); dataI++)
    {
      if (current + (*dataI)->GetSize () > count)
        {
          break;
        }
      current += (*dataI)->GetSize ();
      ++endI;
    }
  data.erase (data.begin (), endI);
  size -= current;
  return current;
}
void
PacketProbe::SetValueByPath (std::string path, Ptr<const Packet> packet)
{
  NS_LOG_FUNCTION (path << packet);
  Ptr<PacketProbe> probe = Names::Find<PacketProbe> (path);
  NS_ASSERT_MSG (probe, "Error:  Can't find probe for path " << path);
  probe->SetValue (packet);
}
void
SSLinkManager::SelectRandomBackoff (void)
{
  NS_ASSERT_MSG (m_rangingCW != 0 && m_rangingBO == 0,
                 "be sure that CW has been set and BO is not already set"); // ensuring CW has been set and BO is not already set

  m_rangingBO = (rand () % m_rangingCW);
  m_isBackoffSet = true;
}
Beispiel #12
0
void
WimaxPhy::StartScanning (uint64_t frequency, Time timeout, Callback<void, bool, uint64_t> callback)
{
  NS_ASSERT_MSG (m_state == PHY_STATE_IDLE || m_state == PHY_STATE_SCANNING,
                 "Error while scanning: The PHY state should be PHY_STATE_SCANNING or PHY_STATE_IDLE");

  m_state = PHY_STATE_SCANNING;
  m_scanningFrequency = frequency;
  m_dlChnlSrchTimeoutEvent = Simulator::Schedule (timeout, &WimaxPhy::EndScanning, this);
  m_scanningCallback = callback;
}
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);
}
void
NetDeviceFace::send(Ptr<Packet> packet)
{
  NS_ASSERT_MSG(packet->GetSize() <= m_netDevice->GetMtu(),
                "Packet size " << packet->GetSize() << " exceeds device MTU "
                               << m_netDevice->GetMtu());

  FwHopCountTag tag;
  packet->RemovePacketTag(tag);
  tag.Increment();
  packet->AddPacketTag(tag);

  m_netDevice->Send(packet, m_netDevice->GetBroadcast(), L3Protocol::ETHERNET_FRAME_TYPE);
}
void
Ipv4AddressHelper::SetBase (
  const Ipv4Address network, 
  const Ipv4Mask mask,
  const Ipv4Address address)
{
  NS_LOG_FUNCTION_NOARGS ();

  m_network = network.Get ();
  m_mask = mask.Get ();
  m_base = m_address = address.Get ();

//
// Some quick reasonableness testing.
//
  NS_ASSERT_MSG ((m_network & ~m_mask) == 0,
                 "Ipv4AddressHelper::SetBase(): Inconsistent network and mask");

//
// Figure out how much to shift network numbers to get them aligned, and what
// the maximum allowed address is with respect to the current mask.
//
  m_shift = NumAddressBits (m_mask);
  m_max = (1 << m_shift) - 2;

  NS_ASSERT_MSG (m_shift <= 32,
                 "Ipv4AddressHelper::SetBase(): Unreasonable address length");

//
// Shift the network down into the normalized position.
//
  m_network >>= m_shift;

  NS_LOG_LOGIC ("m_network == " << m_network);
  NS_LOG_LOGIC ("m_mask == " << m_mask);
  NS_LOG_LOGIC ("m_address == " << m_address);
}
void
A2A4RsrqHandoverAlgorithm::DoReportUeMeas (uint16_t rnti,
                                           LteRrcSap::MeasResults measResults)
{
  NS_LOG_FUNCTION (this << rnti << (uint16_t) measResults.measId);

  if (measResults.measId == m_a2MeasId)
    {
      NS_ASSERT_MSG (measResults.rsrqResult <= m_servingCellThreshold,
                     "Invalid UE measurement report");
      EvaluateHandover (rnti, measResults.rsrqResult);
    }
  else if (measResults.measId == m_a4MeasId)
    {
      if (measResults.haveMeasResultNeighCells
          && !measResults.measResultListEutra.empty ())
        {
          for (std::list <LteRrcSap::MeasResultEutra>::iterator it = measResults.measResultListEutra.begin ();
               it != measResults.measResultListEutra.end ();
               ++it)
            {
              NS_ASSERT_MSG (it->haveRsrqResult == true,
                             "RSRQ measurement is missing from cellId " << it->physCellId);
              UpdateNeighbourMeasurements (rnti, it->physCellId, it->rsrqResult);
            }
        }
      else
        {
          NS_LOG_WARN (this << " Event A4 received without measurement results from neighbouring cells");
        }
    }
  else
    {
      NS_LOG_WARN ("Ignoring measId " << (uint16_t) measResults.measId);
    }

} // end of DoReportUeMeas
NetDeviceFace::NetDeviceFace(Ptr<Node> node, const Ptr<NetDevice>& netDevice)
  : Face(FaceUri("netDeviceFace://"), FaceUri("netDeviceFace://"),getLevelFromNode(node),false)
  , m_node(node)
  , m_netDevice(netDevice)
{
  NS_LOG_FUNCTION(this << netDevice);

  setMetric(1); // default metric

  NS_ASSERT_MSG(m_netDevice != 0, "NetDeviceFace needs to be assigned a valid NetDevice");

  m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceFace::receiveFromNetDevice, this),
                                  L3Protocol::ETHERNET_FRAME_TYPE, m_netDevice,
                                  true /*promiscuous mode*/);
}
Beispiel #18
0
// Application Methods
void
App::StartApplication() // Called at time specified by Start
{
  NS_LOG_FUNCTION_NOARGS();

  NS_ASSERT(m_active != true);
  m_active = true;

  NS_ASSERT_MSG(GetNode()->GetObject<L3Protocol>() != 0,
                "Ndn stack should be installed on the node " << GetNode());

  // step 1. Create a face
  m_face = std::make_shared<AppFace>(this);

  // step 2. Add face to the Ndn stack
  GetNode()->GetObject<L3Protocol>()->addFace(m_face);
}
uint32_t
Ipv4AddressHelper::NumAddressBits (uint32_t maskbits) const
{
  NS_LOG_FUNCTION_NOARGS ();
  for (uint32_t i = 0; i < N_BITS; ++i)
    {
      if (maskbits & 1)
        {
          NS_LOG_LOGIC ("NumAddressBits -> " << i);
          return i;
        }
      maskbits >>= 1;
    }

  NS_ASSERT_MSG (false, "Ipv4AddressHelper::NumAddressBits(): Bad Mask");
  return 0;
}
Beispiel #20
0
void
Socket::BindToNetDevice (Ptr<NetDevice> netdevice)
{
  NS_LOG_FUNCTION (this << netdevice);
  if (netdevice != 0)
    {
      bool found = false;
      for (uint32_t i = 0; i < GetNode ()->GetNDevices (); i++)
        {
          if (GetNode ()->GetDevice (i) == netdevice)
            {
              found = true;
              break;
            }
        }
      NS_ASSERT_MSG (found, "Socket cannot be bound to a NetDevice not existing on the Node");
    }
  m_boundnetdevice = netdevice;
  return;
}
void
SSLinkManager::StartContentionResolution (void)
{
  NS_ASSERT_MSG (
    m_ss->GetState ()
    == SubscriberStationNetDevice::SS_STATE_WAITING_RNG_RSP
    || m_ss->GetState ()
    == SubscriberStationNetDevice::SS_STATE_WAITING_REG_RANG_INTRVL
    || m_ss->GetState ()
    == SubscriberStationNetDevice::SS_STATE_ADJUSTING_PARAMETERS,
    "SS: Can not start connection resolution: The SS state should be SS_STATE_WAITING_RNG_RSP or SS_STATE_WAITING_REG_RANG_INTRVL or SS_STATE_ADJUSTING_PARAMETERS");

  if (m_ss->GetState ()
      == SubscriberStationNetDevice::SS_STATE_WAITING_RNG_RSP)
    {
      m_ss->SetState (
        SubscriberStationNetDevice::SS_STATE_WAITING_REG_RANG_INTRVL);
      IncreaseRangingRequestCW ();
      m_contentionRangingRetries++;
    }
  else if (m_ss->GetState ()
           == SubscriberStationNetDevice::SS_STATE_ADJUSTING_PARAMETERS)
    {
      m_ss->SetState (
        SubscriberStationNetDevice::SS_STATE_WAITING_REG_RANG_INTRVL);
    }

  if (m_contentionRangingRetries == m_ss->GetMaxContentionRangingRetries ())
    {
      StartScanning (SubscriberStationNetDevice::EVENT_NONE, false);
    }
  else
    {
      if (!m_isBackoffSet)
        {
          SelectRandomBackoff ();
        }
    }
}
NetDeviceFace::NetDeviceFace(Ptr<Node> node, const Ptr<NetDevice>& netDevice)
  : Face(FaceUri("netDeviceFace://"),
         FaceUri("netDeviceFace://"),
         false,
         // this is the mod mentioned above
         ( netDevice->GetObject<Object>
             ( TypeId::LookupByName( "ndntac::IsEdgeFlag" ) )
             ? true : false ),
         false )
  , m_node(node)
  , m_netDevice(netDevice)
{
  NS_LOG_FUNCTION(this << netDevice);

  setMetric(1); // default metric

  NS_ASSERT_MSG(m_netDevice != 0, "NetDeviceFace needs to be assigned a valid NetDevice");

  m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceFace::receiveFromNetDevice, this),
                                  L3Protocol::ETHERNET_FRAME_TYPE, m_netDevice,
                                  true /*promiscuous mode*/);
}
Ipv4Address
Ipv4AddressHelper::NewAddress (void)
{
//
// The way this is expected to be used is that an address and network number
// are initialized, and then NewAddress() is called repeatedly to allocate and
// get new addresses on a given subnet.  The client will expect that the first
// address she gets back is the one she used to initialize the generator with.
// This implies that this operation is a post-increment.
//
  NS_ASSERT_MSG (m_address <= m_max,
                 "Ipv4AddressHelper::NewAddress(): Address overflow");

  Ipv4Address addr ((m_network << m_shift) | m_address);
  ++m_address;
//
// The Ipv4AddressGenerator allows us to keep track of the addresses we have
// allocated and will assert if we accidentally generate a duplicate.  This
// avoids some really hard to debug problems.
//
  Ipv4AddressGenerator::AddAllocated (addr);
  return addr;
}
bool
FdNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
{
  NS_LOG_FUNCTION (this << packet << src << dest << protocolNumber);
  NS_LOG_LOGIC ("packet " << packet);
  NS_LOG_LOGIC ("UID is " << packet->GetUid ());

  if (IsLinkUp () == false)
    {
      m_macTxDropTrace (packet);
      return false;
    }

  Mac48Address destination = Mac48Address::ConvertFrom (dest);
  Mac48Address source = Mac48Address::ConvertFrom (src);

  NS_LOG_LOGIC ("Transmit packet with UID " << packet->GetUid ());
  NS_LOG_LOGIC ("Transmit packet from " << source);
  NS_LOG_LOGIC ("Transmit packet to " << destination);

  EthernetHeader header (false);
  header.SetSource (source);
  header.SetDestination (destination);

  if (m_encapMode == LLC)
    {
      LlcSnapHeader llc;
      llc.SetType (protocolNumber);
      packet->AddHeader (llc);

      header.SetLengthType (packet->GetSize ());
    }
  else
    {
      header.SetLengthType (protocolNumber);
    }

  packet->AddHeader (header);

  //
  // there's not much meaning associated with the different layers in this
  // device, so don't be surprised when they're all stacked together in
  // essentially one place.  We do this for trace consistency across devices.
  //
  m_macTxTrace (packet);

  m_promiscSnifferTrace (packet);
  m_snifferTrace (packet);

  NS_LOG_LOGIC ("calling write");

  NS_ASSERT_MSG (packet->GetSize () <= m_mtu, "FdNetDevice::SendFrom(): Packet too big " << packet->GetSize ());

  ssize_t len =  (ssize_t) packet->GetSize ();
  uint8_t *buffer = (uint8_t*)malloc (len);
  packet->CopyData (buffer, len);

  // We need to add the PI header
  if (m_encapMode == DIXPI)
    {
      AddPIHeader (buffer, len);
    }

  ssize_t written = write (m_fd, buffer, len);
  free (buffer);

  if (written == -1 || written != len)
    {
      m_macTxDropTrace (packet);
      return false;
    }

  return true;
}
Beispiel #25
0
void
LteAnr::DoReportUeMeas (LteRrcSap::MeasResults measResults)
{
  uint8_t measId = measResults.measId;
  NS_LOG_FUNCTION (this << m_servingCellId << (uint16_t) measId);

  if (measId != m_measId)
    {
      NS_LOG_WARN (this << " Skipping unexpected measurement identity " << (uint16_t) measId);
    }
  else
    {
      if (measResults.haveMeasResultNeighCells
          && !(measResults.measResultListEutra.empty ()))
        {
          for (std::list <LteRrcSap::MeasResultEutra>::iterator it = measResults.measResultListEutra.begin ();
               it != measResults.measResultListEutra.end ();
               ++it)
            {
              // Keep new RSRQ value reported for the neighbour cell
              NS_ASSERT_MSG (it->haveRsrqResult == true,
                             "RSRQ measure missing for cellId " << it->physCellId);

              // Update Neighbour Relation Table
              NeighbourRelationTable_t::iterator itNrt = m_neighbourRelationTable.find (it->physCellId);
              if (itNrt != m_neighbourRelationTable.end ())
                {
                  // Update neighbour relation entry
                  NS_LOG_LOGIC (this << " updating NRT of cell " << m_servingCellId
                                     << " with entry of cell " << it->physCellId);
                  if (itNrt->second.noX2 == false)
                    {
                      NS_LOG_LOGIC (this << " enabling handover"
                                         << " from cell " << m_servingCellId
                                         << " to cell " << it->physCellId);
                      itNrt->second.noHo = false;
                    }
                  itNrt->second.detectedAsNeighbour = true;
                }
              else
                {
                  // Discovered new neighbour
                  NS_LOG_LOGIC (this << " inserting NRT of cell " << m_servingCellId
                                     << " with newly discovered neighbouring cell "
                                     << it->physCellId);
                  NeighbourRelation_t neighbourRelation;
                  neighbourRelation.noRemove = false;
                  neighbourRelation.noHo = true;
                  neighbourRelation.noX2 = true;
                  neighbourRelation.detectedAsNeighbour = true;
                  m_neighbourRelationTable[it->physCellId] = neighbourRelation;
                }

            } // end of for (it = measResults.measResultListEutra.begin ())

        } // end of if (measResults.haveMeasResultNeighCells && !(measResults.measResultListEutra.empty ()))
      else
        {
          NS_LOG_WARN (this << " Event A4 received without measurement results from neighbouring cells");
          /// \todo Remove neighbours in the NRT.
        }

    } // end of else of if (measId != m_measId)

} // end of DoReportUeMeas
std::string
TopologyReader::Link::GetAttribute (const std::string &name) const
{
  NS_ASSERT_MSG (m_linkAttr.find (name) != m_linkAttr.end (), "Requested topology link attribute not found");
  return m_linkAttr.find (name)->second;
}
void
SSLinkManager::PerformRanging (Cid cid,
                               RngRsp rngrsp)
{
  // need to distinguish initial ranging or periodic ranging

  if (cid == m_ss->GetInitialRangingConnection ()->GetCid ())
    {
      if (rngrsp.GetFrameNumber () == m_rngReqFrameNumber
          && rngrsp.GetInitRangOppNumber () == m_initRangOppNumber)
        {
          Simulator::Cancel (m_waitForRngRspEvent);
          m_nrRngRspsRecvd++;

          // RNG-REQ was undecodable
          ResetRangingRequestCW ();
          AdjustRangingParameters (rngrsp);
          m_ss->SetState (
            SubscriberStationNetDevice::SS_STATE_ADJUSTING_PARAMETERS);
          return;
        }

      if (m_ss->GetAddress () != rngrsp.GetMacAddress ())
        {
          return;
        }

      m_ss->SetBasicConnection (CreateObject<WimaxConnection> (rngrsp.GetBasicCid (),
                                                               Cid::BASIC));

      m_ss->SetPrimaryConnection (CreateObject<WimaxConnection> (rngrsp.GetPrimaryCid (),
                                                                 Cid::PRIMARY));
      m_ss->SetAreManagementConnectionsAllocated (true);
    }
  else
    {
      // either periodic ranging or an additional RNG-RSP during initial ranging
    }

  m_nrRngRspsRecvd++;
  if (m_waitForRngRspEvent.IsRunning ())
    {
      Simulator::Cancel (m_waitForRngRspEvent);
    }

  m_rangingStatus = (WimaxNetDevice::RangingStatus) rngrsp.GetRangStatus ();

  NS_ASSERT_MSG (
    m_rangingStatus == WimaxNetDevice::RANGING_STATUS_CONTINUE
    || m_rangingStatus == WimaxNetDevice::RANGING_STATUS_ABORT
    || m_rangingStatus == WimaxNetDevice::RANGING_STATUS_SUCCESS,
    "SS: Can not perform ranging: the ranging status should be RANGING_STATUS_CONTINUE or RANGING_STATUS_ABORT or RANGING_STATUS_SUCCESS");

  if (m_rangingStatus == WimaxNetDevice::RANGING_STATUS_ABORT)
    {
      if (rngrsp.GetDlFreqOverride ())
        {
          // code to move to new channel/frequency goes here
        }
      // deassigning basic and primary CIDs
      m_ss->SetBasicConnection (0);
      m_ss->SetPrimaryConnection (0);
      m_ss->SetAreManagementConnectionsAllocated (false);
    }
  else
    {
      AdjustRangingParameters (rngrsp);

      if (m_rangingStatus == WimaxNetDevice::RANGING_STATUS_SUCCESS)
        {

          m_ss->SetState (SubscriberStationNetDevice::SS_STATE_REGISTERED);
          // initiate service flows
          if (m_ss->HasServiceFlows () && !m_ss->GetAreServiceFlowsAllocated ())
            {
              m_ss->GetServiceFlowManager ()->InitiateServiceFlows ();
            }

          NegotiateBasicCapabilities ();
        }
      else
        {

          m_ss->SetState (
            SubscriberStationNetDevice::SS_STATE_WAITING_INV_RANG_INTRVL);
          // wait for invited ranging interval assigned to its Basic CID
        }
    }
}
Ptr<Packet>
WimaxMacQueue::Dequeue (MacHeaderType::HeaderType packetType)
{
  if (!IsEmpty ())
    {
      QueueElement element = Front (packetType);
      Pop (packetType);

      if (element.m_hdrType.GetType () == MacHeaderType::HEADER_TYPE_GENERIC)
        {
          NS_LOG_INFO ("Enqueued Packet IS A data packet");
          NS_ASSERT_MSG (m_nrDataPackets >= 1,
                         "Can not enqueue more packets: no space left in the queue");
          m_nrDataPackets--;
        }
      else
        {
          NS_LOG_INFO ("Enqueued Packet IS A Request BW packet");
          NS_ASSERT_MSG (m_nrRequestPackets >= 1,
                         "Can not enqueue more packets: no space left in the queue");
          m_nrRequestPackets--;
        }

      Ptr<Packet> packet = element.m_packet;

      if (!element.m_fragmentation)
        {
          NS_LOG_INFO ("FRAG_DEBUG: Enqueued Packet IS NOT a fragment" << std::endl);
          /*check because may be it is a bandwidth request packet (in which case a Bandwidth Request Header
            has already been added to the packet) in which case Generic MAC Header will not be added to it.
            this will only happen in the case of SS as only SS sends the bandwidth request packet. */
          m_bytes -= element.GetSize ();
          if (element.m_hdrType.GetType () == MacHeaderType::HEADER_TYPE_GENERIC)
            {
              packet->AddHeader (element.m_hdr);
            }
          packet->AddHeader (element.m_hdrType);

          m_traceDequeue (packet);
          return packet;
        }
      else
        {
          /*
           The enqueued packet is a fragment (the latest fragment)
           We must modify type field of the m_hdr and add a fragmentation Subhdr
           */
          NS_LOG_INFO ("\t Enqueued Packet IS a fragment, add subhdr" << std::endl);

          // Create a fragment
          uint32_t fragmentOffset = element.m_fragmentOffset;
          uint32_t fragmentSize = element.m_packet->GetSize () - fragmentOffset;

          NS_LOG_INFO ("\t Create a fragment"
                       "\n\t\t fragmentOffset=" << fragmentOffset <<
                       "\n\t\t packetSize=" << element.m_packet->GetSize () <<
                       "\n\t\t fragmentSize=" << fragmentSize << std::endl);

          Ptr<Packet> fragment = packet->CreateFragment (fragmentOffset,fragmentSize);

          FragmentationSubheader fragmentSubhdr;
          NS_LOG_INFO ("\t Latest Fragment" << std::endl);
          fragmentSubhdr.SetFc (2);   // This is the latest fragment
          fragmentSubhdr.SetFsn (element.m_fragmentNumber);

          NS_LOG_INFO ("\t FragmentSize=" << fragment->GetSize () << std::endl);
          fragment->AddHeader (fragmentSubhdr);

          /*check because may be it is a bandwidth request packet (in which case a Bandwidth Request Header
          has already been added to the packet) in which case Generic MAC Header will not be added to it.
          this will only happen in the case of SS as only SS sends the bandwidth request packet. */
          if (element.m_hdrType.GetType () == MacHeaderType::HEADER_TYPE_GENERIC)
            {
              uint8_t tmpType = element.m_hdr.GetType ();
              tmpType |= 4;
              element.m_hdr.SetType (tmpType);

              uint32_t length = fragmentSize + element.m_hdr.GetSerializedSize ()
                + fragmentSubhdr.GetSerializedSize ();
              element.m_hdr.SetLen ((uint16_t)length);

              fragment->AddHeader (element.m_hdr);
            }
          fragment->AddHeader (element.m_hdrType);
          m_bytes -= fragmentSize;

          m_traceDequeue (fragment);
          return fragment;
        }
    }
  return 0;
}
IpcsClassifierRecord::IpcsClassifierRecord (Tlv tlv)
{
  NS_ASSERT_MSG (tlv.GetType () == CsParamVectorTlvValue::Packet_Classification_Rule, "Invalid TLV");
  ClassificationRuleVectorTlvValue* rules = ((ClassificationRuleVectorTlvValue*)(tlv.PeekValue ()));
  m_priority = 0;
  m_index = 0;
  m_tosLow = 0;
  m_tosHigh = 0;
  m_tosMask = 0;
  m_cid = 0;
  for (std::vector<Tlv*>::const_iterator iter = rules->Begin (); iter != rules->End (); ++iter)
    {
      switch ((*iter)->GetType ())
        {
        case ClassificationRuleVectorTlvValue::Priority:
          {
            m_priority = ((U8TlvValue*)((*iter)->PeekValue ()))->GetValue ();
            break;
          }
        case ClassificationRuleVectorTlvValue::ToS:
          {
            NS_FATAL_ERROR ("ToS Not implemented-- please implement and contribute a patch");
            break;
          }
        case ClassificationRuleVectorTlvValue::Protocol:
          {
            ProtocolTlvValue * list = (ProtocolTlvValue *)(*iter)->PeekValue ();
            for (std::vector<uint8_t>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddProtocol (*iter2);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::IP_src:
          {
            Ipv4AddressTlvValue * list = (Ipv4AddressTlvValue *)(*iter)->PeekValue ();
            for (std::vector<Ipv4AddressTlvValue::ipv4Addr>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddSrcAddr ((*iter2).Address, (*iter2).Mask);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::IP_dst:
          {
            Ipv4AddressTlvValue * list = (Ipv4AddressTlvValue *)(*iter)->PeekValue ();
            for (std::vector<Ipv4AddressTlvValue::ipv4Addr>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddDstAddr ((*iter2).Address, (*iter2).Mask);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::Port_src:
          {
            PortRangeTlvValue * list = (PortRangeTlvValue *)(*iter)->PeekValue ();
            for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddSrcPortRange ((*iter2).PortLow, (*iter2).PortHigh);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::Port_dst:
          {
            PortRangeTlvValue * list = (PortRangeTlvValue *)(*iter)->PeekValue ();
            for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddDstPortRange ((*iter2).PortLow, (*iter2).PortHigh);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::Index:
          {
            m_index = ((U16TlvValue*)((*iter)->PeekValue ()))->GetValue ();
            break;
          }
        }
    }
}
Beispiel #30
0
void Ping6::Send ()
{
  NS_LOG_FUNCTION_NOARGS ();
  NS_ASSERT (m_sendEvent.IsExpired ());
  Ptr<Packet> p = 0;
  uint8_t* data = new uint8_t[m_size];
  Ipv6Address src;
  Ptr<Ipv6> ipv6 = GetNode ()->GetObject<Ipv6> ();

  if (m_ifIndex > 0)
    {
      /* hack to have ifIndex in Ipv6RawSocketImpl
       * maybe add a SetIfIndex in Ipv6RawSocketImpl directly 
       */
      Ipv6InterfaceAddress dstIa (m_peerAddress);
      for (uint32_t i = 0; i < GetNode ()->GetObject<Ipv6> ()->GetNAddresses (m_ifIndex); i++)
        {
          src = GetNode ()->GetObject<Ipv6> ()->GetAddress (m_ifIndex, i).GetAddress ();
          Ipv6InterfaceAddress srcIa (src);
          if ( srcIa.GetScope() == dstIa.GetScope() )
            {
              break;
            }
        }
     }
  else
    {
      src = m_localAddress;
    }

  NS_ASSERT_MSG (m_size >= 4, "ICMPv6 echo request payload size must be >= 4");
  data[0] = 0xDE;
  data[1] = 0xAD;
  data[2] = 0xBE;
  data[3] = 0xEF;

  p = Create<Packet> (data, 4);
  p->AddAtEnd (Create<Packet> (m_size - 4));
  Icmpv6Echo req (1);

  req.SetId (0xBEEF);
  req.SetSeq (m_seq);
  m_seq++;

  /* we do not calculate pseudo header checksum here, because we are not sure about 
   * source IPv6 address. Checksum is calculated in Ipv6RawSocketImpl.
   */

  p->AddHeader (req);
  m_socket->Bind (Inet6SocketAddress (src, 0));

  /* use Loose Routing (routing type 0) */
  if (m_routers.size ())
    {
      Ipv6ExtensionLooseRoutingHeader routingHeader;
      routingHeader.SetNextHeader (Ipv6Header::IPV6_ICMPV6);
      routingHeader.SetLength (m_routers.size () * 16 + 8);
      routingHeader.SetTypeRouting (0);
      routingHeader.SetSegmentsLeft (m_routers.size ());
      routingHeader.SetRoutersAddress (m_routers);
      p->AddHeader (routingHeader);
      m_socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_EXT_ROUTING));
    }

  m_socket->Send (p, 0);
  ++m_sent;

  NS_LOG_INFO ("Sent " << p->GetSize () << " bytes to " << m_peerAddress);

  if (m_sent < m_count)
    {
      ScheduleTransmit (m_interval);
    }

  delete[] data;
}