blob: f94018fc5ef03d622cf0cd56fd1f8ce598154614 [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;
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080034class CcnxFace;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080035
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 */
42class CcnxApp: public Application
43{
44public:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080045 typedef Callback<bool, const Ptr<const Packet>&> ProtocolHandler;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080046
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
84protected:
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
95protected:
96 ProtocolHandler m_protocolHandler;
97 bool m_active;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080098 Ptr<CcnxFace> m_face; // local face that is created
99};
100
101} // namespace ns3
102
103#endif // CCNX_APP_H