blob: 61c3c21ec6a8ba8244a348ed6f3948d38050d4c3 [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
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070061 this->emitSignal(onSendInterest, interest);
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080062
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
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070072 this->emitSignal(onSendData, data);
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080073
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 Afanasyevc3c7f042015-08-21 11:38:00 -070078void
79AppFace::onReceiveInterest(const Interest& interest)
80{
81 this->emitSignal(onReceiveInterest, interest);
82}
83
84void
85AppFace::onReceiveData(const Data& data)
86{
87 this->emitSignal(onReceiveData, data);
88}
89
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070090} // namespace ndn
91} // namespace ns3