blob: 491cae46b5bb26a3cd1137bea19a1e06782bef48 [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;
36class ContentObject;
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 Afanasyev4aac5572012-08-09 10:49:55 -070041 * @ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070042 * @brief Base class that all NDN applications should be derived from.
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080043 *
44 * The class implements virtual calls onInterest, onNack, and onContentObject
45 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070046class App: public Application
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080047{
48public:
Ilya Moiseenko956d0542012-01-02 15:26:40 -080049 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070050 * @brief A callback to pass packets to underlying NDN protocol
Ilya Moiseenko956d0542012-01-02 15:26:40 -080051 */
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070052 typedef Callback<bool, Ptr<const Interest>, Ptr<const Packet> > InterestHandler;
53 typedef Callback<bool, Ptr<const ContentObject>, Ptr<const Packet> > DataHandler;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080054
55 static TypeId GetTypeId ();
56
57 /**
58 * @brief Default constructor
59 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060 App ();
61 virtual ~App ();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080062
63 /**
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080064 * @brief Get application ID (ID of applications face)
65 */
66 uint32_t
67 GetId () const;
68
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080069 /**
70 * @brief Method that will be called every time new Interest arrives
71 * @param interest Interest header
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080072 * @param packet "Payload" of the interests packet. The actual payload should be zero, but packet itself
73 * may be useful to get packet tags
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080074 */
75 virtual void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070076 OnInterest (const Ptr<const Interest> &interest, Ptr<Packet> packet);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080077
78 /**
79 * @brief Method that will be called every time new NACK arrives
80 * @param interest Interest header
81 */
82 virtual void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070083 OnNack (const Ptr<const Interest> &interest, Ptr<Packet> packet);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080084
85 /**
86 * @brief Method that will be called every time new ContentObject arrives
87 * @param contentObject ContentObject header
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080088 * @param payload payload (potentially virtual) of the ContentObject packet (may include packet tags of original packet)
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080089 */
90 virtual void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070091 OnContentObject (const Ptr<const ContentObject> &contentObject,
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080092 Ptr<Packet> payload);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080093
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080094protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070095 /**
96 * @brief Do cleanup when application is destroyed
97 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080098 virtual void
99 DoDispose ();
100
Alexander Afanasyev06d3a612012-04-17 22:25:40 -0700101 // inherited from Application base class. Originally they were private
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800102 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700103 StartApplication (); ///< @brief Called at time specified by Start
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800104
105 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700106 StopApplication (); ///< @brief Called at time specified by Stop
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800107
108protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700109 bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700110 Ptr<Face> m_face; ///< @brief automatically created application face through which application communicates
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800111
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700112 TracedCallback<Ptr<const Interest>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700113 Ptr<App>, Ptr<Face> > m_receivedInterests; ///< @brief App-level trace of received Interests
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800114
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700115 TracedCallback<Ptr<const Interest>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700116 Ptr<App>, Ptr<Face> > m_receivedNacks; ///< @brief App-level trace of received NACKs
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800117
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700118 TracedCallback<Ptr<const ContentObject>, Ptr<const Packet>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119 Ptr<App>, Ptr<Face> > m_receivedContentObjects; ///< @brief App-level trace of received Data
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700120
121
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700122 TracedCallback<Ptr<const Interest>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700123 Ptr<App>, Ptr<Face> > m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700124
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700125 TracedCallback<Ptr<const ContentObject>, Ptr<const Packet>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700126 Ptr<App>, Ptr<Face> > m_transmittedContentObjects; ///< @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