blob: 4e76c5096891fa4effe77f99aa2297aac0d4d44d [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 Afanasyevd6453cd2015-08-20 21:45:36 -070059public:
60 typedef void (*WindowTraceCallback)(uint32_t);
61
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080062protected:
63 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN
65 * protocol
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080066 */
67 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 ScheduleNextPacket();
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080069
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080070private:
71 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 SetWindow(uint32_t window);
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080073
74 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 GetWindow() const;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080076
77 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 SetPayloadSize(uint32_t payload);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080079
80 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 GetPayloadSize() const;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080082
83 double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 GetMaxSize() const;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080085
86 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 SetMaxSize(double size);
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080088
Alexander Afanasyevfdd45412013-05-16 22:24:33 -070089 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 GetSeqMax() const;
Alexander Afanasyevfdd45412013-05-16 22:24:33 -070091
92 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 SetSeqMax(uint32_t seqMax);
Alexander Afanasyevfdd45412013-05-16 22:24:33 -070094
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070095private:
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080096 uint32_t m_payloadSize; // expected payload size
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 double m_maxSize; // max size to request
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080098
Alexander Afanasyevd1f7c7b2013-01-31 13:34:37 -080099 uint32_t m_initialWindow;
100 bool m_setInitialWindowOnTimeout;
101
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -0800102 TracedValue<uint32_t> m_window;
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -0800103 TracedValue<uint32_t> m_inFlight;
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800104};
105
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700106} // namespace ndn
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800107} // namespace ns3
108
109#endif