blob: 5af75b54fabf6248104b0e62a723dd4d833db7ca [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080019
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070020#ifndef NDN_APP_H
21#define NDN_APP_H
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080022
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
Alexander Afanasyevc018a562016-09-08 16:27:31 -070024#include "ns3/ndnSIM/model/ndn-app-link-service.hpp"
25#include "ns3/ndnSIM/NFD/daemon/face/face.hpp"
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070026
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080027#include "ns3/application.h"
28#include "ns3/ptr.h"
29#include "ns3/callback.h"
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080030#include "ns3/traced-callback.h"
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080031
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032namespace ns3 {
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080033
34class Packet;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070035
36namespace ndn {
37
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080038/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070039 * \ingroup ndn
40 * \defgroup ndn-apps NDN applications
41 */
42/**
43 * @ingroup ndn-apps
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070044 * @brief Base class that all NDN applications should be derived from.
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 *
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070046 * The class implements virtual calls onInterest, onNack, and onData
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080047 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048class App : public Application {
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080049public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 static TypeId
51 GetTypeId();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080052
53 /**
54 * @brief Default constructor
55 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 App();
57 virtual ~App();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080058
59 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080060 * @brief Get application ID (ID of applications face)
61 */
62 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 GetId() const;
64
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080065 /**
66 * @brief Method that will be called every time new Interest arrives
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080067 */
68 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070069 OnInterest(shared_ptr<const Interest> interest);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080071 /**
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070072 * @brief Method that will be called every time new Data arrives
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080073 */
74 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070075 OnData(shared_ptr<const Data> data);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076
Alexander Afanasyevc018a562016-09-08 16:27:31 -070077 /**
78 * @brief Method that will be called every time new Nack arrives
79 */
80 virtual void
81 OnNack(shared_ptr<const lp::Nack> nack);
82
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070083public:
84 typedef void (*InterestTraceCallback)(shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>);
85 typedef void (*DataTraceCallback)(shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>);
Spyridon Mastorakis7f2fd422016-12-07 14:33:59 -080086 typedef void (*NackTraceCallback)(shared_ptr<const lp::Nack>, Ptr<App>, shared_ptr<Face>);
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070087
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080088protected:
Alexander Afanasyev6a720c12015-08-21 12:50:13 -070089 virtual void
90 DoInitialize();
91
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080092 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 DoDispose();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080094
Alexander Afanasyev06d3a612012-04-17 22:25:40 -070095 // inherited from Application base class. Originally they were private
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080096 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 StartApplication(); ///< @brief Called at time specified by Start
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080098
99 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 StopApplication(); ///< @brief Called at time specified by Stop
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800101
102protected:
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700103 bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication)
Alexander Afanasyevc018a562016-09-08 16:27:31 -0700104 shared_ptr<Face> m_face;
105 AppLinkService* m_appLink;
106
Alexander Afanasyev6a720c12015-08-21 12:50:13 -0700107 uint32_t m_appId;
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800108
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700109 TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 m_receivedInterests; ///< @brief App-level trace of received Interests
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800111
Mickey Sweatt89046c12014-11-16 20:32:27 -0800112 TracedCallback<shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>>
113 m_receivedDatas; ///< @brief App-level trace of received Data
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800114
Spyridon Mastorakis7f2fd422016-12-07 14:33:59 -0800115 TracedCallback<shared_ptr<const lp::Nack>, Ptr<App>, shared_ptr<Face>>
116 m_receivedNacks; ///< @brief App-level trace of received Nacks
Alexander Afanasyevc018a562016-09-08 16:27:31 -0700117
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700118 TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700120
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700121 TracedCallback<shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122 m_transmittedDatas; ///< @brief App-level trace of transmitted Data
Alexander Afanasyevc018a562016-09-08 16:27:31 -0700123
Spyridon Mastorakis7f2fd422016-12-07 14:33:59 -0800124 TracedCallback<shared_ptr<const lp::Nack>, Ptr<App>, shared_ptr<Face>>
125 m_transmittedNacks; ///< @brief App-level trace of transmitted Nacks
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800126};
127
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700128} // namespace ndn
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800129} // namespace ns3
130
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700131#endif // NDN_APP_H