blob: c3ec37ef73de552b71491cd3e75785d87509511a [file] [log] [blame]
Ilya Moiseenkoa1214112011-08-29 13:03:55 -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>
19 */
20
21#include "ccnx-producer-helper.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070022
23NS_LOG_COMPONENT_DEFINE ("CcnxProducerHelper");
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070024
25namespace ns3
26{
27
28CcnxProducerHelper::CcnxProducerHelper (uint32_t storeCapacity)
29{
30 m_factory.SetTypeId ("ns3::CcnxProducer");
31 m_factory.Set ("Capacity", UintegerValue (storeCapacity));
32}
33
34void
35CcnxProducerHelper::SetAttribute (std::string name, const AttributeValue &value)
36{
37 m_factory.Set (name, value);
38}
39
40ApplicationContainer
41CcnxProducerHelper::Install (Ptr<Node> node)
42{
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070043 NS_LOG_FUNCTION(this);
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070044 return ApplicationContainer (InstallPriv (node));
45}
46
47ApplicationContainer
48CcnxProducerHelper::Install (std::string nodeName)
49{
50 Ptr<Node> node = Names::Find<Node> (nodeName);
51 return ApplicationContainer (InstallPriv (node));
52}
53
54ApplicationContainer
55CcnxProducerHelper::Install (NodeContainer c)
56{
57 ApplicationContainer apps;
58 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
59 {
60 apps.Add (InstallPriv (*i));
61 }
62
63 return apps;
64}
65
66 /*CcnxStackHelper::CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId)
67 {
68 ObjectFactory factory;
69 factory.SetTypeId (typeId);
70 Ptr<Object> protocol = factory.Create <Object> ();
71 node->AggregateObject (protocol);
72 }*/
73Ptr<Application>
74CcnxProducerHelper::InstallPriv (Ptr<Node> node)
75{
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070076 NS_LOG_INFO ("InstallPriv started");
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070077 Ptr<CcnxLocalFace> localFace = Create<CcnxLocalFace> ();
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070078 localFace->SetNode(node);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070079
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070080 //CreateAndAggregateObjectFromTypeId (node, "ns3::CcnxL3Protocol");
81 ObjectFactory factory;
82 factory.SetTypeId("ns3::CcnxL3Protocol");
83 Ptr<Object> protocol = factory.Create<Object> ();
84 node->AggregateObject(protocol);
85
86 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
87
88 if (ccnx == NULL)
89 {
90 NS_FATAL_ERROR ("CcnxProducerHelper::InstallPriv (): Getting Ccnx "
91 "a CcnxStack must be installed on the node");
92 return 0;
93 }
94
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070095 // m_factory.Set ("Face", PointerValue (localFace));
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070096 m_factory.Set ("Ccnx", PointerValue (ccnx));
97 Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> ();
98
99 //app->m_ccnx->m_contentStore->SetMaxSize(app->GetStoreCapacity());
100 localFace->RegisterProtocolHandler (MakeCallback (&CcnxProducer::HandlePacket, app));
101 localFace->SetUp();
102
103 node->AddApplication (app);
104
105 return app;
106}
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700107}