Skip to content

Instantly share code, notes, and snippets.

@dev-ritik
Last active July 6, 2019 16:18
Show Gist options
  • Save dev-ritik/6a35a04c473affbc754a2c76142a02e0 to your computer and use it in GitHub Desktop.
Save dev-ritik/6a35a04c473affbc754a2c76142a02e0 to your computer and use it in GitHub Desktop.
Segment fetcher test details
# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
#
# Copyright (C) 2015-2018, The University of Memphis,
# Arizona Board of Regents,
# Regents of the University of California.
#
# This file is part of Mini-NDN.
# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
#
# Mini-NDN is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mini-NDN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mini-NDN, e.g., in COPYING.md file.
# If not, see <http://www.gnu.org/licenses/>.
# import time
# import sys
# from itertools import cycle
# from mininet.log import info
# from ndn import ExperimentManager
import time
from ndn.experiments.experiment import Experiment
class ChunkAimdExperiment(Experiment):
def __init__(self, args):
Experiment.__init__(self,args)
def setup(self):
self.checkConvergence(70)
def run(self):
nodeA = self.net['a']
nodeB = self.net['b']
nodeB.cmd("ndnputchunks /ndn/b-site/b/large -f 300000 < /usr/local/include/ndnboost/typeof/vector150.hpp &> producer_chunk_aimd_log.txt &")
time.sleep(30)
nodeA.cmd("ndncatchunks -v -p aimd /ndn/b-site/b/large &> consumer_chunk_aimd_log.txt &")
Experiment.register("chunk_aimd", ChunkAimdExperiment)
# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
#
# Copyright (C) 2015-2018, The University of Memphis,
# Arizona Board of Regents,
# Regents of the University of California.
#
# This file is part of Mini-NDN.
# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
#
# Mini-NDN is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mini-NDN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mini-NDN, e.g., in COPYING.md file.
# If not, see <http://www.gnu.org/licenses/>.
# import time
# import sys
# from itertools import cycle
# from mininet.log import info
# from ndn import ExperimentManager
from ndn.experiments.experiment import Experiment
class JndnAimdExperiment(Experiment):
def __init__(self, args):
Experiment.__init__(self,args)
def setup(self):
self.checkConvergence()
def run(self):
nodeA = self.net['a']
nodeB = self.net['b']
nodeB.cmd("ndnputchunks /ndn/b-site/b/large -f 300000 < /usr/local/include/ndnboost/typeof/vector150.hpp &> producer_jndn_aimd_log.txt &")
nodeA.cmd("javac -cp '.:jndn-0.21_aimd.jar' Myclass.java")
nodeA.cmd("java -cp '.:jndn-0.21_aimd.jar' Myclass &> consumer_jndn_aimd_log.txt &")
Experiment.register("jndn_aimd", JndnAimdExperiment)
import net.named_data.jndn.*;
import net.named_data.jndn.util.SegmentFetcher;
import java.io.IOException;
import net.named_data.jndn.util.Blob;
public class Myclass {
private static String formatThroughput(double throughput)
{
int pow = 0;
while (throughput >= 1000.0 && pow < 4) {
throughput /= 1000.0;
pow++;
}
switch (pow) {
case 0:
return throughput + " bit/s";
case 1:
return throughput + " kbit/s";
case 2:
return throughput + " Mbit/s";
case 3:
return throughput + " Gbit/s";
case 4:
return throughput + " Tbit/s";
}
return "";
}
public static void main(String[] argv) {
Name name = new Name("/ndn/b-site/b/large");
// Name name = new Name("/localhost/demo/list1");
Face face = new Face();
Interest baseInterest = new Interest(name);
final boolean[] enabled = new boolean[] { true };
final long[] startTime = new long[] { 0 };
final int[] segmentsReceived = new int[] { 0 };
final int[] receivedSize = new int[] { 0 };
SegmentFetcher.OnComplete onComplete = new SegmentFetcher.OnComplete() {
@Override
public void onComplete(Blob content) {
enabled[0] = false;
// System.out.println(" onComplete "+content);
int timeElapsed = (int)(System.currentTimeMillis() - startTime[0]);
double throughput = receivedSize[0] * (8000 / timeElapsed);
System.out.println(content);
System.out.println("All segments have been received.");
System.out.println("Time elapsed: " + timeElapsed + " milliseconds");
System.out.println("Segments received: "+ segmentsReceived[0]);
System.out.println("Total size: " + (double)receivedSize[0]/1000 + "KB");
System.out.println("Goodput: " + formatThroughput(throughput));
}
};
SegmentFetcher.OnError onError = new SegmentFetcher.OnError() {
@Override
public void onError(SegmentFetcher.ErrorCode errorCode, String message) {
enabled[0] = false;
System.out.println("onError: " + message);
}
};
SegmentFetcher.VerifySegment verifySegment = new SegmentFetcher.VerifySegment() {
@Override
public boolean verifySegment(Data data) {
segmentsReceived[0]++;
receivedSize[0] += data.getContent().size();
// enabled[0] = false;
// System.out.println(" verifySegment "+data.getName());
return true;
}
};
// try {
// face.expressInterest(baseInterest, new OnData() {
// @Override
// public void onData(Interest interest, Data data) {
// enabled[0] = false;
// System.out.println(" onData "+interest);
// System.out.println(" onData "+data.getName());
// }
// }, new OnTimeout() {
// @Override
// public void onTimeout(Interest interest) {
// enabled[0] = false;
// System.out.println(" onTimeout ");
// }
// }, new OnNetworkNack() {
// @Override
// public void onNetworkNack(Interest interest, NetworkNack networkNack) {
// enabled[0] = false;
// System.out.println(" onNetworkNack ");
// }
// }
// );
// } catch (IOException e) {
// enabled[0] = false;
// System.out.println("onError: " + e.getMessage());
// e.printStackTrace();
// }
startTime[0] = System.currentTimeMillis();
SegmentFetcher.fetch(face, baseInterest, verifySegment, onComplete, onError);
// Loop calling processEvents until a callback sets enabled[0] = false.
while (enabled[0]) {
try {
face.processEvents();
// We need to sleep for a few milliseconds so we don't use 100% of
// the CPU.
Thread.sleep(5);
// System.out.println("whiler");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

The parameters used in the test were similar to the ones used in the ndncatchunks available here

The parameters can be found here and here

Only changes made is,

k = 8
maxRto = 4000

to match the ones used in the chunks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment