1# Script for checking LISP counters
2
3help_string = """
4 Params:
5   vat_exec - VAT executable
6   vpp_prefix - shared vpp memory prefix
7   vat_path - VAT template file
8   vni
9   seid
10   deid
11   loc_rloc
12   rmt_rloc
13   pkt_count
14   bytes
15"""
16
17import sys
18import subprocess
19import json
20
21def get_stat_entry(json, vni, seid, deid, loc_rloc, rmt_rloc):
22  if len (json) == 0:
23    return None
24
25  for obj in json:
26    if obj['vni'] == int(vni) and\
27            obj['seid'] == seid and\
28            obj['deid'] == deid and\
29            obj['lloc'] == loc_rloc and\
30            obj['rloc'] == rmt_rloc:
31      return obj
32
33  return None
34
35
36def check_counters(vat_exec, vat_path, vpp_prefix, vni, seid, deid, loc_rloc,
37        rmt_rloc, pkt_count, total_bytes):
38  vat_file = vat_path + '/' + 'dump_stats.tpl'
39  out = subprocess.Popen([vat_exec, "chroot", "prefix", vpp_prefix, "json", "script",
40      "in", vat_file], stdout=subprocess.PIPE).communicate()[0]
41
42  o = json.loads(out)
43  stat_entry = get_stat_entry(o, vni, seid, deid, loc_rloc, rmt_rloc)
44
45  if stat_entry is None:
46    return False
47
48  if stat_entry['pkt_count'] != int(pkt_count):
49    return False
50  if stat_entry['bytes'] != int(total_bytes):
51    return False
52  return True
53
54
55if __name__ == "__main__":
56  if len(sys.argv) < 10:
57    raise Exception('expected 10 parameters: ' + help_string)
58
59  if check_counters(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4],
60          sys.argv[5],
61          sys.argv[6],
62          sys.argv[7],
63          sys.argv[8],
64          sys.argv[9],
65          sys.argv[10]):
66    sys.exit(0)
67  else:
68    sys.exit(1)
69