# Test Set 5: State-Based Rule Production.
#
# Assumes nm_mgr is on ipn:1.1
# Assumes nm_agent is on ipn:1.2
#

###############################################################################
# TC 1 Generate Reports based on a variable.
###############################################################################
# This test will cause an Agent FULL REPORT to be generated
# up to 5 times whenever Variable V5 == 1.
###############################################################################


#------------------------------------------------------------------------------
# Step 1.1: Define UINT V5 = 0.
#------------------------------------------------------------------------------
#
# V5 ARI = 0x0c427635
#
# ari:/IANA:Amp.Agent/Ctrl.add_var(ari://var.v5, (UINT) 0, UINT)
#
#
# CBOR breakout:
#
# CONTROL  TNVC    PARM TYPES       PARM1    PARM2         PARM3
#          TYPE
# add_var   TV    (ARI,EXPR,BYTE)   (V1)     (UINT) 0      UINT
# c1154100  05     03 24 26 11     0c427635 14814300        14
#
#------------------------------------------------------------------------------
c115410005032426110c4276351481430014
WAIT 1


#------------------------------------------------------------------------------
# Step 1.2: Retrieve value of V5 in a report.
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.gen_rpts([ari://var.v5],[])
#
#------------------------------------------------------------------------------
c115410505022523810c42763500
WAIT 1


#------------------------------------------------------------------------------
# Step 1.3: Confirm value of V5 is 0.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Step 1.4: Define Macro M1 generate an agent FULL_REPORT and reset V5 = 0
#------------------------------------------------------------------------------
#
# Macro M1 ARI: 0x04424d31
#
# ARI: ari:/IANA:amp.agent/Ctrl.add_macro("m1", ari://Mac.M1,
#      [ari:/IANA:amp.agent/Ctrl.gen_rpts([ari:/IANA:amp.agent/Rptt.full_report()],[]),
#       ari:/IANA:amp.agent/Ctrl.store_var(ari://var.v5, (UINT)0)])
#
#------------------------------------------------------------------------------
c11541070503122425626d3104424d3182c11541050502252381871819410000c115410e050224260c42763514814300
WAIT 1

#------------------------------------------------------------------------------
# Step 1.5: List Macros
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.gen_tbls([ari:/IANA:amp.agent/Tblt.macros()],[])
#
#------------------------------------------------------------------------------
c115410605022523818a181b410300
WAIT 1

#------------------------------------------------------------------------------
# Step 1.6: Review returned report and make sure MACRO M1 is listed.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Step 1.7: Describe Macro M1
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.desc_macro([ari://Mac.M1])
#
#------------------------------------------------------------------------------
c11541090501258104424d31
WAIT 1

#------------------------------------------------------------------------------
# Step 1.8: Make sure M1 was described correctly.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Step 1.9: Define SRL S1 to run every time V5 >= 2 up to 3 times.
#------------------------------------------------------------------------------
#
# S1 ARI = 0x08425331
# Start = 0
# Expr = [V5, 2, >=]
# MaxEval = 1000
# Count = 3
# Action = [M1]
#
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.add_sbr(ari://Sbr.S1, 0,
#       (UINT) ari://Var.v5 2 >=, 1000, 3, [ari://Mac.M1], "S1")
#
#------------------------------------------------------------------------------
c115410b050724162616162512084253310014830c4276354302c5181842182f001903e8038104424d31625331
WAIT 1

#------------------------------------------------------------------------------
# Step 1.10: List known rules
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.gen_tbls([ari:/IANA:amp.agent/Tblt.rules()],[])
#
#------------------------------------------------------------------------------
c115410605022523818a181b410400
WAIT 1

#------------------------------------------------------------------------------
# Step 1.11: Ensure that S1 is there.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Step 1.12: Describe SRL1
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.desc_rule([ari://Sbr.S1])
#
#------------------------------------------------------------------------------
c115410d0501258108425331
WAIT 1

#------------------------------------------------------------------------------
# Step 1.13: Ensure that S1 matches description
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Step 1.14: Set TBR T1 to run every 20 seconds 6 times that will
# run the command: V5 = V5 + 1 which is: STOR(V5, {(UINT), V5 1 +})
#------------------------------------------------------------------------------
#
# T1 ARI = 0x0b425431
# T1 Start = 0
# T1 Period = 20
# T1 Count = 6
# T1 Action: ari:/IANA:amp.agent/Ctrl.store_var(ari://var.v5, (UINT) ari://var.v5 1 +)
#
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.add_tbr(ari://tbr.T1, 0, 20, 6,
#      [ari:/IANA:amp.agent/Ctrl.store_var(ari://var.v5, (UINT) ari://var.v5 1 +)], "T1")
#
#------------------------------------------------------------------------------
c115410a05062416161625120b42543100140681c115410e050224260c42763514830c4276354301c51818410100625431
WAIT 1

#------------------------------------------------------------------------------
# Step 1.15: Describe T1 and make sure it is correct.
#------------------------------------------------------------------------------
#
# ARI ari:/IANA:amp.agent/Ctrl.desc_rule([ari://Tbr.T1])
#
#------------------------------------------------------------------------------
c115410d050125810b425431
WAIT 1

#------------------------------------------------------------------------------
# Step 1.16: Verify S1 runs 3 times, approximately every 40 seconds.
#------------------------------------------------------------------------------

WAIT 170

#------------------------------------------------------------------------------
# Step 1.17: Inspect ADM reports for correct # TBR and SBR counts.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Step 1.18: List known rules and verify S1 and T1 are no longer listed.
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.gen_tbls([ari:/IANA:amp.agent/Tblt.rules()],[])
#
#------------------------------------------------------------------------------
c115410605022523818a181b410400
WAIT 1


#------------------------------------------------------------------------------
# Step 1.19: Delete S1. i.e. show no issue with deleting a deleted SBR.
#            Expect to see the following in Agent output:
#            "[nm/agent/adm_amp_agent_impl.c:1946]
#            w DEL_RULE Cannot find RULE to be deleted."
#
#------------------------------------------------------------------------------
#
# ARI: ari:/IANA:amp.agent/Ctrl.del_rule([ari://Sbr.S1])
#
#------------------------------------------------------------------------------
c115410c0501258108425331
WAIT 1


#------------------------------------------------------------------------------
# Step 1.20: Restart Agent and verify only 1 Var and 1 Macro restore.
#------------------------------------------------------------------------------
