Skip to content

Instantly share code, notes, and snippets.

@apwiggins
Last active April 13, 2024 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apwiggins/c1ed508d169d297e3d2307096a37e794 to your computer and use it in GitHub Desktop.
Save apwiggins/c1ed508d169d297e3d2307096a37e794 to your computer and use it in GitHub Desktop.
FLUTE service for CORE
# CORE
# Flute service
#
# - FLUTE: http://mad.cs.tut.fi/download.html
# - FLUTE source: http://mad.cs.tut.fi/download/mad_fcl_v1.7_src.tar.gz
#
# To build from source (Ubuntu):
# sudo apt update
# sudo apt install curl libcurl-ocaml libcurl-ocaml-dev libcurl4-gnutls-dev
# edit Makefile to include:
# INSTALL_DIR := /usr/local/bin
# CONF_DIR := /usr/local/etc/flute
# make clean
# make
# sudo make install
'''
flute.py: defines FLUTE services
'''
from core.service import CoreService
class FLUTEService(CoreService):
''' Parent class for FLUTE services.
'''
_name = "FLUTE"
_group = "Utility"
_depends = ()
_dirs = ()
_configs = ()
_startindex = 70
_startup = ()
_shutdown = ()
@classmethod
def generateconfig(cls, node, filename, services):
return ""
class FluteApp(FluteService):
_name = "FluteApp"
_dirs = (
"/usr/local/etc/flute",
"/var/run"
)
_configs = ("flute.sh", "session.SDP", )
_startup = ("sh flute.sh", )
_shutdown = ("killall flute", )
'''_validate = ("pidof flute", )'''
_custom_needed = False
@classmethod
def generateconfig(cls, node, filename, services):
''' Use a startup script for launching FLUTE services
'''
if filename == cls._configs[0]:
return cls.generateFlutesh(node, services)
if filename == cls._configs[1]:
return cls.generateFluteSDP(node, services)
else:
raise ValueError
@classmethod
def generateFlutesh(cls, node, services):
cfg = """\
#!/bin/sh
# auto-generated by FLUTE service (flute.py);
# please change it as needed
# VERSION=1.0
### 1. modify for sender or receiver ###################
FLUTE='receiver'
#FLUTE='sender'
### 2. modify for directory of files to be sent #######
#can you think of a better directory to share?
HOST_CONTENT_DIR=/usr/share/
SEND_FILE_DIR=share
FLUTE_BIN=/usr/local/bin/flute
### COMMON PARAMETERS #################################
# multicast address for FLUTE
MCAST=226.10.40.1
PORT=4001
BASE_DIR=/tmp/pycore.${SESSION}/${NODE_NAME}/
LOG_LVL=1
TPT_SESSION_ID=0
### COMMON PARAMETERS #################################
if [ "$FLUTE" = "receiver" ]; then
#########################
# RECEIVER SCRIPT - all nodes are receivers by default
#########################
mkdir -p $BASE_DIR
($FLUTE_BIN -A \\
-m:$MCAST \\
-p:$PORT \\
-t:$TPT_SESSION_ID \\
-B:$BASE_DIR \\
-v:$LOG_LVL \\
-V:$LOG )&
else
### SENDER PARAMETERS #################################
TX_RATE=75 #kbps
TTL=10
# FEC Encoding
#[0 = Null, 1 = Simple XOR, 2 = Reed-Solomon (old I-D),
# 3 = Reed-Solomon (new I-D)
FEC=3
# FEC-OTI (Object Transmission Info))for file objects
#[0 = FEC-OTI in FDT, 1 = FEC-OTI in EXT_FTI]
FEC_OTI=0
# Encode content [0 = no, 3 = PAD files]
ENCODE=0
# Number of transmissions
NUM_TX=3
FILES='session.SDP'
# Send a Complete FDT in the beginning of the session
# [0 = No, 1 = Yes, 2 = Yes, only Complete FDT]
SEND_COMPLETE_FDT=2
# Send session close packets [0 = No, 1 = Yes]
SEND_SESSION_CLOSE_PKTS=1
# Print CORE node's 'logs to 'flute.log' file,
# default: print to stdout
LOG=${NODE_NAME}_flute.log
#########################
# SENDER SCRIPT - Default sender script
#########################
mkdir -p $BASE_DIR
ln -s $HOST_CONTENT_DIR $BASE_DIR
echo 'sleeping for 5 seconds...'
sleep 5
($FLUTE_BIN -S \\
-m:$MCAST \\
-p:$PORT \\
-r:$TX_RATE \\
-t:$TPT_SESSION_ID \\
-T:$TTL \\
-x:$FEC \\
-e:$FEC_OTI \\
-z:$ENCODE \\
-n:$NUM_TX \\
-B:$BASE_DIR \\
-F:$SEND_FILE_DIR \\
-k:$SEND_COMPLETE_FDT \\
-q:$SEND_SESSION_CLOSE_PKTS \\
-v:$LOG_LVL \\
-V:$LOG )
fi
"""
return cfg
@classmethod
def generateFluteSDP(cls, node, services):
''' Generate a config file used to define app behaviour.
'''
cfg = """\
# http://mad.cs.tut.fi/flute-example-sdp.html
#Example 1: FLUTE session with one channel
v=0
o=user 2890844526 2890842807 IN IP4 10.20.30.40
s=File delivery session example
i=More information
t=2873397496 2873404696
a=source-filter: incl IN IP4 * 10.20.30.40
a=flute-tsi:1
a=flute-ch:1
m=application 4001 FLUTE/UDP 0
c=IN IP4 226.10.40.1/15
##Example 2: FLUTE session with FEC declaration (Reed-Solomon), case 1
#v=0
#o=user 2890844526 2890842807 IN IP4 10.20.30.40
#s=File delivery session example
#i=More information
#t=2873397496 2873404696
#a=source-filter: incl IN IP4 * 10.20.30.40
#a=flute-tsi:1
#a=flute-ch:1
#a=content-desc:http://www.example.com/flute-session/session001
#m=application 4001 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15
#a=FEC-declaration:0 encoding-id=129; instance-id=0
##Example 3: FLUTE session with FEC declaration (Reed-Solomon), case 2
#v=0
#o=user 2890844526 2890842807 IN IP4 10.20.30.40
#s=File delivery session example
#i=More information
#t=2873397496 2873404696
#a=source-filter: incl IN IP4 * 10.20.30.40
#a=flute-tsi:1
#a=flute-ch:2
#a=FEC-declaration:0 encoding-id=129; instance-id=0
#m=application 4001 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15
#a=FEC:0
#m=application 4002 FLUTE/UDP 0
#c=IN IP4 226.10.40.2/15
#a=FEC:0
##Example 4: FLUTE session with three channels identified by destination address and port number
#v=0
#o=user 2890844526 2890842807 IN IP4 10.20.30.40
#s=File delivery session example
#i=More information
#t=2873397496 2873404696
#a=source-filter: incl IN IP4 * 10.20.30.40
#a=flute-tsi:1
#a=flute-ch:3
#m=application 4001 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15
#m=application 4002 FLUTE/UDP 0
#c=IN IP4 226.10.40.2/15
#m=application 4003 FLUTE/UDP 0
#c=IN IP4 226.10.40.3/15
##Example 5: FLUTE session with three channels identified by destination address, case 1
#v=0
#o=user 2890844526 2890842807 IN IP4 10.20.30.40
#s=File delivery session example
#i=More information
#t=2873397496 2873404696
#a=source-filter: incl IN IP4 * 10.20.30.40
#a=flute-tsi:1
#a=flute-ch:3
#m=application 4001 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15
#m=application 4001 FLUTE/UDP 0
#c=IN IP4 226.10.40.2/15
#m=application 4001 FLUTE/UDP 0
#c=IN IP4 226.10.40.3/15
##Example 6: FLUTE session with three channels identified by destination address, case 2
#v=0
#o=user 2890844526 2890842807 IN IP4 10.20.30.40
#s=File delivery session example
#i=More information
#t=2873397496 2873404696
#a=source-filter: incl IN IP4 * 10.20.30.40
#a=flute-tsi:1
#a=flute-ch:3
#m=application 4001 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15/3
##Example 7: FLUTE session with three channels identified by port number, case 1 (not recommended to use)
#v=0
#o=user 2890844526 2890842807 IN IP4 10.20.30.40
#s=File delivery session example
#i=More information
#t=2873397496 2873404696
#a=source-filter: incl IN IP4 * 10.20.30.40
#a=flute-tsi:1
#a=flute-ch:3
#m=application 4001 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15
#m=application 4002 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15
#m=application 4003 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15
##Example 8: FLUTE session with three channels identified by port number, case 2 (not recommended to use)
#v=0
#o=user 2890844526 2890842807 IN IP4 10.20.30.40
#s=File delivery session example
#i=More information
#t=2873397496 2873404696
#a=source-filter: incl IN IP4 * 10.20.30.40
#a=flute-tsi:1
#a=flute-ch:3
#m=application 4001/3 FLUTE/UDP 0
#c=IN IP4 226.10.40.1/15
##Example 9: FLUTE session with three channels, IPv6
#With IPv6 TTL value MUST NOT exist at c-line.
#v=0
#o=user 2890844526 2890842807 IN IP6 1000:900:800:700:600:efdf:2edf:3ece
#s=File delivery session example
#i=More information
#t=2873397496 2873404696
#a=source-filter: incl IN IP6 * 1000:900:800:700:600:efdf:2edf:3ece
#a=flute-tsi:1
#a=flute-ch:1
#m=application 4001 FLUTE/UDP 0
#c=IN IP6 ff1a::1/3
"""
return cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment