blob: 6e407129bb6959fdf6b3582177282e6d43bb78c4 [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
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -070028CcnxProducerHelper::CcnxProducerHelper (const std::string &prefix, uint32_t virtualPayloadSize)
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070029{
30 m_factory.SetTypeId ("ns3::CcnxProducer");
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -070031
32 CcnxNameComponentsValue prefixValue;
33 prefixValue.DeserializeFromString (prefix, MakeCcnxNameComponentsChecker ());
34 m_factory.Set ("Prefix", prefixValue);
35
36 m_factory.Set ("PayloadSize", UintegerValue (virtualPayloadSize));
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070037}
38
39void
40CcnxProducerHelper::SetAttribute (std::string name, const AttributeValue &value)
41{
42 m_factory.Set (name, value);
43}
44
45ApplicationContainer
46CcnxProducerHelper::Install (Ptr<Node> node)
47{
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070048 NS_LOG_FUNCTION(this);
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070049 return ApplicationContainer (InstallPriv (node));
50}
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -070051
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070052ApplicationContainer
53CcnxProducerHelper::Install (std::string nodeName)
54{
55 Ptr<Node> node = Names::Find<Node> (nodeName);
56 return ApplicationContainer (InstallPriv (node));
57}
58
59ApplicationContainer
60CcnxProducerHelper::Install (NodeContainer c)
61{
62 ApplicationContainer apps;
63 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
64 {
65 apps.Add (InstallPriv (*i));
66 }
67
68 return apps;
69}
70
71 /*CcnxStackHelper::CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId)
72 {
73 ObjectFactory factory;
74 factory.SetTypeId (typeId);
75 Ptr<Object> protocol = factory.Create <Object> ();
76 node->AggregateObject (protocol);
77 }*/
78Ptr<Application>
79CcnxProducerHelper::InstallPriv (Ptr<Node> node)
80{
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070081 NS_LOG_INFO ("InstallPriv started");
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -070082 Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> ();
83 node->AddApplication (app);
84
85 /*Ptr<CcnxLocalFace> localFace = Create<CcnxLocalFace> ();
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070086 localFace->SetNode(node);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070087
Ilya Moiseenkoa1214112011-08-29 13:03:55 -070088 //CreateAndAggregateObjectFromTypeId (node, "ns3::CcnxL3Protocol");
89 ObjectFactory factory;
90 factory.SetTypeId("ns3::CcnxL3Protocol");
91 Ptr<Object> protocol = factory.Create<Object> ();
92 node->AggregateObject(protocol);
93
94 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
95
96 if (ccnx == NULL)
97 {
98 NS_FATAL_ERROR ("CcnxProducerHelper::InstallPriv (): Getting Ccnx "
99 "a CcnxStack must be installed on the node");
100 return 0;
101 }
102
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700103 // m_factory.Set ("Face", PointerValue (localFace));
Ilya Moiseenkoa1214112011-08-29 13:03:55 -0700104 m_factory.Set ("Ccnx", PointerValue (ccnx));
105 Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> ();
106
107 //app->m_ccnx->m_contentStore->SetMaxSize(app->GetStoreCapacity());
108 localFace->RegisterProtocolHandler (MakeCallback (&CcnxProducer::HandlePacket, app));
109 localFace->SetUp();
110
Ilya Moiseenkofb2362f2011-10-28 13:08:05 -0700111 node->AddApplication (app);*/
Ilya Moiseenkoa1214112011-08-29 13:03:55 -0700112
113 return app;
114}
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700115}