18 #include "spectrum-manager.h"
19 #include "ns3/yans-wifi-phy.h"
20 #include "ns3/aodv-routing-protocol.h"
46 int id,
Time sense_time,
Time transmit_time) {
53 m_isSwitching =
false;
56 m_senseTime=sense_time;
57 m_transmitTime=transmit_time;
69 SpectrumManager::~SpectrumManager() {
77 m_isPuOn = m_sensingMod->GetSenseResultsFuture(m_nodeId,m_senseTime,m_transmitTime, m_repository->GetRxChannel(m_nodeId));
87 bool available= !(m_isSensing || m_isSwitching);
100 Time time_tx=txDuration;
102 int current_channel=m_repository->GetRxChannel(m_nodeId);
103 bool interference=m_sensingMod->GetSenseResultsFuture(m_nodeId,time_tx,m_transmitTime, current_channel);
105 #ifdef SENSING_VERBOSE_MODE
109 std::sprintf(buffer,
"[SENSING-DBG] Node %d sensed some PU activity on channel %d while receiving data\n", m_nodeId,current_channel);
151 bool need_to_switch=
false;
153 int current_channel=m_repository->GetRxChannel(m_nodeId);
155 #ifdef SENSING_VERBOSE_MODE //abdulla
157 std::sprintf(buffer,
"[SENSING-DBG] Node %d is on channel %d and PU activity is %s", m_nodeId, current_channel, (m_isPuOn)?
"true":
"false");
165 need_to_switch=m_decisionMod->DecideSwitch();
168 if (need_to_switch) {
171 #ifdef CHANNEL_DECISION_MAC_LAYER
174 int next_channel=m_decisionMod->DecideSpectrum(current_channel);
176 m_repository->SetRxChannel(m_nodeId,next_channel);
177 m_isSwitching =
true;
181 #ifdef SENSING_VERBOSE_MODE
183 std::sprintf(buffer,
"[SENSING-DBG] Node %d starts handoff on channel %d to channel %d",m_nodeId,current_channel,next_channel);
194 m_isPuOn = m_sensingMod->GetSenseResultsFuture(m_nodeId,m_senseTime,m_transmitTime, current_channel);
214 #ifdef ENABLE_SPECTRUM_HANDOFF_NOTIFICATION
220 m_isSwitching =
false;
226 m_wifiMac->RestartAccess();
228 #ifdef SENSING_VERBOSE_MODE
230 std::sprintf(buffer,
"[SENSING-DBG] Node %d starts transmitting on channel %d",m_nodeId,current_channel);
246 int current_channel=m_repository->GetRxChannel(m_nodeId);
249 m_isPuOn= m_sensingMod->GetSenseResultsFuture(m_nodeId,m_senseTime,m_transmitTime, current_channel);
254 #ifdef SENSING_VERBOSE_MODE
256 std::sprintf(buffer,
"[SENSING-DBG] Node %d starts sensing on channel %d",m_nodeId,current_channel);
271 int current_channel=m_repository->GetRxChannel(m_nodeId);
274 m_isPuOn = m_sensingMod->GetSenseResultsFuture(m_nodeId,m_senseTime,m_transmitTime, current_channel);
279 #ifdef SENSING_VERBOSE_MODE
282 std::sprintf(buffer,
"[SENSING-DBG] Node %d ends handoff on channel %d",m_nodeId,current_channel);
284 std::sprintf(buffer,
"[SENSING-DBG] Node %d starts sensing on channel %d",m_nodeId,current_channel);
SpectrumManager(Ptr< RegularWifiMac > mac, int id)
smart pointer class similar to boost::intrusive_ptr
void SetPuModel(double prob, Ptr< PUModel > p)
#define NS_LOG_COMPONENT_DEFINE(name)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual void StartSensing(Time duration)=0
Start sensing on current channel.
virtual void SetHandoffEndedCallback(HandoffEndedCallback callback)=0
bool IsPuInterfering(Time txDuration)
virtual void SetSenseEndedCallback(SnsEndedCallback callback)=0
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
bool IsChannelAvailable()
Access to the Ipv4 forwarding table, interfaces, and configuration.
virtual void SetChannelNumber(uint16_t id)=0
Set channel number.
void SetRepository(Ptr< Repository > rep)
#define NS_LOG_DEBUG(msg)
Ptr< T > GetObject(void) const