A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-mac-aloha.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8
9#include "uan-mac-aloha.h"
10
11#include "uan-header-common.h"
12#include "uan-phy.h"
13#include "uan-tx-mode.h"
14
15#include "ns3/log.h"
16
17#include <iostream>
18
19namespace ns3
20{
21
22NS_LOG_COMPONENT_DEFINE("UanMacAloha");
23
25
27 : UanMac(),
28 m_cleared(false)
29{
30}
31
35
36void
38{
39 if (m_cleared)
40 {
41 return;
42 }
43 m_cleared = true;
44 if (m_phy)
45 {
46 m_phy->Clear();
47 m_phy = nullptr;
48 }
49}
50
51void
57
60{
61 static TypeId tid = TypeId("ns3::UanMacAloha")
63 .SetGroupName("Uan")
64 .AddConstructor<UanMacAloha>();
65 return tid;
66}
67
68bool
69UanMacAloha::Enqueue(Ptr<Packet> packet, uint16_t protocolNumber, const Address& dest)
70{
72 << " Queueing packet for " << Mac8Address::ConvertFrom(dest));
73
74 if (!m_phy->IsStateTx())
75 {
78
79 UanHeaderCommon header;
80 header.SetSrc(src);
81 header.SetDest(udest);
82 header.SetType(0);
83 header.SetProtocolNumber(protocolNumber);
84
85 packet->AddHeader(header);
86 m_phy->SendPacket(packet, GetTxModeIndex());
87 return true;
88 }
89 else
90 {
91 return false;
92 }
93}
94
95void
97{
98 m_forUpCb = cb;
99}
100
101void
103{
104 m_phy = phy;
105 m_phy->SetReceiveOkCallback(MakeCallback(&UanMacAloha::RxPacketGood, this));
106 m_phy->SetReceiveErrorCallback(MakeCallback(&UanMacAloha::RxPacketError, this));
107}
108
109void
110UanMacAloha::RxPacketGood(Ptr<Packet> pkt, double /* sinr */, UanTxMode /* txMode */)
111{
112 UanHeaderCommon header;
113 pkt->RemoveHeader(header);
114 NS_LOG_DEBUG("Receiving packet from " << header.GetSrc() << " For " << header.GetDest());
115
116 if (header.GetDest() == GetAddress() || header.GetDest() == Mac8Address::GetBroadcast())
117 {
118 m_forUpCb(pkt, header.GetProtocolNumber(), header.GetSrc());
119 }
120}
121
122void
124{
126 << " Received packet in error with sinr " << sinr);
127}
128
129int64_t
131{
132 NS_LOG_FUNCTION(this << stream);
133 return 0;
134}
135
136} // namespace ns3
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
A class used for addressing MAC8 MAC's.
static Mac8Address GetBroadcast()
Get the broadcast address (255).
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
@ S
second
Definition nstime.h:105
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Common packet header fields.
void SetSrc(Mac8Address src)
Set the source address.
Mac8Address GetDest() const
Get the destination address.
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
Mac8Address GetSrc() const
Get the source address.
void SetDest(Mac8Address dest)
Set the destination address.
void SetType(uint8_t type)
Set the header type.
uint16_t GetProtocolNumber() const
Get the packet type value.
ALOHA MAC Protocol, the simplest MAC protocol for wireless networks.
static TypeId GetTypeId()
Register this type.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
void DoDispose() override
Destructor implementation.
bool m_cleared
Flag when we've been cleared.
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
UanMacAloha()
Default constructor.
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb) override
Set the callback to forward packets up to higher layers.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forUpCb
Forwarding up callback.
void RxPacketGood(Ptr< Packet > pkt, double sinr, UanTxMode txMode)
Receive packet from lower layer (passed to PHY as callback).
~UanMacAloha() override
Dummy destructor, see DoDispose.
void RxPacketError(Ptr< Packet > pkt, double sinr)
Packet received at lower layer in error.
void Clear() override
Clears all pointer references.
Virtual base class for all UAN MAC protocols.
Definition uan-mac.h:35
uint32_t GetTxModeIndex() const
Get the Tx mode index (Modulation type).
Definition uan-mac.cc:35
virtual Address GetAddress()
Get the MAC Address.
Definition uan-mac.cc:41
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684