Advertisement
Guest User

Untitled

a guest
Apr 17th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.90 KB | None | 0 0
  1. From 6e970c647d70aa79d97f7e9e3f4c1b9cb51acdd2 Mon Sep 17 00:00:00 2001
  2. From: parthyadav3105 <parthyadav3105@gmail.com>
  3. Date: Mon, 8 Apr 2019 00:22:20 +0530
  4. Subject: [PATCH] Signed-off-by Parth Yadav<parthyadav3105@gmail.com>
  5.  
  6. ---
  7. scratch/p99-example.cc | 90 ++++++++++
  8. src/internet/helper/internet-stack-helper.cc | 1 +
  9. src/internet/model/ipv4-l3-protocol.cc | 5 +
  10. src/internet/model/p99-header.cc | 150 ++++++++++++++++
  11. src/internet/model/p99-header.h | 96 +++++++++++
  12. src/internet/model/p99-l3-protocol.cc | 172 +++++++++++++++++++
  13. src/internet/model/p99-l3-protocol.h | 130 ++++++++++++++
  14. src/internet/wscript | 4 +
  15. 8 files changed, 648 insertions(+)
  16. create mode 100644 scratch/p99-example.cc
  17. create mode 100644 src/internet/model/p99-header.cc
  18. create mode 100644 src/internet/model/p99-header.h
  19. create mode 100644 src/internet/model/p99-l3-protocol.cc
  20. create mode 100644 src/internet/model/p99-l3-protocol.h
  21.  
  22. diff --git a/scratch/p99-example.cc b/scratch/p99-example.cc
  23. new file mode 100644
  24. index 000000000..d35e0e651
  25. --- /dev/null
  26. +++ b/scratch/p99-example.cc
  27. @@ -0,0 +1,90 @@
  28. +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  29. +/*
  30. + * This program is free software; you can redistribute it and/or modify
  31. + * it under the terms of the GNU General Public License version 2 as
  32. + * published by the Free Software Foundation;
  33. + *
  34. + * This program is distributed in the hope that it will be useful,
  35. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. + * GNU General Public License for more details.
  38. + *
  39. + * You should have received a copy of the GNU General Public License
  40. + * along with this program; if not, write to the Free Software
  41. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  42. + */
  43. +
  44. +#include "ns3/core-module.h"
  45. +#include "ns3/network-module.h"
  46. +#include "ns3/internet-module.h"
  47. +#include "ns3/csma-module.h"
  48. +#include "ns3/point-to-point-module.h"
  49. +#include "ns3/applications-module.h"
  50. +#include "ns3/p99-header.h"
  51. +
  52. +using namespace ns3;
  53. +
  54. +NS_LOG_COMPONENT_DEFINE ("P99ProtocolExample");
  55. +
  56. +void
  57. +Send (Ptr<Node> node, Ptr<NetDevice> device, const Address &dest, uint16_t protocolNumber)
  58. +{
  59. +
  60. + uint64_t requestTime = Simulator::Now () .GetMilliSeconds ();
  61. +
  62. + P99Header p99;
  63. + p99.SetRequest (requestTime);
  64. + Ptr<Packet> packet = Create<Packet> ();
  65. + packet->AddHeader (p99);
  66. +
  67. + NS_LOG_INFO ( "node=" << node->GetId () <<
  68. + " send a P99 request --sending packet");
  69. + device-> Send (packet, dest, protocolNumber);
  70. +}
  71. +
  72. +int
  73. +main (int argc, char *argv[])
  74. +{
  75. + CommandLine cmd;
  76. + cmd.Parse (argc, argv);
  77. +
  78. + Time::SetResolution (Time::NS);
  79. +
  80. + LogComponentEnable ("P99L3Protocol", LOG_INFO);
  81. + //LogComponentEnable ("P99Header", LOG_LEVEL_LOGIC);
  82. +
  83. + LogComponentEnable ("P99ProtocolExample", LOG_LEVEL_ALL);
  84. +
  85. + NS_LOG_INFO("Creating 2 Nodes");
  86. + NodeContainer nodes;
  87. + nodes.Create (2);
  88. +
  89. + CsmaHelper csma;
  90. + csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
  91. + csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
  92. + csma.SetDeviceAttribute ("EncapsulationMode", StringValue("Llc"));
  93. +
  94. + NetDeviceContainer devices;
  95. + devices = csma.Install (nodes);
  96. +
  97. + InternetStackHelper stack;
  98. + stack.Install (nodes);
  99. +
  100. + Ipv4AddressHelper address;
  101. + address.SetBase ("10.1.1.0", "255.255.255.0");
  102. +
  103. + Ipv4InterfaceContainer interfaces = address.Assign (devices);
  104. +
  105. +
  106. +
  107. +
  108. +
  109. + NS_LOG_INFO("Schedulig a P99 Packet from node1 to node2");
  110. + Simulator::Schedule(Seconds(3), &Send, nodes.Get(0) ,devices.Get (0), devices.Get(1)->GetAddress (), 0x0063);
  111. +
  112. + Simulator::Run ();
  113. + Simulator::Destroy ();
  114. + return 0;
  115. +}
  116. +
  117. +
  118. diff --git a/src/internet/helper/internet-stack-helper.cc b/src/internet/helper/internet-stack-helper.cc
  119. index 6d85d58a6..24ec1bd52 100644
  120. --- a/src/internet/helper/internet-stack-helper.cc
  121. +++ b/src/internet/helper/internet-stack-helper.cc
  122. @@ -302,6 +302,7 @@ InternetStackHelper::Install (Ptr<Node> node) const
  123.  
  124. CreateAndAggregateObjectFromTypeId (node, "ns3::ArpL3Protocol");
  125. CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv4L3Protocol");
  126. + CreateAndAggregateObjectFromTypeId (node, "ns3::P99L3Protocol");
  127. CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv4L4Protocol");
  128. if (m_ipv4ArpJitterEnabled == false)
  129. {
  130. diff --git a/src/internet/model/ipv4-l3-protocol.cc b/src/internet/model/ipv4-l3-protocol.cc
  131. index 9384d1bcd..bfafe0c26 100644
  132. --- a/src/internet/model/ipv4-l3-protocol.cc
  133. +++ b/src/internet/model/ipv4-l3-protocol.cc
  134. @@ -38,6 +38,7 @@
  135. #include "arp-l3-protocol.h"
  136. #include "arp-cache.h"
  137. #include "ipv4-l3-protocol.h"
  138. +#include "p99-l3-protocol.h"
  139. #include "icmpv4-l4-protocol.h"
  140. #include "ipv4-interface.h"
  141. #include "ipv4-raw-socket-impl.h"
  142. @@ -377,11 +378,15 @@ Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
  143. Ipv4L3Protocol::PROT_NUMBER, device);
  144. m_node->RegisterProtocolHandler (MakeCallback (&TrafficControlLayer::Receive, tc),
  145. ArpL3Protocol::PROT_NUMBER, device);
  146. + m_node->RegisterProtocolHandler (MakeCallback (&TrafficControlLayer::Receive, tc),
  147. + P99L3Protocol::PROT_NUMBER, device);
  148.  
  149. tc->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, this),
  150. Ipv4L3Protocol::PROT_NUMBER, device);
  151. tc->RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (GetObject<ArpL3Protocol> ())),
  152. ArpL3Protocol::PROT_NUMBER, device);
  153. + tc->RegisterProtocolHandler (MakeCallback (&P99L3Protocol::Receive, PeekPointer (GetObject<P99L3Protocol> ())),
  154. + P99L3Protocol::PROT_NUMBER, device);
  155.  
  156. Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
  157. interface->SetNode (m_node);
  158. diff --git a/src/internet/model/p99-header.cc b/src/internet/model/p99-header.cc
  159. new file mode 100644
  160. index 000000000..b34248b5e
  161. --- /dev/null
  162. +++ b/src/internet/model/p99-header.cc
  163. @@ -0,0 +1,150 @@
  164. +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  165. +/*
  166. + * Copyright (c) 2019
  167. + *
  168. + * This program is free software; you can redistribute it and/or modify
  169. + * it under the terms of the GNU General Public License version 2 as
  170. + * published by the Free Software Foundation;
  171. + *
  172. + * This program is distributed in the hope that it will be useful,
  173. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  174. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  175. + * GNU General Public License for more details.
  176. + *
  177. + * You should have received a copy of the GNU General Public License
  178. + * along with this program; if not, write to the Free Software
  179. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  180. + *
  181. + * Author: Parth Yadav <parthyadav3105@gmail.com>
  182. + */
  183. +
  184. +#include "ns3/assert.h"
  185. +#include "ns3/address-utils.h"
  186. +#include "p99-header.h"
  187. +#include "ns3/log.h"
  188. +
  189. +namespace ns3 {
  190. +
  191. +NS_LOG_COMPONENT_DEFINE ("P99Header");
  192. +
  193. +NS_OBJECT_ENSURE_REGISTERED (P99Header);
  194. +
  195. +void
  196. +P99Header::SetRequest (uint64_t startTime)
  197. +{
  198. + NS_LOG_FUNCTION (this << startTime );
  199. + m_type = P99_TYPE_REQUEST;
  200. + m_startTime = startTime;
  201. +}
  202. +
  203. +void
  204. +P99Header::SetReply (uint64_t startTime)
  205. +{
  206. + NS_LOG_FUNCTION (this << startTime );
  207. + m_type = P99_TYPE_REPLY;
  208. + m_startTime = startTime;
  209. +}
  210. +
  211. +bool
  212. +P99Header::IsRequest (void) const
  213. +{
  214. + NS_LOG_FUNCTION (this);
  215. + return (m_type == P99_TYPE_REQUEST) ? true : false;
  216. +}
  217. +
  218. +bool
  219. +P99Header::IsReply (void) const
  220. +{
  221. + NS_LOG_FUNCTION (this);
  222. + return (m_type == P99_TYPE_REPLY) ? true : false;
  223. +}
  224. +
  225. +uint64_t
  226. +P99Header::GetStartTime (void) const
  227. +{
  228. + NS_LOG_FUNCTION (this);
  229. + return m_startTime;
  230. +}
  231. +
  232. +TypeId
  233. +P99Header::GetTypeId (void)
  234. +{
  235. + static TypeId tid = TypeId ("ns3::P99Header")
  236. + .SetParent<Header> ()
  237. + .SetGroupName ("Internet")
  238. + .AddConstructor<P99Header> ()
  239. + ;
  240. + return tid;
  241. +}
  242. +
  243. +TypeId
  244. +P99Header::GetInstanceTypeId (void) const
  245. +{
  246. + NS_LOG_FUNCTION (this);
  247. + return GetTypeId ();
  248. +}
  249. +
  250. +void
  251. +P99Header::Print (std::ostream &os) const
  252. +{
  253. + NS_LOG_FUNCTION (this << &os);
  254. + if (IsRequest ())
  255. + {
  256. + os << "request ";
  257. + }
  258. + else
  259. + {
  260. + NS_ASSERT (IsReply ());
  261. + os << "reply ";
  262. + }
  263. +}
  264. +
  265. +uint32_t
  266. +P99Header::GetSerializedSize (void) const
  267. +{
  268. + NS_LOG_FUNCTION (this);
  269. +
  270. + uint32_t length = 2; // 2 bytes for m_type
  271. + length+=2; //2 bytes for protocol type
  272. + length +=8; // 8 bytes for storing time
  273. +
  274. + return length;
  275. +}
  276. +
  277. +
  278. +void
  279. +P99Header::Serialize (Buffer::Iterator start) const
  280. +{
  281. + NS_LOG_FUNCTION (this << &start);
  282. + Buffer::Iterator i = start;
  283. +
  284. + i.WriteHtonU16 (0x0063); // write protocol number 99
  285. + i.WriteHtonU16 (m_type); // write packet type request/reply
  286. + i.WriteHtonU64 (m_startTime);
  287. +}
  288. +
  289. +
  290. +
  291. +uint32_t
  292. +P99Header::Deserialize (Buffer::Iterator start)
  293. +{
  294. + NS_LOG_FUNCTION (this << &start);
  295. + Buffer::Iterator i = start;
  296. +
  297. + uint32_t protocolType = i.ReadNtohU16 (); // Read Protocol Number
  298. +
  299. + //
  300. + // It is implicit here that we have a protocol type of 0x0063 (99).
  301. + //
  302. + if (protocolType != 0x0063)
  303. + {
  304. + return 0;
  305. + }
  306. +
  307. + m_type = i.ReadNtohU16 (); // Read OP
  308. + m_startTime = i.ReadNtohU64 ();
  309. + return GetSerializedSize ();
  310. +}
  311. +
  312. +
  313. +} // namespace ns3
  314. diff --git a/src/internet/model/p99-header.h b/src/internet/model/p99-header.h
  315. new file mode 100644
  316. index 000000000..69d51ba37
  317. --- /dev/null
  318. +++ b/src/internet/model/p99-header.h
  319. @@ -0,0 +1,96 @@
  320. +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  321. +/*
  322. + * Copyright (c) 2019
  323. + *
  324. + * This program is free software; you can redistribute it and/or modify
  325. + * it under the terms of the GNU General Public License version 2 as
  326. + * published by the Free Software Foundation;
  327. + *
  328. + * This program is distributed in the hope that it will be useful,
  329. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  330. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  331. + * GNU General Public License for more details.
  332. + *
  333. + * You should have received a copy of the GNU General Public License
  334. + * along with this program; if not, write to the Free Software
  335. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  336. + *
  337. + * Author: Parth Yadav <parthyadav3105@gmail.com>
  338. + */
  339. +
  340. +#ifndef P99_HEADER_H
  341. +#define P99_HEADER_H
  342. +
  343. +#include "ns3/header.h"
  344. +#include "ns3/address.h"
  345. +#include "ns3/ipv4-address.h"
  346. +#include <string>
  347. +
  348. +namespace ns3 {
  349. +
  350. +/**
  351. + * \ingroup p99
  352. + * \brief The packet header for an P99 packet
  353. + */
  354. +class P99Header : public Header
  355. +{
  356. +
  357. +public:
  358. +
  359. + /**
  360. + * \brief Set the P99 request parameters
  361. + * \param startTime the time at which ping request was made
  362. + */
  363. + void SetRequest (uint64_t startTime);
  364. +
  365. + /**
  366. + * \brief Set the P99 reply parameters
  367. + * \param startTime the time at which ping request was made
  368. + */
  369. + void SetReply (uint64_t startTime);
  370. +
  371. + /**
  372. + * \brief Check if the P99 is a request
  373. + * \returns true if it is a request
  374. + */
  375. + bool IsRequest (void) const;
  376. +
  377. + /**
  378. + * \brief Check if the P99 is a reply
  379. + * \returns true if it is a reply
  380. + */
  381. + bool IsReply (void) const;
  382. +
  383. + /**
  384. + * \brief Returns the Time at which P99 request was made
  385. + * \returns Time at which Packet was sent
  386. + */
  387. + uint64_t GetStartTime (void) const;
  388. +
  389. + /**
  390. + * \brief Get the type ID.
  391. + * \return the object TypeId
  392. + */
  393. + static TypeId GetTypeId (void);
  394. + virtual TypeId GetInstanceTypeId (void) const;
  395. + virtual void Print (std::ostream &os) const;
  396. + virtual uint32_t GetSerializedSize (void) const;
  397. + virtual void Serialize (Buffer::Iterator start) const;
  398. + virtual uint32_t Deserialize (Buffer::Iterator start);
  399. +
  400. + /**
  401. + * \brief Enumeration listing the possible P99 types
  402. + */
  403. + enum P99Type_e {
  404. + P99_TYPE_REQUEST = 1,
  405. + P99_TYPE_REPLY = 2
  406. + };
  407. +
  408. + uint16_t m_type; //!< type of the P99 packet (P99_TYPE_REQUEST)
  409. + uint64_t m_startTime; //!< Time at which a request is made in milliseconds
  410. +
  411. +};
  412. +
  413. +} // namespace ns3
  414. +
  415. +#endif /* P99_HEADER_H */
  416. diff --git a/src/internet/model/p99-l3-protocol.cc b/src/internet/model/p99-l3-protocol.cc
  417. new file mode 100644
  418. index 000000000..2ade16e5a
  419. --- /dev/null
  420. +++ b/src/internet/model/p99-l3-protocol.cc
  421. @@ -0,0 +1,172 @@
  422. +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  423. +/*
  424. + * Copyright (c) 2019
  425. + *
  426. + * This program is free software; you can redistribute it and/or modify
  427. + * it under the terms of the GNU General Public License version 2 as
  428. + * published by the Free Software Foundation;
  429. + *
  430. + * This program is distributed in the hope that it will be useful,
  431. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  432. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  433. + * GNU General Public License for more details.
  434. + *
  435. + * You should have received a copy of the GNU General Public License
  436. + * along with this program; if not, write to the Free Software
  437. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  438. + *
  439. + * Author: Parth Yadav <parthyadav3105@gmail.com>
  440. + */
  441. +#include "ns3/packet.h"
  442. +#include "ns3/log.h"
  443. +#include "ns3/node.h"
  444. +#include "ns3/net-device.h"
  445. +#include "ns3/object-vector.h"
  446. +#include "ns3/pointer.h"
  447. +#include "ns3/string.h"
  448. +
  449. +#include "ipv4-l3-protocol.h"
  450. +#include "p99-l3-protocol.h"
  451. +#include "p99-header.h"
  452. +#include "ipv4-interface.h"
  453. +
  454. +namespace ns3 {
  455. +
  456. +NS_LOG_COMPONENT_DEFINE ("P99L3Protocol");
  457. +
  458. +const uint16_t P99L3Protocol::PROT_NUMBER = 0x0063;
  459. +
  460. +NS_OBJECT_ENSURE_REGISTERED (P99L3Protocol);
  461. +
  462. +TypeId
  463. +P99L3Protocol::GetTypeId (void)
  464. +{
  465. + static TypeId tid = TypeId ("ns3::P99L3Protocol")
  466. + .SetParent<Object> ()
  467. + .AddConstructor<P99L3Protocol> ()
  468. + .SetGroupName ("Internet")
  469. + ;
  470. + return tid;
  471. +}
  472. +
  473. +P99L3Protocol::P99L3Protocol ()
  474. +{
  475. + NS_LOG_FUNCTION (this);
  476. +}
  477. +
  478. +P99L3Protocol::~P99L3Protocol ()
  479. +{
  480. + NS_LOG_FUNCTION (this);
  481. +}
  482. +
  483. +void
  484. +P99L3Protocol::SetNode (Ptr<Node> node)
  485. +{
  486. + NS_LOG_FUNCTION (this << node);
  487. + m_node = node;
  488. +}
  489. +
  490. +/*
  491. + * This method is called by AddAgregate and completes the aggregation
  492. + * by setting the node in the ipv4 stack
  493. + */
  494. +void
  495. +P99L3Protocol::NotifyNewAggregate ()
  496. +{
  497. + NS_LOG_FUNCTION (this);
  498. + if (m_node == 0)
  499. + {
  500. + Ptr<Node>node = this->GetObject<Node> ();
  501. + //verify that it's a valid node and that
  502. + //the node was not set before
  503. + if (node != 0)
  504. + {
  505. + this->SetNode (node);
  506. + }
  507. + }
  508. + Object::NotifyNewAggregate ();
  509. +}
  510. +
  511. +void
  512. +P99L3Protocol::DoDispose (void)
  513. +{
  514. + NS_LOG_FUNCTION (this);
  515. + m_node = 0;
  516. + Object::DoDispose ();
  517. +}
  518. +
  519. +void
  520. +P99L3Protocol::Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
  521. + const Address &to, NetDevice::PacketType packetType)
  522. +{
  523. + NS_LOG_FUNCTION (this << device << p->GetSize () << protocol << from << to << packetType);
  524. +
  525. + Ptr<Packet> packet = p->Copy ();
  526. +
  527. + NS_LOG_LOGIC ("P99: received packet of size "<< packet->GetSize ());
  528. +
  529. + // The P99Header will return 0 if it can't deal
  530. + // with the received header.
  531. + P99Header p99;
  532. + uint32_t size = packet->RemoveHeader (p99);
  533. + if (size == 0)
  534. + {
  535. + NS_LOG_LOGIC ("P99: Cannot remove P99 header");
  536. + return;
  537. + }
  538. +
  539. +
  540. + if ( p99.IsRequest () )
  541. + {
  542. +
  543. + NS_LOG_INFO ( "node=" << m_node->GetId () << " got P99 request --echo packet " );
  544. +
  545. + SendP99Reply ( device, from, p99.GetStartTime () );
  546. +
  547. + }
  548. + else if ( p99.IsReply () )
  549. + {
  550. + u_int64_t pingms = ( Simulator::Now ().GetMilliSeconds () ) - p99.GetStartTime () ;
  551. +
  552. + NS_LOG_INFO ( "node=" << m_node->GetId () << " got reply to P99 request in " << pingms << "ms " );
  553. +
  554. + }
  555. +
  556. +}
  557. +
  558. +
  559. +void
  560. +P99L3Protocol::SendP99Request (Ptr<NetDevice> device, const Address &to, uint64_t requestTime)
  561. +{
  562. + NS_LOG_FUNCTION (this << device << to << requestTime );
  563. +
  564. + P99Header p99;
  565. + p99.SetRequest (requestTime);
  566. + Ptr<Packet> packet = Create<Packet> ();
  567. + packet->AddHeader (p99);
  568. +
  569. + NS_LOG_LOGIC ("P99: sending request from node "<<m_node->GetId ()<<
  570. + " || dst: " << to);
  571. +
  572. + device->Send (packet, to, PROT_NUMBER);
  573. +}
  574. +
  575. +
  576. +void
  577. +P99L3Protocol::SendP99Reply (Ptr<NetDevice> device, const Address &to, uint64_t requestTime)
  578. +{
  579. + NS_LOG_FUNCTION (this << device << to << requestTime );
  580. +
  581. + P99Header p99;
  582. + p99.SetReply (requestTime);
  583. + Ptr<Packet> packet = Create<Packet> ();
  584. + packet->AddHeader (p99);
  585. +
  586. + NS_LOG_LOGIC ("P99: sending reply from node "<<m_node->GetId ()<<
  587. + " || dst: " << to);
  588. +
  589. + device->Send (packet, to, PROT_NUMBER);
  590. +}
  591. +
  592. +
  593. +} // namespace ns3
  594. diff --git a/src/internet/model/p99-l3-protocol.h b/src/internet/model/p99-l3-protocol.h
  595. new file mode 100644
  596. index 000000000..0a96c9cf8
  597. --- /dev/null
  598. +++ b/src/internet/model/p99-l3-protocol.h
  599. @@ -0,0 +1,130 @@
  600. +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  601. +/*
  602. + * Copyright (c) 2019
  603. + *
  604. + * This program is free software; you can redistribute it and/or modify
  605. + * it under the terms of the GNU General Public License version 2 as
  606. + * published by the Free Software Foundation;
  607. + *
  608. + * This program is distributed in the hope that it will be useful,
  609. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  610. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  611. + * GNU General Public License for more details.
  612. + *
  613. + * You should have received a copy of the GNU General Public License
  614. + * along with this program; if not, write to the Free Software
  615. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  616. + *
  617. + * Author: Parth Yadav <parthyadav3105@gmail.com>
  618. + */
  619. +#ifndef P99_L3_PROTOCOL_H
  620. +#define P99_L3_PROTOCOL_H
  621. +
  622. +#include <list>
  623. +#include "ns3/net-device.h"
  624. +#include "ns3/address.h"
  625. +#include "ns3/ptr.h"
  626. +
  627. +namespace ns3 {
  628. +
  629. +class NetDevice;
  630. +class Node;
  631. +class Packet;
  632. +
  633. +/**
  634. + * \ingroup ipv4
  635. + * \defgroup p99 P99 protocol.
  636. + *
  637. + * The P99 protocol is responsible for simple ping
  638. + */
  639. +
  640. +/**
  641. + * \ingroup p99
  642. + * \brief An implementation of the P99 protocol.
  643. + */
  644. +class P99L3Protocol : public Object
  645. +{
  646. +public:
  647. +
  648. + /**
  649. + * \brief Get the type ID.
  650. + * \return the object TypeId
  651. + */
  652. + static TypeId GetTypeId (void);
  653. + static const uint16_t PROT_NUMBER; //!< P99 protocol number (0x0063)
  654. +
  655. + P99L3Protocol ();
  656. + virtual ~P99L3Protocol ();
  657. +
  658. + /**
  659. + * \brief Set the node the P99 L3 protocol is associated with
  660. + * \param node the node
  661. + */
  662. + void SetNode (Ptr<Node> node);
  663. +
  664. + /**
  665. + * \brief Receive a packet
  666. + * \param device the source NetDevice
  667. + * \param p the packet
  668. + * \param protocol the protocol
  669. + * \param from the source address
  670. + * \param to the destination address
  671. + * \param packetType type of packet (i.e., unicast, multicast, etc.)
  672. + */
  673. + void Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to,
  674. + NetDevice::PacketType packetType);
  675. +
  676. + /**
  677. + * \brief Send an P99 request to an host
  678. + * \param device the source NetDevice
  679. + * \param to Address of destination Node
  680. + * \param requestTime the time at which request was made
  681. + */
  682. + void SendP99Request (Ptr<NetDevice> device, const Address &to, uint64_t requestTime);
  683. +
  684. + /**
  685. + * \brief Send an P99 reply to an host
  686. + * \param device the source NetDevice
  687. + * \param to Address of destination Node
  688. + * \param requestTime the time at which request was made
  689. + */
  690. + void SendP99Reply (Ptr<NetDevice> device, const Address &to, uint64_t requestTime);
  691. +
  692. +
  693. +protected:
  694. +
  695. + virtual void DoDispose (void);
  696. +
  697. + /*
  698. + * This function will notify other components connected to the node that a new stack member is now connected
  699. + * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
  700. + */
  701. + virtual void NotifyNewAggregate ();
  702. +
  703. +
  704. +
  705. +private:
  706. +
  707. + /**
  708. + * \brief Copy constructor
  709. + *
  710. + * Defined and unimplemented to avoid misuse
  711. + * \param o
  712. + */
  713. + P99L3Protocol (const P99L3Protocol &o);
  714. +
  715. + /**
  716. + * \brief Copy constructor
  717. + *
  718. + * Defined and unimplemented to avoid misuse
  719. + * \param o
  720. + * \returns
  721. + */
  722. + P99L3Protocol &operator = (const P99L3Protocol &o);
  723. +
  724. + Ptr<Node> m_node; //!< node the P99 L3 protocol is associated with
  725. +};
  726. +
  727. +} // namespace ns3
  728. +
  729. +#endif /* P99_L3_PROTOCOL_H */
  730. diff --git a/src/internet/wscript b/src/internet/wscript
  731. index 571afc86d..821b7619a 100644
  732. --- a/src/internet/wscript
  733. +++ b/src/internet/wscript
  734. @@ -227,6 +227,8 @@ def build(bld):
  735. 'model/rip.cc',
  736. 'model/rip-header.cc',
  737. 'helper/rip-helper.cc',
  738. + 'model/p99-l3-protocol.cc',
  739. + 'model/p99-header.cc',
  740. ]
  741.  
  742. internet_test = bld.create_ns3_module_test_library('internet')
  743. @@ -410,6 +412,8 @@ def build(bld):
  744. 'model/rip.h',
  745. 'model/rip-header.h',
  746. 'helper/rip-helper.h',
  747. + 'model/p99-l3-protocol.h',
  748. + 'model/p99-header.h',
  749. ]
  750.  
  751. if bld.env['NSC_ENABLED']:
  752. --
  753. 2.19.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement