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 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 32 | * +------+ <-----> (CustomApp1) |
| 33 | * | Node | |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 34 | * +------+ <-----> (CustomApp2) |
| 35 | * |
| 36 | * NS_LOG=CustomApp ./waf --run=ndn-simple-with-custom-app |
| 37 | */ |
| 38 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | int |
| 40 | main(int argc, char* argv[]) |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 41 | { |
| 42 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 43 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 44 | cmd.Parse(argc, argv); |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 45 | |
| 46 | // Creating nodes |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | Ptr<Node> node = CreateObject<Node>(); |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 48 | |
| 49 | // Install CCNx stack on all nodes |
| 50 | ndn::StackHelper ccnxHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | ccnxHelper.InstallAll(); |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 52 | |
| 53 | // Installing applications |
| 54 | |
| 55 | // Consumer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | ndn::AppHelper consumerHelper("CustomApp"); |
| 57 | ApplicationContainer app1 = consumerHelper.Install(node); |
| 58 | ApplicationContainer app2 = consumerHelper.Install(node); |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | app1.Start(Seconds(1.0)); // will send out Interest, which nobody will receive (Interests |
| 61 | // generated by an app will not got back to the app) |
| 62 | app2.Start( |
| 63 | Seconds(2.0)); // will send out an Interests, which will be received and satisfied by app1 |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | Simulator::Stop(Seconds(3.0)); |
| 66 | |
| 67 | Simulator::Run(); |
| 68 | Simulator::Destroy(); |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 69 | |
| 70 | return 0; |
| 71 | } |