23 #include "ns3/trace-source-accessor.h"
24 #include "ns3/traced-value.h"
25 #include "ns3/object.h"
26 #include "ns3/uinteger.h"
28 NS_LOG_COMPONENT_DEFINE (
"Wsn_node");
33 NS_OBJECT_ENSURE_REGISTERED (Wsn_node);
39 TypeId (
"ns3::Wsn_node")
40 .SetParent<Application> ()
41 .AddConstructor<Wsn_node> ()
42 .AddAttribute (
"ListenerPort",
"Port on which we listen for incoming packets.",
43 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
45 MakeUintegerChecker<uint16_t> ())
46 .AddAttribute (
"OutputManager",
"Manage the output of the simulation", PointerValue (0),
48 MakePointerChecker<OutputManager> ())
49 .AddAttribute (
"OnionValidator",
"Manage onions and when to abort them", PointerValue (0),
51 MakePointerChecker<OnionValidator> ())
52 .AddAttribute (
"Delay",
"Starting delay of sensor nodes, delay is given in milliseconds",
53 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
55 MakeUintegerChecker<uint16_t> ())
56 .AddAttribute (
"MSS",
"Maximum segment size",
57 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
59 MakeUintegerChecker<uint16_t> ())
60 .AddAttribute (
"OnionTimeout",
61 "A watchdog timer set to abort onion messagess, if the timer elepses "
62 "before the onion returns back to the sink node",
63 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
65 MakeUintegerChecker<uint16_t> ())
66 .AddTraceSource (
"AppTx",
"Packet transmitted",
68 "ns3::TracedValueCallback::Packet")
69 .AddTraceSource (
"AppRx",
"Packet received", MakeTraceSourceAccessor (&
Wsn_node::m_appRx),
70 "ns3::TracedValueCallback::Packet");
105 Ptr<Node> PtrNode = this->GetNode ();
106 Ptr<Ipv4> ipv4 = PtrNode->GetObject<Ipv4> ();
107 Ipv4InterfaceAddress iaddr = ipv4->GetAddress (1, 0);
108 Ipv4Address address = iaddr.GetLocal ();
111 m_socket = Socket::CreateSocket (GetNode (), TcpSocketFactory::GetTypeId ());
112 InetSocketAddress local (Ipv4Address::GetAny (),
m_port);
118 Ptr<MobilityModel> mob = PtrNode->GetObject<MobilityModel> ();
119 double coord_x = mob->GetPosition ().x;
120 double coord_y = mob->GetPosition ().y;
138 Ptr<Node> PtrNode = this->GetNode ();
139 Ptr<NetDevice> device = PtrNode->GetDevice (0);
140 Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
142 wifiDevice->GetPhy ()->SetOffMode ();
148 Ptr<Node> PtrNode = this->GetNode ();
149 Ptr<NetDevice> device = PtrNode->GetDevice (0);
150 Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
152 wifiDevice->GetPhy ()->ResumeFromOff ();
166 Ptr<Node> PtrNode = this->GetNode ();
168 Ptr<Ipv4> ipv4Ptr = PtrNode->GetObject<Ipv4> ();
169 Ptr<Ipv4RoutingProtocol> ipv4Routing = ipv4Ptr->GetRoutingProtocol ();
171 Ptr<Ipv4ListRouting> ipv4ListRouting = DynamicCast<Ipv4ListRouting> (ipv4Routing);
173 Ptr<olsr::RoutingProtocol> olsrProtocol;
174 int16_t priority = 10;
175 for (uint32_t i = 0; i < ipv4ListRouting->GetNRoutingProtocols (); i++)
177 Ptr<Ipv4RoutingProtocol> proto = ipv4ListRouting->GetRoutingProtocol (0, priority);
178 olsrProtocol = DynamicCast<olsr::RoutingProtocol> (proto);
180 if (olsrProtocol != 0)
186 NS_ASSERT_MSG (olsrProtocol,
"Didn't find OLSR on this node");
189 ns3::olsr::OlsrState state = olsrProtocol->GetOlsrState ();
190 ns3::olsr::NeighborSet n_set = state.GetNeighbors ();
201 Ipv4Address net_address;
202 net_address.Set (
"10.1.0.0");
203 uint32_t delay = node_address.Get () - net_address.Get ();
220 Ptr<Socket> socket = Socket::CreateSocket (GetNode (), TcpSocketFactory::GetTypeId ());
221 socket->Connect (remote);
223 int pack_size = packet->GetSize ();
224 int seg_num = pack_size /
f_mss;
235 socket->Send (packet);
241 packet->AddByteTag (s_num);
242 socket->Send (packet);
252 Ptr<Packet> p = Create<Packet> ();
254 p = socket->RecvFrom (from);
256 return RecvSeg (socket, p, from);
264 Ptr<Packet> p = Create<Packet> ();
265 p = socket->RecvFrom (from);
267 return RecvSeg (socket, p, from);
282 InetSocketAddress from_address = InetSocketAddress::ConvertFrom (from);
286 if (!p->FindFirstMatchingByteTag (s_num))