blob: 2bf369b17f580e2c1f8a1415c55ed0ef71ec9209 [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"
Alexander Afanasyev07827182011-12-13 01:07:32 -080022#include "ns3/log.h"
23#include "ns3/ccnx-name-components.h"
24#include "ns3/uinteger.h"
25#include "ns3/names.h"
26#include "../apps/ccnx-producer.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070027
28NS_LOG_COMPONENT_DEFINE ("CcnxProducerHelper");
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070029
30namespace ns3
31{
32
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -070033CcnxProducerHelper::CcnxProducerHelper (const std::string &prefix, uint32_t virtualPayloadSize)
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070034{
35 m_factory.SetTypeId ("ns3::CcnxProducer");
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -070036
37 CcnxNameComponentsValue prefixValue;
38 prefixValue.DeserializeFromString (prefix, MakeCcnxNameComponentsChecker ());
39 m_factory.Set ("Prefix", prefixValue);
40
41 m_factory.Set ("PayloadSize", UintegerValue (virtualPayloadSize));
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070042}
43
44void
45CcnxProducerHelper::SetAttribute (std::string name, const AttributeValue &value)
46{
47 m_factory.Set (name, value);
48}
49
50ApplicationContainer
51CcnxProducerHelper::Install (Ptr<Node> node)
52{
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070053 NS_LOG_FUNCTION(this);
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070054 return ApplicationContainer (InstallPriv (node));
55}
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -070056
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070057ApplicationContainer
58CcnxProducerHelper::Install (std::string nodeName)
59{
60 Ptr<Node> node = Names::Find<Node> (nodeName);
61 return ApplicationContainer (InstallPriv (node));
62}
63
64ApplicationContainer
65CcnxProducerHelper::Install (NodeContainer c)
66{
67 ApplicationContainer apps;
68 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
69 {
70 apps.Add (InstallPriv (*i));
71 }
72
73 return apps;
74}
75
76 /*CcnxStackHelper::CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId)
77 {
78 ObjectFactory factory;
79 factory.SetTypeId (typeId);
80 Ptr<Object> protocol = factory.Create <Object> ();
81 node->AggregateObject (protocol);
82 }*/
83Ptr<Application>
84CcnxProducerHelper::InstallPriv (Ptr<Node> node)
85{
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070086 NS_LOG_INFO ("InstallPriv started");
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -070087 Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> ();
88 node->AddApplication (app);
89
90 /*Ptr<CcnxLocalFace> localFace = Create<CcnxLocalFace> ();
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070091 localFace->SetNode(node);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070092
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070093 //CreateAndAggregateObjectFromTypeId (node, "ns3::CcnxL3Protocol");
94 ObjectFactory factory;
95 factory.SetTypeId("ns3::CcnxL3Protocol");
96 Ptr<Object> protocol = factory.Create<Object> ();
97 node->AggregateObject(protocol);
98
99 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
100
101 if (ccnx == NULL)
102 {
103 NS_FATAL_ERROR ("CcnxProducerHelper::InstallPriv (): Getting Ccnx "
104 "a CcnxStack must be installed on the node");
105 return 0;
106 }
107
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700108 // m_factory.Set ("Face", PointerValue (localFace));
Ilya Moiseenkoa1214112011-08-29 13:03:55 -0700109 m_factory.Set ("Ccnx", PointerValue (ccnx));
110 Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> ();
111
112 //app->m_ccnx->m_contentStore->SetMaxSize(app->GetStoreCapacity());
113 localFace->RegisterProtocolHandler (MakeCallback (&CcnxProducer::HandlePacket, app));
114 localFace->SetUp();
115
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -0700116 node->AddApplication (app);*/
Ilya Moiseenkoa1214112011-08-29 13:03:55 -0700117
118 return app;
119}
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700120}