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" |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 22 | |
| 23 | NS_LOG_COMPONENT_DEFINE ("CcnxProducerHelper"); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 24 | |
| 25 | namespace ns3 |
| 26 | { |
| 27 | |
Ilya Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame^] | 28 | CcnxProducerHelper::CcnxProducerHelper (const std::string &prefix, uint32_t virtualPayloadSize) |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 29 | { |
| 30 | m_factory.SetTypeId ("ns3::CcnxProducer"); |
Ilya Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame^] | 31 | |
| 32 | CcnxNameComponentsValue prefixValue; |
| 33 | prefixValue.DeserializeFromString (prefix, MakeCcnxNameComponentsChecker ()); |
| 34 | m_factory.Set ("Prefix", prefixValue); |
| 35 | |
| 36 | m_factory.Set ("PayloadSize", UintegerValue (virtualPayloadSize)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void |
| 40 | CcnxProducerHelper::SetAttribute (std::string name, const AttributeValue &value) |
| 41 | { |
| 42 | m_factory.Set (name, value); |
| 43 | } |
| 44 | |
| 45 | ApplicationContainer |
| 46 | CcnxProducerHelper::Install (Ptr<Node> node) |
| 47 | { |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 48 | NS_LOG_FUNCTION(this); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 49 | return ApplicationContainer (InstallPriv (node)); |
| 50 | } |
Ilya Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame^] | 51 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 52 | ApplicationContainer |
| 53 | CcnxProducerHelper::Install (std::string nodeName) |
| 54 | { |
| 55 | Ptr<Node> node = Names::Find<Node> (nodeName); |
| 56 | return ApplicationContainer (InstallPriv (node)); |
| 57 | } |
| 58 | |
| 59 | ApplicationContainer |
| 60 | CcnxProducerHelper::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 | }*/ |
| 78 | Ptr<Application> |
| 79 | CcnxProducerHelper::InstallPriv (Ptr<Node> node) |
| 80 | { |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 81 | NS_LOG_INFO ("InstallPriv started"); |
Ilya Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame^] | 82 | Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> (); |
| 83 | node->AddApplication (app); |
| 84 | |
| 85 | /*Ptr<CcnxLocalFace> localFace = Create<CcnxLocalFace> (); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 86 | localFace->SetNode(node); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 87 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 88 | //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 Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 103 | // m_factory.Set ("Face", PointerValue (localFace)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 104 | 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 Moiseenko | fb2362f | 2011-10-28 13:08:05 -0700 | [diff] [blame^] | 111 | node->AddApplication (app);*/ |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 112 | |
| 113 | return app; |
| 114 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 115 | } |