blob: 1f229d8c3d5ff9f68e2366be66f4d029c6705420 [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 Afanasyev359bfb72012-01-09 18:42:50 -08004 *
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 Afanasyev359bfb72012-01-09 18:42:50 -08007 *
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 Afanasyev359bfb72012-01-09 18:42:50 -080011 *
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 Afanasyev359bfb72012-01-09 18:42:50 -080015 *
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 Afanasyev359bfb72012-01-09 18:42:50 -080019
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070020#ifndef NDN_CONSUMER_WINDOW_H
21#define NDN_CONSUMER_WINDOW_H
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080022
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyev0c395372014-12-20 15:54:02 -080025#include "ndn-consumer.hpp"
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080026#include "ns3/traced-value.h"
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080027
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070028namespace ns3 {
29namespace ndn {
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080030
31/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070032 * @ingroup ndn-apps
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070033 * \brief Ndn application for sending out Interest packets (window-based)
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070034 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035 * !!! ATTENTION !!! This is highly experimental and relies on experimental features of the
36 *simulator.
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070037 * Behavior may be unpredictable if used incorrectly.
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080038 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039class ConsumerWindow : public Consumer {
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080040public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041 static TypeId
42 GetTypeId();
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080043
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080044 /**
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080045 * \brief Default constructor
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080046 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 ConsumerWindow();
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080048
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049 // From App
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080050 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070051 OnData(shared_ptr<const Data> contentObject);
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080052
53 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 OnTimeout(uint32_t sequenceNumber);
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080055
Alexander Afanasyev79b2fb32013-04-12 11:24:55 -070056 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 WillSendOutInterest(uint32_t sequenceNumber);
Alexander Afanasyev79b2fb32013-04-12 11:24:55 -070058
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080059protected:
60 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN
62 * protocol
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080063 */
64 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 ScheduleNextPacket();
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080066
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080067private:
68 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 SetWindow(uint32_t window);
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080070
71 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 GetWindow() const;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080073
74 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 SetPayloadSize(uint32_t payload);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080076
77 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 GetPayloadSize() const;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080079
80 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 GetMaxSize() const;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080082
83 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 SetMaxSize(double size);
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080085
Alexander Afanasyevfdd45412013-05-16 22:24:33 -070086 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 GetSeqMax() const;
Alexander Afanasyevfdd45412013-05-16 22:24:33 -070088
89 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 SetSeqMax(uint32_t seqMax);
Alexander Afanasyevfdd45412013-05-16 22:24:33 -070091
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070092private:
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080093 uint32_t m_payloadSize; // expected payload size
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 double m_maxSize; // max size to request
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080095
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080096 uint32_t m_initialWindow;
97 bool m_setInitialWindowOnTimeout;
98
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080099 TracedValue<uint32_t> m_window;
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -0800100 TracedValue<uint32_t> m_inFlight;
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800101};
102
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700103} // namespace ndn
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800104} // namespace ns3
105
106#endif