Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * 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 Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * 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 Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * 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 Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | c018a56 | 2016-09-08 16:27:31 -0700 | [diff] [blame] | 20 | #include "ndn-app-link-service.hpp" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | |
| 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 Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 28 | #include "apps/ndn-app.hpp" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | c018a56 | 2016-09-08 16:27:31 -0700 | [diff] [blame] | 30 | NS_LOG_COMPONENT_DEFINE("ndn.AppLinkService"); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 32 | namespace ns3 { |
| 33 | namespace ndn { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 34 | |
Alexander Afanasyev | c018a56 | 2016-09-08 16:27:31 -0700 | [diff] [blame] | 35 | AppLinkService::AppLinkService(Ptr<App> app) |
| 36 | : m_node(app->GetNode()) |
Alexander Afanasyev | 82d5ffe | 2014-12-30 23:55:38 -0800 | [diff] [blame] | 37 | , m_app(app) |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 38 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | NS_LOG_FUNCTION(this << app); |
| 40 | |
| 41 | NS_ASSERT(m_app != 0); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Alexander Afanasyev | c018a56 | 2016-09-08 16:27:31 -0700 | [diff] [blame] | 44 | AppLinkService::~AppLinkService() |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 45 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Alexander Afanasyev | 82d5ffe | 2014-12-30 23:55:38 -0800 | [diff] [blame] | 49 | void |
Alexander Afanasyev | f007a99 | 2022-05-05 15:57:08 -0400 | [diff] [blame] | 50 | AppLinkService::doSendInterest(const Interest& interest) |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 51 | { |
Alexander Afanasyev | 82d5ffe | 2014-12-30 23:55:38 -0800 | [diff] [blame] | 52 | NS_LOG_FUNCTION(this << &interest); |
| 53 | |
Alexander Afanasyev | 82d5ffe | 2014-12-30 23:55:38 -0800 | [diff] [blame] | 54 | // to decouple callbacks |
| 55 | Simulator::ScheduleNow(&App::OnInterest, m_app, interest.shared_from_this()); |
| 56 | } |
| 57 | |
| 58 | void |
Alexander Afanasyev | f007a99 | 2022-05-05 15:57:08 -0400 | [diff] [blame] | 59 | AppLinkService::doSendData(const Data& data) |
Alexander Afanasyev | 82d5ffe | 2014-12-30 23:55:38 -0800 | [diff] [blame] | 60 | { |
| 61 | NS_LOG_FUNCTION(this << &data); |
| 62 | |
Alexander Afanasyev | 82d5ffe | 2014-12-30 23:55:38 -0800 | [diff] [blame] | 63 | // to decouple callbacks |
| 64 | Simulator::ScheduleNow(&App::OnData, m_app, data.shared_from_this()); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 67 | void |
Alexander Afanasyev | f007a99 | 2022-05-05 15:57:08 -0400 | [diff] [blame] | 68 | AppLinkService::doSendNack(const lp::Nack& nack) |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 69 | { |
Alexander Afanasyev | c018a56 | 2016-09-08 16:27:31 -0700 | [diff] [blame] | 70 | NS_LOG_FUNCTION(this << &nack); |
| 71 | |
| 72 | // to decouple callbacks |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 73 | Simulator::ScheduleNow(&App::OnNack, m_app, make_shared<lp::Nack>(nack)); |
Alexander Afanasyev | c018a56 | 2016-09-08 16:27:31 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // |
| 77 | |
| 78 | void |
| 79 | AppLinkService::onReceiveInterest(const Interest& interest) |
| 80 | { |
Alexander Afanasyev | 59090db | 2020-02-21 16:37:43 -0500 | [diff] [blame] | 81 | this->receiveInterest(interest, 0); |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void |
Alexander Afanasyev | c018a56 | 2016-09-08 16:27:31 -0700 | [diff] [blame] | 85 | AppLinkService::onReceiveData(const Data& data) |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 86 | { |
Alexander Afanasyev | 59090db | 2020-02-21 16:37:43 -0500 | [diff] [blame] | 87 | this->receiveData(data, 0); |
Alexander Afanasyev | c018a56 | 2016-09-08 16:27:31 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void |
| 91 | AppLinkService::onReceiveNack(const lp::Nack& nack) |
| 92 | { |
Alexander Afanasyev | 59090db | 2020-02-21 16:37:43 -0500 | [diff] [blame] | 93 | this->receiveNack(nack, 0); |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 96 | } // namespace ndn |
| 97 | } // namespace ns3 |