Project

General

Profile

Bug #2783 » ndn-simple-test.cc

scenario code - 鹏飞 靳, 05/04/2015 05:51 PM

 
1
// ndn-simple.cpp
2

    
3
#include "ns3/core-module.h"
4
#include "ns3/network-module.h"
5
#include "ns3/point-to-point-module.h"
6
#include "ns3/ndnSIM-module.h"
7
#include "ns3/ndnSIM/helper/ndn-link-control-helper.hpp"
8

    
9
namespace ns3 {
10

    
11
int
12
main(int argc, char* argv[])
13
{
14
  // setting default parameters for PointToPoint links and channels
15
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
16
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
17
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
18

    
19
  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
20
  CommandLine cmd;
21
  cmd.Parse(argc, argv);
22

    
23
  // Creating nodes
24
  NodeContainer nodes;
25
  nodes.Create(6);
26

    
27
  // Connecting nodes using two links
28
  PointToPointHelper p2p;
29
  p2p.Install(nodes.Get(0), nodes.Get(1));
30
  p2p.Install(nodes.Get(1), nodes.Get(2));
31
  p2p.Install(nodes.Get(1), nodes.Get(3));
32
  p2p.Install(nodes.Get(2), nodes.Get(4));
33
  p2p.Install(nodes.Get(3), nodes.Get(4));
34
  p2p.Install(nodes.Get(4), nodes.Get(5));
35

    
36
  // Install NDN stack on all nodes
37
  ndn::StackHelper ndnHelper;
38
  ndnHelper.SetDefaultRoutes(true);
39
  ndnHelper.InstallAll();
40

    
41
  // Choosing forwarding strategy
42
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/broadcast");
43

    
44
  // Installing applications
45

    
46
  // Consumer
47
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
48
  // Consumer will request /prefix/0, /prefix/1, ...
49
  consumerHelper.SetPrefix("/prefix");
50
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
51
  consumerHelper.Install(nodes.Get(0));                        // first node
52

    
53
  // Producer
54
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
55
  // Producer will reply to all requests starting with /prefix
56
  producerHelper.SetPrefix("/prefix");
57
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
58

    
59
  // ndn::AppHelper producerHelper("Hijacker");
60
  producerHelper.Install(nodes.Get(5)); // last node
61

    
62
  //   // Calculate and install FIBs
63
  // ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
64
  // ndnGlobalRoutingHelper.InstallAll();
65
  // ndnGlobalRoutingHelper.AddOrigins("/prefix", nodes.Get(5));
66
  // ndn::GlobalRoutingHelper::CalculateRoutes();
67

    
68
  Simulator::Schedule(Seconds(10.0), ndn::LinkControlHelper::FailLink, nodes.Get(2), nodes.Get(4));
69
  Simulator::Schedule(Seconds(20.0), ndn::LinkControlHelper::UpLink, nodes.Get(2), nodes.Get(4));
70
  Simulator::Schedule(Seconds(30.0), ndn::LinkControlHelper::FailLink, nodes.Get(4), nodes.Get(2));
71
  Simulator::Schedule(Seconds(40.0), ndn::LinkControlHelper::UpLink, nodes.Get(4), nodes.Get(2));
72

    
73
  Simulator::Schedule(Seconds(45.0), ndn::LinkControlHelper::FailLink, nodes.Get(2), nodes.Get(3));
74
  Simulator::Schedule(Seconds(50.0), ndn::LinkControlHelper::UpLink, nodes.Get(2), nodes.Get(3));
75
  Simulator::Schedule(Seconds(55.0), ndn::LinkControlHelper::FailLink, nodes.Get(3), nodes.Get(2));
76
  Simulator::Schedule(Seconds(60.0), ndn::LinkControlHelper::UpLink, nodes.Get(3), nodes.Get(2));
77

    
78

    
79
  Simulator::Stop(Seconds(100.0));
80

    
81
  Simulator::Run();
82
  Simulator::Destroy();
83

    
84
  return 0;
85
}
86

    
87
} // namespace ns3
88

    
89
int
90
main(int argc, char* argv[])
91
{
92
  return ns3::main(argc, argv);
93
}
(2-2/2)