/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2011 University of California, Los Angeles * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Ilya Moiseenko * Alexander Afanasyev */ #include "ndn-producer.h" #include "ns3/ptr.h"//(+) (cp)ndn-consumer.h #include "ns3/callback.h"//(+)(cp) ndn-consumer.h #include "ns3/boolean.h"//(+)(cp) ndn-consumer.h #include "ns3/double.h"//(+)(cp) ndn-consumer.h #include "ns3/log.h" #include "ns3/ndn-interest.h" #include "ns3/ndn-content-object.h" #include "ns3/string.h" #include "ns3/uinteger.h" #include "ns3/packet.h" #include "ns3/simulator.h" #include "ns3/ndn-app-face.h" #include "ns3/ndn-fib.h" #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h" #include #include //(+)(cp) ndn-consumer.h #include #include namespace ll = boost::lambda; NS_LOG_COMPONENT_DEFINE ("ndn.Producer"); namespace ns3 { namespace ndn { NS_OBJECT_ENSURE_REGISTERED (Producer); TypeId Producer::GetTypeId (void) { static TypeId tid = TypeId ("ns3::ndn::Producer") .SetGroupName ("Ndn") .SetParent () .AddConstructor () .AddAttribute ("Prefix","Prefix, for which producer has the data", StringValue ("/"), MakeNameAccessor (&Producer::m_prefix), MakeNameChecker ()) .AddAttribute ("PayloadSize", "Virtual payload size for Content packets", UintegerValue (1024), MakeUintegerAccessor(&Producer::m_virtualPayloadSize), MakeUintegerChecker()) .AddAttribute ("Freshness", "Freshness of data packets, if 0, then unlimited freshness", TimeValue (Seconds (0)), MakeTimeAccessor (&Producer::m_freshness), MakeTimeChecker ()) .AddTraceSource ("ServerHits", "Server Hits occuring at the producer", MakeTraceSourceAccessor (&Producer::m_serverHits))//(+)*/ ; return tid; } Producer::Producer () { // NS_LOG_FUNCTION_NOARGS (); } // inherited from Application base class. void Producer::StartApplication () { NS_LOG_FUNCTION_NOARGS (); NS_ASSERT (GetNode ()->GetObject () != 0); App::StartApplication (); NS_LOG_DEBUG ("NodeID: " << GetNode ()->GetId ()); Ptr fib = GetNode ()->GetObject (); Ptr fibEntry = fib->Add (m_prefix, m_face, 0); fibEntry->UpdateStatus (m_face, fib::FaceMetric::NDN_FIB_GREEN); // // make face green, so it will be used primarily // StaticCast (fib)->modify (fibEntry, // ll::bind (&fib::Entry::UpdateStatus, // ll::_1, m_face, fib::FaceMetric::NDN_FIB_GREEN)); } void Producer::StopApplication () { NS_LOG_FUNCTION_NOARGS (); NS_ASSERT (GetNode ()->GetObject () != 0); App::StopApplication (); } void Producer::OnInterest (const Ptr &interest, Ptr origPacket) { App::OnInterest (interest, origPacket); // tracing inside NS_LOG_FUNCTION (this << interest); if (!m_active) return; static ContentObjectTail tail; Ptr header = Create (); header->SetName (Create (interest->GetName ())); header->SetFreshness (m_freshness); NS_LOG_INFO ("node("<< GetNode()->GetId() <<") respodning with ContentObject:\n" << boost::cref(*header)); std::cout << "I am in the producer! Hey!" << std::endl;//(+) m_serverHits (interest);//(+) Ptr packet = Create (m_virtualPayloadSize); packet->AddHeader (*header); packet->AddTrailer (tail); // Echo back FwHopCountTag if exists FwHopCountTag hopCountTag; if (origPacket->RemovePacketTag (hopCountTag)) { packet->AddPacketTag (hopCountTag); } m_protocolHandler (packet); m_transmittedContentObjects (header, packet, this, m_face); } } // namespace ndn } // namespace ns3