author | Craig Dowell <craigdo@ee.washington.edu> |
Mon, 04 Jan 2010 10:35:32 -0800 | |
changeset 6009 | e1b696a1ed28 |
parent 5369 | 86beb5869f67 |
child 6014 | d251d4a44fde |
permissions | -rw-r--r-- |
4745
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
2 |
/* |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
6 |
* |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
11 |
* |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
15 |
* |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
16 |
*/ |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
17 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
18 |
// Test program for this 3-router scenario, using global routing |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
19 |
// |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
20 |
// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32) |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
21 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
22 |
#include <iostream> |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
23 |
#include <fstream> |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
24 |
#include <string> |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
25 |
#include <cassert> |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
26 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
27 |
#include "ns3/csma-net-device.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
28 |
#include "ns3/core-module.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
29 |
#include "ns3/simulator-module.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
30 |
#include "ns3/node-module.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
31 |
#include "ns3/helper-module.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
32 |
#include "ns3/ipv4-static-routing.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
33 |
#include "ns3/ipv4-global-routing.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
34 |
#include "ns3/ipv4-list-routing.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
35 |
#include "ns3/ipv4-routing-table-entry.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
36 |
#include "ns3/global-router-interface.h" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
37 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
38 |
using namespace ns3; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
39 |
using std::cout; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
40 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
41 |
NS_LOG_COMPONENT_DEFINE ("GlobalRouterInjectionTest"); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
42 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
43 |
int |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
44 |
main (int argc, char *argv[]) |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
45 |
{ |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
46 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
47 |
// Allow the user to override any of the defaults and the above |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
48 |
// DefaultValue::Bind ()s at run-time, via command-line arguments |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
49 |
CommandLine cmd; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
50 |
cmd.Parse (argc, argv); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
51 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
52 |
Ptr<Node> nA = CreateObject<Node> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
53 |
Ptr<Node> nB = CreateObject<Node> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
54 |
Ptr<Node> nC = CreateObject<Node> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
55 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
56 |
NodeContainer c = NodeContainer (nA, nB, nC); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
57 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
58 |
InternetStackHelper internet; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
59 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
60 |
// Point-to-point links |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
61 |
NodeContainer nAnB = NodeContainer (nA, nB); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
62 |
NodeContainer nBnC = NodeContainer (nB, nC); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
63 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
64 |
internet.Install (nAnB); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
65 |
Ipv4ListRoutingHelper staticonly; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
66 |
Ipv4ListRoutingHelper staticRouting; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
67 |
staticonly.Add(staticRouting, 0); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
68 |
internet.SetRoutingHelper(staticonly); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
69 |
internet.Install(NodeContainer(nC)); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
70 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
71 |
// We create the channels first without any IP addressing information |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
72 |
PointToPointHelper p2p; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
73 |
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
74 |
p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
75 |
NetDeviceContainer dAdB = p2p.Install (nAnB); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
76 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
77 |
NetDeviceContainer dBdC = p2p.Install (nBnC);; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
78 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
79 |
Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
80 |
deviceA->SetAddress (Mac48Address::Allocate ()); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
81 |
nA->AddDevice (deviceA); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
82 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
83 |
Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
84 |
deviceC->SetAddress (Mac48Address::Allocate ()); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
85 |
nC->AddDevice (deviceC); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
86 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
87 |
// Later, we add IP addresses. |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
88 |
Ipv4AddressHelper ipv4; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
89 |
ipv4.SetBase ("10.1.1.0", "255.255.255.252"); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
90 |
Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
91 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
92 |
ipv4.SetBase ("10.1.1.4", "255.255.255.252"); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
93 |
Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
94 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
95 |
Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
96 |
Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
97 |
Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
98 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
99 |
int32_t ifIndexA = ipv4A->AddInterface (deviceA); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
100 |
int32_t ifIndexC = ipv4C->AddInterface (deviceC); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
101 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
102 |
Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255")); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
103 |
ipv4A->AddAddress (ifIndexA, ifInAddrA); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
104 |
ipv4A->SetMetric (ifIndexA, 1); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
105 |
ipv4A->SetUp (ifIndexA); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
106 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
107 |
Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255")); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
108 |
ipv4C->AddAddress (ifIndexC, ifInAddrC); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
109 |
ipv4C->SetMetric (ifIndexC, 1); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
110 |
ipv4C->SetUp (ifIndexC); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
111 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
112 |
// Create router nodes, initialize routing database and set up the routing |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
113 |
// tables in the nodes. |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
114 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
115 |
// Populate routing tables for nodes nA and nB |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
116 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
117 |
// Inject global routes from Node B, including transit network... |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
118 |
Ptr<GlobalRouter> globalRouterB = nB->GetObject<GlobalRouter> (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
119 |
globalRouterB->InjectRoute ("10.1.1.4", "255.255.255.252"); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
120 |
// ...and the host in network "C" |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
121 |
globalRouterB->InjectRoute ("192.168.1.1", "255.255.255.255"); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
122 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
123 |
Ipv4GlobalRoutingHelper::RecomputeRoutingTables(); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
124 |
// In addition, nB needs a static route to nC so it knows what to do with stuff |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
125 |
// going to 192.168.1.1 |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
126 |
Ipv4StaticRoutingHelper ipv4RoutingHelper; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
127 |
Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting(ipv4B); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
128 |
staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"),2); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
129 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
130 |
// Create the OnOff application to send UDP datagrams of size |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
131 |
// 210 bytes at a rate of 448 Kb/s |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
132 |
uint16_t port = 9; // Discard port (RFC 863) |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
133 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
134 |
Address (InetSocketAddress (ifInAddrC.GetLocal(), port))); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
135 |
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
136 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
137 |
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000))); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
138 |
ApplicationContainer apps = onoff.Install (nA); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
139 |
apps.Start (Seconds (1.0)); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
140 |
apps.Stop (Seconds (10.0)); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
141 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
142 |
// Create a packet sink to receive these packets |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
143 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
144 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
145 |
apps = sink.Install (nC); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
146 |
apps.Start (Seconds (1.0)); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
147 |
apps.Stop (Seconds (10.0)); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
148 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
149 |
std::ofstream ascii; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
150 |
ascii.open ("global-routing-injection32.tr", std::ios_base::binary | std::ios_base::out); |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
151 |
p2p.EnablePcapAll ("global-routing-injection32"); |
4745
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
152 |
PointToPointHelper::EnableAsciiAll (ascii); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
153 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
154 |
Simulator::Run (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
155 |
Simulator::Destroy (); |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
156 |
|
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
157 |
return 0; |
a0e27af57c8d
Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents:
diff
changeset
|
158 |
} |