5G-LENA  nr-v3.0-29-g83cc959
The 5G/NR module for the ns-3 simulator
nr-ch-access-manager.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 
3 // Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4 //
5 // SPDX-License-Identifier: GPL-2.0-only
6 
7 #include "nr-ch-access-manager.h"
8 
9 #include <ns3/double.h>
10 #include <ns3/log.h>
11 
12 namespace ns3
13 {
14 
15 NS_LOG_COMPONENT_DEFINE("NrChAccessManager");
16 NS_OBJECT_ENSURE_REGISTERED(NrChAccessManager);
17 
18 TypeId
20 {
21  static TypeId tid = TypeId("ns3::NrChAccessManager")
22  .SetParent<Object>()
23  .SetGroupName("nr")
24  .AddAttribute("GrantDuration",
25  "Duration of grant for transmitting.",
26  TimeValue(Minutes(1)),
27  MakeTimeAccessor(&NrChAccessManager::SetGrantDuration,
29  MakeTimeChecker());
30  return tid;
31 }
32 
34 {
35  NS_LOG_FUNCTION(this);
36 }
37 
39 {
40  NS_LOG_FUNCTION(this);
41 }
42 
43 void
45 {
46  NS_LOG_FUNCTION(this);
47  m_grantDuration = grantDuration;
48 }
49 
50 Time
52 {
53  NS_LOG_FUNCTION(this);
54  return m_grantDuration;
55 }
56 
57 void
58 NrChAccessManager::SetNrSpectrumPhy(Ptr<NrSpectrumPhy> spectrumPhy)
59 {
60  NS_LOG_FUNCTION(this);
61  m_spectrumPhy = spectrumPhy;
62 }
63 
64 Ptr<NrSpectrumPhy>
66 {
67  NS_LOG_FUNCTION(this);
68  return m_spectrumPhy;
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION(this);
75  m_mac = mac;
76 }
77 
78 Ptr<NrGnbMac>
80 {
81  NS_LOG_FUNCTION(this);
82  return m_mac;
83 }
84 
85 // -----------------------------------------------------------------
86 
87 NS_OBJECT_ENSURE_REGISTERED(NrAlwaysOnAccessManager);
88 
89 TypeId
91 {
92  static TypeId tid = TypeId("ns3::NrAlwaysOnAccessManager")
93  .SetParent<NrChAccessManager>()
94  .SetGroupName("nr")
95  .AddConstructor<NrAlwaysOnAccessManager>();
96  return tid;
97 }
98 
101 {
102  NS_LOG_FUNCTION(this);
103 }
104 
106 {
107  NS_LOG_FUNCTION(this);
108 }
109 
110 void
112 {
113  NS_LOG_FUNCTION(this);
114  // We are always on!!
115  for (const auto& cb : m_accessGrantedCb)
116  {
117  cb(Time::Max() - Simulator::Now());
118  }
119 }
120 
121 void
123 {
124  NS_LOG_FUNCTION(this);
125  m_accessGrantedCb.push_back(cb);
126 }
127 
128 void
130  [[maybe_unused]] const NrChAccessManager::AccessDeniedCallback& cb)
131 {
132  NS_LOG_FUNCTION(this);
133  // Don't store it, as we will not call it..
134 }
135 
136 void
138 {
139  NS_LOG_FUNCTION(this);
140  // Do nothing, we are always on and we call the callback only when RequestAccess()
141  // is called
142 }
143 
144 } // namespace ns3
A Channel access manager that sees the channel always free for transmitting.
void Cancel() override
Cancel a previously invoked request for accessing the channel.
NrAlwaysOnAccessManager()
NrAlwaysOnAccessManager constructor.
void RequestAccess() override
RequestAccess.
void SetAccessGrantedCallback(const AccessGrantedCallback &cb) override
Set Access-Granted Callback.
~NrAlwaysOnAccessManager() override
destructor
static TypeId GetTypeId()
Get the type ID.
void SetAccessDeniedCallback(const AccessDeniedCallback &cb) override
Set Access-Denied Callback.
The Channel Access Manager class.
Time GetGrantDuration() const
Get grant duration time.
void SetGrantDuration(Time grantDuration)
Set duration of grant for transmission.
~NrChAccessManager() override
~ChannelAccessManager
virtual void SetNrGnbMac(Ptr< NrGnbMac > mac)
Set MAC instance for this channel access manager.
std::function< void(const Time &time)> AccessGrantedCallback
A function that signal that the channel has been earned.
std::function< void()> AccessDeniedCallback
A function that signal that the channel is denied and the request should be retried.
Ptr< NrGnbMac > GetNrGnbMac()
Getter for MAC instance to which is connected this channel access manager.
NrChAccessManager()
ChannelAccessManager constructor.
virtual void SetNrSpectrumPhy(Ptr< NrSpectrumPhy > spectrumPhy)
Set spectrum phy instance for this channel access manager.
static TypeId GetTypeId()
Get the type ID.
Ptr< NrSpectrumPhy > GetNrSpectrumPhy()
Getter for spectrum phy instance to which is connected this channel access manager.