5#include "nr-net-device.h"
7#include "ns3/channel.h"
8#include "ns3/error-model.h"
9#include "ns3/ipv4-l3-protocol.h"
10#include "ns3/ipv6-header.h"
11#include "ns3/ipv6-l3-protocol.h"
14#include "ns3/pointer.h"
15#include "ns3/uinteger.h"
20NS_LOG_COMPONENT_DEFINE(
"NrNetDevice");
22NS_OBJECT_ENSURE_REGISTERED(NrNetDevice);
28 TypeId(
"ns3::NrNetDevice")
29 .SetParent<NetDevice>()
31 "The MAC-level Maximum Transmission Unit",
33 MakeUintegerAccessor(&NrNetDevice::SetMtu, &NrNetDevice::GetMtu),
34 MakeUintegerChecker<uint16_t>())
35 .AddAttribute(
"ReceiveErrorModel",
36 "An optional packet error model to simulate packet loss",
38 MakePointerAccessor(&NrNetDevice::m_receiveErrorModel),
39 MakePointerChecker<ErrorModel>())
41 "A packet has been transmitted with the Address as the recipient",
43 "ns3::Packet::AddressTracedCallback")
45 "A packet has been received",
47 "ns3::Packet::TracedCallback")
48 .AddTraceSource(
"Drop",
49 "A packet has been dropped by the receive error model",
51 "ns3::Packet::TracedCallback");
58 NS_LOG_FUNCTION(
this);
63 NS_LOG_FUNCTION(
this);
67NrNetDevice::DoDispose()
70 NetDevice::DoDispose();
74NrNetDevice::SetIfIndex(
const uint32_t index)
80NrNetDevice::GetIfIndex()
const
86NrNetDevice::GetChannel()
const
92NrNetDevice::SetAddress(Address address)
94 NS_LOG_FUNCTION(
this << address);
95 m_macaddress = Mac48Address::ConvertFrom(address);
99NrNetDevice::GetAddress()
const
101 NS_LOG_FUNCTION(
this);
106NrNetDevice::SetMtu(
const uint16_t mtu)
113NrNetDevice::GetMtu()
const
119NrNetDevice::IsLinkUp()
const
125NrNetDevice::AddLinkChangeCallback([[maybe_unused]] Callback<void> callback)
130NrNetDevice::IsBroadcast()
const
136NrNetDevice::GetBroadcast()
const
138 return Mac48Address::GetBroadcast();
142NrNetDevice::IsMulticast()
const
148NrNetDevice::GetMulticast([[maybe_unused]] Ipv4Address multicastGroup)
const
150 return Mac48Address(
"01:00:5e:00:00:00");
154NrNetDevice::IsBridge()
const
160NrNetDevice::IsPointToPoint()
const
166NrNetDevice::SendFrom([[maybe_unused]] Ptr<Packet> packet,
167 [[maybe_unused]]
const Address& source,
168 [[maybe_unused]]
const Address& dest,
169 [[maybe_unused]] uint16_t protocolNumber)
171 NS_FATAL_ERROR(
"Send from not supported");
176NrNetDevice::GetNode()
const
182NrNetDevice::SetNode(Ptr<Node> node)
188NrNetDevice::NeedsArp()
const
194NrNetDevice::GetMulticast([[maybe_unused]] Ipv6Address addr)
const
200NrNetDevice::SetReceiveCallback(ReceiveCallback cb)
202 NS_LOG_FUNCTION(
this);
207NrNetDevice::SetPromiscReceiveCallback([[maybe_unused]] PromiscReceiveCallback cb)
212NrNetDevice::SupportsSendFrom()
const
218NrNetDevice::Receive(Ptr<Packet> p)
220 NS_LOG_FUNCTION(
this << p);
222 Ipv4Header ipv4Header;
223 Ipv6Header ipv6Header;
225 if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt(p))
227 NS_LOG_INFO(
"Dropping " << p->GetSize() <<
" bytes on " << m_macaddress);
231 if (p->PeekHeader(ipv4Header) != 0)
233 NS_LOG_INFO(
"Received " << p->GetSize() <<
" bytes on " << m_macaddress
234 <<
". IPv4 packet from " << ipv4Header.GetSource() <<
" to "
235 << ipv4Header.GetDestination());
237 m_rxCallback(
this, p, Ipv4L3Protocol::PROT_NUMBER, Address());
239 else if (p->PeekHeader(ipv6Header) != 0)
241 NS_LOG_INFO(
"Received " << p->GetSize() <<
" bytes on " << m_macaddress
242 <<
". IPv6 packet from " << ipv6Header.GetSource() <<
" to "
243 << ipv6Header.GetDestination());
245 m_rxCallback(
this, p, Ipv6L3Protocol::PROT_NUMBER, Address());
249 NS_ABORT_MSG(
"Unknown IP type");
254NrNetDevice::Send(Ptr<Packet> packet,
const Address& dest, uint16_t protocolNumber)
256 bool ret = DoSend(packet, dest, protocolNumber);
TracedCallback< Ptr< const Packet > > m_dropTrace
Traced Callback for dropped packets.
~NrNetDevice() override
~NrNetDevice
TracedCallback< Ptr< const Packet >, const Address & > m_txTrace
Traced Callback for transmitted packets.
TracedCallback< Ptr< const Packet > > m_rxTrace
Traced Callback for received packets.
NrNetDevice()
NrNetDevice.
static TypeId GetTypeId()
GetTypeId.