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