3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.ec import ExperimentController
24 def add_ns3_node(ec, simu):
25 node = ec.register_resource("ns3::Node")
26 ec.register_connection(node, simu)
28 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
29 ec.register_connection(node, ipv4)
31 arp = ec.register_resource("ns3::ArpL3Protocol")
32 ec.register_connection(node, arp)
34 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
35 ec.register_connection(node, icmp)
37 udp = ec.register_resource("ns3::UdpL4Protocol")
38 ec.register_connection(node, udp)
40 tcp = ec.register_resource("ns3::TcpL4Protocol")
41 ec.register_connection(node, tcp)
45 def add_device(ec, node, ip, prefix):
46 dev = ec.register_resource("ns3::PointToPointNetDevice")
48 ec.set(dev, "prefix", prefix)
49 ec.register_connection(node, dev)
51 queue = ec.register_resource("ns3::DropTailQueue")
52 ec.register_connection(dev, queue)
56 ec = ExperimentController(exp_id = "dce-custom-ccn")
58 node = ec.register_resource("linux::Node")
59 ec.set(node, "hostname", "localhost")
60 ec.set(node, "cleanProcesses", True)
62 simu = ec.register_resource("linux::ns3::Simulation")
63 ec.set(simu, "verbose", True)
64 ec.register_connection(simu, node)
66 nsnode1 = add_ns3_node(ec, simu)
67 dev1 = add_device(ec, nsnode1, "10.0.0.1", "30")
68 ec.set(dev1, "DataRate", "5Mbps")
70 nsnode2 = add_ns3_node(ec, simu)
71 dev2 = add_device(ec, nsnode2, "10.0.0.2", "30")
72 ec.set(dev2, "DataRate", "5Mbps")
75 chan = ec.register_resource("ns3::PointToPointChannel")
76 ec.set(chan, "Delay", "2ms")
78 ec.register_connection(chan, dev1)
79 ec.register_connection(chan, dev2)
81 ### create applications
83 # Add a LinuxCCNDceApplication to ns-3 node 1 to install custom ccnx sources
84 # and run a CCNx daemon
85 ccnd1 = ec.register_resource("linux::ns3::dce::CCNApplication")
86 # NOTE THAT INSTALLATION MIGHT FAIL IF openjdk-6-jdk is not installed
87 ec.set(ccnd1, "depends", "libpcap0.8-dev openjdk-6-jdk ant1.8 autoconf "
88 "libssl-dev libexpat-dev libpcap-dev libecryptfs0 libxml2-utils auto"
89 "make gawk gcc g++ git-core pkg-config libpcre3-dev openjdk-6-jre-lib")
90 ec.set (ccnd1, "sources", "http://www.ccnx.org/releases/ccnx-0.7.2.tar.gz")
91 ec.set (ccnd1, "build", "tar zxf ${SRC}/ccnx-0.7.2.tar.gz && "
93 " INSTALL_BASE=${BIN_DCE}/.. ./configure && "
94 " make MORE_LDLIBS='-pie -rdynamic' && "
96 " cp ${BIN_DCE}/../bin/ccn* ${BIN_DCE} && "
98 ec.set (ccnd1, "binary", "ccnd")
99 ec.set (ccnd1, "stackSize", 1<<20)
100 ec.set (ccnd1, "environment", "CCND_CAP=50000; CCND_DEBUG=7")
101 ec.set (ccnd1, "StartTime", "1s")
102 ec.set (ccnd1, "StopTime", "20s")
103 ec.register_connection(ccnd1, nsnode1)
105 # Add a CCN repository to ns-3 node1 manually configuring all
107 repofile = os.path.join(
108 os.path.dirname(os.path.realpath(__file__)),
109 "..", "..", "test", "resources", "linux",
110 "ns3", "ccn", "repoFile1")
112 ccnr = ec.register_resource("linux::ns3::dce::CCNApplication")
113 ec.set (ccnr, "binary", "ccnr")
114 ec.set (ccnr, "environment", "CCNR_DIRECTORY=/REPO/")
115 ec.set (ccnr, "files", "%s=/REPO/repoFile1" % repofile)
116 ec.set (ccnr, "stackSize", 1<<20)
117 ec.set (ccnr, "StartTime", "2s")
118 ec.set (ccnr, "StopTime", "120s")
119 ec.register_connection(ccnr, nsnode1)
121 # Add a LinuxCCNDceApplication to ns-3 node 1 to run a CCN
122 # daemon. Note that the CCNx sources and build instructions
123 # do not need to be specified again (NEPI will take the
124 # instructions from the first definition).
125 ccnd2 = ec.register_resource("linux::ns3::dce::CCNApplication")
126 ec.set (ccnd2, "binary", "ccnd")
127 ec.set (ccnd2, "stackSize", 1<<20)
128 ec.set (ccnd2, "environment", "CCND_CAP=50000; CCND_DEBUG=7")
129 ec.set (ccnd2, "StartTime", "1s")
130 ec.set (ccnd2, "StopTime", "120s")
131 ec.register_connection(ccnd2, nsnode2)
133 # Add DCE application to configure peer CCN faces between
135 ccndc1 = ec.register_resource("linux::ns3::dce::CCNApplication")
136 ec.set (ccndc1, "binary", "ccndc")
137 ec.set (ccndc1, "arguments", "-v;add;ccnx:/;udp;10.0.0.2")
138 ec.set (ccndc1, "stackSize", 1<<20)
139 ec.set (ccndc1, "StartTime", "2s")
140 ec.set (ccndc1, "StopTime", "120s")
141 ec.register_connection(ccndc1, nsnode1)
143 ccndc2 = ec.register_resource("linux::ns3::dce::CCNApplication")
144 ec.set (ccndc2, "binary", "ccndc")
145 ec.set (ccndc2, "arguments", "-v;add;ccnx:/;udp;10.0.0.1")
146 ec.set (ccndc2, "stackSize", 1<<20)
147 ec.set (ccndc2, "StartTime", "2s")
148 ec.set (ccndc2, "StopTime", "120s")
149 ec.register_connection(ccndc2, nsnode2)
151 # Add a DCE application to perform a ccncat and retrieve content
152 ccncat = ec.register_resource("linux::ns3::dce::CCNApplication")
153 ec.set (ccncat, "binary", "ccncat")
154 ec.set (ccncat, "arguments", "ccnx:/test/bunny.ts")
155 ec.set (ccncat, "stdinFile", "")
156 ec.set (ccncat, "stackSize", 1<<20)
157 ec.set (ccncat, "StartTime", "4s")
158 ec.set (ccncat, "StopTime", "120s")
159 ec.register_connection(ccncat, nsnode2)
163 ec.wait_finished([ccncat])
165 stdout = ec.trace(ccncat, "stdout")
166 # convert from bytes to MB
167 print "%0.2f MBytes received" % (len(stdout) / 1024.0 / 1024.0 )