Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 3 | #include <ns3/core-module.h> |
| 4 | #include <ns3/network-module.h> |
| 5 | #include <ns3/NDNabstraction-module.h> |
| 6 | #include <ns3/point-to-point-module.h> |
| 7 | |
| 8 | #include "sync-logic.h" |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame] | 9 | #include "sync-logic-helper.h" |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 10 | |
| 11 | using namespace ns3; |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 12 | using namespace Sync; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 13 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 14 | NS_LOG_COMPONENT_DEFINE ("SyncExample"); |
| 15 | |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame] | 16 | void OnUpdate (const std::string &prefix, const SeqNo &newSeq, const SeqNo &/*oldSeq*/) |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 17 | { |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame] | 18 | NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << Simulator::GetContext () << ", prefix: " << prefix << ", seqNo: " << newSeq); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 19 | } |
| 20 | |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame] | 21 | void OnRemove (const std::string &prefix) |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 22 | { |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame] | 23 | NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << Simulator::GetContext () << ", prefix: "<< prefix); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 24 | } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 25 | |
| 26 | int |
| 27 | main (int argc, char *argv[]) |
| 28 | { |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 29 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 30 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms")); |
| 31 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
| 32 | |
| 33 | Config::SetDefault ("ns3::CcnxFloodingStrategy::SmartFlooding", StringValue ("false")); |
| 34 | |
| 35 | LogComponentEnable ("SyncExample", LOG_ALL); |
| 36 | |
| 37 | Time finishTime = Seconds (3.0); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 38 | |
| 39 | CommandLine cmd; |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 40 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 41 | cmd.Parse (argc, argv); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 43 | // Creating nodes |
| 44 | NodeContainer nodes; |
Chaoyi Bian | 17e746b | 2012-04-13 16:57:19 -0700 | [diff] [blame] | 45 | nodes.Create (11); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 46 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 47 | // Connecting nodes using two links |
| 48 | PointToPointHelper p2p; |
Chaoyi Bian | 17e746b | 2012-04-13 16:57:19 -0700 | [diff] [blame] | 49 | p2p.Install (nodes.Get (0), nodes.Get (4)); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 50 | p2p.Install (nodes.Get (1), nodes.Get (2)); |
Chaoyi Bian | 17e746b | 2012-04-13 16:57:19 -0700 | [diff] [blame] | 51 | p2p.Install (nodes.Get (1), nodes.Get (4)); |
| 52 | p2p.Install (nodes.Get (1), nodes.Get (5)); |
| 53 | p2p.Install (nodes.Get (2), nodes.Get (6)); |
| 54 | p2p.Install (nodes.Get (2), nodes.Get (7)); |
| 55 | p2p.Install (nodes.Get (3), nodes.Get (4)); |
| 56 | p2p.Install (nodes.Get (3), nodes.Get (8)); |
| 57 | p2p.Install (nodes.Get (4), nodes.Get (5)); |
| 58 | p2p.Install (nodes.Get (4), nodes.Get (8)); |
| 59 | p2p.Install (nodes.Get (5), nodes.Get (6)); |
| 60 | p2p.Install (nodes.Get (5), nodes.Get (9)); |
| 61 | p2p.Install (nodes.Get (5), nodes.Get (10)); |
| 62 | p2p.Install (nodes.Get (6), nodes.Get (10)); |
| 63 | p2p.Install (nodes.Get (7), nodes.Get (10)); |
| 64 | p2p.Install (nodes.Get (8), nodes.Get (9)); |
| 65 | p2p.Install (nodes.Get (9), nodes.Get (10)); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 67 | Names::Add ("0", nodes.Get (0)); |
| 68 | Names::Add ("1", nodes.Get (1)); |
| 69 | Names::Add ("2", nodes.Get (2)); |
Chaoyi Bian | 17e746b | 2012-04-13 16:57:19 -0700 | [diff] [blame] | 70 | Names::Add ("3", nodes.Get(3)); |
| 71 | Names::Add ("4", nodes.Get(4)); |
| 72 | Names::Add ("5", nodes.Get(5)); |
| 73 | Names::Add ("6", nodes.Get(6)); |
| 74 | Names::Add ("7", nodes.Get(7)); |
| 75 | Names::Add ("8", nodes.Get(8)); |
| 76 | Names::Add ("9", nodes.Get(9)); |
| 77 | Names::Add ("10", nodes.Get(10)); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 78 | |
| 79 | // Install CCNx stack on all nodes |
| 80 | NS_LOG_INFO ("Installing CCNx stack"); |
| 81 | CcnxStackHelper ccnxHelper; |
| 82 | ccnxHelper.SetForwardingStrategy ("ns3::CcnxFloodingStrategy"); |
| 83 | ccnxHelper.SetDefaultRoutes (false); |
| 84 | ccnxHelper.InstallAll (); |
| 85 | |
| 86 | ccnxHelper.AddRoute ("0", "/sync", 0, 0); |
| 87 | ccnxHelper.AddRoute ("1", "/sync", 0, 0); |
| 88 | ccnxHelper.AddRoute ("1", "/sync", 1, 0); |
Chaoyi Bian | 17e746b | 2012-04-13 16:57:19 -0700 | [diff] [blame] | 89 | ccnxHelper.AddRoute ("1", "/sync", 2, 0); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 90 | ccnxHelper.AddRoute ("2", "/sync", 0, 0); |
Chaoyi Bian | 17e746b | 2012-04-13 16:57:19 -0700 | [diff] [blame] | 91 | ccnxHelper.AddRoute ("2", "/sync", 1, 0); |
| 92 | ccnxHelper.AddRoute ("2", "/sync", 2, 0); |
| 93 | ccnxHelper.AddRoute ("3", "/sync", 0, 0); |
| 94 | ccnxHelper.AddRoute ("3", "/sync", 1, 0); |
| 95 | ccnxHelper.AddRoute ("4", "/sync", 0, 0); |
| 96 | ccnxHelper.AddRoute ("4", "/sync", 1, 0); |
| 97 | ccnxHelper.AddRoute ("4", "/sync", 2, 0); |
| 98 | ccnxHelper.AddRoute ("4", "/sync", 3, 0); |
| 99 | ccnxHelper.AddRoute ("4", "/sync", 4, 0); |
| 100 | ccnxHelper.AddRoute ("5", "/sync", 0, 0); |
| 101 | ccnxHelper.AddRoute ("5", "/sync", 1, 0); |
| 102 | ccnxHelper.AddRoute ("5", "/sync", 2, 0); |
| 103 | ccnxHelper.AddRoute ("5", "/sync", 3, 0); |
| 104 | ccnxHelper.AddRoute ("5", "/sync", 4, 0); |
| 105 | ccnxHelper.AddRoute ("6", "/sync", 0, 0); |
| 106 | ccnxHelper.AddRoute ("6", "/sync", 1, 0); |
| 107 | ccnxHelper.AddRoute ("6", "/sync", 2, 0); |
| 108 | ccnxHelper.AddRoute ("7", "/sync", 0, 0); |
| 109 | ccnxHelper.AddRoute ("7", "/sync", 1, 0); |
| 110 | ccnxHelper.AddRoute ("8", "/sync", 0, 0); |
| 111 | ccnxHelper.AddRoute ("8", "/sync", 1, 0); |
| 112 | ccnxHelper.AddRoute ("8", "/sync", 2, 0); |
| 113 | ccnxHelper.AddRoute ("9", "/sync", 0, 0); |
| 114 | ccnxHelper.AddRoute ("9", "/sync", 1, 0); |
| 115 | ccnxHelper.AddRoute ("9", "/sync", 2, 0); |
| 116 | ccnxHelper.AddRoute ("10", "/sync", 0, 0); |
| 117 | ccnxHelper.AddRoute ("10", "/sync", 1, 0); |
| 118 | ccnxHelper.AddRoute ("10", "/sync", 2, 0); |
| 119 | ccnxHelper.AddRoute ("10", "/sync", 3, 0); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 120 | |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame] | 121 | SyncLogicHelper logicHelper; |
| 122 | logicHelper.SetPrefix ("/sync"); |
| 123 | logicHelper.SetCallbacks (OnUpdate, OnRemove); |
| 124 | ApplicationContainer apps = logicHelper.Install (NodeContainer (nodes.Get (0), nodes.Get (1))); |
| 125 | |
Alexander Afanasyev | 9cbebab | 2012-04-09 15:47:19 -0700 | [diff] [blame] | 126 | // one data |
| 127 | Simulator::ScheduleWithContext (0, Seconds (0.5), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 1); |
| 128 | |
| 129 | // two producers at the same time |
| 130 | Simulator::ScheduleWithContext (0, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 2); |
| 131 | Simulator::ScheduleWithContext (1, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (1)), "/1", 1, 2); |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame] | 132 | |
| 133 | logicHelper.Install (nodes.Get (2)). |
| 134 | Start (Seconds (2.001)); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 135 | |
| 136 | Simulator::Stop (finishTime); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 137 | Simulator::Run (); |
| 138 | Simulator::Destroy (); |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | |