blob: 1de26e3697136c708dfe1eac6a88a8efb070e014 [file] [log] [blame]
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07001/* -*- 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 * Ilya Moiseenko <iliamo@cs.ucla.edu>
20 *
21 */
22
23#include "ndn-app-face.h"
24
25#include "ns3/log.h"
26#include "ns3/packet.h"
27#include "ns3/node.h"
28#include "ns3/assert.h"
29#include "ns3/simulator.h"
30
31#include "ns3/ndn-header-helper.h"
32#include "ns3/ndn-app.h"
33
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080034#include "ndn-interest.h"
Alexander Afanasyev6eba36f2013-08-07 17:42:54 -070035#include "ndn-data.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070036
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037NS_LOG_COMPONENT_DEFINE ("ndn.AppFace");
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070038
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070039namespace ns3 {
40namespace ndn {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070041
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070042NS_OBJECT_ENSURE_REGISTERED (AppFace);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070043
44TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045AppFace::GetTypeId ()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070046{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070047 static TypeId tid = TypeId ("ns3::ndn::AppFace")
48 .SetParent<Face> ()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070049 .SetGroupName ("Ndn")
50 ;
51 return tid;
52}
53
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070054AppFace::AppFace (Ptr<App> app)
55 : Face (app->GetNode ())
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070056 , m_app (app)
57{
58 NS_LOG_FUNCTION (this << app);
59
60 NS_ASSERT (m_app != 0);
Alexander Afanasyevdd9fa4f2013-05-15 16:35:04 -070061 SetFlags (Face::APPLICATION);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070062}
63
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070064AppFace::~AppFace ()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070065{
66 NS_LOG_FUNCTION_NOARGS ();
67}
68
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070069AppFace::AppFace ()
70 : Face (0)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070071{
72}
73
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070074AppFace::AppFace (const AppFace &)
75 : Face (0)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070076{
77}
78
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070079AppFace&
80AppFace::operator= (const AppFace &)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070081{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070082 return *((AppFace*)0);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070083}
84
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070085bool
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070086AppFace::SendInterest (Ptr<const Interest> interest)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070087{
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070088 NS_LOG_FUNCTION (this << interest);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070089
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070090 if (!IsUp ())
91 {
92 return false;
93 }
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070094
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070095 if (interest->GetNack () > 0)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070096 m_app->OnNack (interest);
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070097 else
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070098 m_app->OnInterest (interest);
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070099
100 return true;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700101}
102
103bool
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700104AppFace::SendData (Ptr<const Data> data)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700105{
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700106 NS_LOG_FUNCTION (this << data);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700107
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700108 if (!IsUp ())
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700109 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700110 return false;
111 }
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700112
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700113 m_app->OnData (data);
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700114 return true;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700115}
116
117std::ostream&
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700118AppFace::Print (std::ostream& os) const
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700119{
120 os << "dev=local(" << GetId() << ")";
121 return os;
122}
123
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124} // namespace ndn
125} // namespace ns3
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700126