satellite-isl-arbiter-unicast.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  * Copyright (c) 2018 CNES
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Inspired and adapted from Hypatia: https://github.com/snkas/hypatia
20  *
21  * Author: Bastien Tauran <bastien.tauran@viveris.fr>
22  */
23 
24 #include <ns3/satellite-isl-arbiter-unicast.h>
25 
26 NS_LOG_COMPONENT_DEFINE("SatIslArbiterUnicast");
27 
28 namespace ns3
29 {
30 
31 NS_OBJECT_ENSURE_REGISTERED(SatIslArbiterUnicast);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId("ns3::SatIslArbiterUnicast")
37  .SetParent<SatIslArbiter>()
38  .AddConstructor<SatIslArbiterUnicast>();
39  return tid;
40 }
41 
43  : SatIslArbiter()
44 {
45  NS_LOG_FUNCTION(this);
46 
47  NS_FATAL_ERROR("Default constructor not in use");
48 }
49 
51  : SatIslArbiter(node)
52 {
53  NS_LOG_FUNCTION(this << node);
54 }
55 
56 SatIslArbiterUnicast::SatIslArbiterUnicast(Ptr<Node> node, std::map<uint32_t, uint32_t> nextHopMap)
57  : SatIslArbiter(node)
58 {
59  NS_LOG_FUNCTION(this << node);
60  m_nextHopMap = nextHopMap;
61 }
62 
63 int32_t
64 SatIslArbiterUnicast::Decide(int32_t sourceSatId, int32_t targetSatId, Ptr<Packet> pkt)
65 {
66  NS_LOG_FUNCTION(this << sourceSatId << targetSatId << pkt);
67 
68  if (m_nextHopMap.count(targetSatId) == 0)
69  {
70  return -1;
71  }
72  return m_nextHopMap[targetSatId];
73 }
74 
75 std::string
77 {
78  NS_LOG_FUNCTION(this);
79 
80  std::ostringstream res;
81  res << "Unicast state of node " << m_nodeId << std::endl;
82 
83  std::map<uint32_t, uint32_t>::iterator nextHopMapIterator;
84 
85  std::map<uint32_t, std::vector<uint32_t>> mapReversed;
86  std::map<uint32_t, std::vector<uint32_t>>::iterator mapReversedIterator;
87 
88  for (nextHopMapIterator = m_nextHopMap.begin(); nextHopMapIterator != m_nextHopMap.end();
89  nextHopMapIterator++)
90  {
91  if (mapReversed.count(nextHopMapIterator->second) == 0)
92  {
93  mapReversed[nextHopMapIterator->second] = std::vector<uint32_t>();
94  }
95  mapReversed[nextHopMapIterator->second].push_back(nextHopMapIterator->first);
96  }
97 
98  for (mapReversedIterator = mapReversed.begin(); mapReversedIterator != mapReversed.end();
99  mapReversedIterator++)
100  {
101  res << mapReversedIterator->first << " -> : {";
102  bool first = true;
103  for (uint32_t targetId : mapReversedIterator->second)
104  {
105  if (!first)
106  {
107  res << ",";
108  }
109  res << " " << targetId;
110  first = false;
111  }
112  res << "}" << std::endl;
113  }
114 
115  return res.str();
116 }
117 
118 void
119 SatIslArbiterUnicast::AddNextHopEntry(uint32_t destinationId, uint32_t netDeviceIndex)
120 {
121  NS_LOG_FUNCTION(this << destinationId << netDeviceIndex);
122 
123  m_nextHopMap.insert(std::make_pair(destinationId, netDeviceIndex));
124 }
125 
126 } // namespace ns3
int32_t Decide(int32_t sourceSatId, int32_t targetSatId, Ptr< Packet > pkt)
Decide how to forward.
std::string StringReprOfForwardingState()
Unicast routing table.
void AddNextHopEntry(uint32_t destinationId, uint32_t netDeviceIndex)
Add an entry on arbiter.
std::map< uint32_t, uint32_t > m_nextHopMap
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.