#!/bin/bash

# Script for setup port rate
# v0.0.1 2012 Sergio Kviato sergey.kviato@onapp.com
#
# --int interface name
# --rate port rate

### Setup ###
OVSVSCTL=$(whereis -b ovs-vsctl | awk '{print $2}')
OVSOFCTL=$(whereis -b ovs-ofctl | awk '{print $2}')
RUNPATH="/var/run/openvswitch"
OVSVSCTL="$OVSVSCTL --db=unix:$RUNPATH/db.sock"
SWITCH="onapp-ovs0"
INTERFACE=""

### The Code ###
# Check if there any arguments
if [ -z $1 ]; then
 echo "Just what do you think you're doing, there no arguments"
exit 1
fi

# Process command line arguments
for arg in {1..12}
do
    case "${!arg}" in
	"--int") 
	((argn=arg+1))
	INTERFACE=${!argn}
	;;
	"--rate")
	((argn=arg+1))
	VLAN=${!argn}
	;;
    esac
done

PORT=$($OVSVSCTL -- get Interface $INTERFACE ofport)
#$OVSOFCTL add-flow $SWITCH "in_port=$PORT priority=1 action=normal"

# max-rate in bit/s
# Port Speed outgoing from VM
#ovs-vsctl -- set interface dwzh8qrczm5k9m ingress_policing_rate=1000
# Port Speed incoming to VM
#$OVSOFCTL -- set Port $PORT qos=@newqos$PORT -- --id=@newqos$PORT create qos type=linux-htb other-config:max-rate=1048576 queues:0=@newqueue$PORT -- --id=@newqueue$PORT create queue other-config:max-rate=1048576

exit 0

