A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
repository.cc
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * Author: Abdulla K. Al-Ali <abdulla.alali@qu.edu.qa>
16  */
17 
18 // Class Repository
19 // Cross-Layer Repository to enable channel information sharing between MAC and routing protocols
20 
21 #include "repository.h"
22 
23 NS_LOG_COMPONENT_DEFINE ("CogRepository");
24 
25 namespace ns3 {
26 
27 TypeId
28 Repository::GetTypeId (void)
29 {
30  static TypeId tid = TypeId ("ns3::Repository")
31  .SetParent<Object> ()
32  .AddConstructor<Repository> ()
33  ;
34  return tid;
35 }
36 
37 
38 // Initializer
39 Repository::Repository() {
40 
41  NS_LOG_FUNCTION (this);
42  // Set randomly the receiver channel for each node
43  for (int i=0; i<MAX_NODES; i++) {
44  int channel=GetRandomChannel();
45  m_repositoryTable[i].rxChannel= channel;
46  }
47  char mystring [50];
48  for (int i=0; i<5; i++) {
49  sprintf(mystring, "node %i got channel %i",i, m_repositoryTable[i].rxChannel);
50  NS_LOG_DEBUG(mystring);
51  }
52 
53  // Initialize each sending channel as NOT active for each node
54  for (int node=0; node<MAX_NODES; node++)
55  for (int channel=0; channel< MAX_CHANNELS; channel++)
56  m_repositoryTableSender[node][channel].active=false;
57 
58 
59 
60 }
61 
62 
63 
64 
65 //GetRxChannel: Return the receiving channel for a node
66 int
67 Repository::GetRxChannel(int node) {
68  if (node < MAX_NODES)
69  return m_repositoryTable[node].rxChannel;
70  else
71  return -1;
72 
73 }
74 
75 
76 //SetRxChannel: Set the receiving channel for a node
77 void
78 Repository::SetRxChannel(int node, int channel) {
79  if (node < MAX_NODES)
80  m_repositoryTable[node].rxChannel=channel;
81 
82 }
83 
84 
85 // UpdateTxChannel: Set the sending channel as active, at the current time
86 void
87 Repository::UpdateTxChannel(int node, int channel, double time) {
88 
89  if (node < MAX_NODES) {
90 
91  m_repositoryTableSender[node][channel].active=true;
92  m_repositoryTableSender[node][channel].time=time;
93 
94  }
95 
96 }
97 
98 //GetRandomChannel: Return a random channel between 1 and MAX_CHANNELS
99 int
100 Repository::GetRandomChannel() {
101  Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable>();
102  uv->SetAttribute ("Min", DoubleValue (1));
103  uv->SetAttribute ("Max", DoubleValue (MAX_CHANNELS));
104  int channel=uv->GetInteger();
105  if (channel >= MAX_CHANNELS)
106  channel = MAX_CHANNELS-1;
107  return channel;
108 }
109 
110 // Switchable Interface Implementation END
111 
112 
113 }
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_DEBUG(msg)
Definition: log.h:255