blob: 57dda5868699bb15293413c59190bc6a70252be4 [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"
24#include "ns3/ndnSIM/model/ndn-app-face.hpp"
25
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080026#include "ns3/application.h"
27#include "ns3/ptr.h"
28#include "ns3/callback.h"
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080029#include "ns3/traced-callback.h"
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080030
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070031namespace ns3 {
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080032
33class Packet;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070034
35namespace ndn {
36
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080037/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070038 * \ingroup ndn
39 * \defgroup ndn-apps NDN applications
40 */
41/**
42 * @ingroup ndn-apps
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070043 * @brief Base class that all NDN applications should be derived from.
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044 *
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070045 * The class implements virtual calls onInterest, onNack, and onData
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080046 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047class App : public Application {
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080048public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049 static TypeId
50 GetTypeId();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080051
52 /**
53 * @brief Default constructor
54 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 App();
56 virtual ~App();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080057
58 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080059 * @brief Get application ID (ID of applications face)
60 */
61 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 GetId() const;
63
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080064 /**
65 * @brief Method that will be called every time new Interest arrives
66 * @param interest Interest header
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 * @param packet "Payload" of the interests packet. The actual payload should be zero, but
68 * packet itself
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080069 * may be useful to get packet tags
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080070 */
71 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070072 OnInterest(shared_ptr<const Interest> interest);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080074 /**
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070075 * @brief Method that will be called every time new Data arrives
76 * @param contentObject Data header
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 * @param payload payload (potentially virtual) of the Data packet (may include packet tags of
78 * original packet)
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080079 */
80 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070081 OnData(shared_ptr<const Data> data);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082
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>);
86
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080087protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070088 /**
89 * @brief Do cleanup when application is destroyed
90 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080091 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 DoDispose();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080093
Alexander Afanasyev06d3a612012-04-17 22:25:40 -070094 // inherited from Application base class. Originally they were private
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080095 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 StartApplication(); ///< @brief Called at time specified by Start
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080097
98 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 StopApplication(); ///< @brief Called at time specified by Stop
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800100
101protected:
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700102 bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication)
103 shared_ptr<AppFace> m_face; ///< @brief automatically created application face through which application communicates
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800104
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700105 TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 m_receivedInterests; ///< @brief App-level trace of received Interests
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800107
Mickey Sweatt89046c12014-11-16 20:32:27 -0800108 TracedCallback<shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>>
109 m_receivedDatas; ///< @brief App-level trace of received Data
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800110
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700111 TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700113
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700114 TracedCallback<shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800115 m_transmittedDatas; ///< @brief App-level trace of transmitted Data
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800116};
117
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700118} // namespace ndn
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800119} // namespace ns3
120
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700121#endif // NDN_APP_H