blob: 57d1d83344f3640f67fd26768f4f02506b33d355 [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
38typedef Interest InterestHeader;
39typedef ContentObject ContentObjectHeader;
40
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070041class Face;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080042
43/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070044 * @ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045 * @brief Base class that all NDN applications should be derived from.
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080046 *
47 * The class implements virtual calls onInterest, onNack, and onContentObject
48 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049class App: public Application
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080050{
51public:
Ilya Moiseenko956d0542012-01-02 15:26:40 -080052 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070053 * @brief A callback to pass packets to underlying NDN protocol
Ilya Moiseenko956d0542012-01-02 15:26:40 -080054 */
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080055 typedef Callback<bool, const Ptr<const Packet>&> ProtocolHandler;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080056
57 static TypeId GetTypeId ();
58
59 /**
60 * @brief Default constructor
61 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070062 App ();
63 virtual ~App ();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080064
65 /**
66 * @brief Register lower layer callback (to send interests from the application)
67 */
68 void
69 RegisterProtocolHandler (ProtocolHandler handler);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -080070
71 /**
72 * @brief Get application ID (ID of applications face)
73 */
74 uint32_t
75 GetId () const;
76
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080077 /**
78 * @brief Method that will be called every time new Interest arrives
79 * @param interest Interest header
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080080 * @param packet "Payload" of the interests packet. The actual payload should be zero, but packet itself
81 * may be useful to get packet tags
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080082 */
83 virtual void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070084 OnInterest (const Ptr<const Interest> &interest, Ptr<Packet> packet);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080085
86 /**
87 * @brief Method that will be called every time new NACK arrives
88 * @param interest Interest header
89 */
90 virtual void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070091 OnNack (const Ptr<const Interest> &interest, Ptr<Packet> packet);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080092
93 /**
94 * @brief Method that will be called every time new ContentObject arrives
95 * @param contentObject ContentObject header
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080096 * @param payload payload (potentially virtual) of the ContentObject packet (may include packet tags of original packet)
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080097 */
98 virtual void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070099 OnContentObject (const Ptr<const ContentObject> &contentObject,
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800100 Ptr<Packet> payload);
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800101
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800102protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700103 /**
104 * @brief Do cleanup when application is destroyed
105 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800106 virtual void
107 DoDispose ();
108
Alexander Afanasyev06d3a612012-04-17 22:25:40 -0700109 // inherited from Application base class. Originally they were private
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800110 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700111 StartApplication (); ///< @brief Called at time specified by Start
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800112
113 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700114 StopApplication (); ///< @brief Called at time specified by Stop
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800115
116protected:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700117 ProtocolHandler m_protocolHandler; ///< @brief A callback to pass packets to underlying NDN protocol
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700118 bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119 Ptr<Face> m_face; ///< @brief automatically created application face through which application communicates
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800120
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700121 TracedCallback<Ptr<const Interest>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700122 Ptr<App>, Ptr<Face> > m_receivedInterests; ///< @brief App-level trace of received Interests
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800123
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700124 TracedCallback<Ptr<const Interest>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700125 Ptr<App>, Ptr<Face> > m_receivedNacks; ///< @brief App-level trace of received NACKs
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800126
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700127 TracedCallback<Ptr<const ContentObject>, Ptr<const Packet>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700128 Ptr<App>, Ptr<Face> > m_receivedContentObjects; ///< @brief App-level trace of received Data
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700129
130
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700131 TracedCallback<Ptr<const Interest>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700132 Ptr<App>, Ptr<Face> > m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700133
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700134 TracedCallback<Ptr<const ContentObject>, Ptr<const Packet>,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700135 Ptr<App>, Ptr<Face> > m_transmittedContentObjects; ///< @brief App-level trace of transmitted Data
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800136};
137
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700138} // namespace ndn
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800139} // namespace ns3
140
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700141#endif // NDN_APP_H