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" |
| 27 | |
| 28 | namespace ns3 |
| 29 | { |
| 30 | |
| 31 | class Packet; |
| 32 | class CcnxInterestHeader; |
| 33 | class CcnxContentObjectHeader; |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 34 | class CcnxFace; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * @ingroup ccnx |
| 38 | * @brief Base class that all CCNx applications should be derived from. |
| 39 | * |
| 40 | * The class implements virtual calls onInterest, onNack, and onContentObject |
| 41 | */ |
| 42 | class CcnxApp: public Application |
| 43 | { |
| 44 | public: |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 45 | typedef Callback<bool, const Ptr<const Packet>&> ProtocolHandler; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 46 | |
| 47 | static TypeId GetTypeId (); |
| 48 | |
| 49 | /** |
| 50 | * @brief Default constructor |
| 51 | */ |
| 52 | CcnxApp (); |
| 53 | virtual ~CcnxApp (); |
| 54 | |
| 55 | /** |
| 56 | * @brief Register lower layer callback (to send interests from the application) |
| 57 | */ |
| 58 | void |
| 59 | RegisterProtocolHandler (ProtocolHandler handler); |
| 60 | |
| 61 | /** |
| 62 | * @brief Method that will be called every time new Interest arrives |
| 63 | * @param interest Interest header |
| 64 | */ |
| 65 | virtual void |
| 66 | OnInterest (const Ptr<const CcnxInterestHeader> &interest); |
| 67 | |
| 68 | /** |
| 69 | * @brief Method that will be called every time new NACK arrives |
| 70 | * @param interest Interest header |
| 71 | */ |
| 72 | virtual void |
| 73 | OnNack (const Ptr<const CcnxInterestHeader> &interest); |
| 74 | |
| 75 | /** |
| 76 | * @brief Method that will be called every time new ContentObject arrives |
| 77 | * @param contentObject ContentObject header |
| 78 | * @param payload payload (potentially virtual) of the ContentObject packet |
| 79 | */ |
| 80 | virtual void |
| 81 | OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
| 82 | const Ptr<const Packet> &payload); |
| 83 | |
| 84 | protected: |
| 85 | virtual void |
| 86 | DoDispose (); |
| 87 | |
| 88 | // inherited from Application base class. |
| 89 | virtual void |
| 90 | StartApplication (); // Called at time specified by Start |
| 91 | |
| 92 | virtual void |
| 93 | StopApplication (); // Called at time specified by Stop |
| 94 | |
| 95 | protected: |
| 96 | ProtocolHandler m_protocolHandler; |
| 97 | bool m_active; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 98 | Ptr<CcnxFace> m_face; // local face that is created |
| 99 | }; |
| 100 | |
| 101 | } // namespace ns3 |
| 102 | |
| 103 | #endif // CCNX_APP_H |