-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBiomarkerNetDevice.cc
138 lines (114 loc) · 4.18 KB
/
BiomarkerNetDevice.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
/*
* NanoNetDevice.h
* 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: 2024. 04. 15.
* Author: Saswati Pal
*/
#include "BiomarkerNetDevice.h"
#include "BiomarkerChannel.h"
#include "NanoNetDevice.h"
#include "ns3/log.h"
#include "ns3/address.h"
#include "ns3/packet.h"
#include "ns3/node.h"
#include "ns3/mobility-module.h"
#include "Constants.h"
#include "Biomarker.h"
#include "Bloodvessel.h"
#include "Nanobot.h"
namespace ns3 {
NS_LOG_COMPONENT_DEFINE("BiomarkerNetDevice");
// Constructor /// BiomarkerNetDevice::BiomarkerNetDevice()
BiomarkerNetDevice::BiomarkerNetDevice()
: m_address(Mac48Address::Allocate()),
m_channel(nullptr),
m_node(nullptr),
m_biomarker(nullptr) {}
/**BiomarkerNetDevice::BiomarkerNetDevice(Ptr<Biomarker> biomarker) : m_biomarker(biomarker)
{
m_channel = nullptr;
m_node = nullptr;
} **/
// Destructor
BiomarkerNetDevice::~BiomarkerNetDevice() {}
// Set the BiomarkerChannel
void BiomarkerNetDevice::SetChannel(Ptr<BiomarkerChannel> channel) {
NS_LOG_FUNCTION(this);
m_channel = channel;
}
// Get the BiomarkerChannel
Ptr<BiomarkerChannel> BiomarkerNetDevice::GetBiomarkerChannel() {
NS_LOG_FUNCTION(this);
return m_channel;
}
// Install the device to the node
void BiomarkerNetDevice::InstallToNode(Ptr<Node> node) {
NS_LOG_FUNCTION(this);
m_node = node;
}
Ptr<Biomarker> BiomarkerNetDevice::GetBiomarker() {
return m_biomarker; // We have a member variable 'm_biomarker' in the BiomarkerNetDevice class to store the associated Biomarker
}
/** Ptr<Packet> BiomarkerNetDevice::GetPacket()
{
return packet; // Return the packet
} **/
// Transmit biomarker data over the channel
bool BiomarkerNetDevice::Send(Ptr<ns3::Packet> packet, const Address& dest, uint16_t protocolNumber)
{
return SendFrom(packet, m_address, dest, protocolNumber);
}
bool BiomarkerNetDevice::SendFrom(Ptr<ns3::Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
{
NS_LOG_FUNCTION(this << packet << source << dest << protocolNumber);
// Ensure the Biomarker is correctly attached to a Bloodvessel
Ptr<Bloodvessel> bloodvessel = m_node->GetObject<Biomarker>()->GetObject<Bloodvessel>();
if (!bloodvessel) {
NS_LOG_ERROR("BiomarkerNetDevice::SendFrom: Bloodvessel not found for biomarker.");
return false;
}
Ptr<Biomarker> biomarker = m_node->GetObject<Biomarker>();
// Get list of nearby nanobot IDs
std::list<int> nearbyNanobotIds = bloodvessel->IsNanobotInRange(biomarker, ns3::COMMUNICATION_THRESHOLD);
if (!nearbyNanobotIds.empty()) {
// Use the channel to transmit the data to nearby nanobots
m_channel->SendToNanobots(packet, biomarker);
// Log successful transmission
NS_LOG_INFO("Biomarker " << biomarker->GetBiomarkerID() << " sent data to nanobots in vessel "
<< bloodvessel->GetbloodvesselID());
return true;
} else {
NS_LOG_WARN("BiomarkerNetDevice: No nanobot in range for data transmission.");
return false;
}
}
// Override functions from the NetDevice base class (dummy implementations)
Ptr<Channel> BiomarkerNetDevice::GetChannel() const {
return m_channel;
}
void BiomarkerNetDevice::SetAddress(Address address) {
m_address = Mac48Address::ConvertFrom(address);
}
Address BiomarkerNetDevice::GetAddress() const {
return m_address;
}
Ptr<Node> BiomarkerNetDevice::GetNode() const {
return m_node;
}
void BiomarkerNetDevice::SetNode(Ptr<Node> node) {
m_node = node;
}
} // namespace ns3