blob: a8f83e1dbe401130b7c1d7d8b7e188427fec5afe [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev68de7952012-12-12 18:02:29 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev68de7952012-12-12 18:02:29 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyev68de7952012-12-12 18:02:29 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev68de7952012-12-12 18:02:29 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev68de7952012-12-12 18:02:29 -080019
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080020// custom-app.hpp
Alexander Afanasyev68de7952012-12-12 18:02:29 -080021
22#ifndef CUSTOM_APP_H_
23#define CUSTOM_APP_H_
24
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070025#include "ns3/ndnSIM/model/ndn-common.hpp"
26
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080027#include "ns3/ndnSIM/apps/ndn-app.hpp"
Alexander Afanasyev68de7952012-12-12 18:02:29 -080028
29namespace ns3 {
30
31/**
32 * @brief A simple custom application
33 *
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070034 * This applications demonstrates how to send Interests and respond with Datas to incoming interests
Alexander Afanasyev68de7952012-12-12 18:02:29 -080035 *
36 * When application starts it "sets interest filter" (install FIB entry) for /prefix/sub, as well as
37 * sends Interest for this prefix
38 *
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070039 * When an Interest is received, it is replied with a Data with 1024-byte fake payload
Alexander Afanasyev68de7952012-12-12 18:02:29 -080040 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041class CustomApp : public ndn::App {
Alexander Afanasyev68de7952012-12-12 18:02:29 -080042public:
43 // register NS-3 type "CustomApp"
44 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 GetTypeId();
46
Alexander Afanasyev68de7952012-12-12 18:02:29 -080047 // (overridden from ndn::App) Processing upon start of the application
48 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049 StartApplication();
Alexander Afanasyev68de7952012-12-12 18:02:29 -080050
51 // (overridden from ndn::App) Processing when application is stopped
52 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 StopApplication();
Alexander Afanasyev68de7952012-12-12 18:02:29 -080054
55 // (overridden from ndn::App) Callback that will be called when Interest arrives
56 virtual void
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080057 OnInterest(shared_ptr<const ndn::Interest> interest);
Alexander Afanasyev68de7952012-12-12 18:02:29 -080058
59 // (overridden from ndn::App) Callback that will be called when Data arrives
60 virtual void
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080061 OnData(shared_ptr<const ndn::Data> contentObject);
Alexander Afanasyev68de7952012-12-12 18:02:29 -080062
63private:
64 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 SendInterest();
Alexander Afanasyev68de7952012-12-12 18:02:29 -080066};
67
68} // namespace ns3
69
70#endif // CUSTOM_APP_H_