blob: edede34192b97dab151300172df4eec50d37a497 [file] [log] [blame]
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#ifndef NDN_APP_H
22#define NDN_APP_H
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080023
24#include "ns3/application.h"
25#include "ns3/ptr.h"
26#include "ns3/callback.h"
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080027#include "ns3/traced-callback.h"
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080028
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070029namespace ns3 {
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080030
31class Packet;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032
33namespace ndn {
34
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070035class Interest;
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070036class Data;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070037
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070038class Face;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080039
40/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070041 * \ingroup ndn
42 * \defgroup ndn-apps NDN applications
43 */
44/**
45 * @ingroup ndn-apps
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070046 * @brief Base class that all NDN applications should be derived from.
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 *
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070048 * The class implements virtual calls onInterest, onNack, and onData
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080049 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050class App : public Application {
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080051public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 static TypeId
53 GetTypeId();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080054
55 /**
56 * @brief Default constructor
57 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 App();
59 virtual ~App();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080060
61 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080062 * @brief Get application ID (ID of applications face)
63 */
64 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 GetId() const;
66
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080067 /**
68 * @brief Method that will be called every time new Interest arrives
69 * @param interest Interest header
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 * @param packet "Payload" of the interests packet. The actual payload should be zero, but
71 * packet itself
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080072 * may be useful to get packet tags
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080073 */
74 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 OnInterest(Ptr<const Interest> interest);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080076
77 /**
78 * @brief Method that will be called every time new NACK arrives
79 * @param interest Interest header
80 */
81 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 OnNack(Ptr<const Interest> interest);
83
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080084 /**
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070085 * @brief Method that will be called every time new Data arrives
86 * @param contentObject Data header
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 * @param payload payload (potentially virtual) of the Data packet (may include packet tags of
88 * original packet)
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080089 */
90 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 OnData(Ptr<const Data> contentObject);
92
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080093protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070094 /**
95 * @brief Do cleanup when application is destroyed
96 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080097 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 DoDispose();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080099
Alexander Afanasyev06d3a612012-04-17 22:25:40 -0700100 // inherited from Application base class. Originally they were private
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800101 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 StartApplication(); ///< @brief Called at time specified by Start
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800103
104 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 StopApplication(); ///< @brief Called at time specified by Stop
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800106
107protected:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication
109 /// and StopApplication)
110 Ptr<Face> m_face; ///< @brief automatically created application face through which application
111 /// communicates
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800112
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113 TracedCallback<Ptr<const Interest>, Ptr<App>, Ptr<Face>>
114 m_receivedInterests; ///< @brief App-level trace of received Interests
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800115
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 TracedCallback<Ptr<const Interest>, Ptr<App>, Ptr<Face>>
117 m_receivedNacks; ///< @brief App-level trace of received NACKs
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800118
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 TracedCallback<Ptr<const Data>, Ptr<App>, Ptr<Face>>
120 m_receivedDatas; ///< @brief App-level trace of received Data
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700121
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122 TracedCallback<Ptr<const Interest>, Ptr<App>, Ptr<Face>>
123 m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700124
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800125 TracedCallback<Ptr<const Data>, Ptr<App>, Ptr<Face>>
126 m_transmittedDatas; ///< @brief App-level trace of transmitted Data
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800127};
128
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700129} // namespace ndn
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800130} // namespace ns3
131
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700132#endif // NDN_APP_H