satellite-geo-net-device.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
22 
23 #include "satellite-address-tag.h"
24 #include "satellite-channel.h"
27 #include "satellite-geo-user-mac.h"
28 #include "satellite-geo-user-phy.h"
30 #include "satellite-id-mapper.h"
31 #include "satellite-mac.h"
32 #include "satellite-phy-rx.h"
33 #include "satellite-phy-tx.h"
34 #include "satellite-phy.h"
35 #include "satellite-time-tag.h"
37 
38 #include <ns3/channel.h>
39 #include <ns3/error-model.h>
40 #include <ns3/ipv4-header.h>
41 #include <ns3/ipv4-l3-protocol.h>
42 #include <ns3/log.h>
43 #include <ns3/node.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>
50 
51 NS_LOG_COMPONENT_DEFINE("SatGeoNetDevice");
52 
53 namespace ns3
54 {
55 
56 NS_OBJECT_ENSURE_REGISTERED(SatGeoNetDevice);
57 
58 TypeId
60 {
61  static TypeId tid =
62  TypeId("ns3::SatGeoNetDevice")
63  .SetParent<NetDevice>()
64  .AddConstructor<SatGeoNetDevice>()
65  .AddAttribute("ReceiveErrorModel",
66  "The receiver error model used to simulate packet loss",
67  PointerValue(),
68  MakePointerAccessor(&SatGeoNetDevice::m_receiveErrorModel),
69  MakePointerChecker<ErrorModel>())
70  .AddAttribute("UserPhy",
71  "The User Phy objects attached to this device.",
72  ObjectMapValue(),
73  MakeObjectMapAccessor(&SatGeoNetDevice::m_userPhy),
74  MakeObjectMapChecker<SatPhy>())
75  .AddAttribute("FeederPhy",
76  "The Feeder Phy objects attached to this device.",
77  ObjectMapValue(),
78  MakeObjectMapAccessor(&SatGeoNetDevice::m_feederPhy),
79  MakeObjectMapChecker<SatPhy>())
80  .AddAttribute("UserMac",
81  "The User MAC objects attached to this device.",
82  ObjectMapValue(),
83  MakeObjectMapAccessor(&SatGeoNetDevice::m_userMac),
84  MakeObjectMapChecker<SatMac>())
85  .AddAttribute("FeederMac",
86  "The Feeder MAC objects attached to this device.",
87  ObjectMapValue(),
88  MakeObjectMapAccessor(&SatGeoNetDevice::m_feederMac),
89  MakeObjectMapChecker<SatMac>())
90  .AddAttribute("EnableStatisticsTags",
91  "If true, some tags will be added to each transmitted packet to assist "
92  "with statistics computation",
93  BooleanValue(false),
94  MakeBooleanAccessor(&SatGeoNetDevice::m_isStatisticsTagsEnabled),
95  MakeBooleanChecker())
96  .AddTraceSource("PacketTrace",
97  "Packet event trace",
98  MakeTraceSourceAccessor(&SatGeoNetDevice::m_packetTrace),
99  "ns3::SatTypedefs::PacketTraceCallback")
100  .AddTraceSource("Tx",
101  "A packet to be sent",
102  MakeTraceSourceAccessor(&SatGeoNetDevice::m_txTrace),
103  "ns3::Packet::TracedCallback")
104  .AddTraceSource("SignallingTx",
105  "A signalling packet to be sent",
106  MakeTraceSourceAccessor(&SatGeoNetDevice::m_signallingTxTrace),
107  "ns3::SatTypedefs::PacketDestinationAddressCallback")
108  .AddTraceSource("RxFeeder",
109  "A packet received on feeder",
110  MakeTraceSourceAccessor(&SatGeoNetDevice::m_rxFeederTrace),
111  "ns3::SatTypedefs::PacketSourceAddressCallback")
112  .AddTraceSource("RxUser",
113  "A packet received on user",
114  MakeTraceSourceAccessor(&SatGeoNetDevice::m_rxUserTrace),
115  "ns3::SatTypedefs::PacketSourceAddressCallback")
116  .AddTraceSource("RxFeederLinkDelay",
117  "A packet is received with feeder link delay information",
118  MakeTraceSourceAccessor(&SatGeoNetDevice::m_rxFeederLinkDelayTrace),
119  "ns3::SatTypedefs::PacketDelayAddressCallback")
120  .AddTraceSource("RxFeederLinkJitter",
121  "A packet is received with feeder link jitter information",
122  MakeTraceSourceAccessor(&SatGeoNetDevice::m_rxFeederLinkJitterTrace),
123  "ns3::SatTypedefs::PacketJitterAddressCallback")
124  .AddTraceSource("RxUserLinkDelay",
125  "A packet is received with feeder link delay information",
126  MakeTraceSourceAccessor(&SatGeoNetDevice::m_rxUserLinkDelayTrace),
127  "ns3::SatTypedefs::PacketDelayAddressCallback")
128  .AddTraceSource("RxUserLinkJitter",
129  "A packet is received with feeder link jitter information",
130  MakeTraceSourceAccessor(&SatGeoNetDevice::m_rxUserLinkJitterTrace),
131  "ns3::SatTypedefs::PacketJitterAddressCallback");
132  return tid;
133 }
134 
136  : m_node(0),
137  m_mtu(0xffff),
138  m_ifIndex(0)
139 {
140  NS_LOG_FUNCTION(this);
141 }
142 
143 void
144 SatGeoNetDevice::ReceivePacketUser(Ptr<Packet> packet, const Address& userAddress)
145 {
146  NS_LOG_FUNCTION(this << packet);
147  NS_LOG_INFO("Receiving a packet: " << packet->GetUid());
148 
149  Mac48Address macUserAddress = Mac48Address::ConvertFrom(userAddress);
150 
151  m_packetTrace(Simulator::Now(),
154  m_nodeId,
155  macUserAddress,
158  SatUtils::GetPacketInfo(packet));
159 
160  /*
161  * Invoke the `Rx` and `RxDelay` trace sources. We look at the packet's tags
162  * for information, but cannot remove the tags because the packet is a const.
163  */
165  {
166  Address addr = GetRxUtAddress(packet, SatEnums::LD_RETURN);
167 
168  m_rxUserTrace(packet, addr);
169 
170  SatDevLinkTimeTag linkTimeTag;
171  if (packet->RemovePacketTag(linkTimeTag))
172  {
173  NS_LOG_DEBUG(this << " contains a SatDevLinkTimeTag tag");
174  Time delay = Simulator::Now() - linkTimeTag.GetSenderTimestamp();
175  m_rxUserLinkDelayTrace(delay, addr);
176  if (m_lastDelays[macUserAddress].IsZero() == false)
177  {
178  Time jitter = Abs(delay - m_lastDelays[macUserAddress]);
179  m_rxUserLinkJitterTrace(jitter, addr);
180  }
181  m_lastDelays[macUserAddress] = delay;
182  }
183  }
184 
185  SatGroundStationAddressTag groundStationAddressTag;
186  if (!packet->PeekPacketTag(groundStationAddressTag))
187  {
188  NS_FATAL_ERROR("SatGroundStationAddressTag not found");
189  }
190  Mac48Address destination = groundStationAddressTag.GetGroundStationAddress();
191 
192  if (m_gwConnected.count(destination))
193  {
194  SatUplinkInfoTag satUplinkInfoTag;
195  if (!packet->PeekPacketTag(satUplinkInfoTag))
196  {
197  NS_FATAL_ERROR("SatUplinkInfoTag not found");
198  }
199 
201  {
202  // Add a SatDevLinkTimeTag tag for packet link delay computation at the receiver end.
203  packet->AddPacketTag(SatDevLinkTimeTag(Simulator::Now()));
204  }
205 
206  DynamicCast<SatGeoFeederMac>(m_feederMac[satUplinkInfoTag.GetBeamId()])
207  ->EnquePacket(packet);
208  }
209  else
210  {
211  if (m_islNetDevices.size() > 0)
212  {
213  SendToIsl(packet, destination);
214  }
215  }
216 }
217 
218 void
219 SatGeoNetDevice::ReceivePacketFeeder(Ptr<Packet> packet, const Address& feederAddress)
220 {
221  NS_LOG_FUNCTION(this << packet);
222  NS_LOG_INFO("Receiving a packet: " << packet->GetUid());
223 
224  Mac48Address macFeederAddress = Mac48Address::ConvertFrom(feederAddress);
225 
226  m_packetTrace(Simulator::Now(),
229  m_nodeId,
230  macFeederAddress,
233  SatUtils::GetPacketInfo(packet));
234 
235  /*
236  * Invoke the `Rx` and `RxDelay` trace sources. We look at the packet's tags
237  * for information, but cannot remove the tags because the packet is a const.
238  */
240  {
241  Address addr = GetRxUtAddress(packet, SatEnums::LD_FORWARD);
242 
243  m_rxFeederTrace(packet, addr);
244 
245  SatDevLinkTimeTag linkTimeTag;
246  if (packet->RemovePacketTag(linkTimeTag))
247  {
248  NS_LOG_DEBUG(this << " contains a SatDevLinkTimeTag tag");
249  Time delay = Simulator::Now() - linkTimeTag.GetSenderTimestamp();
250  m_rxFeederLinkDelayTrace(delay, addr);
251  if (m_lastDelays[macFeederAddress].IsZero() == false)
252  {
253  Time jitter = Abs(delay - m_lastDelays[macFeederAddress]);
254  m_rxFeederLinkJitterTrace(jitter, addr);
255  }
256  m_lastDelays[macFeederAddress] = delay;
257  }
258  }
259 
260  SatGroundStationAddressTag groundStationAddressTag;
261  if (!packet->PeekPacketTag(groundStationAddressTag))
262  {
263  NS_FATAL_ERROR("SatGroundStationAddressTag not found");
264  }
265  Mac48Address destination = groundStationAddressTag.GetGroundStationAddress();
266 
267  if (destination.IsBroadcast())
268  {
269  m_broadcastReceived.insert(packet->GetUid());
270  }
271 
272  if (m_utConnected.count(destination) > 0 || destination.IsBroadcast())
273  {
274  SatUplinkInfoTag satUplinkInfoTag;
275  if (!packet->PeekPacketTag(satUplinkInfoTag))
276  {
277  NS_FATAL_ERROR("SatUplinkInfoTag not found");
278  }
279 
281  {
282  // Add a SatDevLinkTimeTag tag for packet link delay computation at the receiver end.
283  packet->AddPacketTag(SatDevLinkTimeTag(Simulator::Now()));
284  }
285 
286  DynamicCast<SatGeoUserMac>(m_userMac[satUplinkInfoTag.GetBeamId()])->EnquePacket(packet);
287  }
288  if ((m_utConnected.count(destination) == 0 || destination.IsBroadcast()) &&
289  m_islNetDevices.size() > 0)
290  {
291  SendToIsl(packet, destination);
292  }
293 }
294 
295 void
297  Ptr<SatSignalParameters> rxParams)
298 {
299  NS_LOG_FUNCTION(this << rxParams->m_packetsInBurst.size() << rxParams);
300  NS_LOG_INFO("Receiving a packet at the satellite from user link");
301 
303  {
306  DynamicCast<SatGeoFeederPhy>(m_feederPhy[rxParams->m_beamId])->SendPduWithParams(rxParams);
307  break;
308  }
310  for (SatPhy::PacketContainer_t::const_iterator it = rxParams->m_packetsInBurst.begin();
311  it != rxParams->m_packetsInBurst.end();
312  ++it)
313  {
314  DynamicCast<SatGeoFeederMac>(m_feederMac[rxParams->m_beamId])->EnquePacket(*it);
315  }
316 
317  break;
318  }
320  NS_FATAL_ERROR(
321  "SatGeoNetDevice::ReceiveUser should not be used in case of network regeneration");
322  }
323  default: {
324  NS_FATAL_ERROR("Not implemented yet");
325  }
326  }
327 }
328 
329 void
331  Ptr<SatSignalParameters> rxParams)
332 {
333  NS_LOG_FUNCTION(this << rxParams->m_packetsInBurst.size() << rxParams);
334  NS_LOG_INFO("Receiving a packet at the satellite from feeder link");
335 
337  {
340  DynamicCast<SatGeoUserPhy>(m_userPhy[rxParams->m_beamId])->SendPduWithParams(rxParams);
341  break;
342  }
344  NS_FATAL_ERROR(
345  "SatGeoNetDevice::ReceiveFeeder should not be used in case of network regeneration");
346  }
347  default: {
348  NS_FATAL_ERROR("Not implemented yet");
349  }
350  }
351 }
352 
353 bool
354 SatGeoNetDevice::SendControlMsgToFeeder(Ptr<SatControlMessage> msg,
355  const Address& dest,
356  Ptr<SatSignalParameters> rxParams)
357 {
358  NS_LOG_FUNCTION(this << msg << dest);
359 
360  Ptr<Packet> packet = Create<Packet>(msg->GetSizeInBytes());
361 
363  {
364  // Add a SatAddressTag tag with this device's address as the source address.
365  packet->AddByteTag(SatAddressTag(m_address));
366 
367  // Add a SatDevLinkTimeTag tag for packet link delay computation at the receiver end.
368  packet->AddPacketTag(SatDevLinkTimeTag(Simulator::Now()));
369  }
370 
371  SatAddressE2ETag addressE2ETag;
372  addressE2ETag.SetE2ESourceAddress(m_address);
373  addressE2ETag.SetE2EDestAddress(Mac48Address::ConvertFrom(dest));
374  packet->AddPacketTag(addressE2ETag);
375 
376  SatMacTag macTag;
377  macTag.SetSourceAddress(m_address);
378  macTag.SetDestAddress(Mac48Address::ConvertFrom(dest));
379  packet->AddPacketTag(macTag);
380 
381  // Add control tag to message and write msg to container in MAC
382  SatControlMsgTag tag;
383  tag.SetMsgId(0);
384  tag.SetMsgType(msg->GetMsgType());
385  packet->AddPacketTag(tag);
386 
388  {
389  SatUplinkInfoTag satUplinkInfoTag;
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);
394  }
395 
396  rxParams->m_packetsInBurst.clear();
397  rxParams->m_packetsInBurst.push_back(packet);
398 
400  {
403  DynamicCast<SatGeoFeederPhy>(m_feederPhy[rxParams->m_beamId])->SendPduWithParams(rxParams);
404  break;
405  }
408  for (SatPhy::PacketContainer_t::const_iterator it = rxParams->m_packetsInBurst.begin();
409  it != rxParams->m_packetsInBurst.end();
410  ++it)
411  {
412  DynamicCast<SatGeoFeederMac>(m_feederMac[rxParams->m_beamId])->EnquePacket(*it);
413  }
414  break;
415  }
416  default: {
417  NS_FATAL_ERROR("Not implemented yet");
418  }
419  }
420 
421  return true;
422 }
423 
424 void
426 {
427  NS_LOG_FUNCTION(this << em);
428  m_receiveErrorModel = em;
429 }
430 
431 void
433  SatEnums::RegenerationMode_t forwardLinkRegenerationMode)
434 {
435  m_forwardLinkRegenerationMode = forwardLinkRegenerationMode;
436 }
437 
438 void
440  SatEnums::RegenerationMode_t returnLinkRegenerationMode)
441 {
442  m_returnLinkRegenerationMode = returnLinkRegenerationMode;
443 }
444 
445 void
447 {
448  m_nodeId = nodeId;
449 }
450 
451 void
452 SatGeoNetDevice::SetIfIndex(const uint32_t index)
453 {
454  NS_LOG_FUNCTION(this << index);
455  m_ifIndex = index;
456 }
457 
458 uint32_t
460 {
461  NS_LOG_FUNCTION(this);
462  return m_ifIndex;
463 }
464 
465 void
467 {
468  NS_LOG_FUNCTION(this << address);
469  m_address = Mac48Address::ConvertFrom(address);
470 }
471 
472 Address
474 {
475  //
476  // Implicit conversion from Mac48Address to Address
477  //
478  NS_LOG_FUNCTION(this);
479  return m_address;
480 }
481 
482 bool
483 SatGeoNetDevice::SetMtu(const uint16_t mtu)
484 {
485  NS_LOG_FUNCTION(this << mtu);
486  m_mtu = mtu;
487  return true;
488 }
489 
490 uint16_t
492 {
493  NS_LOG_FUNCTION(this);
494  return m_mtu;
495 }
496 
497 bool
499 {
500  NS_LOG_FUNCTION(this);
501  return true;
502 }
503 
504 void
506 {
507  NS_LOG_FUNCTION(this << &callback);
508 }
509 
510 bool
512 {
513  NS_LOG_FUNCTION(this);
514  return true;
515 }
516 
517 Address
519 {
520  NS_LOG_FUNCTION(this);
521  return Mac48Address("ff:ff:ff:ff:ff:ff");
522 }
523 
524 bool
526 {
527  NS_LOG_FUNCTION(this);
528  return false;
529 }
530 
531 Address
532 SatGeoNetDevice::GetMulticast(Ipv4Address multicastGroup) const
533 {
534  NS_LOG_FUNCTION(this << multicastGroup);
535  return Mac48Address::GetMulticast(multicastGroup);
536 }
537 
538 Address
539 SatGeoNetDevice::GetMulticast(Ipv6Address addr) const
540 {
541  NS_LOG_FUNCTION(this << addr);
542  return Mac48Address::GetMulticast(addr);
543 }
544 
545 bool
547 {
548  NS_LOG_FUNCTION(this);
549  return false;
550 }
551 
552 bool
554 {
555  NS_LOG_FUNCTION(this);
556  return false;
557 }
558 
559 bool
560 SatGeoNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
561 {
562  NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
563 
568  NS_ASSERT(false);
569  return false;
570 }
571 
572 bool
573 SatGeoNetDevice::SendFrom(Ptr<Packet> packet,
574  const Address& source,
575  const Address& dest,
576  uint16_t protocolNumber)
577 {
578  NS_LOG_FUNCTION(this << packet << source << dest << protocolNumber);
579 
584  NS_ASSERT(false);
585  return false;
586 }
587 
588 Ptr<Node>
590 {
591  NS_LOG_FUNCTION(this);
592  return m_node;
593 }
594 
595 void
597 {
598  NS_LOG_FUNCTION(this << node);
599  m_node = node;
600 }
601 
602 bool
604 {
605  NS_LOG_FUNCTION(this);
606  return false;
607 }
608 
609 void
610 SatGeoNetDevice::SetReceiveCallback(NetDevice::ReceiveCallback cb)
611 {
612  NS_LOG_FUNCTION(this << &cb);
613 }
614 
615 void
617 {
618  NS_LOG_FUNCTION(this);
619  m_node = 0;
621  m_userPhy.clear();
622  m_feederPhy.clear();
623  m_userMac.clear();
624  m_feederMac.clear();
625  m_addressMapFeeder.clear();
626  NetDevice::DoDispose();
627 }
628 
629 void
631 {
632  NS_LOG_FUNCTION(this << &cb);
633  m_promiscCallback = cb;
634 }
635 
636 bool
638 {
639  NS_LOG_FUNCTION(this);
640  return false;
641 }
642 
643 Ptr<Channel>
645 {
646  NS_LOG_FUNCTION(this);
647  return NULL;
648 }
649 
650 void
651 SatGeoNetDevice::AddUserPhy(Ptr<SatPhy> phy, uint32_t beamId)
652 {
653  NS_LOG_FUNCTION(this << phy << beamId);
654  m_userPhy.insert(std::pair<uint32_t, Ptr<SatPhy>>(beamId, phy));
655 }
656 
657 void
658 SatGeoNetDevice::AddFeederPhy(Ptr<SatPhy> phy, uint32_t beamId)
659 {
660  NS_LOG_FUNCTION(this << phy << beamId);
661  m_feederPhy.insert(std::pair<uint32_t, Ptr<SatPhy>>(beamId, phy));
662 }
663 
664 Ptr<SatPhy>
666 {
667  if (m_userPhy.count(beamId))
668  {
669  return m_userPhy[beamId];
670  }
671  NS_FATAL_ERROR("User Phy does not exist for beam " << beamId);
672 }
673 
674 Ptr<SatPhy>
676 {
677  if (m_userPhy.count(beamId))
678  {
679  return m_feederPhy[beamId];
680  }
681  NS_FATAL_ERROR("User Phy does not exist for beam " << beamId);
682 }
683 
684 std::map<uint32_t, Ptr<SatPhy>>
686 {
687  return m_userPhy;
688 }
689 
690 std::map<uint32_t, Ptr<SatPhy>>
692 {
693  return m_feederPhy;
694 }
695 
696 void
697 SatGeoNetDevice::AddUserMac(Ptr<SatMac> mac, uint32_t beamId)
698 {
699  NS_LOG_FUNCTION(this << mac << beamId);
700  m_userMac.insert(std::pair<uint32_t, Ptr<SatMac>>(beamId, mac));
701 }
702 
703 void
704 SatGeoNetDevice::AddFeederMac(Ptr<SatMac> mac, Ptr<SatMac> macUsed, uint32_t beamId)
705 {
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));
709 }
710 
711 Ptr<SatMac>
713 {
714  if (m_userMac.count(beamId))
715  {
716  return m_userMac[beamId];
717  }
718  NS_FATAL_ERROR("User MAC does not exist for beam " << beamId);
719 }
720 
721 Ptr<SatMac>
723 {
724  if (m_feederMac.count(beamId))
725  {
726  return m_feederMac[beamId];
727  }
728  NS_FATAL_ERROR("User MAC does not exist for beam " << beamId);
729 }
730 
731 std::map<uint32_t, Ptr<SatMac>>
733 {
734  return m_userMac;
735 }
736 
737 std::map<uint32_t, Ptr<SatMac>>
739 {
740  return m_feederMac;
741 }
742 
743 std::map<uint32_t, Ptr<SatMac>>
745 {
746  return m_allFeederMac;
747 }
748 
749 void
750 SatGeoNetDevice::AddFeederPair(uint32_t beamId, Mac48Address satelliteFeederAddress)
751 {
752  m_addressMapFeeder.insert(std::pair<uint32_t, Mac48Address>(beamId, satelliteFeederAddress));
753 }
754 
755 Mac48Address
757 {
758  if (m_addressMapFeeder.count(beamId))
759  {
760  return m_addressMapFeeder[beamId];
761  }
762  NS_FATAL_ERROR("Satellite MAC does not exist for GW " << beamId);
763 }
764 
765 Address
767 {
768  NS_LOG_FUNCTION(this << packet);
769 
770  Address utAddr; // invalid address.
771 
772  SatAddressE2ETag addressE2ETag;
773  if (packet->PeekPacketTag(addressE2ETag))
774  {
775  NS_LOG_DEBUG(this << " contains a SatE2E tag");
776  if (ld == SatEnums::LD_FORWARD)
777  {
778  utAddr = addressE2ETag.GetE2EDestAddress();
779  }
780  else if (ld == SatEnums::LD_RETURN)
781  {
782  utAddr = addressE2ETag.GetE2ESourceAddress();
783  }
784  }
785 
786  return utAddr;
787 }
788 
789 void
790 SatGeoNetDevice::ConnectGw(Mac48Address gwAddress)
791 {
792  NS_LOG_FUNCTION(this << gwAddress);
793 
794  m_gwConnected.insert(gwAddress);
795  Singleton<SatIdMapper>::Get()->AttachMacToSatIdIsl(gwAddress, m_nodeId);
796 }
797 
798 void
799 SatGeoNetDevice::DisconnectGw(Mac48Address gwAddress)
800 {
801  NS_LOG_FUNCTION(this << gwAddress);
802 
803  m_gwConnected.erase(gwAddress);
804  Singleton<SatIdMapper>::Get()->RemoveMacToSatIdIsl(gwAddress);
805 }
806 
807 std::set<Mac48Address>
809 {
810  NS_LOG_FUNCTION(this);
811 
812  return m_gwConnected;
813 }
814 
815 void
816 SatGeoNetDevice::ConnectUt(Mac48Address utAddress)
817 {
818  NS_LOG_FUNCTION(this << utAddress);
819 
820  m_utConnected.insert(utAddress);
821  Singleton<SatIdMapper>::Get()->AttachMacToSatIdIsl(utAddress, m_nodeId);
822 }
823 
824 void
825 SatGeoNetDevice::DisconnectUt(Mac48Address utAddress)
826 {
827  NS_LOG_FUNCTION(this << utAddress);
828 
829  m_utConnected.erase(utAddress);
830  Singleton<SatIdMapper>::Get()->RemoveMacToSatIdIsl(utAddress);
831 }
832 
833 std::set<Mac48Address>
835 {
836  NS_LOG_FUNCTION(this);
837 
838  return m_utConnected;
839 }
840 
841 void
842 SatGeoNetDevice::AddIslsNetDevice(Ptr<PointToPointIslNetDevice> islNetDevices)
843 {
844  NS_LOG_FUNCTION(this);
845 
846  m_islNetDevices.push_back(islNetDevices);
847 }
848 
849 std::vector<Ptr<PointToPointIslNetDevice>>
851 {
852  NS_LOG_FUNCTION(this);
853 
854  return m_islNetDevices;
855 }
856 
857 void
858 SatGeoNetDevice::SetArbiter(Ptr<SatIslArbiter> arbiter)
859 {
860  NS_LOG_FUNCTION(this << arbiter);
861 
862  m_arbiter = arbiter;
863 }
864 
865 Ptr<SatIslArbiter>
867 {
868  NS_LOG_FUNCTION(this);
869 
870  return m_arbiter;
871 }
872 
873 void
874 SatGeoNetDevice::SendToIsl(Ptr<Packet> packet, Mac48Address destination)
875 {
876  NS_LOG_FUNCTION(this << packet << destination);
877 
878  // If ISLs, arbiter must be set
879  NS_ASSERT_MSG(m_arbiter != nullptr, "Arbiter not set");
880 
881  if (destination.IsBroadcast())
882  {
883  // Send to all interfaces
884  for (uint32_t i = 0; i < m_islNetDevices.size(); i++)
885  {
886  m_islNetDevices[i]->Send(packet->Copy(), Address(), 0x0800);
887  }
888  return;
889  }
890 
891  int32_t islInterfaceIndex = m_arbiter->BaseDecide(packet, destination);
892 
893  if (islInterfaceIndex < 0)
894  {
895  NS_LOG_INFO("Cannot route packet form node " << m_nodeId << " to " << destination);
896  }
897  else if (uint32_t(islInterfaceIndex) >= m_islNetDevices.size())
898  {
899  NS_FATAL_ERROR("Incorrect interface index from arbiter: "
900  << islInterfaceIndex << ". Max is " << m_islNetDevices.size() - 1);
901  }
902  else
903  {
904  m_islNetDevices[islInterfaceIndex]->Send(packet, Address(), 0x0800);
905  }
906 }
907 
908 void
909 SatGeoNetDevice::ReceiveFromIsl(Ptr<Packet> packet, Mac48Address destination)
910 {
911  NS_LOG_FUNCTION(this << packet << destination);
912 
913  if (destination.IsBroadcast())
914  {
915  if (m_broadcastReceived.count(packet->GetUid()) > 0)
916  {
917  // Packet already received, drop it
918  return;
919  }
920  else
921  {
922  // Insert in list of receuived broadcast
923  m_broadcastReceived.insert(packet->GetUid());
924  }
925  }
926 
927  if (m_gwConnected.count(destination) > 0)
928  {
929  SatUplinkInfoTag satUplinkInfoTag;
930  if (!packet->PeekPacketTag(satUplinkInfoTag))
931  {
932  NS_FATAL_ERROR("SatUplinkInfoTag not found");
933  }
934 
936  {
937  // Add a SatDevLinkTimeTag tag for packet link delay computation at the receiver end.
938  packet->AddPacketTag(SatDevLinkTimeTag(Simulator::Now()));
939  }
940 
941  DynamicCast<SatGeoFeederMac>(m_feederMac[satUplinkInfoTag.GetBeamId()])
942  ->EnquePacket(packet);
943  }
944  else
945  {
946  if (m_utConnected.count(destination) > 0 || destination.IsBroadcast())
947  {
948  SatUplinkInfoTag satUplinkInfoTag;
949  if (!packet->PeekPacketTag(satUplinkInfoTag))
950  {
951  NS_FATAL_ERROR("SatUplinkInfoTag not found");
952  }
953 
954  if (m_isStatisticsTagsEnabled && !destination.IsBroadcast())
955  {
956  // Add a SatDevLinkTimeTag tag for packet link delay computation at the receiver
957  // end.
958  packet->AddPacketTag(SatDevLinkTimeTag(Simulator::Now()));
959  }
960 
961  DynamicCast<SatGeoUserMac>(m_userMac[satUplinkInfoTag.GetBeamId()])
962  ->EnquePacket(packet);
963  }
964  if ((m_utConnected.count(destination) == 0 || destination.IsBroadcast()) &&
965  m_islNetDevices.size() > 0)
966  {
967  SendToIsl(packet, destination);
968  }
969  }
970 }
971 
972 } // namespace ns3
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.
SatLinkDir_t
Link direction used for packet tracing.
RegenerationMode_t
The regeneration mode used in satellites.
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.
Definition: satellite-phy.h:78
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.