blob: bbfa7a448badea345078b54053953df561327bee [file] [log] [blame]
Jeff Burke0d10e342012-12-08 11:47:11 -08001/*
2 NDN Ping example
3
4 Using ping responder on NDN testbed, which responds to Interests in
5 /<topo-prefix>/ping/<random-number>
6
7 Jeff Burke
8 jburke@remap.ucla.edu
9
10 See COPYING for copyright and distribution information.
11
12*/
13
14 // One of NDN project default hubs
Jeff Thompson8b0e3872013-07-08 18:30:37 -070015 var hostip = "B.ws.ndn.ucla.edu";
Jeff Burke0d10e342012-12-08 11:47:11 -080016
Jeff Thompson8b0e3872013-07-08 18:30:37 -070017 var AsyncGetClosure = function AsyncGetClosure(T0) {
18 this.T0 = T0;
Jeff Burke0d10e342012-12-08 11:47:11 -080019 Closure.call(this);
20 };
21
Jeff Thompson8b0e3872013-07-08 18:30:37 -070022 AsyncGetClosure.gotFirstUpcall = false;
Jeff Burke0d10e342012-12-08 11:47:11 -080023 AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
Jeff Thompson8b0e3872013-07-08 18:30:37 -070024 if (!AsyncGetClosure.gotFirstUpcall) {
25 AsyncGetClosure.gotFirstUpcall = true;
26 dopings();
27 }
28
Jeff Burke0d10e342012-12-08 11:47:11 -080029 if (kind == Closure.UPCALL_FINAL) {
30 // Do nothing.
31 } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
32
33 nameStr = upcallInfo.interest.name.getName().split("/").slice(0,-2).join("/");
34 document.getElementById('pingreport').innerHTML += '<tr><td width="65%">' + nameStr + ' </td><td align="right">timeout</td></tr>' ;
35 } else if (kind == Closure.UPCALL_CONTENT) {
36 var T1 = new Date();
37 var content = upcallInfo.contentObject;
38 nameStr = content.name.getName().split("/").slice(0,-2).join("/");
39 strContent = DataUtils.toString(content.content);
40 if (strContent=="ping ack") {
41 document.getElementById('pingreport').innerHTML += '<tr><td width="65%">' + nameStr + ' </td><td align="right">' + (T1-this.T0) + ' ms</td></tr>' ;
42 } else {
43 console.log("Unknown content received.");
44 };
45 }
46 return Closure.RESULT_OK;
47 };
48
49 function ping(name) {
50 pingname = name + "/ping/" + Math.floor(Math.random()*100000);
51 ndn.expressInterest(new Name(pingname), new AsyncGetClosure( new Date() ));
52 };
53
54 function dopings() {
Jeff Burke0d10e342012-12-08 11:47:11 -080055 ping("/ndn/caida.org");
56 ping("/ndn/colostate.edu/netsec")
57 ping("/ndn/memphis.edu/netlab")
58 ping("/ndn/neu.edu/northpole")
59 ping("/ndn/parc.com");
60 ping("/ndn/pku.edu");
61 ping("/ndn/uci.edu");
62 ping("/ndn/ucla.edu");
63 ping("/ndn/ucla.edu/apps");
64 ping("/ndn/uiuc.edu");
65 ping("/ndn/wustl.edu");
Jeff Burke0d10e342012-12-08 11:47:11 -080066 };
67
Jeff Thompson8b0e3872013-07-08 18:30:37 -070068 var ndn = new NDN({host:hostip});
Jeff Burke0d10e342012-12-08 11:47:11 -080069 var T0 = 0;
Jeff Thompson8b0e3872013-07-08 18:30:37 -070070 // Do the first ping to get started. The remaining pings are requested on the first upcall.
71 ping("/ndn/arizona.edu");