#!/bin/sh
# Copyright (C) 2009 Ubicom, Inc.

. /etc/rgw_config

echo Start Test procedure item L from section 2.4.10 of StreamEngine procedure.

#
# Priorities are essentially queue indicies - the lower the number the higher the priority
#
PRIORITY_HIGH=1
PRIORITY_MEDIUM=2
PRIORITY_LOW=3

#
# Priority marks are used to mark packets that match rules on which we want to assign custom priorities
#
PRIORITY_MARK_HIGH=6901
PRIORITY_MARK_MEDIUM=6902
PRIORITY_MARK_LOW=6903

#
# Create a table into which we add our test rules that direct packets to certain priorities.
# NOTE: We use the mangle table because we will be using MARK destination
#
iptables -t mangle -N test_rule_table

#
# Add test rules into the table.
# Since Streamengine QoS can only affect packets going to the internet we only need to look
# out for packets in that direction.
#
iptables -t mangle -A test_rule_table -m iprange --src-range 192.168.0.10-192.168.0.20 -j MARK --set-mark $PRIORITY_MARK_MEDIUM -i $BRINTERFACE
iptables -t mangle -A test_rule_table -s 192.168.0.30 -j MARK --set-mark $PRIORITY_MARK_LOW -i $BRINTERFACE

#
# Add the test rules into netfilter
#
iptables -t mangle -A FORWARD -j test_rule_table
iptables -t mangle -A OUTPUT -j test_rule_table

#
# Add some filter rules that, for marked packets, we assign those packets to the correct priority queue
#
tc filter add dev $WAN_MODE_INTERFACE protocol ip prio $PRIORITY_MARK_HIGH handle $PRIORITY_MARK_HIGH fw flowid 1:$PRIORITY_HIGH
tc filter add dev $WAN_MODE_INTERFACE protocol ip prio $PRIORITY_MARK_MEDIUM handle $PRIORITY_MARK_MEDIUM fw flowid 1:$PRIORITY_MEDIUM
tc filter add dev $WAN_MODE_INTERFACE protocol ip prio $PRIORITY_MARK_LOW handle $PRIORITY_MARK_LOW fw flowid 1:$PRIORITY_LOW

