75 std::cout <<
"[DEMO] Teleportation (A->B) with classical communication starting\n";
77 ns3::RngSeedManager::SetSeed(1);
78 ns3::RngSeedManager::SetRun(1);
91 ch->SetAttribute(
"Delay", TimeValue(NanoSeconds(10)));
95 InternetStackHelper internet;
99 PointToPointHelper p2p;
100 p2p.SetDeviceAttribute(
"DataRate", StringValue(
"100Mbps"));
101 p2p.SetChannelAttribute(
"Delay", StringValue(
"1ms"));
102 NetDeviceContainer devices = p2p.Install(A, B);
104 Ipv4AddressHelper ip;
105 ip.SetBase(
"10.1.1.0",
"255.255.255.0");
106 Ipv4InterfaceContainer interfaces = ip.Assign(devices);
108 const uint16_t port = 9000;
110 Ptr<Socket> bobSocket = Socket::CreateSocket(B, UdpSocketFactory::GetTypeId());
111 bobSocket->Bind(InetSocketAddress(Ipv4Address::GetAny(), port));
113 Ptr<Socket> aliceSocket = Socket::CreateSocket(A, UdpSocketFactory::GetTypeId());
114 aliceSocket->Connect(InetSocketAddress(interfaces.GetAddress(1), port));
124 B->SetRecvCallback([B, &bobInfo](std::shared_ptr<Qubit> q) {
125 std::cout <<
"[RECV][quantum][B]: yes\n";
126 bobInfo.qubitArrived =
true;
127 bobInfo.qBremote = q;
135 bobSocket->SetRecvCallback([B, &bobInfo](Ptr<Socket> socket) {
136 while (Ptr<Packet> packet = socket->Recv()) {
137 bobInfo.bitsArrived =
true;
139 uint8_t bytes[2] = {0, 0};
140 packet->CopyData(bytes, 2);
142 bobInfo.m1 = bytes[0] & 1;
143 bobInfo.m2 = bytes[1] & 1;
145 std::cout <<
"[RECV][classical][B] m1=" << bobInfo.m1 <<
", m2=" << bobInfo.m2 <<
"\n";
157 Simulator::Schedule(NanoSeconds(1), [&]() {
158 auto [qA, qBremote] = A->CreateBellPair();
159 bool ok = A->Send(qBremote, B->GetId());
160 std::cout <<
"[SEND][quantum] A->B: " << (ok ?
"ok" :
"failed") <<
"\n";
162 auto qAToTeleport = A->CreateQubit();
163 A->Apply(
gates::H(), {qAToTeleport});
164 auto [
m1,
m2] = A->MeasureBell(qAToTeleport, qA);
165 std::cout <<
"[A] BSM results: " <<
m1 <<
", " <<
m2 <<
"\n";
167 uint8_t bytes[2] = {
static_cast<uint8_t
>(
m1),
static_cast<uint8_t
>(
m2)};
168 aliceSocket->Send(Create<Packet>(bytes, 2));
169 std::cout <<
"[SEND][classical] A->B: m1=" <<
m1 <<
", m2=" <<
m2 <<
"\n";
174 Simulator::Stop(Seconds(10));
177 std::cout <<
"[DONE] Teleportation (A->B) with classical communication finished\n";
179 Simulator::Destroy();