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 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 27 | namespace ns3 { |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 30 | * This scenario simulates a one-node two-custom-app scenario: |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 31 | * |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 32 | * +------+ <-----> (CustomApp1) |
| 33 | * | Node | |
| 34 | * +------+ <-----> (CustomApp2) |
Alexander Afanasyev | 68de795 | 2012-12-12 18:02:29 -0800 | [diff] [blame] | 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 |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 50 | ndn::StackHelper ndnHelper; |
| 51 | ndnHelper.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 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 72 | |
| 73 | } // namespace ns3 |
| 74 | |
| 75 | int |
| 76 | main(int argc, char* argv[]) |
| 77 | { |
| 78 | return ns3::main(argc, argv); |
| 79 | } |