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