blob: d267f6b4036840744ade7bce235ce36f579258ce [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
Alexander Afanasyev0c395372014-12-20 15:54:02 -080023#include "ndn-app-face.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070024
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
Alexander Afanasyev0c395372014-12-20 15:54:02 -080031#include "ns3/ndn-header-helper.hpp"
32#include "ns3/ndn-app.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070033
Alexander Afanasyev0c395372014-12-20 15:54:02 -080034#include "ndn-interest.hpp"
35#include "ndn-data.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070036
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080037NS_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 Afanasyevbe55cf62014-12-20 17:51:09 -080042NS_OBJECT_ENSURE_REGISTERED(AppFace);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070043
44TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045AppFace::GetTypeId()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070046{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 static TypeId tid = TypeId("ns3::ndn::AppFace").SetParent<Face>().SetGroupName("Ndn");
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070048 return tid;
49}
50
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051AppFace::AppFace(Ptr<App> app)
52 : Face(app->GetNode())
53 , m_app(app)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070054{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 NS_LOG_FUNCTION(this << app);
56
57 NS_ASSERT(m_app != 0);
58 SetFlags(Face::APPLICATION);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070059}
60
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061AppFace::~AppFace()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070062{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 NS_LOG_FUNCTION_NOARGS();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070064}
65
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066AppFace::AppFace()
67 : Face(0)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070068{
69}
70
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071AppFace::AppFace(const AppFace&)
72 : Face(0)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070073{
74}
75
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070076AppFace&
77AppFace::operator= (const AppFace &)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070078{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070079 return *((AppFace*)0);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070080}
81
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070082bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083AppFace::SendInterest(Ptr<const Interest> interest)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070084{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 NS_LOG_FUNCTION(this << interest);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070086
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 if (!IsUp()) {
88 return false;
89 }
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070090
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 if (interest->GetNack() > 0)
92 m_app->OnNack(interest);
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070093 else
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 m_app->OnInterest(interest);
95
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -070096 return true;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070097}
98
99bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100AppFace::SendData(Ptr<const Data> data)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700101{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 NS_LOG_FUNCTION(this << data);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700103
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 if (!IsUp()) {
105 return false;
106 }
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700107
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 m_app->OnData(data);
Alexander Afanasyev5bee19e2013-07-10 14:33:57 -0700109 return true;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700110}
111
112std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113AppFace::Print(std::ostream& os) const
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700114{
115 os << "dev=local(" << GetId() << ")";
116 return os;
117}
118
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119} // namespace ndn
120} // namespace ns3