1from lutil import luCommand
2
3holddownFactorSet = luCommand(
4    "r1",
5    'vtysh -c "show running"',
6    "rfp holddown-factor",
7    "none",
8    "Holddown factor set",
9)
10if not holddownFactorSet:
11    to = "-1"
12    cost = ""
13else:
14    to = "6"
15    cost = "cost 50"
16luCommand(
17    "r1",
18    'vtysh -c "debug rfapi-dev open vn 10.0.0.1 un 1.1.1.1"',
19    "rfapi_set_response_cb: status 0",
20    "pass",
21    "Opened RFAPI",
22)
23luCommand(
24    "r1",
25    'vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 11.11.11.11"',
26    "rc=2",
27    "pass",
28    "Clean query",
29)
30luCommand(
31    "r1",
32    'vtysh -c "debug rfapi-dev register vn 10.0.0.1 un 1.1.1.1 prefix 11.11.11.0/24 lifetime {}"'.format(
33        to
34    ),
35    "",
36    "none",
37    "Prefix registered",
38)
39luCommand(
40    "r1",
41    'vtysh -c "show vnc registrations local"',
42    "1 out of 1",
43    "wait",
44    "Local registration",
45)
46luCommand("r1", 'vtysh -c "debug rfapi-dev response-omit-self off"', ".", "none")
47luCommand(
48    "r1",
49    'vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 11.11.11.11"',
50    "11.11.11.0/24",
51    "pass",
52    "Query self",
53)
54
55luCommand(
56    "r3",
57    'vtysh -c "debug rfapi-dev open vn 10.0.0.2 un 2.2.2.2"',
58    "rfapi_set_response_cb: status 0",
59    "pass",
60    "Opened RFAPI",
61)
62luCommand(
63    "r3",
64    'vtysh -c "debug rfapi-dev register vn 10.0.0.2 un 2.2.2.2 prefix 22.22.22.0/24 lifetime {}"'.format(
65        to
66    ),
67    "",
68    "none",
69    "Prefix registered",
70)
71luCommand(
72    "r3",
73    'vtysh -c "show vnc registrations local"',
74    "1 out of 1",
75    "wait",
76    "Local registration",
77)
78luCommand("r3", 'vtysh -c "debug rfapi-dev response-omit-self on"', ".", "none")
79luCommand(
80    "r3",
81    'vtysh -c "debug rfapi-dev query vn 10.0.0.2 un 2.2.2.2 target 22.22.22.22"',
82    "rc=2",
83    "pass",
84    "Self excluded",
85)
86luCommand(
87    "r3",
88    'vtysh -c "debug rfapi-dev open vn 10.0.1.2 un 2.1.1.2"',
89    "rfapi_set_response_cb: status 0",
90    "pass",
91    "Opened query only RFAPI",
92)
93luCommand(
94    "r3",
95    'vtysh -c "debug rfapi-dev query vn 10.0.1.2 un 2.1.1.2 target 22.22.22.22"',
96    "22.22.22.0/24",
97    "pass",
98    "See local",
99)
100
101luCommand(
102    "r4",
103    'vtysh -c "debug rfapi-dev open vn 10.0.0.3 un 3.3.3.3"',
104    "rfapi_set_response_cb: status 0",
105    "pass",
106    "Opened RFAPI",
107)
108luCommand(
109    "r4",
110    'vtysh -c "debug rfapi-dev register vn 10.0.0.3 un 3.3.3.3 prefix 33.33.33.0/24 lifetime {}"'.format(
111        to
112    ),
113    "",
114    "none",
115    "Prefix registered",
116)
117luCommand(
118    "r4",
119    'vtysh -c "show vnc registrations local"',
120    "1 out of 1",
121    "wait",
122    "Local registration",
123)
124luCommand("r4", 'vtysh -c "debug rfapi-dev response-omit-self off"', ".", "none")
125luCommand(
126    "r4",
127    'vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 33.33.33.33"',
128    "33.33.33.0/24",
129    "pass",
130    "Query self",
131)
132
133luCommand(
134    "r4",
135    'vtysh -c "debug rfapi-dev register vn 10.0.0.3 un 3.3.3.3 prefix 11.11.11.0/24 lifetime {} {}"'.format(
136        to, cost
137    ),
138    "",
139    "none",
140    "MP Prefix registered",
141)
142luCommand(
143    "r4",
144    'vtysh -c "show vnc registrations local"',
145    "2 out of 2",
146    "wait",
147    "Local registration",
148)
149luCommand(
150    "r4",
151    'vtysh -c "debug rfapi-dev query vn 10.0.0.3 un 3.3.3.3 target 11.11.11.11"',
152    "11.11.11.0/24",
153    "pass",
154    "Query self MP",
155)
156
157luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none")
158luCommand("r3", 'vtysh -c "show vnc registrations"', ".", "none")
159luCommand("r4", 'vtysh -c "show vnc registrations"', ".", "none")
160