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 | |
| 21 | #ifndef CCNX_APP_H |
| 22 | #define CCNX_APP_H |
| 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 | |
| 29 | namespace ns3 |
| 30 | { |
| 31 | |
| 32 | class Packet; |
| 33 | class CcnxInterestHeader; |
| 34 | class CcnxContentObjectHeader; |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 35 | class CcnxFace; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * @ingroup ccnx |
| 39 | * @brief Base class that all CCNx applications should be derived from. |
| 40 | * |
| 41 | * The class implements virtual calls onInterest, onNack, and onContentObject |
| 42 | */ |
| 43 | class CcnxApp: public Application |
| 44 | { |
| 45 | public: |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 46 | /** |
| 47 | * \typedef A callback to pass packets to underlying CCNx protocol |
| 48 | */ |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 49 | typedef Callback<bool, const Ptr<const Packet>&> ProtocolHandler; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 50 | |
| 51 | static TypeId GetTypeId (); |
| 52 | |
| 53 | /** |
| 54 | * @brief Default constructor |
| 55 | */ |
| 56 | CcnxApp (); |
| 57 | virtual ~CcnxApp (); |
| 58 | |
| 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 Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 68 | * @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 Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 70 | */ |
| 71 | virtual void |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 72 | OnInterest (const Ptr<const CcnxInterestHeader> &interest, Ptr<Packet> packet); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * @brief Method that will be called every time new NACK arrives |
| 76 | * @param interest Interest header |
| 77 | */ |
| 78 | virtual void |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 79 | OnNack (const Ptr<const CcnxInterestHeader> &interest, Ptr<Packet> packet); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * @brief Method that will be called every time new ContentObject arrives |
| 83 | * @param contentObject ContentObject header |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 84 | * @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] | 85 | */ |
| 86 | virtual void |
| 87 | OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 88 | Ptr<Packet> payload); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 89 | |
| 90 | protected: |
| 91 | virtual void |
| 92 | DoDispose (); |
| 93 | |
| 94 | // inherited from Application base class. |
| 95 | virtual void |
| 96 | StartApplication (); // Called at time specified by Start |
| 97 | |
| 98 | virtual void |
| 99 | StopApplication (); // Called at time specified by Stop |
| 100 | |
| 101 | protected: |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 102 | ProtocolHandler m_protocolHandler; ///< \brief A callback to pass packets to underlying CCNx protocol |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 103 | bool m_active; |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 104 | Ptr<CcnxFace> m_face; // local face that is created |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 105 | |
| 106 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 107 | Ptr<CcnxApp>, Ptr<CcnxFace> > m_receivedInterests; |
| 108 | |
| 109 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 110 | Ptr<CcnxApp>, Ptr<CcnxFace> > m_receivedNacks; |
| 111 | |
| 112 | TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, |
| 113 | Ptr<CcnxApp>, Ptr<CcnxFace> > m_receivedContentObjects; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace ns3 |
| 117 | |
| 118 | #endif // CCNX_APP_H |