All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 51082970 authored by Robert Ricci's avatar Robert Ricci

Add a new shell script for running the monitor with libnetmon - unlike

the other way of invoking the monitor, this one takes the application
to run on the command line.

Monitor now finishes when it gets an eof on stdin.

Allow monitor.py to skip input lines it doesn't understand, since when
run with libnetmon, it sees the stdout of the application.
parent 84fd81d4
...@@ -5,6 +5,7 @@ import os ...@@ -5,6 +5,7 @@ import os
import time import time
import socket import socket
import select import select
import re
#emulated_to_real = {'10.0.0.1' : '10.1.0.1', #emulated_to_real = {'10.0.0.1' : '10.1.0.1',
# '10.0.0.2' : '10.1.0.2'} # '10.0.0.2' : '10.1.0.2'}
...@@ -24,7 +25,8 @@ def main_loop(): ...@@ -24,7 +25,8 @@ def main_loop():
read_args() read_args()
populate_ip_tables() populate_ip_tables()
quanta = 5 # in seconds quanta = 5 # in seconds
stub_address = 'planet0.pelab.tbres.emulab.net' # emulated_to_real[this_ip] #stub_address = 'planet0.pelab.tbres.emulab.net' # emulated_to_real[this_ip]
stub_address = 'localhost'
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect((stub_address, 4200)) conn.connect((stub_address, 4200))
poll = select.poll() poll = select.poll()
...@@ -43,8 +45,13 @@ def main_loop(): ...@@ -43,8 +45,13 @@ def main_loop():
for pos in fdlist: for pos in fdlist:
if pos[0] == sys.stdin.fileno() and not done: if pos[0] == sys.stdin.fileno() and not done:
# A line of data from tcpdump is available. # A line of data from tcpdump is available.
packet = get_next_packet() try:
packet_list = packet_list + [packet] packet = get_next_packet()
except EOFError:
sys.stdout.write('Done: Got EOF on stdin\n')
done = 1
if (packet):
packet_list = packet_list + [packet]
elif pos[0] == conn.fileno() and not done: elif pos[0] == conn.fileno() and not done:
# A record for change in link characteristics is available. # A record for change in link characteristics is available.
done = not receive_characteristic(conn) done = not receive_characteristic(conn)
...@@ -74,17 +81,27 @@ def populate_ip_tables(): ...@@ -74,17 +81,27 @@ def populate_ip_tables():
def get_next_packet(): def get_next_packet():
line = sys.stdin.readline() line = sys.stdin.readline()
ip_list = line.split('>', 1)[1].strip().split('.', 4) if line == "":
ip = ip_list[0] + '.' + ip_list[1] + '.' + ip_list[2] + '.' + ip_list[3] raise EOFError
# sys.stdout.write('dest: ' + result + '\n') # Could move this elsewhere to avoid re-compiling, but I'd like to keep it
time = float(line.split(' ', 1)[0]) # with this code for better readability
size_list = line.split('(', 1) linexp = re.compile('^(\d+\.\d+) > (\d+\.\d+\.\d+\.\d+)\.(\d+) (\((\d+)\))?$')
if len(size_list) > 1: match = linexp.match(line)
size = int(size_list[1].split(')', 1)[0]) if (match) :
time = float(match.group(1))
ipaddr = match.group(2)
port = int(match.group(3))
size_given = match.group(4) != ''
size = int(match.group(5))
sys.stdout.write('dest: ' + ipaddr + ' port: ' + str(port) + ' size: '
+ str(size) + '\n')
if not size_given:
size = 0
return (ipaddr, time, size)
else: else:
size = 0 sys.stdout.write('skipped line in the wrong format: ' + line + '\n')
return (ip, time, size) return None
def receive_characteristic(conn): def receive_characteristic(conn):
buffer = conn.recv(12) buffer = conn.recv(12)
if len(buffer) == 12: if len(buffer) == 12:
......
#!/bin/sh
LIB_LOCATION=../libnetmon/
LIB_SO=libnetmon.so
if ! [ -x $LIB_LOCATION/$LIB_SO ]; then
echo "$LIB_LOCATION/$LIB_SO missing - run 'gmake' in $LIB_LOCATION to build it"
exit 1;
fi
export LD_LIBRARY_PATH=$LIB_LOCATION
export LD_PRELOAD=$LIB_SO
PID=shift
EID=shift
echo "$0 running $@";
$@ | python monitor.py ip-mapping.txt $PID $EID
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment