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