blob: 97597711907b372c35f04d09f6ce54a043a4e505 [file] [log] [blame]
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07001/* -*- 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 Afanasyev0c395372014-12-20 15:54:02 -080023#include "ndn-app-face.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070024
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
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070031#include "apps/ndn-app.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070032
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033NS_LOG_COMPONENT_DEFINE("ndn.AppFace");
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070034
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070035namespace ns3 {
36namespace ndn {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070037
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038AppFace::AppFace(Ptr<App> app)
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080039 : LocalFace(FaceUri("appFace://"), FaceUri("appFace://"))
40 , m_node(app->GetNode())
41 , m_app(app)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043 NS_LOG_FUNCTION(this << app);
44
45 NS_ASSERT(m_app != 0);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070046}
47
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048AppFace::~AppFace()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070049{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 NS_LOG_FUNCTION_NOARGS();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070051}
52
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080053void
54AppFace::close()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070055{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070056}
57
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080058void
59AppFace::sendInterest(const Interest& interest)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070060{
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080061 NS_LOG_FUNCTION(this << &interest);
62
63 this->onSendInterest(interest);
64
65 // to decouple callbacks
66 Simulator::ScheduleNow(&App::OnInterest, m_app, interest.shared_from_this());
67}
68
69void
70AppFace::sendData(const Data& data)
71{
72 NS_LOG_FUNCTION(this << &data);
73
74 this->onSendData(data);
75
76 // to decouple callbacks
77 Simulator::ScheduleNow(&App::OnData, m_app, data.shared_from_this());
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070078}
79
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080} // namespace ndn
81} // namespace ns3