-
Notifications
You must be signed in to change notification settings - Fork 0
/
NanoNetDevice.cc
158 lines (114 loc) · 3.76 KB
/
NanoNetDevice.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* NanoNetDevice.cc
* Copyright (c) 2024 Technische Universität Berlin
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Created on: 2023. 12. 6.
* Author: Laurenz Ebner
*/
#include "NanoNetDevice.h"
namespace ns3 {
/*
TypeId
NanoNetDevice::GetTypeId()
{
static TypeId tid = TypeId("ns3::SimpleTag")
.SetParent<Tag>()
.SetGroupName("Network")
.AddConstructor<NanoNetDevice>();
return tid;
}
*/
NanoNetDevice::NanoNetDevice ()
{
m_channel = nullptr;
m_node = nullptr;
vector<int> zero_bits(TESTPACKETSIZE, 0);
vector<double> zero_samples(TESTPACKETSIZE, 0);
m_mac_phy_data = new MAC_PHY_DATA;
(*m_mac_phy_data).nanobot_ID = 0;
(*m_mac_phy_data).tissue_ID = 0;
(*m_mac_phy_data).PDU_RX = zero_bits;
(*m_mac_phy_data).PDU_TX = zero_bits;
(*m_mac_phy_data).SEQ_RX = zero_samples;
(*m_mac_phy_data).SEQ_TX = zero_samples;
}
NanoNetDevice::~NanoNetDevice ()
{
}
Address NanoNetDevice::GetAddress() const
{
return m_address;
}
void NanoNetDevice::SetAddress(Address address)
{
m_address = Mac48Address::ConvertFrom(address);
}
Ptr<Channel> NanoNetDevice::GetChannel() const
{
return m_channel;
}
Ptr<BVSChannel> NanoNetDevice::GetBVSChannel()
{
return m_channel;
}
void NanoNetDevice::SetChannel(Ptr<BVSChannel> channel)
{
m_channel = channel;
}
Ptr<Node> NanoNetDevice::GetNode() const
{
return m_node;
}
void NanoNetDevice::SetNode(Ptr<Node> node)
{
m_node = node;
}
bool NanoNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
{
return SendFrom(packet, m_address, dest, protocolNumber);
}
bool NanoNetDevice::SendFrom(Ptr<Packet> packet,
const Address& source,
const Address& dest,
uint16_t protocolNumber)
{
return false;
}
void NanoNetDevice::installToNode(Ptr<Node> node)
{
node->AddDevice(this);
}
void NanoNetDevice::createMacPhyData(int tissue_ID, int nanobot_ID){
vector<int> random_bits(TESTPACKETSIZE, 0);
vector<double> random_samples(TESTPACKETSIZE, 0);
// create random bit and apply OOK modulation scheme
for(int i = 0; i < TESTPACKETSIZE; i++ )
{
random_bits[i] = rand()%2;
if (random_bits[i] == 1)
random_samples[i] = 1;
else
random_samples[i] = -1;
}
(*m_mac_phy_data).PDU_TX = random_bits;
(*m_mac_phy_data).SEQ_TX = random_samples;
(*m_mac_phy_data).nanobot_ID = nanobot_ID;
(*m_mac_phy_data).tissue_ID = tissue_ID;
}
MAC_PHY_DATA *NanoNetDevice::getMacPhyData()
{
return m_mac_phy_data;
}
}