blob: 6d36eb3b6e5b7bc4ba2463a8a9261187b854bde2 [file] [log] [blame]
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -07001/* -*- 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 Afanasyev09c7deb2011-11-23 14:50:10 -080019 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070020 */
21
22#include "ccnx-producer.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080023#include "ns3/log.h"
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080024#include "ns3/ccnx-interest-header.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080025#include "ns3/ccnx-content-object-header.h"
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080026#include "ns3/string.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080027#include "ns3/uinteger.h"
28#include "ns3/packet.h"
Alexander Afanasyevfaf95812012-06-05 21:28:11 -070029#include "ns3/simulator.h"
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070030
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070031#include "ns3/ccnx-app-face.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080032#include "ns3/ccnx-fib.h"
Alexander Afanasyev78057c32012-07-06 15:18:46 -070033#include "../model/ccnx-fib-impl.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080034
35#include <boost/ref.hpp>
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080036#include <boost/lambda/lambda.hpp>
37#include <boost/lambda/bind.hpp>
38namespace ll = boost::lambda;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070039
40NS_LOG_COMPONENT_DEFINE ("CcnxProducer");
41
42namespace ns3
43{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080044
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070045NS_OBJECT_ENSURE_REGISTERED (CcnxProducer);
46
47TypeId
48CcnxProducer::GetTypeId (void)
49{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080050 static TypeId tid = TypeId ("ns3::CcnxProducer")
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070051 .SetGroupName ("Ccnx")
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080052 .SetParent<CcnxApp> ()
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070053 .AddConstructor<CcnxProducer> ()
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070054 .AddAttribute ("Prefix","Prefix, for which producer has the data",
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080055 StringValue ("/"),
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070056 MakeCcnxNameComponentsAccessor (&CcnxProducer::m_prefix),
57 MakeCcnxNameComponentsChecker ())
58 .AddAttribute ("PayloadSize", "Virtual payload size for Content packets",
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080059 UintegerValue (1024),
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070060 MakeUintegerAccessor(&CcnxProducer::m_virtualPayloadSize),
61 MakeUintegerChecker<uint32_t>())
Alexander Afanasyevfaf95812012-06-05 21:28:11 -070062
63 // optional attributes
64 .AddAttribute ("SignatureBits", "SignatureBits field",
65 UintegerValue (0),
66 MakeUintegerAccessor(&CcnxProducer::m_signatureBits),
67 MakeUintegerChecker<uint32_t> ())
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070068 ;
69
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080070 return tid;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070071}
72
73CcnxProducer::CcnxProducer ()
74{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080075 // NS_LOG_FUNCTION_NOARGS ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070076}
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080077
78// inherited from Application base class.
79void
80CcnxProducer::StartApplication ()
81{
82 NS_LOG_FUNCTION_NOARGS ();
83 NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0);
84
85 CcnxApp::StartApplication ();
86
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070087 NS_LOG_DEBUG ("NodeID: " << GetNode ()->GetId ());
88
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080089 Ptr<CcnxFib> fib = GetNode ()->GetObject<CcnxFib> ();
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070090
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070091 Ptr<CcnxFibEntry> fibEntry = fib->Add (m_prefix, m_face, 0);
Alexander Afanasyev1aa4bbc2012-07-09 17:17:25 -070092
93 fibEntry->UpdateStatus (m_face, CcnxFibFaceMetric::NDN_FIB_GREEN);
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070094
Alexander Afanasyev1aa4bbc2012-07-09 17:17:25 -070095 // // make face green, so it will be used primarily
96 // StaticCast<CcnxFibImpl> (fib)->modify (fibEntry,
97 // ll::bind (&CcnxFibEntry::UpdateStatus,
98 // ll::_1, m_face, CcnxFibFaceMetric::NDN_FIB_GREEN));
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080099}
100
101void
102CcnxProducer::StopApplication ()
103{
104 NS_LOG_FUNCTION_NOARGS ();
105 NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0);
106
107 CcnxApp::StopApplication ();
108}
109
110
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700111void
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800112CcnxProducer::OnInterest (const Ptr<const CcnxInterestHeader> &interest, Ptr<Packet> origPacket)
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700113{
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800114 CcnxApp::OnInterest (interest, origPacket); // tracing inside
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800115
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800116 NS_LOG_FUNCTION (this << interest);
Ilya Moiseenkob62c7402011-10-28 13:02:18 -0700117
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800118 if (!m_active) return;
Ilya Moiseenkob62c7402011-10-28 13:02:18 -0700119
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800120 static CcnxContentObjectTail tail;
121 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
122 header->SetName (Create<CcnxNameComponents> (interest->GetName ()));
Alexander Afanasyevfaf95812012-06-05 21:28:11 -0700123 header->GetSignedInfo ().SetTimestamp (Simulator::Now ());
124 header->GetSignature ().SetSignatureBits (m_signatureBits);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800125
Lucasa3295ab2012-02-04 13:36:31 -0800126 NS_LOG_INFO ("node("<< GetNode()->GetId() <<") respodning with ContentObject:\n" << boost::cref(*header));
Ilya Moiseenkob62c7402011-10-28 13:02:18 -0700127
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800128 Ptr<Packet> packet = Create<Packet> (m_virtualPayloadSize);
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800129 // Ptr<const WeightsPathStretchTag> tag = origPacket->RemovePacketTag<WeightsPathStretchTag> ();
130 // if (tag != 0)
131 // {
132 // // std::cout << Simulator::Now () << ", " << m_app->GetInstanceTypeId ().GetName () << "\n";
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800133
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800134 // // echo back WeightsPathStretchTag
135 // packet->AddPacketTag (CreateObject<WeightsPathStretchTag> (*tag));
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800136
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800137 // // \todo
138 // // packet->AddPacketTag should actually accept Ptr<const WeightsPathStretchTag> instead of
139 // // Ptr<WeightsPathStretchTag>. Echoing will be simplified after change is done
140 // }
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800141
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800142 packet->AddHeader (*header);
143 packet->AddTrailer (tail);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800144
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800145 m_protocolHandler (packet);
Alexander Afanasyev15f92992012-04-09 14:56:56 -0700146
147 m_transmittedContentObjects (header, packet, this, m_face);
Ilya Moiseenkob62c7402011-10-28 13:02:18 -0700148}
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800149
150} // namespace ns3