blob: c10ceaaeee1459798ccff9e1bf32492ad9860df6 [file] [log] [blame]
Alexander Afanasyev68de7952012-12-12 18:02:29 -08001/* -*- 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
27using namespace ns3;
28
29/**
30 * This scenario simulates a one-node two-app scenario:
31 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080032 * +------+ <-----> (CustomApp1)
33 * | Node |
Alexander Afanasyev68de7952012-12-12 18:02:29 -080034 * +------+ <-----> (CustomApp2)
35 *
36 * NS_LOG=CustomApp ./waf --run=ndn-simple-with-custom-app
37 */
38
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039int
40main(int argc, char* argv[])
Alexander Afanasyev68de7952012-12-12 18:02:29 -080041{
42 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
43 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044 cmd.Parse(argc, argv);
Alexander Afanasyev68de7952012-12-12 18:02:29 -080045
46 // Creating nodes
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 Ptr<Node> node = CreateObject<Node>();
Alexander Afanasyev68de7952012-12-12 18:02:29 -080048
49 // Install CCNx stack on all nodes
50 ndn::StackHelper ccnxHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 ccnxHelper.InstallAll();
Alexander Afanasyev68de7952012-12-12 18:02:29 -080052
53 // Installing applications
54
55 // Consumer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 ndn::AppHelper consumerHelper("CustomApp");
57 ApplicationContainer app1 = consumerHelper.Install(node);
58 ApplicationContainer app2 = consumerHelper.Install(node);
Alexander Afanasyev68de7952012-12-12 18:02:29 -080059
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 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 Afanasyev68de7952012-12-12 18:02:29 -080064
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 Simulator::Stop(Seconds(3.0));
66
67 Simulator::Run();
68 Simulator::Destroy();
Alexander Afanasyev68de7952012-12-12 18:02:29 -080069
70 return 0;
71}