blob: 7a3cfd7d3a2991f956a1662f83fdcb6c7b4c66c0 [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
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
25#include "ns3/ndnSIM/model/ndn-app-face.hpp"
26
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
67 * @param interest Interest header
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 * @param packet "Payload" of the interests packet. The actual payload should be zero, but
69 * packet itself
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080070 * may be useful to get packet tags
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080071 */
72 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070073 OnInterest(shared_ptr<const Interest> interest);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080075 /**
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070076 * @brief Method that will be called every time new Data arrives
77 * @param contentObject Data header
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 * @param payload payload (potentially virtual) of the Data packet (may include packet tags of
79 * original packet)
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080080 */
81 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070082 OnData(shared_ptr<const Data> data);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080084protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070085 /**
86 * @brief Do cleanup when application is destroyed
87 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080088 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 DoDispose();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080090
Alexander Afanasyev06d3a612012-04-17 22:25:40 -070091 // inherited from Application base class. Originally they were private
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080092 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 StartApplication(); ///< @brief Called at time specified by Start
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080094
95 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 StopApplication(); ///< @brief Called at time specified by Stop
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080097
98protected:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication
100 /// and StopApplication)
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700101 shared_ptr<Face> m_face; ///< @brief automatically created application face through which application
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 /// communicates
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800103
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700104 TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 m_receivedInterests; ///< @brief App-level trace of received Interests
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800106
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700107 TracedCallback<shared_ptr<const Data>, Ptr<App>,
108 shared_ptr<Face>> m_receivedDatas; ///< @brief App-level trace of received Data
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800109
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700110 TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800111 m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700112
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700113 TracedCallback<shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 m_transmittedDatas; ///< @brief App-level trace of transmitted Data
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800115};
116
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700117} // namespace ndn
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800118} // namespace ns3
119
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700120#endif // NDN_APP_H