A Discrete-Event Network Simulator
API
sink.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 
3 
4 /*
5 * Copyright (c) 2020 DLTLT
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation;
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Corresponding author: Niki Hrovatin <niki.hrovatin@famnit.upr.si>
21 */
22 
23 
24 #ifndef SINK_H
25 #define SINK_H
26 
27 #include <sodium.h>
28 
29 #include <assert.h> /* assert */
30 #include <iostream>
31 #include <map>
32 
33 #include "ns3/wsn_node.h"
34 #include "ns3/proto-packet.pb.h"
35 #include "ns3/serializationwrapper.h"
36 #include "ns3/network-module.h"
37 #include "ns3/enums.h"
38 
39 namespace ns3 {
40 
49 class Sink : public Wsn_node
50 {
51 public:
56  static TypeId GetTypeId (void);
57 
63  Sink ();
64 
70  virtual ~Sink ();
71 
82  void Setup (uint16_t *onionPathlengths, uint16_t numOnionLengths, int repeateTimes);
83 
92  void Accept (Ptr<Socket> socket, const ns3::Address &from);
93 
99  void SinkTasks ();
100 
105  void CheckOnion (void);
106 
107 private:
118  virtual void StartApplication (void);
119 
125  virtual void StopApplication (void);
126 
138  void ReceivePacket (Ptr<Socket> socket);
139 
150  void RecvHandshake (protomessage::ProtoPacket_Handshake *handshake_data, InetSocketAddress from);
151 
162 
175  void SelectRoute (int *route, int routeLen);
176 
189  void PrepareOnion (int *route, int routeLen);
190 
204  void SendOnion (uint32_t firstHop, int routeLen, unsigned char *cipher, int cipherLen);
205 
206  uint16_t m_numnodes;
207  uint32_t m_onionDelay;
208  std::map<uint32_t, std::string>
210  uint32_t m_decoyNum =
211  1203;
212  bool
214  enum BodyOptions m_bodyOptions; //<! Specifies how the onion body must behave
215  uint16_t m_bodySize; //<! the onion body size in bytes if ns3::BodyOptions is set appropriately
216 
217  //simulation task
219  int m_repeateCount = 0;
221  uint16_t *m_onionPathLengths;
222  uint16_t m_numOnionLengths;
223 
224  //onion sequence number
225  int m_onionId = 1;
226 
227  //VErbosity of onion
228  std::stringstream m_onionStream;
229 
230  //sink node keys
231  std::string m_publickey;
232  std::string m_secretkey;
233 };
234 
235 } // namespace ns3
236 
237 #endif /* SINK_H */
ns3::Sink::SendOnion
void SendOnion(uint32_t firstHop, int routeLen, unsigned char *cipher, int cipherLen)
The method constructs the onion message as a protobuf object.
Definition: sink.cc:272
ns3::Sink::m_onionId
int m_onionId
onion ID incremented each time a new onion is issued
Definition: sink.h:225
ns3::Sink::m_publickey
std::string m_publickey
the encryption key: publickey
Definition: sink.h:231
ns3
Definition: sensornode-helper.cc:26
ns3::BodyOptions
BodyOptions
Specifies how the onion body must behave.
Definition: enums.h:106
ns3::Sink::m_bodySize
uint16_t m_bodySize
Definition: sink.h:215
ns3::Sink::m_repeateTimes
int m_repeateTimes
Integer specifying the number of times to generate the onion message for each value in the m_onionPat...
Definition: sink.h:218
ns3::Sink::m_onionStream
std::stringstream m_onionStream
a string stream holding the onion represented as a string
Definition: sink.h:228
ns3::Sink::Setup
void Setup(uint16_t *onionPathlengths, uint16_t numOnionLengths, int repeateTimes)
Setup sink node parameters after the application installation.
Definition: sink.cc:73
ns3::Sink::m_decoyNum
uint32_t m_decoyNum
dummy decoy value used to obfuscate the value carried in the onion body
Definition: sink.h:210
ns3::Sink::m_repeateCount
int m_repeateCount
how many times the onion was sent at the current path length
Definition: sink.h:219
ns3::Sink::m_onionDelay
uint32_t m_onionDelay
The sink will start sending onion messagess after OnionDelay seconds.
Definition: sink.h:207
ns3::Sink::StartApplication
virtual void StartApplication(void)
1.Start the application run ns3::Wsn_node::Configure() 2.Generate new encryption keys 3....
Definition: sink.cc:346
ns3::Sink::CheckOnion
void CheckOnion(void)
Each five seconds call the ns3::OnionValidator and check if at least one onion message is alive Other...
Definition: sink.cc:330
ns3::Sink::~Sink
virtual ~Sink()
Default destructor.
Definition: sink.cc:67
ns3::Sink::StopApplication
virtual void StopApplication(void)
Stop the application.
Definition: sink.cc:367
ns3::Sink::m_nodeManager
std::map< uint32_t, std::string > m_nodeManager
hashmap to manage data about nodes in the WSN// pair <IP,publickey>
Definition: sink.h:209
ns3::Sink::m_bodyOptions
enum BodyOptions m_bodyOptions
Definition: sink.h:214
protomessage::ProtoPacket_OnionBody
Definition: proto-packet.pb.h:271
ns3::Sink::m_fixedOnionSize
bool m_fixedOnionSize
maintain the onion size fixed by adding padding (after layer decryption)
Definition: sink.h:213
ns3::Sink::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: sink.cc:32
ns3::Wsn_node
The wsn node base class that manages the sending and receiving of packets and basic configuration of ...
Definition: wsn_node.h:61
ns3::Sink::RecvHandshake
void RecvHandshake(protomessage::ProtoPacket_Handshake *handshake_data, InetSocketAddress from)
When receiving a new handshake with a node.
Definition: sink.cc:142
ns3::Sink::Sink
Sink()
Default constructor.
Definition: sink.cc:63
ns3::Sink::m_secretkey
std::string m_secretkey
the encryption key: secretkey
Definition: sink.h:232
ns3::Sink::SinkTasks
void SinkTasks()
Schedule the creation of a new onion based on the path length specified in m_onionPathLengths If all ...
Definition: sink.cc:163
ns3::Sink
The application of the sink node. The node that generates onion messagess.
Definition: sink.h:49
ns3::Sink::m_numnodes
uint16_t m_numnodes
The number of sensor nodes in the simulation.
Definition: sink.h:206
protomessage::ProtoPacket_Handshake
Definition: proto-packet.pb.h:442
ns3::Sink::ReceivePacket
void ReceivePacket(Ptr< Socket > socket)
Recieve a new packet from socket Check if the packet is a handshake packet or a packet containing an ...
Definition: sink.cc:95
ns3::Sink::Accept
void Accept(Ptr< Socket > socket, const ns3::Address &from)
Accept new TCP connections.
Definition: sink.cc:87
ns3::Sink::m_onionLengthIndex
int m_onionLengthIndex
index of the current onion path length
Definition: sink.h:220
ns3::Sink::SelectRoute
void SelectRoute(int *route, int routeLen)
The method builds the path of the onion message by randomly selecting sensor nodes from the m_nodeMan...
Definition: sink.cc:202
ns3::Sink::PrepareOnion
void PrepareOnion(int *route, int routeLen)
Method that constructs the onion head from route and routeLen parameters.
Definition: sink.cc:230
ns3::Sink::m_onionPathLengths
uint16_t * m_onionPathLengths
array holding onion path lengths
Definition: sink.h:221
ns3::Sink::RecvOnion
void RecvOnion(protomessage::ProtoPacket_OnionBody *onion_body)
Triggered when an onion message is received back at the sink node Data about the message is captured ...
Definition: sink.cc:154
ns3::Sink::m_numOnionLengths
uint16_t m_numOnionLengths
size of the array m_onionPathsLengths
Definition: sink.h:222