Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 23 | #include "ndn-app-face.hpp" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 31 | #include "ns3/ndn-header-helper.hpp" |
| 32 | #include "ns3/ndn-app.hpp" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 34 | #include "ndn-interest.hpp" |
| 35 | #include "ndn-data.hpp" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 37 | NS_LOG_COMPONENT_DEFINE("ndn.AppFace"); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 38 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 39 | namespace ns3 { |
| 40 | namespace ndn { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 42 | NS_OBJECT_ENSURE_REGISTERED(AppFace); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 43 | |
| 44 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | AppFace::GetTypeId() |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 46 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | static TypeId tid = TypeId("ns3::ndn::AppFace").SetParent<Face>().SetGroupName("Ndn"); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 48 | return tid; |
| 49 | } |
| 50 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | AppFace::AppFace(Ptr<App> app) |
| 52 | : Face(app->GetNode()) |
| 53 | , m_app(app) |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 54 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | NS_LOG_FUNCTION(this << app); |
| 56 | |
| 57 | NS_ASSERT(m_app != 0); |
| 58 | SetFlags(Face::APPLICATION); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | AppFace::~AppFace() |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 62 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 63 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | AppFace::AppFace() |
| 67 | : Face(0) |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 68 | { |
| 69 | } |
| 70 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | AppFace::AppFace(const AppFace&) |
| 72 | : Face(0) |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 73 | { |
| 74 | } |
| 75 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 76 | AppFace& |
| 77 | AppFace::operator= (const AppFace &) |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 78 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 79 | return *((AppFace*)0); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 82 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | AppFace::SendInterest(Ptr<const Interest> interest) |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 84 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | NS_LOG_FUNCTION(this << interest); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 86 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | if (!IsUp()) { |
| 88 | return false; |
| 89 | } |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | if (interest->GetNack() > 0) |
| 92 | m_app->OnNack(interest); |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 93 | else |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 94 | m_app->OnInterest(interest); |
| 95 | |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 96 | return true; |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | AppFace::SendData(Ptr<const Data> data) |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 101 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | NS_LOG_FUNCTION(this << data); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | if (!IsUp()) { |
| 105 | return false; |
| 106 | } |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 107 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 108 | m_app->OnData(data); |
Alexander Afanasyev | 5bee19e | 2013-07-10 14:33:57 -0700 | [diff] [blame] | 109 | return true; |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | std::ostream& |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 113 | AppFace::Print(std::ostream& os) const |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 114 | { |
| 115 | os << "dev=local(" << GetId() << ")"; |
| 116 | return os; |
| 117 | } |
| 118 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 119 | } // namespace ndn |
| 120 | } // namespace ns3 |