blob: 1488dff45df4fd4031cf2709804682d767f2072a [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070019
Alexander Afanasyev0c395372014-12-20 15:54:02 -080020#include "ndn-app-face.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021
22#include "ns3/log.h"
23#include "ns3/packet.h"
24#include "ns3/node.h"
25#include "ns3/assert.h"
26#include "ns3/simulator.h"
27
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070028#include "apps/ndn-app.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070029
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080030NS_LOG_COMPONENT_DEFINE("ndn.AppFace");
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070031
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032namespace ns3 {
33namespace ndn {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070034
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035AppFace::AppFace(Ptr<App> app)
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080036 : LocalFace(FaceUri("appFace://"), FaceUri("appFace://"))
37 , m_node(app->GetNode())
38 , m_app(app)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070039{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040 NS_LOG_FUNCTION(this << app);
41
42 NS_ASSERT(m_app != 0);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070043}
44
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045AppFace::~AppFace()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070046{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 NS_LOG_FUNCTION_NOARGS();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070048}
49
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080050void
51AppFace::close()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070052{
Mickey Sweatt89046c12014-11-16 20:32:27 -080053 this->fail("Close connection");
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070054}
55
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080056void
57AppFace::sendInterest(const Interest& interest)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070058{
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080059 NS_LOG_FUNCTION(this << &interest);
60
61 this->onSendInterest(interest);
62
63 // to decouple callbacks
64 Simulator::ScheduleNow(&App::OnInterest, m_app, interest.shared_from_this());
65}
66
67void
68AppFace::sendData(const Data& data)
69{
70 NS_LOG_FUNCTION(this << &data);
71
72 this->onSendData(data);
73
74 // to decouple callbacks
75 Simulator::ScheduleNow(&App::OnData, m_app, data.shared_from_this());
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070076}
77
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070078} // namespace ndn
79} // namespace ns3