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 | |
| 28 | CcnxProducerHelper::CcnxProducerHelper (uint32_t storeCapacity) |
| 29 | { |
| 30 | m_factory.SetTypeId ("ns3::CcnxProducer"); |
| 31 | m_factory.Set ("Capacity", UintegerValue (storeCapacity)); |
| 32 | } |
| 33 | |
| 34 | void |
| 35 | CcnxProducerHelper::SetAttribute (std::string name, const AttributeValue &value) |
| 36 | { |
| 37 | m_factory.Set (name, value); |
| 38 | } |
| 39 | |
| 40 | ApplicationContainer |
| 41 | CcnxProducerHelper::Install (Ptr<Node> node) |
| 42 | { |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame^] | 43 | NS_LOG_FUNCTION(this); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 44 | return ApplicationContainer (InstallPriv (node)); |
| 45 | } |
| 46 | |
| 47 | ApplicationContainer |
| 48 | CcnxProducerHelper::Install (std::string nodeName) |
| 49 | { |
| 50 | Ptr<Node> node = Names::Find<Node> (nodeName); |
| 51 | return ApplicationContainer (InstallPriv (node)); |
| 52 | } |
| 53 | |
| 54 | ApplicationContainer |
| 55 | CcnxProducerHelper::Install (NodeContainer c) |
| 56 | { |
| 57 | ApplicationContainer apps; |
| 58 | for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 59 | { |
| 60 | apps.Add (InstallPriv (*i)); |
| 61 | } |
| 62 | |
| 63 | return apps; |
| 64 | } |
| 65 | |
| 66 | /*CcnxStackHelper::CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId) |
| 67 | { |
| 68 | ObjectFactory factory; |
| 69 | factory.SetTypeId (typeId); |
| 70 | Ptr<Object> protocol = factory.Create <Object> (); |
| 71 | node->AggregateObject (protocol); |
| 72 | }*/ |
| 73 | Ptr<Application> |
| 74 | CcnxProducerHelper::InstallPriv (Ptr<Node> node) |
| 75 | { |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame^] | 76 | NS_LOG_INFO ("InstallPriv started"); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 77 | Ptr<CcnxLocalFace> localFace = Create<CcnxLocalFace> (); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 78 | localFace->SetNode(node); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 79 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 80 | //CreateAndAggregateObjectFromTypeId (node, "ns3::CcnxL3Protocol"); |
| 81 | ObjectFactory factory; |
| 82 | factory.SetTypeId("ns3::CcnxL3Protocol"); |
| 83 | Ptr<Object> protocol = factory.Create<Object> (); |
| 84 | node->AggregateObject(protocol); |
| 85 | |
| 86 | Ptr<Ccnx> ccnx = node->GetObject<Ccnx> (); |
| 87 | |
| 88 | if (ccnx == NULL) |
| 89 | { |
| 90 | NS_FATAL_ERROR ("CcnxProducerHelper::InstallPriv (): Getting Ccnx " |
| 91 | "a CcnxStack must be installed on the node"); |
| 92 | return 0; |
| 93 | } |
| 94 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 95 | // m_factory.Set ("Face", PointerValue (localFace)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 96 | m_factory.Set ("Ccnx", PointerValue (ccnx)); |
| 97 | Ptr<CcnxProducer> app = m_factory.Create<CcnxProducer> (); |
| 98 | |
| 99 | //app->m_ccnx->m_contentStore->SetMaxSize(app->GetStoreCapacity()); |
| 100 | localFace->RegisterProtocolHandler (MakeCallback (&CcnxProducer::HandlePacket, app)); |
| 101 | localFace->SetUp(); |
| 102 | |
| 103 | node->AddApplication (app); |
| 104 | |
| 105 | return app; |
| 106 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 107 | } |