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 | |
| 22 | #include "ccnx-producer.h" |
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/ccnx-interest-header.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 25 | #include "ns3/ccnx-content-object-header.h" |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 26 | #include "ns3/string.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 27 | #include "ns3/uinteger.h" |
| 28 | #include "ns3/packet.h" |
Alexander Afanasyev | faf9581 | 2012-06-05 21:28:11 -0700 | [diff] [blame] | 29 | #include "ns3/simulator.h" |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame] | 31 | #include "ns3/ccnx-app-face.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 32 | #include "ns3/ccnx-fib.h" |
| 33 | |
| 34 | #include <boost/ref.hpp> |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 35 | #include <boost/lambda/lambda.hpp> |
| 36 | #include <boost/lambda/bind.hpp> |
| 37 | namespace ll = boost::lambda; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 38 | |
| 39 | NS_LOG_COMPONENT_DEFINE ("CcnxProducer"); |
| 40 | |
| 41 | namespace ns3 |
| 42 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 43 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 44 | NS_OBJECT_ENSURE_REGISTERED (CcnxProducer); |
| 45 | |
| 46 | TypeId |
| 47 | CcnxProducer::GetTypeId (void) |
| 48 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 49 | static TypeId tid = TypeId ("ns3::CcnxProducer") |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 50 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 51 | .SetParent<CcnxApp> () |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 52 | .AddConstructor<CcnxProducer> () |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 53 | .AddAttribute ("Prefix","Prefix, for which producer has the data", |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 54 | StringValue ("/"), |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 55 | MakeCcnxNameComponentsAccessor (&CcnxProducer::m_prefix), |
| 56 | MakeCcnxNameComponentsChecker ()) |
| 57 | .AddAttribute ("PayloadSize", "Virtual payload size for Content packets", |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 58 | UintegerValue (1024), |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 59 | MakeUintegerAccessor(&CcnxProducer::m_virtualPayloadSize), |
| 60 | MakeUintegerChecker<uint32_t>()) |
Alexander Afanasyev | faf9581 | 2012-06-05 21:28:11 -0700 | [diff] [blame] | 61 | |
| 62 | // optional attributes |
| 63 | .AddAttribute ("SignatureBits", "SignatureBits field", |
| 64 | UintegerValue (0), |
| 65 | MakeUintegerAccessor(&CcnxProducer::m_signatureBits), |
| 66 | MakeUintegerChecker<uint32_t> ()) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 67 | ; |
| 68 | |
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 | } |
| 71 | |
| 72 | CcnxProducer::CcnxProducer () |
| 73 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -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 |
| 79 | CcnxProducer::StartApplication () |
| 80 | { |
| 81 | NS_LOG_FUNCTION_NOARGS (); |
| 82 | NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0); |
| 83 | |
| 84 | CcnxApp::StartApplication (); |
| 85 | |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 86 | Ptr<CcnxFib> fib = GetNode ()->GetObject<CcnxFib> (); |
| 87 | CcnxFibEntryContainer::type::iterator fibEntry = fib->Add (m_prefix, m_face, 0); |
| 88 | |
| 89 | // make face green, so it will be used primarily |
| 90 | fib->m_fib.modify (fibEntry, |
| 91 | ll::bind (&CcnxFibEntry::UpdateStatus, |
| 92 | ll::_1, m_face, CcnxFibFaceMetric::NDN_FIB_GREEN)); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void |
| 96 | CcnxProducer::StopApplication () |
| 97 | { |
| 98 | NS_LOG_FUNCTION_NOARGS (); |
| 99 | NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0); |
| 100 | |
| 101 | CcnxApp::StopApplication (); |
| 102 | } |
| 103 | |
| 104 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 105 | void |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 106 | CcnxProducer::OnInterest (const Ptr<const CcnxInterestHeader> &interest, Ptr<Packet> origPacket) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 107 | { |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 108 | CcnxApp::OnInterest (interest, origPacket); // tracing inside |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 109 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 110 | NS_LOG_FUNCTION (this << interest); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 111 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 112 | if (!m_active) return; |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 113 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 114 | static CcnxContentObjectTail tail; |
| 115 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 116 | header->SetName (Create<CcnxNameComponents> (interest->GetName ())); |
Alexander Afanasyev | faf9581 | 2012-06-05 21:28:11 -0700 | [diff] [blame] | 117 | header->GetSignedInfo ().SetTimestamp (Simulator::Now ()); |
| 118 | header->GetSignature ().SetSignatureBits (m_signatureBits); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 119 | |
Lucas | a3295ab | 2012-02-04 13:36:31 -0800 | [diff] [blame] | 120 | NS_LOG_INFO ("node("<< GetNode()->GetId() <<") respodning with ContentObject:\n" << boost::cref(*header)); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 121 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 122 | Ptr<Packet> packet = Create<Packet> (m_virtualPayloadSize); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 123 | // Ptr<const WeightsPathStretchTag> tag = origPacket->RemovePacketTag<WeightsPathStretchTag> (); |
| 124 | // if (tag != 0) |
| 125 | // { |
| 126 | // // std::cout << Simulator::Now () << ", " << m_app->GetInstanceTypeId ().GetName () << "\n"; |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 127 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 128 | // // echo back WeightsPathStretchTag |
| 129 | // packet->AddPacketTag (CreateObject<WeightsPathStretchTag> (*tag)); |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 130 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 131 | // // \todo |
| 132 | // // packet->AddPacketTag should actually accept Ptr<const WeightsPathStretchTag> instead of |
| 133 | // // Ptr<WeightsPathStretchTag>. Echoing will be simplified after change is done |
| 134 | // } |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 136 | packet->AddHeader (*header); |
| 137 | packet->AddTrailer (tail); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 138 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 139 | m_protocolHandler (packet); |
Alexander Afanasyev | 15f9299 | 2012-04-09 14:56:56 -0700 | [diff] [blame] | 140 | |
| 141 | m_transmittedContentObjects (header, packet, this, m_face); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 142 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 143 | |
| 144 | } // namespace ns3 |