Commit ca119e40 authored by Binh Nguyen's avatar Binh Nguyen

Fix bug: parsing intra area prefix LSA

parent 11b554a2
......@@ -482,16 +482,24 @@ def parseOspfLsaIntraAreaPrefix(lsa, verbose=1, level=0):
(nprefixes, reflstype, reflsid, refadvrouter) = struct.unpack(OSPFV3_LSAINTRAPREFIX, lsa[:OSPFV3_LSAINTRAPREFIX_LEN])
if verbose > 1: print (level+1)*INDENT + "nprefixes:%s, reflstype:%s, reflsid:%s, refadvrouter:%s" % (nprefixes, reflstype, reflsid, refadvrouter)
lsa = lsa[OSPFV3_LSAINTRAPREFIX_LEN:] ; cnt = 0; pr_len = struct.calcsize(">BBH LLL") ; prefixes = []
lsa = lsa[OSPFV3_LSAINTRAPREFIX_LEN:] ; cnt = 0;
prefixes = []
while cnt < int(nprefixes):
(pr_len_bit,) = struct.unpack('>B', lsa[:struct.calcsize('>B')])
pr_len = pr_len_bit/8
if verbose > 1: print prtbin((level+1)*INDENT, lsa[:pr_len])
(pl, popts, _, p1, p2, p3) = struct.unpack('>BBH LLL', lsa[:pr_len])
prefix = int2ipv6(p1,p2,p3,0)
prefix_cnt = pr_len/struct.calcsize('>L')
(pl, popts, _) = struct.unpack('>BBH', lsa[:struct.calcsize('>BBH')])
lsa = lsa[struct.calcsize('>BBH'):]
p = [0,0,0,0]
for i in range(0, prefix_cnt):
(p[i],) = struct.unpack('>L', lsa[:struct.calcsize('>L')])
lsa = lsa[struct.calcsize('>L'):]
prefix = int2ipv6(p[0], p[1], p[2], p[3])
if verbose > 0:
print (level+1)*INDENT + "prefix:%s" % prefix
prefixes.append(prefix)
lsa = lsa[pr_len:]
cnt += 1
return {
......
......@@ -17,9 +17,9 @@ class LSAR(object):
print (level+1)*INDENT + json_s
def send_ospf_msg(self, ospf_msg):
uri = 'http://%s:%s/ospf_monitor/lsa_put' % (self.dst_ip, self.dst_port)
uri = 'http://%s:%s/lsa_put' % (self.dst_ip, self.dst_port)
try:
r = requests.post(uri, data=ospf_msg)
r = requests.post(uri, json=ospf_msg)
if (r.status_code != 200):
print "Sent OSPF message to %s,return code = %s" % (uri, r.status_code)
except:
......
......@@ -13,7 +13,11 @@ if __name__ == "__main__":
VERBOSE = 1
DUMP_MRTD = 0
ADDRESS = "::"
lsar = LSAR("155.98.39.112", 8080)
LSAA_HOST = "155.98.39.112"
LSAA_PORT = 5002
#lsar = LSAR("155.98.39.112", 8080)
lsar = LSAR(LSAA_HOST, LSAA_PORT)
#---------------------------------------------------------------------------
......@@ -27,8 +31,9 @@ if __name__ == "__main__":
while 1:
rv = ospf.parseMsg(VERBOSE, 0)
lsar.print_ospf_json(rv, VERBOSE, 0)
lsar.send_ospf_msg(rv)
if MSG_TYPES[int(rv['T'])] == "LSUPD":
lsar.print_ospf_json(rv, VERBOSE, 0)
lsar.send_ospf_msg(rv)
except (KeyboardInterrupt):
ospf.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment