blob: 2aef361926e875b20fea87497bc488e5a6871870 [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
15 hostip="A.ws.ndn.ucla.edu";
16
17 var AsyncGetClosure = function AsyncGetClosure(T0) {
18 this.T0 = T0;
19 Closure.call(this);
20 };
21
22 AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
23 if (kind == Closure.UPCALL_FINAL) {
24 // Do nothing.
25 } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
26
27 nameStr = upcallInfo.interest.name.getName().split("/").slice(0,-2).join("/");
28 document.getElementById('pingreport').innerHTML += '<tr><td width="65%">' + nameStr + ' </td><td align="right">timeout</td></tr>' ;
29 } else if (kind == Closure.UPCALL_CONTENT) {
30 var T1 = new Date();
31 var content = upcallInfo.contentObject;
32 nameStr = content.name.getName().split("/").slice(0,-2).join("/");
33 strContent = DataUtils.toString(content.content);
34 if (strContent=="ping ack") {
35 document.getElementById('pingreport').innerHTML += '<tr><td width="65%">' + nameStr + ' </td><td align="right">' + (T1-this.T0) + ' ms</td></tr>' ;
36 } else {
37 console.log("Unknown content received.");
38 };
39 }
40 return Closure.RESULT_OK;
41 };
42
43 function ping(name) {
44 pingname = name + "/ping/" + Math.floor(Math.random()*100000);
45 ndn.expressInterest(new Name(pingname), new AsyncGetClosure( new Date() ));
46 };
47
48 function dopings() {
49 ping("/ndn/arizona.edu");
50 ping("/ndn/caida.org");
51 ping("/ndn/colostate.edu/netsec")
52 ping("/ndn/memphis.edu/netlab")
53 ping("/ndn/neu.edu/northpole")
54 ping("/ndn/parc.com");
55 ping("/ndn/pku.edu");
56 ping("/ndn/uci.edu");
57 ping("/ndn/ucla.edu");
58 ping("/ndn/ucla.edu/apps");
59 ping("/ndn/uiuc.edu");
60 ping("/ndn/wustl.edu");
61
62 };
63
64 openHandle = function() { dopings(); };
65 var ndn = new NDN({host:hostip, onopen:openHandle});
66 var T0 = 0;
67 ndn.transport.connectWebSocket(ndn);
68