159 const uint16_t port = 9000;
162 const Time qDelay = MicroSeconds(
static_cast<int64_t
>(std::llround(5.0 * distanceKm)));
163 const Time cDelay = MicroSeconds(
static_cast<int64_t
>(std::llround(5.0 * distanceKm)));
166 Time tStart = Seconds(0);
176 auto qIdealPlus = ref->CreateQubit();
177 ref->Apply(
gates::H(), {qIdealPlus});
180 auto depol = CreateObject<DepolarizingQMap>();
182 const double ratePerSecond = 1000.0 / TDepMs;
183 depol->SetAttribute(
"Rate", DoubleValue(ratePerSecond));
185 depol->SetAttribute(
"Probability", DoubleValue(0.0));
188 auto u = CreateObject<UniformRandomVariable>();
192 ch->SetAttribute(
"Delay", TimeValue(qDelay));
195 InternetStackHelper internet;
199 PointToPointHelper p2p;
200 p2p.SetDeviceAttribute(
"DataRate", StringValue(
"100Mbps"));
201 p2p.SetChannelAttribute(
"Delay", TimeValue(cDelay));
202 NetDeviceContainer devices = p2p.Install(A, B);
204 Ipv4AddressHelper ip;
205 ip.SetBase(
"10.1.1.0",
"255.255.255.0");
206 Ipv4InterfaceContainer interfaces = ip.Assign(devices);
208 Ptr<Socket> bobSocket = Socket::CreateSocket(B, UdpSocketFactory::GetTypeId());
209 bobSocket->Bind(InetSocketAddress(Ipv4Address::GetAny(), port));
211 Ptr<Socket> aliceSocket = Socket::CreateSocket(A, UdpSocketFactory::GetTypeId());
212 aliceSocket->Connect(InetSocketAddress(interfaces.GetAddress(1), port));
215 bobSocket->SetRecvCallback(
216 [B, &bobInfo, &net, depol, u, qIdealPlus, &tStart, verbose](Ptr<Socket> socket) {
217 while (Ptr<Packet> packet = socket->Recv()) {
218 uint8_t bytes[2] = {0, 0};
219 const uint32_t n = packet->CopyData(bytes, 2);
226 bobInfo.
m1 = bytes[0] & 1;
227 bobInfo.
m2 = bytes[1] & 1;
231 std::cout <<
"[RECV][classical][B][udp] t=" << std::fixed << std::setprecision(6)
232 << Simulator::Now().GetSeconds() <<
" s"
233 <<
" m1=" << bobInfo.
m1 <<
" m2=" << bobInfo.
m2 <<
"\n";
236 TryCorrections(B, net, bobInfo, depol, u, qIdealPlus, tStart, verbose);
242 [B, &bobInfo, &net, depol, u, qIdealPlus, &tStart, verbose](std::shared_ptr<Qubit> q) {
244 bobInfo.qubitArrived =
true;
245 bobInfo.tQubitArrive = Simulator::Now();
248 std::cout <<
"[RECV][quantum][B] t=" << std::fixed << std::setprecision(6)
249 << Simulator::Now().GetSeconds() <<
" s\n";
252 TryCorrections(B, net, bobInfo, depol, u, qIdealPlus, tStart, verbose);
256 Simulator::Schedule(NanoSeconds(1), [&]() {
257 tStart = Simulator::Now();
259 auto [qA, qBRemote] = A->CreateBellPair();
260 const bool ok = A->Send(qBRemote, B->GetId());
263 std::cout <<
"[SEND][quantum] A->B: " << (ok ?
"ok" :
"failed") <<
"\n";
266 auto psi = A->CreateQubit();
269 auto [
m1,
m2] = A->MeasureBell(psi, qA);
272 std::cout <<
"[A] BSM results: " <<
m1 <<
", " <<
m2 <<
"\n";
276 static_cast<uint8_t
>(
m1),
277 static_cast<uint8_t
>(
m2),
280 aliceSocket->Send(Create<Packet>(bytes, 2));
283 std::cout <<
"[SEND][classical][udp] A->B\n";
287 Simulator::Stop(Seconds(5));
289 Simulator::Destroy();
292 r.fidelity = bobInfo.finalFidelity;
293 r.completionMs = bobInfo.completionMs;