blob: 457172e6c9e98cc7c32a34481b8521ba8f76c509 [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"
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080027#include "ns3/traced-callback.h"
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080028
29namespace ns3
30{
31
32class Packet;
33class CcnxInterestHeader;
34class CcnxContentObjectHeader;
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080035class CcnxFace;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080036
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 */
43class CcnxApp: public Application
44{
45public:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080046 typedef Callback<bool, const Ptr<const Packet>&> ProtocolHandler;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080047
48 static TypeId GetTypeId ();
49
50 /**
51 * @brief Default constructor
52 */
53 CcnxApp ();
54 virtual ~CcnxApp ();
55
56 /**
57 * @brief Register lower layer callback (to send interests from the application)
58 */
59 void
60 RegisterProtocolHandler (ProtocolHandler handler);
61
62 /**
63 * @brief Method that will be called every time new Interest arrives
64 * @param interest Interest header
65 */
66 virtual void
67 OnInterest (const Ptr<const CcnxInterestHeader> &interest);
68
69 /**
70 * @brief Method that will be called every time new NACK arrives
71 * @param interest Interest header
72 */
73 virtual void
74 OnNack (const Ptr<const CcnxInterestHeader> &interest);
75
76 /**
77 * @brief Method that will be called every time new ContentObject arrives
78 * @param contentObject ContentObject header
79 * @param payload payload (potentially virtual) of the ContentObject packet
80 */
81 virtual void
82 OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
83 const Ptr<const Packet> &payload);
84
85protected:
86 virtual void
87 DoDispose ();
88
89 // inherited from Application base class.
90 virtual void
91 StartApplication (); // Called at time specified by Start
92
93 virtual void
94 StopApplication (); // Called at time specified by Stop
95
96protected:
97 ProtocolHandler m_protocolHandler;
98 bool m_active;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080099 Ptr<CcnxFace> m_face; // local face that is created
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800100
101 TracedCallback<Ptr<const CcnxInterestHeader>,
102 Ptr<CcnxApp>, Ptr<CcnxFace> > m_receivedInterests;
103
104 TracedCallback<Ptr<const CcnxInterestHeader>,
105 Ptr<CcnxApp>, Ptr<CcnxFace> > m_receivedNacks;
106
107 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
108 Ptr<CcnxApp>, Ptr<CcnxFace> > m_receivedContentObjects;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800109};
110
111} // namespace ns3
112
113#endif // CCNX_APP_H