|
|
| 1 |
#include "ns3/internet-node-module.h" |
| 2 |
#include "ns3/core-module.h" |
| 3 |
#include "ns3/simulator-module.h" |
| 4 |
#include "ns3/node-module.h" |
| 5 |
#include "ns3/common-module.h" |
| 6 |
#include "ns3/point-to-point-module.h" |
| 7 |
|
| 8 |
using namespace ns3; |
| 9 |
|
| 10 |
NS_LOG_COMPONENT_DEFINE ("Bug154"); |
| 11 |
|
| 12 |
class Bug154 |
| 13 |
{ |
| 14 |
public: |
| 15 |
void ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from); |
| 16 |
bool run(void); |
| 17 |
}; |
| 18 |
|
| 19 |
int |
| 20 |
main (int argc, char *argv[]) |
| 21 |
{ |
| 22 |
LogComponentEnable("Bug154", LOG_LEVEL_ALL); |
| 23 |
Bug154 teste; |
| 24 |
teste.run(); |
| 25 |
NS_LOG_INFO ("Run Simulation."); |
| 26 |
Simulator::StopAt (Seconds (3.0)); |
| 27 |
Simulator::Run (); |
| 28 |
Simulator::Destroy (); |
| 29 |
NS_LOG_INFO ("Done."); |
| 30 |
} |
| 31 |
|
| 32 |
void Bug154::ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from) |
| 33 |
{ |
| 34 |
NS_LOG_INFO("receive packet of size "<<packet->GetSize()); |
| 35 |
} |
| 36 |
|
| 37 |
bool |
| 38 |
Bug154::run(void) |
| 39 |
{ |
| 40 |
Ptr<InternetNode> n0 = CreateObject<InternetNode>(); |
| 41 |
Ptr<InternetNode> rxNode = CreateObject<InternetNode>(); |
| 42 |
|
| 43 |
Ptr<PointToPointChannel> channel0 |
| 44 |
= PointToPointTopology::AddPointToPointLink |
| 45 |
(n0, rxNode, DataRate(1000000), MilliSeconds(10)); |
| 46 |
|
| 47 |
PointToPointTopology::AddIpv4Addresses (channel0, n0, Ipv4Address("10.1.4.1"), |
| 48 |
rxNode, Ipv4Address("10.1.4.2")); |
| 49 |
PointToPointTopology::AddIpv4Routes(n0, rxNode, channel0); |
| 50 |
n0->GetObject<Ipv4> ()->SetDefaultRoute (Ipv4Address ("10.1.4.2"), 1); |
| 51 |
rxNode->GetObject<Ipv4> ()->SetDefaultRoute (Ipv4Address ("10.1.4.1"), 1); |
| 52 |
|
| 53 |
NS_LOG_INFO ("create receive socket"); |
| 54 |
Ptr<SocketFactory> socketFactory= rxNode->GetObject<Udp> (); |
| 55 |
Ptr<Socket> rxSocket= socketFactory->CreateSocket(); |
| 56 |
rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.1.4.2"), 1234)); |
| 57 |
rxSocket->SetRecvCallback (MakeCallback (&Bug154::ReceivePacket, this)); |
| 58 |
|
| 59 |
NS_LOG_INFO("create send socket "); |
| 60 |
Ptr<SocketFactory> n0SocketFactory = n0->GetObject<Udp> (); |
| 61 |
Ptr<Socket> n0socket = n0SocketFactory->CreateSocket (); |
| 62 |
Ptr<Packet> packet=Create <Packet>(101); |
| 63 |
n0socket->SendTo (InetSocketAddress (Ipv4Address("10.1.4.2"),1234),packet); |
| 64 |
|
| 65 |
return true; |
| 66 |
} |