Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #ifndef NDN_APP_H |
| 22 | #define NDN_APP_H |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 23 | |
| 24 | #include "ns3/application.h" |
| 25 | #include "ns3/ptr.h" |
| 26 | #include "ns3/callback.h" |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 27 | #include "ns3/traced-callback.h" |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 29 | namespace ns3 { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 30 | |
| 31 | class Packet; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ndn { |
| 34 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 35 | class Interest; |
| 36 | class ContentObject; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 37 | |
| 38 | typedef Interest InterestHeader; |
| 39 | typedef ContentObject ContentObjectHeader; |
| 40 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 41 | class Face; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 42 | |
| 43 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 44 | * @ingroup ndn |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 45 | * @brief Base class that all NDN applications should be derived from. |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 46 | * |
| 47 | * The class implements virtual calls onInterest, onNack, and onContentObject |
| 48 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 49 | class App: public Application |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 50 | { |
| 51 | public: |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 52 | /** |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 53 | * @brief A callback to pass packets to underlying NDN protocol |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 54 | */ |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 55 | typedef Callback<bool, const Ptr<const Packet>&> ProtocolHandler; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 56 | |
| 57 | static TypeId GetTypeId (); |
| 58 | |
| 59 | /** |
| 60 | * @brief Default constructor |
| 61 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 62 | App (); |
| 63 | virtual ~App (); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * @brief Register lower layer callback (to send interests from the application) |
| 67 | */ |
| 68 | void |
| 69 | RegisterProtocolHandler (ProtocolHandler handler); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * @brief Get application ID (ID of applications face) |
| 73 | */ |
| 74 | uint32_t |
| 75 | GetId () const; |
| 76 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 77 | /** |
| 78 | * @brief Method that will be called every time new Interest arrives |
| 79 | * @param interest Interest header |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 80 | * @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 Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 82 | */ |
| 83 | virtual void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 84 | OnInterest (const Ptr<const Interest> &interest, Ptr<Packet> packet); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * @brief Method that will be called every time new NACK arrives |
| 88 | * @param interest Interest header |
| 89 | */ |
| 90 | virtual void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 91 | OnNack (const Ptr<const Interest> &interest, Ptr<Packet> packet); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * @brief Method that will be called every time new ContentObject arrives |
| 95 | * @param contentObject ContentObject header |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 96 | * @param payload payload (potentially virtual) of the ContentObject packet (may include packet tags of original packet) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 97 | */ |
| 98 | virtual void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 99 | OnContentObject (const Ptr<const ContentObject> &contentObject, |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 100 | Ptr<Packet> payload); |
Alexander Afanasyev | db64ff1 | 2013-01-18 16:37:31 -0800 | [diff] [blame] | 101 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 102 | protected: |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 103 | /** |
| 104 | * @brief Do cleanup when application is destroyed |
| 105 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 106 | virtual void |
| 107 | DoDispose (); |
| 108 | |
Alexander Afanasyev | 06d3a61 | 2012-04-17 22:25:40 -0700 | [diff] [blame] | 109 | // inherited from Application base class. Originally they were private |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 110 | virtual void |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 111 | StartApplication (); ///< @brief Called at time specified by Start |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 112 | |
| 113 | virtual void |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 114 | StopApplication (); ///< @brief Called at time specified by Stop |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 115 | |
| 116 | protected: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 117 | ProtocolHandler m_protocolHandler; ///< @brief A callback to pass packets to underlying NDN protocol |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 118 | bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication) |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 119 | Ptr<Face> m_face; ///< @brief automatically created application face through which application communicates |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 120 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 121 | TracedCallback<Ptr<const Interest>, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 122 | Ptr<App>, Ptr<Face> > m_receivedInterests; ///< @brief App-level trace of received Interests |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 123 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 124 | TracedCallback<Ptr<const Interest>, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 125 | Ptr<App>, Ptr<Face> > m_receivedNacks; ///< @brief App-level trace of received NACKs |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 126 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 127 | TracedCallback<Ptr<const ContentObject>, Ptr<const Packet>, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 128 | Ptr<App>, Ptr<Face> > m_receivedContentObjects; ///< @brief App-level trace of received Data |
Alexander Afanasyev | 15f9299 | 2012-04-09 14:56:56 -0700 | [diff] [blame] | 129 | |
| 130 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 131 | TracedCallback<Ptr<const Interest>, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 132 | Ptr<App>, Ptr<Face> > m_transmittedInterests; ///< @brief App-level trace of transmitted Interests |
Alexander Afanasyev | 15f9299 | 2012-04-09 14:56:56 -0700 | [diff] [blame] | 133 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 134 | TracedCallback<Ptr<const ContentObject>, Ptr<const Packet>, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 135 | Ptr<App>, Ptr<Face> > m_transmittedContentObjects; ///< @brief App-level trace of transmitted Data |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 136 | }; |
| 137 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 138 | } // namespace ndn |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 139 | } // namespace ns3 |
| 140 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 141 | #endif // NDN_APP_H |