Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 22 | #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 Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 27 | |
| 28 | NS_LOG_COMPONENT_DEFINE ("CcnxProducerHelper"); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ns3 |
| 31 | { |
| 32 | |
Ilya Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame] | 33 | CcnxProducerHelper::CcnxProducerHelper (const std::string &prefix, uint32_t virtualPayloadSize) |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 34 | { |
| 35 | m_factory.SetTypeId ("ns3::CcnxProducer"); |
Ilya Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame] | 36 | |
| 37 | CcnxNameComponentsValue prefixValue; |
| 38 | prefixValue.DeserializeFromString (prefix, MakeCcnxNameComponentsChecker ()); |
| 39 | m_factory.Set ("Prefix", prefixValue); |
| 40 | |
| 41 | m_factory.Set ("PayloadSize", UintegerValue (virtualPayloadSize)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void |
| 45 | CcnxProducerHelper::SetAttribute (std::string name, const AttributeValue &value) |
| 46 | { |
| 47 | m_factory.Set (name, value); |
| 48 | } |
| 49 | |
| 50 | ApplicationContainer |
| 51 | CcnxProducerHelper::Install (Ptr<Node> node) |
| 52 | { |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 53 | NS_LOG_FUNCTION(this); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 54 | return ApplicationContainer (InstallPriv (node)); |
| 55 | } |
Ilya Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame] | 56 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 57 | ApplicationContainer |
| 58 | CcnxProducerHelper::Install (std::string nodeName) |
| 59 | { |
| 60 | Ptr<Node> node = Names::Find<Node> (nodeName); |
| 61 | return ApplicationContainer (InstallPriv (node)); |
| 62 | } |
| 63 | |
| 64 | ApplicationContainer |
| 65 | CcnxProducerHelper::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 | }*/ |
| 83 | Ptr<Application> |
| 84 | CcnxProducerHelper::InstallPriv (Ptr<Node> node) |
| 85 | { |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 86 | NS_LOG_INFO ("InstallPriv started"); |
Ilya Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame] | 87 | Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> (); |
| 88 | node->AddApplication (app); |
| 89 | |
| 90 | /*Ptr<CcnxLocalFace> localFace = Create<CcnxLocalFace> (); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 91 | localFace->SetNode(node); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 92 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 93 | //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 Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 108 | // m_factory.Set ("Face", PointerValue (localFace)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 109 | 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 Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame] | 116 | node->AddApplication (app);*/ |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 117 | |
| 118 | return app; |
| 119 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 120 | } |