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