#!/bin/bash
# Test 7
# Check when marking enabled with multiple inner vlans marking
# remains active till the last one is removed.
INTERFACE=$1
set policy qos profile prof bandwidth 2mbit
set policy qos name trunk shaper default prof
set policy qos name test shaper class 1 match 1 mark pcp 3
set policy qos name test shaper class 1 match 1 mark pcp-inner
set policy qos name test shaper class 1 profile prof
set policy qos name test shaper default prof
set int data $INTERFACE policy qos trunk
set int data $INTERFACE vif 10 inner-vlan 20
set int data $INTERFACE vif 10 policy qos test
set int data $INTERFACE vif 10 vlan 10
commit
ret=`run sh queuing $INTERFACE.10 class | grep markpcp | grep active | wc -l`
if [ $ret -ne 1 ]; then
   echo "Failed to activate marking";
   exit 1;
fi

set int data $INTERFACE vif 11 inner-vlan 21
set int data $INTERFACE vif 11 vlan 10
commit

ret=`run sh queuing $INTERFACE.10 class | grep markpcp | grep inner | grep active | wc -l`
if [ $ret -ne 1 ]; then
   echo "Failed to activate a marking using 2 inner vlans on vlan";
   exit 1;
fi
# Now check it was active and not inactive
ret=`run sh queuing $INTERFACE.10 class | grep markpcp | grep inactive | wc -l`
if [ $ret -ne 0 ]; then
   echo "Failed to activate a policer using 2 inner vlans on vlan";
   exit 1;
fi

del int data $INTERFACE vif 11
commit
ret=`run sh queuing $INTERFACE.10 class | grep markpcp | grep inner | grep active | wc -l`
if [ $ret -ne 1 ]; then
   echo "Failed to activate a marking using 2 inner vlans on vlan";
   exit 1;
fi
# Now check it was active and not inactive
ret=`run sh queuing $INTERFACE.10 class | grep markpcp | grep inactive | wc -l`
if [ $ret -ne 0 ]; then
   echo "Failed to activate a policer using 2 inner vlans on vlan";
   exit 1;
fi

# Delete second inner vlan and check state goes inactive
del int data $INTERFACE vif 10 inner-vlan
commit
ret=`run sh queuing $INTERFACE.10 class | grep markpcp | grep inactive | wc -l`
if [ $ret -ne 1 ]; then
   echo "Failed to activate a policer using 2 inner vlans on vlan";
   exit 1;
fi

# Tidy up
del int data $INTERFACE policy
del int data $INTERFACE vif 10
del policy
commit

echo "Test 7 passed"
