blob: c152ff2c01293567ad6aa6104c31a790ef610397 [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
29namespace ns3
30{
31
32class Packet;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070033class NdnInterestHeader;
34class NdnContentObjectHeader;
35class NdnFace;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080036
37/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070038 * @ingroup ndn
39 * @brief Base class that all Ndn applications should be derived from.
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080040 *
41 * The class implements virtual calls onInterest, onNack, and onContentObject
42 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070043class NdnApp: public Application
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080044{
45public:
Ilya Moiseenko956d0542012-01-02 15:26:40 -080046 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070047 * @brief A callback to pass packets to underlying Ndn protocol
Ilya Moiseenko956d0542012-01-02 15:26:40 -080048 */
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080049 typedef Callback<bool, const Ptr<const Packet>&> ProtocolHandler;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080050
51 static TypeId GetTypeId ();
52
53 /**
54 * @brief Default constructor
55 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070056 NdnApp ();
57 virtual ~NdnApp ();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080058
59 /**
60 * @brief Register lower layer callback (to send interests from the application)
61 */
62 void
63 RegisterProtocolHandler (ProtocolHandler handler);
64
65 /**
66 * @brief Method that will be called every time new Interest arrives
67 * @param interest Interest header
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080068 * @param packet "Payload" of the interests packet. The actual payload should be zero, but packet itself
69 * may be useful to get packet tags
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080070 */
71 virtual void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070072 OnInterest (const Ptr<const NdnInterestHeader> &interest, Ptr<Packet> packet);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080073
74 /**
75 * @brief Method that will be called every time new NACK arrives
76 * @param interest Interest header
77 */
78 virtual void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070079 OnNack (const Ptr<const NdnInterestHeader> &interest, Ptr<Packet> packet);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080080
81 /**
82 * @brief Method that will be called every time new ContentObject arrives
83 * @param contentObject ContentObject header
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080084 * @param payload payload (potentially virtual) of the ContentObject packet (may include packet tags of original packet)
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080085 */
86 virtual void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070087 OnContentObject (const Ptr<const NdnContentObjectHeader> &contentObject,
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080088 Ptr<Packet> payload);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080089
90protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070091 /**
92 * @brief Do cleanup when application is destroyed
93 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080094 virtual void
95 DoDispose ();
96
Alexander Afanasyev06d3a612012-04-17 22:25:40 -070097 // inherited from Application base class. Originally they were private
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080098 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070099 StartApplication (); ///< @brief Called at time specified by Start
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800100
101 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700102 StopApplication (); ///< @brief Called at time specified by Stop
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800103
104protected:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700105 ProtocolHandler m_protocolHandler; ///< @brief A callback to pass packets to underlying Ndn protocol
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700106 bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700107 Ptr<NdnFace> m_face; ///< @brief automatically created application face through which application communicates
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800108
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700109 TracedCallback<Ptr<const NdnInterestHeader>,
110 Ptr<NdnApp>, Ptr<NdnFace> > m_receivedInterests; ///< @brief App-level trace of received Interests
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800111
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700112 TracedCallback<Ptr<const NdnInterestHeader>,
113 Ptr<NdnApp>, Ptr<NdnFace> > m_receivedNacks; ///< @brief App-level trace of received NACKs
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800114
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700115 TracedCallback<Ptr<const NdnContentObjectHeader>, Ptr<const Packet>,
116 Ptr<NdnApp>, Ptr<NdnFace> > m_receivedContentObjects; ///< @brief App-level trace of received Data
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700117
118
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700119 TracedCallback<Ptr<const NdnInterestHeader>,
120 Ptr<NdnApp>, Ptr<NdnFace> > m_transmittedInterests; ///< @brief App-level trace of transmitted Interests
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700121
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700122 TracedCallback<Ptr<const NdnContentObjectHeader>, Ptr<const Packet>,
123 Ptr<NdnApp>, Ptr<NdnFace> > m_transmittedContentObjects; ///< @brief App-level trace of transmitted Data
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800124};
125
126} // namespace ns3
127
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700128#endif // NDN_APP_H