Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
a1bf143
r2py version of allpairsping.repy
Aug 5, 2014
3e48b5c
Update allpairsping.r2py
us341 Aug 7, 2014
0496790
Update allpairsping.r2py
us341 Aug 9, 2014
1819bf9
Update allpairsping.r2py
us341 Aug 9, 2014
dc6e74c
Create allpairspingmap.mix
us341 Aug 12, 2014
968563f
Create allpairping_new.r2py
us341 Aug 14, 2014
8bf53c1
Create allpairsping.r2py
us341 Aug 14, 2014
22b4c07
this is latest
Aug 16, 2014
df21954
Update allpairsping.r2py
us341 Aug 21, 2014
e5d5d84
latest
Aug 21, 2014
45cbe13
Update allpairsping.r2py
us341 Aug 21, 2014
5adceb4
after sleep update
Aug 21, 2014
34afa62
Merge branch 'master' of https://github.com/us341/tutorial
Aug 21, 2014
20c51ce
after sleep update
Aug 21, 2014
6d74aa0
these are for infosec
Aug 21, 2014
9170b89
Update samplesecurity.r2py
us341 Aug 21, 2014
a29c102
Update allpairspingmap.mix
us341 Aug 26, 2014
9deaad6
Update allpairsping.r2py
us341 Aug 26, 2014
428917d
Update allpairsping.r2py
us341 Aug 27, 2014
b702b54
Update allpairping_new.r2py
us341 Aug 27, 2014
0852695
Update allpairspingmap.mix
us341 Aug 27, 2014
52b3d63
Update allpairspingmap.mix
us341 Aug 27, 2014
4acbb7d
Update allpairspingmap.mix
us341 Aug 27, 2014
56a9d24
Update allpairspingmap.mix
us341 Aug 27, 2014
5e010e3
Update allpairspingmap.mix
us341 Aug 27, 2014
9b631fb
Update allpairsping.r2py
us341 Aug 27, 2014
e8461d0
Update allpairspingmap.mix
us341 Aug 27, 2014
228d0ed
Update allpairspingmap.mix
us341 Aug 28, 2014
1cf2d51
running version of allpairspingmap
Aug 28, 2014
6efb17f
Update allpairspingmap.r2py
us341 Sep 3, 2014
190d739
java script for allpairspingmap.r2py
Sep 3, 2014
20886da
Update allpairsping.r2py
us341 Sep 3, 2014
b22f820
Update samplesecurity.r2py
us341 Sep 4, 2014
cbfd806
Update samplesecuritytest.r2py
us341 Sep 4, 2014
08c5ead
Update samplesecuritytest.r2py
us341 Sep 4, 2014
b26f8bb
Delete samplesecurity.r2py
us341 Sep 8, 2014
f79599b
Delete samplesecuritytest.r2py
us341 Sep 8, 2014
4740d3c
Delete allpairsping.r2py
us341 Sep 8, 2014
d7568e9
Delete allpairsping.r2py
us341 Sep 8, 2014
4065c27
Delete allpairping_new.r2py
us341 Sep 8, 2014
1d45182
Delete allpairspingmap.mix
us341 Sep 8, 2014
1c35413
Create allpairsping.r2py
us341 Sep 8, 2014
560908c
Delete allpairsping.r2py
us341 Sep 8, 2014
f5c248a
Delete allpairspingmap.r2py
us341 Sep 8, 2014
620a66c
Delete jquerygmaps.js
us341 Sep 8, 2014
0aaf98d
Delete allpairsping.r2py
us341 Sep 8, 2014
4635ac3
allpairsping is added to apps
Sep 8, 2014
c623c44
allpairspingmap added
Sep 8, 2014
7a6cc9f
allpairsping and allpairspingmap added with required files
Sep 8, 2014
8900d02
Delete allpairsping.r2py
us341 Sep 11, 2014
0604f52
Create allpairsping.r2py
us341 Sep 11, 2014
f573788
Update allpairsping.r2py
us341 Sep 16, 2014
293ea8c
Update allpairsping.r2py
us341 Sep 16, 2014
26f66b2
Update allpairsping.r2py
us341 Sep 16, 2014
eced328
Update allpairsping.r2py
us341 Sep 16, 2014
82196d0
improved:blank lines in neighboriplist.txt are skipped without error
Sep 20, 2014
9d16477
Create allpairspingmap_new,r2py
us341 Sep 22, 2014
d71004f
Update allpairsping.r2py
us341 Sep 22, 2014
ad3f057
Create httpserver.r2py
us341 Sep 30, 2014
a8360e9
debugging in process for getting list out of index inside httpretriev…
us341 Dec 3, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions allpairsping.r2py
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
"""
<Author>
Urvashi Soni

<Description>
gives the connectivity graph and latency information of all nodes in a group.

"""

