blob: 6b89b426eda35c9186c41d7bc51c5cf525c6aee4 [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 Afanasyevc018a562016-09-08 16:27:31 -070020#include "ndn-app-link-service.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 Afanasyevc018a562016-09-08 16:27:31 -070030NS_LOG_COMPONENT_DEFINE("ndn.AppLinkService");
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 Afanasyevc018a562016-09-08 16:27:31 -070035AppLinkService::AppLinkService(Ptr<App> app)
36 : m_node(app->GetNode())
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080037 , m_app(app)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070038{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039 NS_LOG_FUNCTION(this << app);
40
41 NS_ASSERT(m_app != 0);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042}
43
Alexander Afanasyevc018a562016-09-08 16:27:31 -070044AppLinkService::~AppLinkService()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070045{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 NS_LOG_FUNCTION_NOARGS();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070047}
48
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080049void
Alexander Afanasyevc018a562016-09-08 16:27:31 -070050AppLinkService::doSendInterest(const Interest& interest)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070051{
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080052 NS_LOG_FUNCTION(this << &interest);
53
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080054 // to decouple callbacks
55 Simulator::ScheduleNow(&App::OnInterest, m_app, interest.shared_from_this());
56}
57
58void
Alexander Afanasyevc018a562016-09-08 16:27:31 -070059AppLinkService::doSendData(const Data& data)
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080060{
61 NS_LOG_FUNCTION(this << &data);
62
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080063 // to decouple callbacks
64 Simulator::ScheduleNow(&App::OnData, m_app, data.shared_from_this());
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070065}
66
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070067void
Alexander Afanasyevc018a562016-09-08 16:27:31 -070068AppLinkService::doSendNack(const lp::Nack& nack)
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070069{
Alexander Afanasyevc018a562016-09-08 16:27:31 -070070 NS_LOG_FUNCTION(this << &nack);
71
72 // to decouple callbacks
73 // Simulator::ScheduleNow(&App::OnNack, m_app, nack.shared_from_this());
74}
75
76//
77
78void
79AppLinkService::onReceiveInterest(const Interest& interest)
80{
81 this->receiveInterest(interest);
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070082}
83
84void
Alexander Afanasyevc018a562016-09-08 16:27:31 -070085AppLinkService::onReceiveData(const Data& data)
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070086{
Alexander Afanasyevc018a562016-09-08 16:27:31 -070087 this->receiveData(data);
88}
89
90void
91AppLinkService::onReceiveNack(const lp::Nack& nack)
92{
93 this->receiveNack(nack);
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070094}
95
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070096} // namespace ndn
97} // namespace ns3