Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | // ndn-simple-with-custom-app.cc |
| 22 | |
| 23 | #include "ns3/core-module.h" |
| 24 | #include "ns3/network-module.h" |
| 25 | #include "ns3/ndnSIM-module.h" |
| 26 | |
| 27 | using namespace ns3; |
| 28 | |
| 29 | /** |
| 30 | * This scenario simulates a one-node two-app scenario: |
| 31 | * |
| 32 | * +------+ <-----> (CustomApp1) |
| 33 | * | Node | |
| 34 | * +------+ <-----> (CustomApp2) |
| 35 | * |
| 36 | * NS_LOG=CustomApp ./waf --run=ndn-simple-with-custom-app |
| 37 | */ |
| 38 | |
| 39 | int |
| 40 | main (int argc, char *argv[]) |
| 41 | { |
| 42 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 43 | CommandLine cmd; |
| 44 | cmd.Parse (argc, argv); |
| 45 | |
| 46 | // Creating nodes |
| 47 | Ptr<Node> node = CreateObject<Node> (); |
| 48 | |
| 49 | // Install CCNx stack on all nodes |
| 50 | ndn::StackHelper ccnxHelper; |
| 51 | ccnxHelper.InstallAll (); |
| 52 | |
| 53 | // Installing applications |
| 54 | |
| 55 | // Consumer |
| 56 | ndn::AppHelper consumerHelper ("CustomApp"); |
| 57 | ApplicationContainer app1 = consumerHelper.Install (node); |
| 58 | ApplicationContainer app2 = consumerHelper.Install (node); |
| 59 | |
| 60 | app1.Start (Seconds (1.0)); // will send out Interest, which nobody will receive (Interests generated by an app will not got back to the app) |
| 61 | app2.Start (Seconds (2.0)); // will send out an Interests, which will be received and satisfied by app1 |
| 62 | |
| 63 | Simulator::Stop (Seconds (3.0)); |
| 64 | |
| 65 | Simulator::Run (); |
| 66 | Simulator::Destroy (); |
| 67 | |
| 68 | return 0; |
| 69 | } |