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. |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -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. |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -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. |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -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. |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -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 | **/ |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 20 | #include "ndn-producer.hpp" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 21 | #include "ns3/log.h" |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 22 | #include "ns3/string.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 23 | #include "ns3/uinteger.h" |
| 24 | #include "ns3/packet.h" |
Alexander Afanasyev | faf9581 | 2012-06-05 21:28:11 -0700 | [diff] [blame] | 25 | #include "ns3/simulator.h" |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 26 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 27 | #include "model/ndn-l3-protocol.hpp" |
| 28 | #include "helper/ndn-fib-helper.hpp" |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 29 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 30 | #include <memory> |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 32 | NS_LOG_COMPONENT_DEFINE("ndn.Producer"); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 34 | namespace ns3 { |
| 35 | namespace ndn { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 36 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 37 | NS_OBJECT_ENSURE_REGISTERED(Producer); |
Alexander Afanasyev | e722148 | 2013-07-15 18:24:37 -0700 | [diff] [blame] | 38 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 39 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 40 | Producer::GetTypeId(void) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 41 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 42 | static TypeId tid = |
| 43 | TypeId("ns3::ndn::Producer") |
| 44 | .SetGroupName("Ndn") |
| 45 | .SetParent<App>() |
| 46 | .AddConstructor<Producer>() |
| 47 | .AddAttribute("Prefix", "Prefix, for which producer has the data", StringValue("/"), |
| 48 | MakeNameAccessor(&Producer::m_prefix), MakeNameChecker()) |
| 49 | .AddAttribute( |
| 50 | "Postfix", |
| 51 | "Postfix that is added to the output data (e.g., for adding producer-uniqueness)", |
| 52 | StringValue("/"), MakeNameAccessor(&Producer::m_postfix), MakeNameChecker()) |
| 53 | .AddAttribute("PayloadSize", "Virtual payload size for Content packets", UintegerValue(1024), |
| 54 | MakeUintegerAccessor(&Producer::m_virtualPayloadSize), |
| 55 | MakeUintegerChecker<uint32_t>()) |
| 56 | .AddAttribute("Freshness", "Freshness of data packets, if 0, then unlimited freshness", |
| 57 | TimeValue(Seconds(0)), MakeTimeAccessor(&Producer::m_freshness), |
| 58 | MakeTimeChecker()) |
| 59 | .AddAttribute( |
| 60 | "Signature", |
| 61 | "Fake signature, 0 valid signature (default), other values application-specific", |
| 62 | UintegerValue(0), MakeUintegerAccessor(&Producer::m_signature), |
| 63 | MakeUintegerChecker<uint32_t>()) |
| 64 | .AddAttribute("KeyLocator", |
| 65 | "Name to be used for key locator. If root, then key locator is not used", |
| 66 | NameValue(), MakeNameAccessor(&Producer::m_keyLocator), MakeNameChecker()); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 67 | return tid; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 68 | } |
Alexander Afanasyev | e722148 | 2013-07-15 18:24:37 -0700 | [diff] [blame] | 69 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | Producer::Producer() |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 71 | { |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 72 | NS_LOG_FUNCTION_NOARGS(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 73 | } |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 74 | |
| 75 | // inherited from Application base class. |
| 76 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | Producer::StartApplication() |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 78 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | App::StartApplication(); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 81 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 82 | FibHelper::AddRoute(GetNode(), m_prefix, m_face, 0); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | Producer::StopApplication() |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 87 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | App::StopApplication(); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 93 | void |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 94 | Producer::OnInterest(shared_ptr<const Interest> interest) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 95 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 96 | App::OnInterest(interest); // tracing inside |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | NS_LOG_FUNCTION(this << interest); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | if (!m_active) |
| 101 | return; |
Alexander Afanasyev | e722148 | 2013-07-15 18:24:37 -0700 | [diff] [blame] | 102 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 103 | Name dataName(interest->getName()); |
| 104 | // dataName.append(m_postfix); |
| 105 | // dataName.appendVersion(); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 106 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 107 | auto data = make_shared<Data>(); |
| 108 | data->setName(dataName); |
| 109 | data->setFreshnessPeriod(::ndn::time::milliseconds(m_freshness.GetMilliSeconds())); |
| 110 | |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 111 | data->setContent(make_shared< ::ndn::Buffer>(m_virtualPayloadSize)); |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 112 | |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 113 | SignatureInfo signatureInfo(static_cast< ::ndn::tlv::SignatureTypeValue>(255)); |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 115 | if (m_keyLocator.size() > 0) { |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 116 | signatureInfo.setKeyLocator(m_keyLocator); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 117 | } |
Alexander Afanasyev | e722148 | 2013-07-15 18:24:37 -0700 | [diff] [blame] | 118 | |
Alexander Afanasyev | f007a99 | 2022-05-05 15:57:08 -0400 | [diff] [blame] | 119 | data->setSignatureInfo(signatureInfo); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 120 | |
Alexander Afanasyev | f007a99 | 2022-05-05 15:57:08 -0400 | [diff] [blame] | 121 | ::ndn::EncodingEstimator estimator; |
| 122 | ::ndn::EncodingBuffer encoder(estimator.appendVarNumber(m_signature), 0); |
| 123 | encoder.appendVarNumber(m_signature); |
| 124 | data->setSignatureValue(encoder.getBuffer()); |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 125 | |
Spyridon Mastorakis | db60230 | 2015-07-14 21:04:39 -0700 | [diff] [blame] | 126 | NS_LOG_INFO("node(" << GetNode()->GetId() << ") responding with Data: " << data->getName()); |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 127 | |
| 128 | // to create real wire encoding |
| 129 | data->wireEncode(); |
| 130 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 131 | m_transmittedDatas(data, this, m_face); |
Alexander Afanasyev | 50ea1a3 | 2016-09-08 15:44:08 -0700 | [diff] [blame] | 132 | m_appLink->onReceiveData(*data); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 133 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 134 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 135 | } // namespace ndn |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 136 | } // namespace ns3 |