13#include "ns3/address.h"
15#include "ns3/nstime.h"
16#include "ns3/socket.h"
17#include "ns3/simulator.h"
18#include "ns3/packet.h"
19#include "ns3/uinteger.h"
20#include "ns3/trace-source-accessor.h"
38 static TypeId tid =
TypeId(
"ns3::QKDPostprocessingApplication")
40 .SetGroupName(
"Applications")
42 .AddAttribute(
"KeySize",
"The amount of data to be added to QKD Buffer(in bytes).",
46 .AddAttribute(
"KeyRate",
"The average QKD key rate.",
50 .AddAttribute(
"DataRate",
"The average data rate of communication.",
54 .AddAttribute(
"PacketSize",
"The size of packets sent in post-processing state",
58 .AddAttribute(
"MaxSiftingPackets",
"The size of packets sent in sifting state",
63 .AddAttribute(
"Protocol",
"The type of protocol to use(TCP by default).",
67 .AddAttribute(
"ProtocolSifting",
"The type of protocol to use for sifting(UDP by default).",
72 .AddAttribute(
"Remote",
"The address of the destination",
76 .AddAttribute(
"Local",
"The local address on which to bind the listening socket.",
80 .AddAttribute(
"Remote_Sifting",
"The address of the destination for sifting traffic.",
84 .AddAttribute(
"Local_Sifting",
"The local address on which to bind the listening sifting socket.",
88 .AddAttribute(
"Local_KMS",
"The local KSM address.",
92 .AddTraceSource(
"Tx",
"A new packet is created and is sent",
94 "ns3::QKDPostprocessingApplication::Tx")
95 .AddTraceSource(
"Rx",
"A packet has been received",
97 "ns3::QKDPostprocessingApplication::Rx")
98 .AddTraceSource(
"TxKMS",
"A new packet is created and is sent to LKMS",
100 "ns3::QKDPostprocessingApplication::TxKMS")
101 .AddTraceSource(
"RxKMS",
"A packet has been received from LKMS",
103 "ns3::QKDPostprocessingApplication::RxLKMS")
135 for(
size_t i = 0;
i <
padded.length();
i += 8) {
136 bytes +=
static_cast<char>(std::bitset<8>(
padded.substr(
i, 8)).to_ulong());
176 std::list<Ptr<Socket> >
264 Ptr<NetDevice>
netDevice = ipv4->GetNetDevice(interface);
268 MakeCallback(&QKDPostprocessingApplication::ConnectionSucceeded, this),
269 MakeCallback(&QKDPostprocessingApplication::ConnectionFailed, this)
272 MakeCallback(&QKDPostprocessingApplication::DataSend, this)
279 "Connecting QKDApp(" <<
280 InetSocketAddress::ConvertFrom(m_peer).GetIpv4() << " port " << InetSocketAddress::ConvertFrom(m_peer).GetPort() <<
282 InetSocketAddress::ConvertFrom(m_local).GetIpv4() << " port " << InetSocketAddress::ConvertFrom(m_local).GetPort()
288 if(!m_sinkSocket_sifting) m_sinkSocket_sifting = Socket::CreateSocket(GetNode(), m_tidSifting);
289 if(m_sinkSocket_sifting->Bind(m_local_sifting) == -1) NS_FATAL_ERROR("Failed to bind SIFTING socket " << m_local_sifting);
290 m_sinkSocket_sifting->Listen();
291 m_sinkSocket_sifting->ShutdownSend();
292 m_sinkSocket_sifting->SetRecvCallback(MakeCallback(&QKDPostprocessingApplication::HandleReadSifting, this));
295 if(!m_sendSocket_sifting) m_sendSocket_sifting = Socket::CreateSocket(GetNode(), m_tidSifting);
296 m_sendSocket_sifting->Connect(m_peer_sifting);
297 m_sendSocket_sifting->ShutdownRecv();
303 this << "BIND QISKIT socket to port " <<
304 InetSocketAddress::ConvertFrom(m_local).GetPort()+50
308 if(!m_sinkSocketQiskit) m_sinkSocketQiskit = Socket::CreateSocket(GetNode(), m_tid);
309 InetSocketAddress sinkAddressQiskit = InetSocketAddress(
310 Ipv4Address::GetAny(),
312 InetSocketAddress::ConvertFrom(m_local).GetPort()+50
314 if(m_sinkSocketQiskit->Bind(sinkAddressQiskit) == -1) NS_FATAL_ERROR("Failed to bind QISKIT socket " << m_local);
315 m_sinkSocketQiskit->Listen();
316 m_sinkSocketQiskit->ShutdownSend();
317 m_sinkSocketQiskit->SetRecvCallback(MakeCallback(&QKDPostprocessingApplication::HandleReadQiskit, this));
318 m_sinkSocketQiskit->SetAcceptCallback(
319 MakeNullCallback<bool, Ptr<Socket>, const Address &>(),
320 MakeCallback(&QKDPostprocessingApplication::HandleAcceptQiskit, this)
322 m_sinkSocketQiskit->SetCloseCallbacks(
323 MakeCallback(&QKDPostprocessingApplication::HandlePeerCloseQiskit, this),
324 MakeCallback(&QKDPostprocessingApplication::HandlePeerErrorQiskit, this)
330 if(!m_sendSocketKMS) m_sendSocketKMS = Socket::CreateSocket(GetNode(), m_tid);
331 Ipv4Address localIpv4 = InetSocketAddress::ConvertFrom(m_local).GetIpv4();
338 m_sendSocketKMS->Bind();
339 m_sendSocketKMS->ShutdownRecv();
340 m_sendSocketKMS->SetConnectCallback(
341 MakeCallback(&QKDPostprocessingApplication::ConnectionSucceededKMS, this),
342 MakeCallback(&QKDPostprocessingApplication::ConnectionFailedKMS, this));
343 m_sendSocketKMS->SetDataSentCallback(
344 MakeCallback(&QKDPostprocessingApplication::DataSendKMS, this));
345 m_sendSocketKMS->TraceConnectWithoutContext("RTT", MakeCallback(&QKDPostprocessingApplication::RegisterAckTime, this));
346 m_sendSocketKMS->Connect(m_kms);
349 Address allocatedLocalAddress;
350 m_sendSocketKMS->GetSockName(allocatedLocalAddress);
352 Address localAddress = InetSocketAddress(
353 InetSocketAddress::ConvertFrom(m_local).GetIpv4(),
354 InetSocketAddress::ConvertFrom(allocatedLocalAddress).GetPort()+100
357 m_sinkSocketKMS = Socket::CreateSocket(GetNode(), TcpSocketFactory::GetTypeId() );
362 if(m_sinkSocketKMS->Bind(localAddress) == -1) NS_FATAL_ERROR("Failed to bind socket");
363 m_sinkSocketKMS->Listen();
364 m_sinkSocketKMS->ShutdownSend();
365 m_sinkSocketKMS->SetRecvCallback(MakeCallback(&QKDPostprocessingApplication::HandleReadKMS, this));
366 m_sinkSocketKMS->SetAcceptCallback(
367 MakeNullCallback<bool, Ptr<Socket>, const Address &>(),
368 MakeCallback(&QKDPostprocessingApplication::HandleAcceptKMS, this));
370 MakeCallback(&QKDPostprocessingApplication::HandlePeerCloseKMS, this),
371 MakeCallback(&QKDPostprocessingApplication::HandlePeerErrorKMS, this));
376 InetSocketAddress::ConvertFrom(m_kms).GetIpv4() << " port " << InetSocketAddress::ConvertFrom(m_kms).GetPort() <<
378 localIpv4 << " port" << InetSocketAddress::ConvertFrom(allocatedLocalAddress).GetPort()
383 QKDPostprocessingApplication::StopApplication()
385 NS_LOG_FUNCTION(this << "\nQKD module ID:" << GetId() << ";\nMatching QKD module ID:" << GetPeerId());
388 m_sendSocket->Close();
390 NS_LOG_WARN("QKDPostprocessingApplication found null socket to close in StopApplication()!");
392 while(!m_sinkSocketList.empty()){
393 Ptr<Socket> acceptedSocket = m_sinkSocketList.front();
394 m_sinkSocketList.pop_front();
395 acceptedSocket->Close();
398 m_sinkSocket->Close();
399 m_sinkSocket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket> >());
403 Simulator::Cancel(m_sendEvent);
407 QKDPostprocessingApplication::ScheduleNextReset()
410 Time nextTime(Seconds((m_keySize*8) / static_cast<double>(m_keyRate.GetBitRate())));
411 Simulator::Schedule(nextTime, &QKDPostprocessingApplication::ResetCounter, this);
413 NS_LOG_FUNCTION(this << nextTime);
417 QKDPostprocessingApplication::ResetCounter()
419 NS_LOG_FUNCTION(this << "Reached packet number:" << m_packetNumber);
421 if(m_master) m_packetNumber = 0;
430 QKDPostprocessingApplication::SendData()
433 NS_LOG_FUNCTION(this << "********************** MASTER **********************");
435 NS_LOG_FUNCTION(this << "********************** SLAVE **********************");
437 NS_LOG_DEBUG(this << "\tSending packet " << m_packetNumber);
438 if(m_packetNumber > 0){
439 nlohmann::json msgBody = {
440 {"ACTION", "QKDPPS"},
441 {"NUMBER", m_packetNumber}
443 std::string message = msgBody.dump();
444 PrepareOutput(message, "qkdpps");
447 NS_LOG_FUNCTION(this << "m_lastUUID:\t" << m_lastUUID);
451 UUID keyIdRaw = UUID::Sequential();
452 keyId = keyIdRaw.string();
458 GenerateRandomKeyId();
459 nlohmann::json msgBody = {
460 {"ACTION", "ADDKEY"},
463 {"srid", m_randomSeed}
465 std::string message = msgBody.dump();
466 PrepareOutput(message, "addkey");
469 if(m_master && m_connected)
473 std::string byteKey = GenerateRandomString(m_keySize);
475 std::string keyValue = m_encryptor->Base64Encode(byteKey);
477 NS_LOG_FUNCTION(this << "ADDKEY:" << keyId);
478 NS_LOG_FUNCTION(this << "m_keySize:" << m_keySize);
479 NS_LOG_FUNCTION(this << "byteKey.size():" << byteKey.size());
483 StoreKey(keyId, keyValue);
494 QKDPostprocessingApplication::PrepareOutput(std::string value, std::string action)
496 NS_LOG_FUNCTION(this << Simulator::Now() << action);
498 if(static_cast<double>(m_dataRate.GetBitRate()) > 0 && m_pktSize > 0)
500 std::ostringstream msg;
503 msg << std::string(m_random->GetValue(m_pktSize, m_pktSize*1.1), '0');
506 Ptr<Packet> packet = Create<Packet>((uint8_t*) msg.str().c_str(), msg.str().length());
507 NS_LOG_DEBUG(this << "\t!!!SENDING PACKET WITH CONTENT:" << value << " of size " << packet->GetSize());
509 uint32_t bits = packet->GetSize() * 8;
510 NS_LOG_LOGIC(this << "bits = " << bits);
512 if(action == "qkdpps"){
513 Time nextTime(Seconds(bits / static_cast<double>(m_dataRate.GetBitRate())));
514 NS_LOG_FUNCTION(this << "CALCULATED NEXTTIME:" << bits / m_dataRate.GetBitRate());
515 NS_LOG_LOGIC("nextTime = " << nextTime);
516 m_sendEvent = Simulator::Schedule(nextTime, &QKDPostprocessingApplication::SendPacket, this, packet);
518 }else if(action == "addkey")
525 QKDPostprocessingApplication::SendPacket(Ptr<Packet> packet)
527 NS_LOG_FUNCTION(this << "\t" << packet << "PACKETID: " << packet->GetUid() << packet->GetSize());
530 m_sendSocket->Send(packet);
535 QKDPostprocessingApplication::StoreKey(std::string keyId, std::string keyValue)
537 NS_LOG_FUNCTION(this << keyId);
538 nlohmann::json msgBody = {
539 {"qkd_module_ID", GetId()},
540 {"matching_qkd_module_ID", GetPeerId()},
544 std::string msg = msgBody.dump();
546 std::string headerUri = "http://" + GetStringAddress(m_kms) + "/api/v1/keys/" + GetPeerId() + "/store_key";
548 NS_LOG_FUNCTION(this <<"aaaa:" << headerUri);
549 HTTPMessage httpMessage;
550 httpMessage.CreateRequest(headerUri, "POST", msg);
551 httpMessage.SetHeader("User-Agent", "QKDModule_" + GetId());
552 std::string hMessage = httpMessage.ToString();
553 Ptr<Packet> packet = Create<Packet>(
554 (uint8_t*)(hMessage).c_str(),
559 NS_LOG_FUNCTION(this << "Sending PACKETID: "
561 << " of size: " << packet->GetSize()
562 << " method name:" << "store_key"
563 << " key_id: " << keyId
564 << " via socket " << m_sendSocketKMS
565 << httpMessage.GetUri()
569 m_txTraceKMS(packet);
570 m_sendSocketKMS->Send(packet);
575 QKDPostprocessingApplication::GetStringAddress(Address m_address)
577 NS_LOG_FUNCTION(this << m_address);
578 Ipv4Address ipv4Adr = InetSocketAddress::ConvertFrom(m_address).GetIpv4();
579 std::ostringstream ipv4AdrTemp;
580 ipv4Adr.Print(ipv4AdrTemp);
582 return ipv4AdrTemp.str();
586 QKDPostprocessingApplication::SendSiftingPacket()
588 NS_LOG_FUNCTION(this);
590 Ptr<Packet> packet = Create<Packet>( uint32_t(800 + m_random->GetValue(100, 300)) );
591 m_sendSocket_sifting->Send(packet);
592 NS_LOG_FUNCTION(this << "Sending SIFTING packet" << "PACKETID: " << packet->GetUid() << " of size: " << packet->GetSize());
594 m_packetNumber_sifting++;
595 if(m_packetNumber_sifting < m_maxPackets_sifting)
596 Simulator::Schedule(MicroSeconds(400), &QKDPostprocessingApplication::SendSiftingPacket, this);
598 m_packetNumber_sifting = 0;
602 QKDPostprocessingApplication::HandleReadKMS(Ptr<Socket> socket)
605 NS_LOG_FUNCTION(this << "--------------MASTER--------------");
607 NS_LOG_FUNCTION(this << "--------------SLAVE--------------");
611 while((packet = socket->RecvFrom(from))){
613 if(packet->GetSize() == 0) break;
615 NS_LOG_FUNCTION(this << packet << "PACKETID: " << packet->GetUid() << " of size: " << packet->GetSize() );
617 m_totalRx += packet->GetSize();
618 if(InetSocketAddress::IsMatchingType(from))
619 NS_LOG_FUNCTION(this << "At time " << Simulator::Now().GetSeconds()
620 << "s packet sink received "
621 << packet->GetSize() << " bytes from "
622 << InetSocketAddress::ConvertFrom(from).GetIpv4()
623 << " port " << InetSocketAddress::ConvertFrom(from).GetPort()
624 << " total Rx " << m_totalRx << " bytes");
625 m_rxTraceKMS(packet, from);
631 QKDPostprocessingApplication::HandleReadQiskit(Ptr<Socket> socket)
634 NS_LOG_FUNCTION(this << "--------------MASTER--------------");
636 NS_LOG_FUNCTION(this << "--------------SLAVE--------------");
640 while((packet = socket->RecvFrom(from)))
642 if(packet->GetSize() == 0) break;
644 NS_LOG_FUNCTION(this << packet << "PACKETID: " << packet->GetUid() << " of size: " << packet->GetSize() );
645 PacketReceived(packet, from, socket);
649QKDPostprocessingApplication::PacketReceived(const Ptr<Packet> &p, const Address &from, Ptr<Socket> socket)
651 NS_LOG_FUNCTION(this << p->GetUid() << p->GetSize() << from);
654 Ptr<Packet> &buffer = m_buffer[from];
655 if (!buffer) buffer = Create<Packet>(0);
657 NS_LOG_DEBUG("Buffer after append: " << buffer->GetSize());
659 HTTPMessageParser parser;
660 while (buffer->GetSize() > 0) {
662 std::string bufferStr(buffer->GetSize(), '\0');
663 buffer->CopyData(reinterpret_cast<uint8_t*>(&bufferStr[0]), bufferStr.size());
665 std::string httpMessageStr;
666 size_t httpMessageSize = 0;
668 if (!parser.TryExtractHttpMessage(bufferStr, httpMessageStr, httpMessageSize)) {
669 NS_LOG_DEBUG("[DEBUG] Incomplete or fragmented HTTP message. Awaiting more data.");
675 parser.Parse(&request, httpMessageStr);
677 if (request.IsFragmented() || request.GetSize() == 0) {
678 NS_LOG_WARN("[WARN] Fragmented or malformed HTTP message. Waiting...");
683 Ptr<Packet> completePacket = buffer->CreateFragment(0, static_cast<uint32_t>(httpMessageSize));
684 buffer->RemoveAtStart(static_cast<uint32_t>(httpMessageSize));
686 NS_LOG_DEBUG("[DEBUG] Processing Qiskit request, size: " << httpMessageSize);
687 ProcessQiskitRequest(request, completePacket, socket);
695 QKDPostprocessingApplication::ProcessQiskitRequest(HTTPMessage headerIn, Ptr<Packet> packet, Ptr<Socket> socket)
697 NS_LOG_FUNCTION(this << headerIn.GetUri() << packet->GetUid());
698 NS_ASSERT(!headerIn.GetUri().empty());
700 std::string payloadRaw = headerIn.GetMessageBodyString();
701 if(!payloadRaw.empty()){
703 nlohmann::json jresponse;
705 jresponse = nlohmann::json::parse(payloadRaw);
707 NS_FATAL_ERROR(this << "JSON parse error!");
710 if(jresponse.contains("ACTION")) label = jresponse["ACTION"];
711 NS_LOG_DEBUG(this << "\tLABEL:\t" << label << "\tPACKETVALUE:\t" << socket);
713 if(label == "SAVEQISKITKEY")
718 std::string keyValueBits;
719 std::string keyValue;
720 if(jresponse.contains("keyid")) keyId = jresponse["keyid"];
721 if(jresponse.contains("keyvalue")) keyValueBits = jresponse["keyvalue"];
723 NS_LOG_FUNCTION(this << "SAVEQISKITKEY" << keyId);
726 std::string byteKey = bitsToBytes(keyValueBits);
729 keyValue = m_encryptor->Base64Encode(byteKey);
731 if(!keyId.empty() && !keyValue.empty())
732 StoreKey(keyId, keyValue);
735 HTTPMessage httpMessage;
736 httpMessage.CreateResponse(HTTPMessage::HttpStatus::Ok, "", {
737 {"Content-Type", "application/json; charset=utf-8"},
738 {"Request URI", headerIn.GetUri() }
740 std::string hMessage = httpMessage.ToString();
741 Ptr<Packet> packetR = Create<Packet>(
742 (uint8_t*)(hMessage).c_str(),
745 socket->Send(packetR);
765 QKDPostprocessingApplication::HandleRead(Ptr<Socket> socket)
768 NS_LOG_FUNCTION(this << "--------------MASTER--------------");
770 NS_LOG_FUNCTION(this << "--------------SLAVE--------------");
774 while((packet = socket->RecvFrom(from))){
776 if(packet->GetSize() == 0) break;
778 NS_LOG_FUNCTION(this << packet << "PACKETID: " << packet->GetUid() << " of size: " << packet->GetSize() );
780 m_totalRx += packet->GetSize();
781 if(InetSocketAddress::IsMatchingType(from))
782 NS_LOG_FUNCTION(this << "At time " << Simulator::Now().GetSeconds()
783 << "s packet sink received "
784 << packet->GetSize() << " bytes from "
785 << InetSocketAddress::ConvertFrom(from).GetIpv4()
786 << " port " << InetSocketAddress::ConvertFrom(from).GetPort()
787 << " total Rx " << m_totalRx << " bytes");
790 m_rxTrace(packet, from);
791 if(!m_master) ProcessIncomingPacket(packet);
798 QKDPostprocessingApplication::ProcessIncomingPacket(Ptr<Packet> packet)
803 uint8_t *buffer = new uint8_t[packet->GetSize()];
804 packet->CopyData(buffer, packet->GetSize());
805 std::string s = std::string((char*)buffer);
810 NS_LOG_FUNCTION(this << "payload:" << s);
811 std::size_t pos = s.find(";");
812 std::string payloadRaw = s.substr(0,pos);
813 NS_LOG_FUNCTION(this << "payloadRaw:" << payloadRaw);
816 nlohmann::json jresponse;
818 jresponse = nlohmann::json::parse(payloadRaw);
820 NS_FATAL_ERROR(this << "JSON parse error!");
823 if(jresponse.contains("ACTION")) label = jresponse["ACTION"];
824 NS_LOG_DEBUG(this << "\tLABEL:\t" << jresponse["ACTION"] << "\tPACKETVALUE:\t" << s);
826 if(label == "ADDKEY"){
829 uint32_t keySize = m_keySize;
830 if(jresponse.contains("size")) keySize = uint32_t(jresponse["size"]);
831 if(jresponse.contains("uuid")) m_lastUUID = jresponse["uuid"];
832 if(jresponse.contains("srid")) m_randomSeed = jresponse["srid"];
834 NS_LOG_FUNCTION(this << "ADDKEY" << m_lastUUID);
837 std::string byteKey = GenerateRandomString(keySize);
839 std::string keyValue = m_encryptor->Base64Encode(byteKey);
841 StoreKey(m_lastUUID, keyValue);
851 QKDPostprocessingApplication::HandleReadSifting(Ptr<Socket> socket)
853 NS_LOG_FUNCTION(this << socket);
856 NS_LOG_FUNCTION(this << "***MASTER***" );
858 NS_LOG_FUNCTION(this << "!!!SLAVE!!!");
861 packet = socket->Recv(65535, 0);
865 QKDPostprocessingApplication::HandlePeerClose(Ptr<Socket> socket)
867 NS_LOG_FUNCTION(this << socket);
871 QKDPostprocessingApplication::HandlePeerCloseKMS(Ptr<Socket> socket)
873 NS_LOG_FUNCTION(this << socket);
877 QKDPostprocessingApplication::HandlePeerCloseQiskit(Ptr<Socket> socket)
879 NS_LOG_FUNCTION(this << socket);
883 QKDPostprocessingApplication::HandlePeerError(Ptr<Socket> socket)
885 NS_LOG_FUNCTION(this << socket);
889 QKDPostprocessingApplication::HandlePeerErrorQiskit(Ptr<Socket> socket)
891 NS_LOG_FUNCTION(this << socket);
896 QKDPostprocessingApplication::HandlePeerErrorKMS(Ptr<Socket> socket)
898 NS_LOG_FUNCTION(this << socket);
902 QKDPostprocessingApplication::HandleAccept(Ptr<Socket> s, const Address& from)
904 NS_LOG_FUNCTION(this << s << from);
905 s->SetRecvCallback(MakeCallback(&QKDPostprocessingApplication::HandleRead, this));
906 m_sinkSocketList.push_back(s);
910 QKDPostprocessingApplication::HandleAcceptKMS(Ptr<Socket> s, const Address& from)
912 NS_LOG_FUNCTION(this << s << from);
913 s->SetRecvCallback(MakeCallback(&QKDPostprocessingApplication::HandleReadKMS, this));
917 QKDPostprocessingApplication::HandleAcceptQiskit(Ptr<Socket> s, const Address& from)
919 NS_LOG_FUNCTION(this << s << from);
920 s->SetRecvCallback(MakeCallback(&QKDPostprocessingApplication::HandleReadQiskit, this));
924 QKDPostprocessingApplication::HandleAcceptSifting(Ptr<Socket> s, const Address& from)
926 NS_LOG_FUNCTION(this << s << from);
927 s->SetRecvCallback(MakeCallback(&QKDPostprocessingApplication::HandleReadSifting, this));
928 m_sinkSocketList.push_back(s);
932 QKDPostprocessingApplication::ConnectionSucceeded(Ptr<Socket> socket)
934 NS_LOG_FUNCTION(this << socket);
935 NS_LOG_FUNCTION(this << "QKDPostprocessingApplication Connection succeeded");
937 if(m_sendSocket == socket || m_sinkSocket == socket){
942 NS_LOG_FUNCTION(this << "m_master:" << m_master);
943 NS_LOG_FUNCTION(this << "m_dataRate.GetBitRate():" << m_dataRate.GetBitRate());
944 NS_LOG_FUNCTION(this << "m_pktSize:" << m_pktSize);
946 if(static_cast<double>(m_dataRate.GetBitRate()) > 0 && m_pktSize > 0)
957 QKDPostprocessingApplication::ConnectionSucceededSifting(Ptr<Socket> socket)
959 NS_LOG_FUNCTION(this << socket);
960 NS_LOG_FUNCTION(this << "QKDPostprocessingApplication SIFTING Connection succeeded");
964 QKDPostprocessingApplication::ConnectionFailed(Ptr<Socket> socket)
966 NS_LOG_FUNCTION(this << socket);
967 NS_LOG_FUNCTION(this << "QKDPostprocessingApplication, Connection Failed");
971 QKDPostprocessingApplication::DataSend(Ptr<Socket> socket, uint32_t value)
973 NS_LOG_FUNCTION(this);
977 QKDPostprocessingApplication::ConnectionSucceededKMS(Ptr<Socket> socket)
979 NS_LOG_FUNCTION(this << socket);
980 NS_LOG_FUNCTION(this << "QKDPostprocessingApplication-KMS Connection succeeded");
984 QKDPostprocessingApplication::ConnectionFailedKMS(Ptr<Socket> socket)
986 NS_LOG_FUNCTION(this << socket);
987 NS_LOG_FUNCTION(this << "QKDPostprocessingApplication-KMS Connection Failed");
991 QKDPostprocessingApplication::DataSendKMS(Ptr<Socket> socket, uint32_t value)
993 NS_LOG_FUNCTION(this);
997 QKDPostprocessingApplication::RegisterAckTime(Time oldRtt, Time newRtt)
999 NS_LOG_FUNCTION(this << oldRtt << newRtt);
1000 m_lastAck = Simulator::Now();
1004 QKDPostprocessingApplication::GetLastAckTime()
1006 NS_LOG_FUNCTION(this);
1011 QKDPostprocessingApplication::GenerateRandomString(const int len) {
1013 NS_LOG_FUNCTION( this << len );
1016 static const char alphanum[] =
1018 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1019 "abcdefghijklmnopqrstuvwxyz";
1021 for(int i = 0; i < len; ++i){
1022 tmp_s += alphanum[rand() %(sizeof(alphanum) - 1)];
a polymophic address class
AttributeValue implementation for Address.
The base class for all ns3 applications.
void DoDispose() override
Destructor implementation.
Ptr< Node > GetNode() const
Class for representing data rates.
AttributeValue implementation for DataRate.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
static Ipv4Address GetAny()
Implement the IPv4 layer.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
QKDPostprocessingApplication is a class used to generate QKD key in key establishment process.
Ptr< Socket > m_sinkSocketKMS
Associated socket.
void HandleRead(Ptr< Socket > socket)
Handle a packet received by the application.
std::list< Ptr< Socket > > GetAcceptedSockets() const
void HandleAccept(Ptr< Socket > socket, const Address &from)
Handle an incoming connection.
std::list< Ptr< Socket > > m_sinkSocketList
the accepted sockets
void StartApplication() override
Called at time specified by Start.
bool m_connected
Connection Status.
Ptr< Socket > GetSendSocket() const
static TypeId GetTypeId()
Get the type ID.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTraceKMS
Ptr< Node > GetSrc()
pointer to associated source node
~QKDPostprocessingApplication() override
Ptr< Socket > GetSinkSocket() const
set the sink socket
Ptr< Node > GetDst()
pointer to associated destination node
QKDPostprocessingApplication()
Ptr< QKDEncryptor > m_encryptor
Address m_peer_sifting
Peer address for sifting.
uint32_t m_maxPackets_sifting
Limitation for the number of sifting packets.
void SetSiftingSocket(std::string type, Ptr< Socket > socket)
uint64_t m_randomSeed
Random seed used when generating key values.
void HandlePeerError(Ptr< Socket > socket)
Handle an connection error KMS.
Ptr< Socket > m_sendSocket_sifting
Sockets used for SIFTING.
uint32_t m_pktSize
Size of packets.
DataRate m_dataRate
Rate that data is generatedm_pktSize.
Ptr< Socket > m_sinkSocket_sifting
Associated socket for sifting.
void SetSocket(std::string type, Ptr< Socket > socket, bool isMaster)
void DoDispose() override
Destructor implementation.
TracedCallback< Ptr< const Packet > > m_txTrace
void GenerateRandomKeyId()
Generate Random Seed Used to Generate Key Values.
Address m_local_sifting
Local address for sifting to bind to.
bool m_master
Alice(1) or Bob(0)
std::string GetPeerId()
Get matching QKD module ID.
std::string GetId()
Get QKD module ID.
Address m_local
Local address to bind to.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
EventId m_sendEvent
Event id of pending "send packet" event.
uint32_t m_totalRx
Total bytes received.
uint32_t m_keySize
KeyRate of the QKDlink.
Ptr< UniformRandomVariable > m_random
Ptr< Socket > m_sendSocket
IMITATE post-processing traffic(CASCADE, PRIVACY AMPLIFICATION and etc.
Ptr< Socket > m_sinkSocket
Associated socket.
uint32_t GetTotalRx() const
DataRate m_keyRate
QKD Key rate.
TracedCallback< Ptr< const Packet > > m_txTraceKMS
static uint32_t m_applicationCounts
uint32_t m_packetNumber_sifting
How many sifting packets have been sent.
Address m_peer
Peer address.
void HandlePeerClose(Ptr< Socket > socket)
Handle an connection close.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
void SetAcceptCallback(Callback< bool, Ptr< Socket >, const Address & > connectionRequest, Callback< void, Ptr< Socket >, const Address & > newConnectionCreated)
Accept connection requests from remote hosts.
virtual int ShutdownSend()=0
void SetCloseCallbacks(Callback< void, Ptr< Socket > > normalClose, Callback< void, Ptr< Socket > > errorClose)
Detect socket recv() events such as graceful shutdown or error.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual int Listen()=0
Listen for incoming connections.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
AttributeValue implementation for TypeId.
static TypeId GetTypeId()
Get the type ID.
Hold an unsigned integer type.
Callback< R, Args... > MakeNullCallback()
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeDataRateAccessor(T1 a1)
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeAddressChecker()
Ptr< const AttributeChecker > MakeDataRateChecker()
Ptr< const AttributeChecker > MakeTypeIdChecker()
std::string bitsToBytes(const std::string &bits)
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)