38 #include <ns3/channel.h>
39 #include <ns3/error-model.h>
40 #include <ns3/ipv4-header.h>
41 #include <ns3/ipv4-l3-protocol.h>
44 #include <ns3/object-map.h>
45 #include <ns3/packet.h>
46 #include <ns3/pointer.h>
47 #include <ns3/singleton.h>
48 #include <ns3/trace-source-accessor.h>
49 #include <ns3/uinteger.h>
51 NS_LOG_COMPONENT_DEFINE(
"SatGeoNetDevice");
56 NS_OBJECT_ENSURE_REGISTERED(SatGeoNetDevice);
62 TypeId(
"ns3::SatGeoNetDevice")
63 .SetParent<NetDevice>()
64 .AddConstructor<SatGeoNetDevice>()
65 .AddAttribute(
"ReceiveErrorModel",
66 "The receiver error model used to simulate packet loss",
69 MakePointerChecker<ErrorModel>())
70 .AddAttribute(
"UserPhy",
71 "The User Phy objects attached to this device.",
74 MakeObjectMapChecker<SatPhy>())
75 .AddAttribute(
"FeederPhy",
76 "The Feeder Phy objects attached to this device.",
79 MakeObjectMapChecker<SatPhy>())
80 .AddAttribute(
"UserMac",
81 "The User MAC objects attached to this device.",
84 MakeObjectMapChecker<SatMac>())
85 .AddAttribute(
"FeederMac",
86 "The Feeder MAC objects attached to this device.",
89 MakeObjectMapChecker<SatMac>())
90 .AddAttribute(
"EnableStatisticsTags",
91 "If true, some tags will be added to each transmitted packet to assist "
92 "with statistics computation",
96 .AddTraceSource(
"PacketTrace",
99 "ns3::SatTypedefs::PacketTraceCallback")
100 .AddTraceSource(
"Tx",
101 "A packet to be sent",
103 "ns3::Packet::TracedCallback")
104 .AddTraceSource(
"SignallingTx",
105 "A signalling packet to be sent",
107 "ns3::SatTypedefs::PacketDestinationAddressCallback")
108 .AddTraceSource(
"RxFeeder",
109 "A packet received on feeder",
111 "ns3::SatTypedefs::PacketSourceAddressCallback")
112 .AddTraceSource(
"RxUser",
113 "A packet received on user",
115 "ns3::SatTypedefs::PacketSourceAddressCallback")
116 .AddTraceSource(
"RxFeederLinkDelay",
117 "A packet is received with feeder link delay information",
119 "ns3::SatTypedefs::PacketDelayAddressCallback")
120 .AddTraceSource(
"RxFeederLinkJitter",
121 "A packet is received with feeder link jitter information",
123 "ns3::SatTypedefs::PacketJitterAddressCallback")
124 .AddTraceSource(
"RxUserLinkDelay",
125 "A packet is received with feeder link delay information",
127 "ns3::SatTypedefs::PacketDelayAddressCallback")
128 .AddTraceSource(
"RxUserLinkJitter",
129 "A packet is received with feeder link jitter information",
131 "ns3::SatTypedefs::PacketJitterAddressCallback");
140 NS_LOG_FUNCTION(
this);
146 NS_LOG_FUNCTION(
this << packet);
147 NS_LOG_INFO(
"Receiving a packet: " << packet->GetUid());
149 Mac48Address macUserAddress = Mac48Address::ConvertFrom(userAddress);
171 if (packet->RemovePacketTag(linkTimeTag))
173 NS_LOG_DEBUG(
this <<
" contains a SatDevLinkTimeTag tag");
178 Time jitter = Abs(delay -
m_lastDelays[macUserAddress]);
186 if (!packet->PeekPacketTag(groundStationAddressTag))
188 NS_FATAL_ERROR(
"SatGroundStationAddressTag not found");
195 if (!packet->PeekPacketTag(satUplinkInfoTag))
197 NS_FATAL_ERROR(
"SatUplinkInfoTag not found");
207 ->EnquePacket(packet);
221 NS_LOG_FUNCTION(
this << packet);
222 NS_LOG_INFO(
"Receiving a packet: " << packet->GetUid());
224 Mac48Address macFeederAddress = Mac48Address::ConvertFrom(feederAddress);
246 if (packet->RemovePacketTag(linkTimeTag))
248 NS_LOG_DEBUG(
this <<
" contains a SatDevLinkTimeTag tag");
253 Time jitter = Abs(delay -
m_lastDelays[macFeederAddress]);
261 if (!packet->PeekPacketTag(groundStationAddressTag))
263 NS_FATAL_ERROR(
"SatGroundStationAddressTag not found");
267 if (destination.IsBroadcast())
272 if (
m_utConnected.count(destination) > 0 || destination.IsBroadcast())
275 if (!packet->PeekPacketTag(satUplinkInfoTag))
277 NS_FATAL_ERROR(
"SatUplinkInfoTag not found");
286 DynamicCast<SatGeoUserMac>(
m_userMac[satUplinkInfoTag.
GetBeamId()])->EnquePacket(packet);
288 if ((
m_utConnected.count(destination) == 0 || destination.IsBroadcast()) &&
297 Ptr<SatSignalParameters> rxParams)
299 NS_LOG_FUNCTION(
this << rxParams->m_packetsInBurst.size() << rxParams);
300 NS_LOG_INFO(
"Receiving a packet at the satellite from user link");
306 DynamicCast<SatGeoFeederPhy>(
m_feederPhy[rxParams->m_beamId])->SendPduWithParams(rxParams);
310 for (SatPhy::PacketContainer_t::const_iterator it = rxParams->m_packetsInBurst.begin();
311 it != rxParams->m_packetsInBurst.end();
314 DynamicCast<SatGeoFeederMac>(
m_feederMac[rxParams->m_beamId])->EnquePacket(*it);
321 "SatGeoNetDevice::ReceiveUser should not be used in case of network regeneration");
324 NS_FATAL_ERROR(
"Not implemented yet");
331 Ptr<SatSignalParameters> rxParams)
333 NS_LOG_FUNCTION(
this << rxParams->m_packetsInBurst.size() << rxParams);
334 NS_LOG_INFO(
"Receiving a packet at the satellite from feeder link");
340 DynamicCast<SatGeoUserPhy>(
m_userPhy[rxParams->m_beamId])->SendPduWithParams(rxParams);
345 "SatGeoNetDevice::ReceiveFeeder should not be used in case of network regeneration");
348 NS_FATAL_ERROR(
"Not implemented yet");
356 Ptr<SatSignalParameters> rxParams)
358 NS_LOG_FUNCTION(
this << msg << dest);
360 Ptr<Packet> packet = Create<Packet>(msg->GetSizeInBytes());
374 packet->AddPacketTag(addressE2ETag);
379 packet->AddPacketTag(macTag);
385 packet->AddPacketTag(tag);
390 satUplinkInfoTag.
SetSinr(std::numeric_limits<double>::infinity(), 0);
391 satUplinkInfoTag.
SetBeamId(rxParams->m_beamId);
392 satUplinkInfoTag.
SetSatId(rxParams->m_satId);
393 packet->AddPacketTag(satUplinkInfoTag);
396 rxParams->m_packetsInBurst.clear();
397 rxParams->m_packetsInBurst.push_back(packet);
403 DynamicCast<SatGeoFeederPhy>(
m_feederPhy[rxParams->m_beamId])->SendPduWithParams(rxParams);
408 for (SatPhy::PacketContainer_t::const_iterator it = rxParams->m_packetsInBurst.begin();
409 it != rxParams->m_packetsInBurst.end();
412 DynamicCast<SatGeoFeederMac>(
m_feederMac[rxParams->m_beamId])->EnquePacket(*it);
417 NS_FATAL_ERROR(
"Not implemented yet");
427 NS_LOG_FUNCTION(
this << em);
454 NS_LOG_FUNCTION(
this << index);
461 NS_LOG_FUNCTION(
this);
468 NS_LOG_FUNCTION(
this << address);
469 m_address = Mac48Address::ConvertFrom(address);
478 NS_LOG_FUNCTION(
this);
485 NS_LOG_FUNCTION(
this << mtu);
493 NS_LOG_FUNCTION(
this);
500 NS_LOG_FUNCTION(
this);
507 NS_LOG_FUNCTION(
this << &callback);
513 NS_LOG_FUNCTION(
this);
520 NS_LOG_FUNCTION(
this);
521 return Mac48Address(
"ff:ff:ff:ff:ff:ff");
527 NS_LOG_FUNCTION(
this);
534 NS_LOG_FUNCTION(
this << multicastGroup);
535 return Mac48Address::GetMulticast(multicastGroup);
541 NS_LOG_FUNCTION(
this << addr);
542 return Mac48Address::GetMulticast(addr);
548 NS_LOG_FUNCTION(
this);
555 NS_LOG_FUNCTION(
this);
562 NS_LOG_FUNCTION(
this << packet << dest << protocolNumber);
574 const Address& source,
576 uint16_t protocolNumber)
578 NS_LOG_FUNCTION(
this << packet << source << dest << protocolNumber);
591 NS_LOG_FUNCTION(
this);
598 NS_LOG_FUNCTION(
this << node);
605 NS_LOG_FUNCTION(
this);
612 NS_LOG_FUNCTION(
this << &cb);
618 NS_LOG_FUNCTION(
this);
626 NetDevice::DoDispose();
632 NS_LOG_FUNCTION(
this << &cb);
639 NS_LOG_FUNCTION(
this);
646 NS_LOG_FUNCTION(
this);
653 NS_LOG_FUNCTION(
this << phy << beamId);
654 m_userPhy.insert(std::pair<uint32_t, Ptr<SatPhy>>(beamId, phy));
660 NS_LOG_FUNCTION(
this << phy << beamId);
661 m_feederPhy.insert(std::pair<uint32_t, Ptr<SatPhy>>(beamId, phy));
671 NS_FATAL_ERROR(
"User Phy does not exist for beam " << beamId);
681 NS_FATAL_ERROR(
"User Phy does not exist for beam " << beamId);
684 std::map<uint32_t, Ptr<SatPhy>>
690 std::map<uint32_t, Ptr<SatPhy>>
699 NS_LOG_FUNCTION(
this << mac << beamId);
700 m_userMac.insert(std::pair<uint32_t, Ptr<SatMac>>(beamId, mac));
706 NS_LOG_FUNCTION(
this << mac << macUsed << beamId);
707 m_feederMac.insert(std::pair<uint32_t, Ptr<SatMac>>(beamId, macUsed));
708 m_allFeederMac.insert(std::pair<uint32_t, Ptr<SatMac>>(beamId, mac));
718 NS_FATAL_ERROR(
"User MAC does not exist for beam " << beamId);
728 NS_FATAL_ERROR(
"User MAC does not exist for beam " << beamId);
731 std::map<uint32_t, Ptr<SatMac>>
737 std::map<uint32_t, Ptr<SatMac>>
743 std::map<uint32_t, Ptr<SatMac>>
752 m_addressMapFeeder.insert(std::pair<uint32_t, Mac48Address>(beamId, satelliteFeederAddress));
762 NS_FATAL_ERROR(
"Satellite MAC does not exist for GW " << beamId);
768 NS_LOG_FUNCTION(
this << packet);
773 if (packet->PeekPacketTag(addressE2ETag))
775 NS_LOG_DEBUG(
this <<
" contains a SatE2E tag");
792 NS_LOG_FUNCTION(
this << gwAddress);
795 Singleton<SatIdMapper>::Get()->AttachMacToSatIdIsl(gwAddress,
m_nodeId);
801 NS_LOG_FUNCTION(
this << gwAddress);
804 Singleton<SatIdMapper>::Get()->RemoveMacToSatIdIsl(gwAddress);
807 std::set<Mac48Address>
810 NS_LOG_FUNCTION(
this);
818 NS_LOG_FUNCTION(
this << utAddress);
821 Singleton<SatIdMapper>::Get()->AttachMacToSatIdIsl(utAddress,
m_nodeId);
827 NS_LOG_FUNCTION(
this << utAddress);
830 Singleton<SatIdMapper>::Get()->RemoveMacToSatIdIsl(utAddress);
833 std::set<Mac48Address>
836 NS_LOG_FUNCTION(
this);
844 NS_LOG_FUNCTION(
this);
849 std::vector<Ptr<PointToPointIslNetDevice>>
852 NS_LOG_FUNCTION(
this);
860 NS_LOG_FUNCTION(
this << arbiter);
868 NS_LOG_FUNCTION(
this);
876 NS_LOG_FUNCTION(
this << packet << destination);
879 NS_ASSERT_MSG(
m_arbiter !=
nullptr,
"Arbiter not set");
881 if (destination.IsBroadcast())
891 int32_t islInterfaceIndex =
m_arbiter->BaseDecide(packet, destination);
893 if (islInterfaceIndex < 0)
895 NS_LOG_INFO(
"Cannot route packet form node " <<
m_nodeId <<
" to " << destination);
899 NS_FATAL_ERROR(
"Incorrect interface index from arbiter: "
911 NS_LOG_FUNCTION(
this << packet << destination);
913 if (destination.IsBroadcast())
930 if (!packet->PeekPacketTag(satUplinkInfoTag))
932 NS_FATAL_ERROR(
"SatUplinkInfoTag not found");
942 ->EnquePacket(packet);
946 if (
m_utConnected.count(destination) > 0 || destination.IsBroadcast())
949 if (!packet->PeekPacketTag(satUplinkInfoTag))
951 NS_FATAL_ERROR(
"SatUplinkInfoTag not found");
962 ->EnquePacket(packet);
964 if ((
m_utConnected.count(destination) == 0 || destination.IsBroadcast()) &&
This class implements a tag that carries the satellite MAC of GW and UT.
void SetE2ESourceAddress(Mac48Address e2eSourceAddress)
Set E2E source MAC address.
Mac48Address GetE2ESourceAddress(void) const
Get E2E source MAC address.
void SetE2EDestAddress(Mac48Address e2eDestAddress)
Set E2E destination MAC address.
Mac48Address GetE2EDestAddress(void) const
Get E2E destination MAC address.
This class implements a tag that carries the MAC address of the sender of the packet.
This class implements a tag that is used to identify control messages (packages).
void SetMsgType(SatControlMsgType_t type)
Set type of the control message.
virtual void SetMsgId(uint32_t msgId)
Set message type specific identifier.
Time tag used to identify the time when packet is enqueued at device level.
Time GetSenderTimestamp(void) const
Get sender time stamp of this tag.
SatLinkDir_t
Link direction used for packet tracing.
RegenerationMode_t
The regeneration mode used in satellites.
bool m_isStatisticsTagsEnabled
void ReceiveFromIsl(Ptr< Packet > packet, Mac48Address destination)
Receive a packet from ISL.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual uint16_t GetMtu(void) const
Mac48Address GetSatelliteFeederAddress(uint32_t beamId)
Get satellite feeder entry from associated beam ID.
virtual Address GetAddress(void) const
TracedCallback< const Time &, const Address & > m_rxFeederLinkJitterTrace
Traced callback for all received packets, including feeder link jitter information and the address of...
virtual bool IsBridge(void) const
Ptr< SatIslArbiter > GetArbiter()
Get the arbiter for ISL routing.
std::map< Mac48Address, Time > m_lastDelays
SatGeoNetDevice()
Default constructor.
std::map< uint32_t, Ptr< SatMac > > GetAllFeederMac()
Get all Feeder MAC objects attached to this satellite.
SatEnums::RegenerationMode_t m_returnLinkRegenerationMode
void DisconnectGw(Mac48Address gwAddress)
Disconnect a GW to this satellite.
SatEnums::RegenerationMode_t m_forwardLinkRegenerationMode
std::set< Mac48Address > m_utConnected
Set containing all connected UTs.
virtual bool SetMtu(const uint16_t mtu)
void AddUserPhy(Ptr< SatPhy > phy, uint32_t beamId)
Add the User Phy object for the beam.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual void SetAddress(Address address)
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
void AddIslsNetDevice(Ptr< PointToPointIslNetDevice > islNetDevices)
Add a ISL Net Device to this satellite.
NetDevice::PromiscReceiveCallback m_promiscCallback
std::map< uint32_t, Ptr< SatPhy > > m_userPhy
std::map< uint32_t, Ptr< SatMac > > m_userMac
std::map< uint32_t, Ptr< SatPhy > > GetFeederPhy()
Get all Feeder Phy objects attached to this satellite.
Address GetRxUtAddress(Ptr< Packet > packet, SatEnums::SatLinkDir_t ld)
Get UT MAC address associated to this packet.
static TypeId GetTypeId(void)
Get the type ID.
std::set< Mac48Address > m_gwConnected
Set containing all connected GWs.
void SetForwardLinkRegenerationMode(SatEnums::RegenerationMode_t forwardLinkRegenerationMode)
Set the forward link regeneration mode.
virtual bool SupportsSendFrom(void) const
std::map< uint32_t, Ptr< SatMac > > m_allFeederMac
void SetArbiter(Ptr< SatIslArbiter > arbiter)
Set the arbiter for ISL routing.
std::set< uint32_t > m_broadcastReceived
Keep a count of all incoming broadcast data to avoid handling them several times.
TracedCallback< Ptr< const Packet >, const Address & > m_signallingTxTrace
Traced callback for all signalling (control message) packets sent, including the destination address.
std::map< uint32_t, Ptr< SatPhy > > m_feederPhy
std::set< Mac48Address > GetUtConnected()
The the list of UT MAC connected to this satellite.
virtual void SetIfIndex(const uint32_t index)
virtual bool IsMulticast(void) const
void ReceivePacketFeeder(Ptr< Packet > packet, const Address &feederAddress)
Receive the packet from the lower layers, in network regeneration on forward link.
void SendToIsl(Ptr< Packet > packet, Mac48Address destination)
Send a packet to ISL.
virtual Address GetBroadcast(void) const
virtual bool IsLinkUp(void) const
void ConnectUt(Mac48Address utAddress)
Connect a UT to this satellite.
void AddFeederMac(Ptr< SatMac > mac, Ptr< SatMac > macUsed, uint32_t beamId)
Add the Feeder MAC object for the beam.
void AddUserMac(Ptr< SatMac > mac, uint32_t beamId)
Add the User MAC object for the beam.
std::map< uint32_t, Ptr< SatMac > > GetUserMac()
Get all User MAC objects attached to this satellite.
std::map< uint32_t, Mac48Address > m_addressMapFeeder
Ptr< ErrorModel > m_receiveErrorModel
void AddFeederPair(uint32_t beamId, Mac48Address satelliteFeederAddress)
Add an entry in the database to get satellite feeder address from beam ID.
virtual void DoDispose(void)
Dispose of this class instance.
std::map< uint32_t, Ptr< SatMac > > GetFeederMac()
Get all Feeder MAC objects attached to this satellite that are in use.
virtual bool NeedsArp(void) const
virtual uint32_t GetIfIndex(void) const
TracedCallback< const Time &, const Address & > m_rxFeederLinkDelayTrace
Traced callback for all received packets, including feeder link delay information and the address of ...
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SatGeoNetDevice.
void DisconnectUt(Mac48Address utAddress)
Disconnect a UT to this satellite.
bool SendControlMsgToFeeder(Ptr< SatControlMessage > msg, const Address &dest, Ptr< SatSignalParameters > rxParams)
Send a control packet on the feeder link.
std::vector< Ptr< PointToPointIslNetDevice > > m_islNetDevices
List of ISLs starting from this node.
Ptr< SatIslArbiter > m_arbiter
Arbiter used to route on ISLs.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced callback for all packets received to be transmitted.
virtual Ptr< Node > GetNode(void) const
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual void SetNode(Ptr< Node > node)
void SetReturnLinkRegenerationMode(SatEnums::RegenerationMode_t returnLinkRegenerationMode)
Set the return link regeneration mode.
virtual bool IsPointToPoint(void) const
std::vector< Ptr< PointToPointIslNetDevice > > GetIslsNetDevices()
Get all the ISL Net devices.
TracedCallback< const Time &, const Address & > m_rxUserLinkJitterTrace
Traced callback for all received packets, including user link jitter information and the address of t...
void ReceiveUser(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters > rxParams)
Receive the packet from the lower layers.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
void ReceivePacketUser(Ptr< Packet > packet, const Address &userAddress)
Receive the packet from the lower layers, in network regeneration on return link.
void ConnectGw(Mac48Address gwAddress)
Connect a GW to this satellite.
TracedCallback< const Time &, const Address & > m_rxUserLinkDelayTrace
Traced callback for all received packets, including user link delay information and the address of th...
std::set< Mac48Address > GetGwConnected()
The the list of MAC GW connected to this satellite.
void SetNodeId(uint32_t nodeId)
TracedCallback< Time, SatEnums::SatPacketEvent_t, SatEnums::SatNodeType_t, uint32_t, Mac48Address, SatEnums::SatLogLevel_t, SatEnums::SatLinkDir_t, std::string > m_packetTrace
void ReceiveFeeder(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters > rxParams)
Receive the packet from the lower layers.
virtual bool IsBroadcast(void) const
virtual Ptr< Channel > GetChannel(void) const
void AddFeederPhy(Ptr< SatPhy > phy, uint32_t beamId)
Add the Feeder Phy object for the beam.
std::map< uint32_t, Ptr< SatPhy > > GetUserPhy()
Get all User Phy objects attached to this satellite.
TracedCallback< Ptr< const Packet >, const Address & > m_rxUserTrace
Traced callback for all received packets on user, including the address of the senders.
std::map< uint32_t, Ptr< SatMac > > m_feederMac
TracedCallback< Ptr< const Packet >, const Address & > m_rxFeederTrace
Traced callback for all received packets on feeder, including the address of the senders.
Tag to store ground station destination address.
Mac48Address GetGroundStationAddress(void) const
Get the ground station MAC address.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
void SetDestAddress(Mac48Address dest)
Set destination MAC address.
void SetSourceAddress(Mac48Address source)
Set source MAC address.
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
Tag to store uplink phy info that need to be forwarded to the downlink.
void SetSinr(double sinr, double additionalInterference)
Set uplink SINR.
void SetBeamId(uint32_t beamId)
Set the UT beam ID.
uint32_t GetBeamId(void) const
Get the UT beam ID.
void SetSatId(uint32_t satId)
Set the UT sat ID.
static std::string GetPacketInfo(const Ptr< const Packet > p)
Get packet information in std::string for printing purposes.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.