Monday, October 04, 2010

Skype-Facebook partnership: A response to Google (Talk+email)?

http://www.cnn.com/2010/TECH/social.media/10/04/facebook.skype.partnership/index.html

Social media meets real-time communication? Facebook needs Skype because they do not have a real-time communication network. Skype needs Facebook because they do not have access to their user's email graph (like Google). Its really Facebook and Skype's answer to Google's growing threat to their businesses.

Friday, September 17, 2010

Using tc to regulate downlink speed

tc qdisc add dev eth0 handle ffff: ingress
tc filter add dev eth0 parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate
100kbit burst 10k drop flowid :1

The second command limits the download rate to 100kbit by dropping packets. Since we do not want to drop too many packets, we setup a burst size size of 10k.

See this link for more details.
http://lartc.org/howto/lartc.cookbook.ultimate-tc.html

Using tc to regulate uplink speed

Here is a nice script that I found:

----------------

#!/bin/bash
#
# tc uses the following units when passed as a parameter.
# kbps: Kilobytes per second
# mbps: Megabytes per second
# kbit: Kilobits per second
# mbit: Megabits per second
# bps: Bytes per second
# Amounts of data can be specified in:
# kb or k: Kilobytes
# mb or m: Megabytes
# mbit: Megabits
# kbit: Kilobits
# To get the byte figure from bits, divide the number by 8 bit
#

#
#Name of the traffic control command.
TC=/sbin/tc

# The network interface we're planning on limiting bandwidth.
IF=eth0 # Interface

# Download limit (in mega bits)
DNLD=1mbit # DOWNLOAD Limit

# Upload limit (in mega bits)
UPLD=1mbit # UPLOAD Limit

# IP address of the machine we are controlling
IP=128.59.9.113 # Host IP

# Filter options for limiting the intended interface.
U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32"

start() {

# We'll use Hierarchical Token Bucket (HTB) to shape bandwidth.
# For detailed configuration options, please consult Linux man
# page.

$TC qdisc add dev $IF root handle 1: htb default 30
$TC class add dev $IF parent 1: classid 1:1 htb rate $DNLD
$TC class add dev $IF parent 1: classid 1:2 htb rate $UPLD
$U32 match ip dst $IP/32 flowid 1:1
$U32 match ip src $IP/32 flowid 1:2

# The first line creates the root qdisc, and the next two lines
# create two child qdisc that are to be used to shape download
# and upload bandwidth.
#
# The 4th and 5th line creates the filter to match the interface.
# The 'dst' IP address is used to limit download speed, and the
# 'src' IP address is used to limit upload speed.

}

stop() {

# Stop the bandwidth shaping.
$TC qdisc del dev $IF root

}

restart() {

# Self-explanatory.
stop
sleep 1
start

}

show() {

# Display status of traffic control status.
$TC -s qdisc ls dev $IF

}

case "$1" in

start)

echo -n "Starting bandwidth shaping: "
start
echo "done"
;;

stop)

echo -n "Stopping bandwidth shaping: "
stop
echo "done"
;;

restart)

echo -n "Restarting bandwidth shaping: "
restart
echo "done"
;;

show)

echo "Bandwidth shaping status for $IF:"
show
echo ""
;;

*)

pwd=$(pwd)
echo "Usage: tc.bash {start|stop|restart|show}"
;;

esac exit 0

Thursday, August 05, 2010

Limiting bandwidth per process in Linux

A friend of mine recently asked me how to limit bandwidth per process in Linux. Here are the steps for accomplishing this using iptables and tc. The idea is to create a traffic class, specify the class priority and the bit-rate etc, tell the traffic class that packets with a handle [x] should be handled by this class, and assign packets a handle using iptables. iptables allows to assign a handle using gid or pid. Here are the commands. These commands do not limit incoming traffic so, one has to set iptables for INPUT accordingly.

#setting the root queuing class (can be ignored)
tc qdisc add dev eth0 root handle 1: htb default 15

#specify the class with priorty 1. The class id is 1:1
tc class add dev eth0 parent 1: classid 1:1 htb rate 10kbit ceil 10kbit prio 1

#specify the filter. so packets with handle '10' go into the class 1:1
tc filter add dev eth0 parent 1:0 protocol ip prio 1 handle 10 fw classid 1:1

#now give the packets a handle of 10
iptables -t mangle -A OUTPUT -m owner --gid-owner [gid] -j MARK --set-mark 0xa

A good description of of traffic shaping in Linux can be found here.
http://lartc.org/howto/lartc.cookbook.fullnat.intro.html

Monday, May 31, 2010

Matlab and embedding fonts in pdf

I typically create figures using Matlab and incorporate the eps files in my pdf file. Matlab print function does not correctly embed the fonts in the pdf file. However, there are many ways of generating eps files in Matlab with correctly embedded fonts:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/172388

Here is another link that I found useful:
http://do.whileloop.org/soft/tricks/pdflatex-fonts.php