# send a probe message to each neighbor
def probe_neighbors_forever():
# Call me again in 10 seconds
while True:
for neighborip in mycontext["neighborlist"]:
mycontext['sendtime'][neighborip] = getruntime()
if neighborip == mycontext['myip']:
#skip if ip address in neighboriplist matches the local ip because in repy we cann't have same localip and dest ip
continue
sendmessage(neighborip, mycontext['port'], 'ping',mycontext['myip'],mycontext['port'])
sendmessage(neighborip,mycontext['port'],'share'+encode_row(mycontext['myip'],mycontext["neighborlist"],mycontext['latency'].copy()),mycontext['myip'],mycontext['port'])
sleep(0.5)
#sleep for 10 sec and start from while loop again
sleep(10)




# Handle an incoming message
def got_message(srcip,srcport,mess):
if mess == 'ping':
sendmessage(srcip,srcport,'pong',mycontext['myip'], pingport)
elif mess == 'pong':
# elapsed time is now - time when I sent the ping
mycontext['latency'][srcip] = getruntime() - mycontext['sendtime'][srcip]
elif mess.startswith('share'):
mycontext['row'][srcip] = mess[len('share'):]



def encode_row(rowip, neighborlist, latencylist):
retstring = "<tr><td>"+rowip+"</td>"
for neighborip in neighborlist:
if neighborip in latencylist:
retstring = retstring + "<td>"+str(latencylist[neighborip])[:4]+"s</td>"
else:
retstring = retstring + "<td>Unknown</td>"

retstring = retstring + "</tr>"
return retstring



# Generates a HTML page that represents the current status of the program
def generate_status_page():
webpage = "<html><head><title>Latency Information</title></head><body><h1>Latency information from "+mycontext['myip']+' </h1><table border="1">'
webpage = webpage + "<tr><td></td><td>"+ "</td><td>".join(mycontext['neighborlist'])+"</td></tr>"
for nodeip in mycontext['neighborlist']:
if nodeip in mycontext['row']:
webpage = webpage + mycontext['row'][nodeip]+'\n'
else:
webpage = webpage + '<tr><td>'+nodeip+'</td><td>No Data Reported</td></tr>\n'

# now the footer...
webpage = webpage + '</table></html>'
return webpage



# Displays a web page with the latency information
def handle_http_request(srcip,srcport,connobj):
log('received request from',srcip,'\n')

# Get the header
total_data = ''
# The HTTP header ends once we see the char combination '\n\n', which
# is an empty string.
while '\n\n' not in total_data:
# Receive in chunks to avoid reading too much data
try:
data = connobj.recv(4096)
except SocketWouldBlockError:
# retry if they haven't completed sending the header
sleep(.05)
continue
except SocketClosedRemote:
log('client from',srcip,'aborted before sending HTTP header...\n')
return
total_data += data
total_data = total_data.replace('\r\n', '\n')

header, overflow = total_data.split('\n\n', 1)


# Get the request path, which is inbetween the HTTP action keyword and the
# HTTP version number.
# The http action keyword is the first word with no whitespace.
everything_after_httpaction = header.split(None, 1)[1]
# Following the path is the HTTP/[VERSION_NUMBER].
# We can use that as a delimiter to extract the path.
request_path = everything_after_httpaction.split(" HTTP/")[0]

# Generate the data to send back
# Don't respond with anything if they have something in the request path.
# This include favicons. We don't want to generate the webpage needlessly.
if request_path != '/':
data = 'HTTP/1.1 404 Not Found\n\n'
else:
webpage = generate_status_page()
# combine everything into one unit for sending
data = 'HTTP/1.1 200 OK\nContent-Type: text/html\nContent-Length: '+str(len(webpage))+'\nServer: Seattle Testbed\n\n'+webpage

# send the response

sent = 0
while sent < len(data):
try:
sent += connobj.send(data[sent:])
except SocketWouldBlockError:
# retry if response hasn't been sent yet
sleep(.05)
continue
except SocketClosedRemote:
log('client from',srcip,'aborted before response could be sent...\n')
return
# and we're done, so let's close this connection...
connobj.close()

def handle_message_forever():
while True:
try:
srcip, srcport, mess = udpserversocket.getmessage()
except SocketWouldBlockError:
sleep(0.1)
continue
got_message(srcip, srcport, mess)



def handle_connection_forever():
while True:
try:
ret_ip, ret_port, ret_socket = connobj.getconnection()
except SocketWouldBlockError:
sleep(0.1)
continue
handle_http_request(ret_ip, ret_port, ret_socket)



if callfunc == 'initialize':
#check if user has provided port number as call argument
if len(callargs) != 1:
raise Exception("Must specify the port to use")

pingport = int(callargs[0])
mycontext['port'] = pingport

# this holds the response information (i.e. when nodes responded)
mycontext['latency'] = {}
mycontext['myip'] = getmyip()

# this remembers when we sent a probe
mycontext['sendtime'] = {}

# this remembers row data from the other nodes
mycontext['row'] = {}
# get the nodes to probe
mycontext['neighborlist'] = []

try:
fileobject = openfile('neighboriplist.txt',False)
except FileNotFoundError, e:
#raise error if file doesn't exists
raise FileNotFoundError("neighboriplist.txt file doesn't exist. Please provide the required file in same directory.")

filecontent = fileobject.readat(None,0)
neighbor_array = filecontent.splitlines()
for line in neighbor_array:
if line == '':
#skip if file contains any blank line
continue
mycontext['neighborlist'].append(line.strip())



#listen for a new message and call handle_message in new thread
udpserversocket = listenformessage(mycontext['myip'], mycontext['port'])
createthread(handle_message_forever)

createthread(probe_neighbors_forever)

#listen for connection and call handle_http_request once a connection is got
connobj = listenforconnection(mycontext['myip'],mycontext['port'])
createthread(handle_connection_forever)



194 changes: 194 additions & 0 deletions apps/allpairsping/allpairsping.r2py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
"""
<Author>
Urvashi Soni

<Description>
gives the connectivity graph and latency information of all nodes in a group.

"""

# send a probe message to each neighbor
def probe_neighbors_forever():
# Call me again in 10 seconds
while True:
for neighborip in mycontext["neighborlist"]:
mycontext['sendtime'][neighborip] = getruntime()
if neighborip == mycontext['myip']:
#skip if ip address in neighboriplist matches the local ip because in repy we cann't have same localip and dest ip
continue
sendmessage(neighborip, mycontext['port'], 'ping',mycontext['myip'],mycontext['port'])
sendmessage(neighborip,mycontext['port'],'share'+encode_row(mycontext['myip'],mycontext["neighborlist"],mycontext['latency'].copy()),mycontext['myip'],mycontext['port'])
sleep(0.5)
#sleep for 10 sec and start from while loop again
sleep(10)




# Handle an incoming message
def got_message(srcip,srcport,mess):
if mess == 'ping':
sendmessage(srcip,srcport,'pong',mycontext['myip'], pingport)
elif mess == 'pong':
# elapsed time is now - time when I sent the ping
mycontext['latency'][srcip] = getruntime() - mycontext['sendtime'][srcip]
elif mess.startswith('share'):
mycontext['row'][srcip] = mess[len('share'):]



def encode_row(rowip, neighborlist, latencylist):
retstring = "<tr><td>"+rowip+"</td>"
for neighborip in neighborlist:
if neighborip in latencylist:
retstring = retstring + "<td>"+str(latencylist[neighborip])[:4]+"s</td>"
else:
retstring = retstring + "<td>Unknown</td>"

retstring = retstring + "</tr>"
return retstring



# Generates a HTML page that represents the current status of the program
def generate_status_page():
webpage = "<html><head><title>Latency Information</title></head><body><h1>Latency information from "+mycontext['myip']+' </h1><table border="1">'
webpage = webpage + "<tr><td></td><td>"+ "</td><td>".join(mycontext['neighborlist'])+"</td></tr>"
for nodeip in mycontext['neighborlist']:
if nodeip in mycontext['row']:
webpage = webpage + mycontext['row'][nodeip]+'\n'
else:
webpage = webpage + '<tr><td>'+nodeip+'</td><td>No Data Reported</td></tr>\n'

# now the footer...
webpage = webpage + '</table></html>'
return webpage



# Displays a web page with the latency information
def handle_http_request(srcip,srcport,connobj):
log('received request from',srcip,'\n')

# Get the header
total_data = ''
# The HTTP header ends once we see the char combination '\n\n', which
# is an empty string.
while '\n\n' not in total_data:
# Receive in chunks to avoid reading too much data
try:
data = connobj.recv(4096)
except SocketWouldBlockError:
# retry if they haven't completed sending the header
sleep(.05)
continue
except SocketClosedRemote:
log('client from',srcip,'aborted before sending HTTP header...\n')
return
total_data += data
total_data = total_data.replace('\r\n', '\n')

header, overflow = total_data.split('\n\n', 1)


# Get the request path, which is inbetween the HTTP action keyword and the
# HTTP version number.
# The http action keyword is the first word with no whitespace.
everything_after_httpaction = header.split(None, 1)[1]
# Following the path is the HTTP/[VERSION_NUMBER].
# We can use that as a delimiter to extract the path.
request_path = everything_after_httpaction.split(" HTTP/")[0]

# Generate the data to send back
# Don't respond with anything if they have something in the request path.
# This include favicons. We don't want to generate the webpage needlessly.
if request_path != '/':
data = 'HTTP/1.1 404 Not Found\n\n'
else:
webpage = generate_status_page()
# combine everything into one unit for sending
data = 'HTTP/1.1 200 OK\nContent-Type: text/html\nContent-Length: '+str(len(webpage))+'\nServer: Seattle Testbed\n\n'+webpage

# send the response

sent = 0
while sent < len(data):
try:
sent += connobj.send(data[sent:])
except SocketWouldBlockError:
# retry if response hasn't been sent yet
sleep(.05)
continue
except SocketClosedRemote:
log('client from',srcip,'aborted before response could be sent...\n')
return
# and we're done, so let's close this connection...
connobj.close()

def handle_message_forever():
while True:
try:
srcip, srcport, mess = udpserversocket.getmessage()
got_message(srcip, srcport, mess)
except SocketWouldBlockError:
sleep(0.1)


def handle_connection_forever():
while True:
try:
ret_ip, ret_port, ret_socket = connobj.getconnection()
handle_http_request(ret_ip, ret_port, ret_socket)
except SocketWouldBlockError:
sleep(0.1)


if callfunc == 'initialize':
#check if user has provided port number as call argument
if len(callargs) != 1:
raise Exception("Must specify the port to use")

pingport = int(callargs[0])
mycontext['port'] = pingport

# this holds the response information (i.e. when nodes responded)
mycontext['latency'] = {}
mycontext['myip'] = getmyip()
log(mycontext['myip'])

# this remembers when we sent a probe
mycontext['sendtime'] = {}

# this remembers row data from the other nodes
mycontext['row'] = {}
# get the nodes to probe
mycontext['neighborlist'] = []

try:
fileobject = openfile('neighboriplist.txt',False)
except FileNotFoundError, e:
#raise error if file doesn't exists
raise FileNotFoundError("neighboriplist.txt file doesn't exist. Please provide the required file in same directory.")

filecontent = fileobject.readat(None,0)
neighbor_array = filecontent.splitlines()
for line in neighbor_array:
if line == '':
#skip if file contains any blank line
continue
mycontext['neighborlist'].append(line.strip())



#listen for a new message and call handle_message in new thread
udpserversocket = listenformessage(mycontext['myip'], mycontext['port'])
createthread(handle_message_forever)

createthread(probe_neighbors_forever)

#listen for connection and call handle_http_request once a connection is got
connobj = listenforconnection(mycontext['myip'],mycontext['port'])
createthread(handle_connection_forever)



Loading