38 std::cout <<
"[DEMO] Classical communication (A->B) starting\n";
40 ns3::RngSeedManager::SetSeed(1);
41 ns3::RngSeedManager::SetRun(1);
52 InternetStackHelper internet;
59 PointToPointHelper p2p;
60 p2p.SetDeviceAttribute(
"DataRate", StringValue(
"100Mbps"));
61 p2p.SetChannelAttribute(
"Delay", StringValue(
"1ms"));
62 NetDeviceContainer devices = p2p.Install(A, B);
68 ip.SetBase(
"10.1.1.0",
"255.255.255.0");
69 Ipv4InterfaceContainer interfaces = ip.Assign(devices);
74 const uint16_t port = 9000;
78 Ptr<Socket> bobSocket = Socket::CreateSocket(B, UdpSocketFactory::GetTypeId());
79 InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(), port);
80 bobSocket->Bind(local);
81 bobSocket->SetRecvCallback([](Ptr<Socket> socket) {
82 while (Ptr<Packet> packet = socket->Recv()) {
83 std::cout <<
"[B][classical] Received UDP packet at " << Simulator::Now().GetSeconds()
84 <<
" s, size = " << packet->GetSize() <<
" bytes\n";
91 Ptr<Socket> aliceSocket = Socket::CreateSocket(A, UdpSocketFactory::GetTypeId());
92 InetSocketAddress remote = InetSocketAddress(interfaces.GetAddress(1), port);
93 aliceSocket->Connect(remote);
99 Simulator::Schedule(Seconds(1.0), [aliceSocket]() {
100 Ptr<Packet> packet = Create<Packet>(4);
101 aliceSocket->Send(packet);
102 std::cout <<
"[A][classical] Sent UDP packet at " << Simulator::Now().GetSeconds() <<
" s\n";
105 Simulator::Stop(Seconds(10));
108 std::cout <<
"[DONE] Classical communication (A->B) finished\n";
110 Simulator::Destroy();