blob: 433a15a5a2bec63a88108e071ff2dae805ad259f [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"
22#include "ns3/string.h"
23#include "ns3/names.h"
24
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{
43 return ApplicationContainer (InstallPriv (node));
44}
45
46ApplicationContainer
47CcnxProducerHelper::Install (std::string nodeName)
48{
49 Ptr<Node> node = Names::Find<Node> (nodeName);
50 return ApplicationContainer (InstallPriv (node));
51}
52
53ApplicationContainer
54CcnxProducerHelper::Install (NodeContainer c)
55{
56 ApplicationContainer apps;
57 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
58 {
59 apps.Add (InstallPriv (*i));
60 }
61
62 return apps;
63}
64
65 /*CcnxStackHelper::CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId)
66 {
67 ObjectFactory factory;
68 factory.SetTypeId (typeId);
69 Ptr<Object> protocol = factory.Create <Object> ();
70 node->AggregateObject (protocol);
71 }*/
72Ptr<Application>
73CcnxProducerHelper::InstallPriv (Ptr<Node> node)
74{
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070075 Ptr<CcnxLocalFace> localFace = Create<CcnxLocalFace> ();
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070076 localFace->SetNode(node);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070077
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070078 //CreateAndAggregateObjectFromTypeId (node, "ns3::CcnxL3Protocol");
79 ObjectFactory factory;
80 factory.SetTypeId("ns3::CcnxL3Protocol");
81 Ptr<Object> protocol = factory.Create<Object> ();
82 node->AggregateObject(protocol);
83
84 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
85
86 if (ccnx == NULL)
87 {
88 NS_FATAL_ERROR ("CcnxProducerHelper::InstallPriv (): Getting Ccnx "
89 "a CcnxStack must be installed on the node");
90 return 0;
91 }
92
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070093 // m_factory.Set ("Face", PointerValue (localFace));
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070094 m_factory.Set ("Ccnx", PointerValue (ccnx));
95 Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> ();
96
97 //app->m_ccnx->m_contentStore->SetMaxSize(app->GetStoreCapacity());
98 localFace->RegisterProtocolHandler (MakeCallback (&CcnxProducer::HandlePacket, app));
99 localFace->SetUp();
100
101 node->AddApplication (app);
102
103 return app;
104}
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700105}