|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
27 NS_OBJECT_ENSURE_REGISTERED (Sink);
29 NS_LOG_COMPONENT_DEFINE (
"sink");
37 .AddConstructor<Sink> ()
38 .AddAttribute (
"NumNodes",
"The number of sensor nodes in the simulation.",
39 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
41 MakeUintegerChecker<uint16_t> ())
43 "OnionDelay",
"The sink will start sending onion messagess after OnionDelay seconds.",
44 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET, UintegerValue (5),
46 .AddAttribute (
"FixedOnionSize",
"Maintain a fixed onion size by adding padding.",
47 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
49 MakeBooleanChecker ())
50 .AddAttribute (
"BodyOptions",
"Modify the behaviour of the onion body",
56 "BodySize",
"Size of the onion body maintained fixed during the simulation",
57 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET, UintegerValue (128),
73 Sink::Setup (uint16_t *onionPathlengths, uint16_t numOnionLengths,
int repeateTimes)
76 for (
int i = 0; i < numOnionLengths; ++i)
104 InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
106 p->RemoveHeader (sw);
131 NS_LOG_INFO (
"Ghost onion received, deleted with onion id: "
133 <<
", at time: " << std::to_string (Simulator::Now ().GetSeconds ()));
144 std::string pk = handshake_message->
publickey ();
205 assert (routeLen >= 3);
207 Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
214 int i = routeLen - 1;
218 if (node_id != prev_id)
233 unsigned char cipher[cipherLen];
235 unsigned char *ipRoute[routeLen + 1];
237 unsigned char *keys[routeLen + 1];
245 std::map<uint32_t, std::string>::iterator item;
248 for (
int i = 0; i < routeLen; ++i)
251 std::advance (item, route[i]);
261 std::advance (item, route[0]);
262 SendOnion (item->first, routeLen, cipher, cipherLen);
265 for (
int i = 0; i < routeLen; ++i)
272 Sink::SendOnion (uint32_t firstHop,
int routeLen,
unsigned char *cipher,
int cipherLen)
308 Ptr<Packet> p = Create<Packet> ();
311 InetSocketAddress remote = InetSocketAddress (Ipv4Address (firstHop),
m_port);
355 m_socket->SetAcceptCallback (MakeNullCallback<
bool, Ptr<Socket>,
const Address &> (),
void SendOnion(uint32_t firstHop, int routeLen, unsigned char *cipher, int cipherLen)
The method constructs the onion message as a protobuf object.
unsigned char * IpToBuff(uint32_t in)
Convert an Ipv4 address given as an unsigned integer value to buffer array of 4Bytes.
Ptr< Socket > m_socket
listening socket
::protomessage::ProtoPacket_Handshake * mutable_h_shake()
Ptr< Packet > RecvSegment(Ptr< Socket > socket)
method for receiving a segment calls ns3::Wsn_node::RecvSeg()
int m_onionId
onion ID incremented each time a new onion is issued
std::string GetPKtoString()
accessor
int o_sequenceNum
sequence number of the onion, should be same as onion_id
std::string m_publickey
the encryption key: publickey
void SendSegment(InetSocketAddress remote, Ptr< Packet > packet, bool b_onion)
Send a packet through a TCP connection to the remote address.
::protomessage::ProtoPacket_OnionBody * mutable_o_body()
size_t ByteSizeLong() const final
Ptr< OnionValidator > m_onionValidator
Pointer to the ns3::OnionValidator.
uint16_t OnionLength(uint16_t routeLen, uint16_t contentLen)
std::string UcharToString(unsigned char *seq, int len)
Convert an array of unsigned chars to a std::string.
unsigned char * StringToUchar(std::string in)
Convert a string to an array of unsigned chars.
int m_repeateTimes
Integer specifying the number of times to generate the onion message for each value in the m_onionPat...
Ipv4Address m_address
ns3::Ipv4Address of this node
std::string GetSKtoString()
accessor
void Setup(uint16_t *onionPathlengths, uint16_t numOnionLengths, int repeateTimes)
Setup sink node parameters after the application installation.
@ FixedSize
the onion body will have a fixed size specified by the ns3::Sink::BodySize attribute
uint32_t m_decoyNum
dummy decoy value used to obfuscate the value carried in the onion body
const std::string & publickey() const
int m_repeateCount
how many times the onion was sent at the current path length
uint32_t m_onionDelay
The sink will start sending onion messagess after OnionDelay seconds.
::protomessage::ProtoPacket_OnionHead * mutable_o_head()
virtual void StartApplication(void)
1.Start the application run ns3::Wsn_node::Configure() 2.Generate new encryption keys 3....
void CheckOnion(void)
Each five seconds call the ns3::OnionValidator and check if at least one onion message is alive Other...
void set_padding(ArgT0 &&arg0, ArgT... args)
void set_onion_message(ArgT0 &&arg0, ArgT... args)
virtual ~Sink()
Default destructor.
virtual void StopApplication(void)
Stop the application.
void NotifyRx(Ptr< const Packet > packet)
Call to signal the receipt of a Packet at the application layer.
OnionManager m_onionManager
The ns3::OnionManager object.
@ NO_Body
The onion message won't have an onion body.
Class for the serialization-deserialization of the messagess to send in packets.
@ Aggregate
The onion body will only aggregate a value.
std::map< uint32_t, std::string > m_nodeManager
hashmap to manage data about nodes in the WSN// pair <IP,publickey>
@ AggregateAndFixed
The onion body will aggregate a value and will maintain a fixed size apecified by the ns3::Sink::Body...
enum BodyOptions m_bodyOptions
Ptr< OutputManager > m_outputManager
Pointer to the ns3::OutputManager.
bool m_fixedOnionSize
maintain the onion size fixed by adding padding (after layer decryption)
uint16_t m_port
port of the application
static TypeId GetTypeId(void)
Register this type.
The wsn node base class that manages the sending and receiving of packets and basic configuration of ...
void GenerateNewKeyPair(void)
Generate a new public/private keypair using the libsodium library.
void RecvHandshake(protomessage::ProtoPacket_Handshake *handshake_data, InetSocketAddress from)
When receiving a new handshake with a node.
Sink()
Default constructor.
std::string m_secretkey
the encryption key: secretkey
int BuildOnion(uint8_t *cipher, uint8_t **route, uint16_t routeLen, uint8_t **keys, uint8_t *content, uint16_t contentLen)
void SinkTasks()
Schedule the creation of a new onion based on the path length specified in m_onionPathLengths If all ...
void NotifyTx(Ptr< const Packet > packet)
Call to signal the transmission of a Packet at the application layer.
uint16_t m_numnodes
The number of sensor nodes in the simulation.
void set_onionid(int32_t value)
void ReceivePacket(Ptr< Socket > socket)
Recieve a new packet from socket Check if the packet is a handshake packet or a packet containing an ...
void Accept(Ptr< Socket > socket, const ns3::Address &from)
Accept new TCP connections.
int m_onionLengthIndex
index of the current onion path length
void set_aggregatedvalue(int32_t value)
void set_padding(ArgT0 &&arg0, ArgT... args)
void OnionReceived(void)
Signal to the ns3::OnionValidator that the onion was corrctly received.
void SelectRoute(int *route, int routeLen)
The method builds the path of the onion message by randomly selecting sensor nodes from the m_nodeMan...
void PrepareOnion(int *route, int routeLen)
Method that constructs the onion head from route and routeLen parameters.
uint16_t * m_onionPathLengths
array holding onion path lengths
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 ...
void GetData(protomessage::ProtoPacket *message)
Getter of the data in the protocol header.
size_t ByteSizeLong() const final
uint16_t m_delay
delay after which the handshake process will start
uint16_t m_numOnionLengths
size of the array m_onionPathsLengths