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 
25 
26 #include <iostream>
27 #include <map>
28 #include <sstream>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 NS_LOG_COMPONENT_DEFINE("SatIslArbiterUnicast");
34 
35 namespace ns3
36 {
37 
38 NS_OBJECT_ENSURE_REGISTERED(SatIslArbiterUnicast);
39 
40 TypeId
42 {
43  static TypeId tid = TypeId("ns3::SatIslArbiterUnicast")
44  .SetParent<SatIslArbiter>()
45  .AddConstructor<SatIslArbiterUnicast>();
46  return tid;
47 }
48 
50  : SatIslArbiter()
51 {
52  NS_LOG_FUNCTION(this);
53 
54  NS_FATAL_ERROR("Default constructor not in use");
55 }
56 
58  : SatIslArbiter(node)
59 {
60  NS_LOG_FUNCTION(this << node);
61 }
62 
63 SatIslArbiterUnicast::SatIslArbiterUnicast(Ptr<Node> node, std::map<uint32_t, uint32_t> nextHopMap)
64  : SatIslArbiter(node)
65 {
66  NS_LOG_FUNCTION(this << node);
67  m_nextHopMap = nextHopMap;
68 }
69 
70 int32_t
71 SatIslArbiterUnicast::Decide(int32_t sourceSatId, int32_t targetSatId, Ptr<Packet> pkt)
72 {
73  NS_LOG_FUNCTION(this << sourceSatId << targetSatId << pkt);
74 
75  if (m_nextHopMap.count(targetSatId) == 0)
76  {
77  return -1;
78  }
79  return m_nextHopMap[targetSatId];
80 }
81 
82 std::string
84 {
85  NS_LOG_FUNCTION(this);
86 
87  std::ostringstream res;
88  res << "Unicast state of node " << m_nodeId << std::endl;
89 
90  std::map<uint32_t, uint32_t>::iterator nextHopMapIterator;
91 
92  std::map<uint32_t, std::vector<uint32_t>> mapReversed;
93  std::map<uint32_t, std::vector<uint32_t>>::iterator mapReversedIterator;
94 
95  for (nextHopMapIterator = m_nextHopMap.begin(); nextHopMapIterator != m_nextHopMap.end();
96  nextHopMapIterator++)
97  {
98  if (mapReversed.count(nextHopMapIterator->second) == 0)
99  {
100  mapReversed[nextHopMapIterator->second] = std::vector<uint32_t>();
101  }
102  mapReversed[nextHopMapIterator->second].push_back(nextHopMapIterator->first);
103  }
104 
105  for (mapReversedIterator = mapReversed.begin(); mapReversedIterator != mapReversed.end();
106  mapReversedIterator++)
107  {
108  res << mapReversedIterator->first << " -> : {";
109  bool first = true;
110  for (uint32_t targetId : mapReversedIterator->second)
111  {
112  if (!first)
113  {
114  res << ",";
115  }
116  res << " " << targetId;
117  first = false;
118  }
119  res << "}" << std::endl;
120  }
121 
122  return res.str();
123 }
124 
125 void
126 SatIslArbiterUnicast::AddNextHopEntry(uint32_t destinationId, uint32_t netDeviceIndex)
127 {
128  NS_LOG_FUNCTION(this << destinationId << netDeviceIndex);
129 
130  m_nextHopMap.insert(std::make_pair(destinationId, netDeviceIndex));
131 }
132 
133 } // 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.