Commit 6cd1cee6 authored by Binh Nguyen's avatar Binh Nguyen

LSAR sends LSAs to SDN controller via REST

parent 0f8b3c5c
......@@ -274,7 +274,7 @@ def str2ipv6(s):
def int2ipv6(i1, i2, i3, i4):
s = u"%02X:%04X:%04X:%04X:%02X:%02X:%02X:%02X" % ((i1&(0XFFFF<<(8*2)))>>(8*2), i1&0XFFFF, (i2&(0XFFFF<<(8*2)))>>(8*2), i2&0XFFFF, (i3&(0XFFFF<<(8*2)))>>(8*2), i3&0XFFFF, (i4&(0XFFFF<<(8*2)))>>(8*2), i4&0XFFFF)
return ipaddress.IPv6Address(s)
return str(ipaddress.IPv6Address(s))
################################################################################
......
# !/usr/bin/env python
import sys, select
import sys, json, requests
sys.path.insert(0, '/users/binh/sripv6-linux/ospf_monitor/lib')
from ospfv3 import *
def consume_ospf(ospf):
class LSAR(object):
def __init__(self, dst_ip, dst_port):
self.dst_ip = dst_ip
self.dst_port = dst_port
def print_ospf_json(self, ospf_msg, verbose=1, level=0):
json_s = json.dumps(ospf_msg, ensure_ascii=False)
if verbose > 1:
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)
try:
r = requests.post(uri, data=json.dumps(ospf_msg, ensure_ascii=False))
if (r.status_code != 200):
print "Sent OSPF message to %s,return code = %s" % (uri, r.status_code)
except:
print "Can't send OSPF message to %s (server is not running?)" % (uri)
pass
# !/usr/bin/env python
import sys, select
from lsa_receiver import *
sys.path.insert(0, '/users/binh/sripv6-linux/ospf_monitor/lib')
from ospfv3 import *
if __name__ == "__main__":
#import mrtd
global VERBOSE, DUMP_MRTD, ADDRESS
VERBOSE = 1
DUMP_MRTD = 0
ADDRESS = "::"
lsar = LSAR("155.98.39.112", 8080)
#mrtd_type = None
#---------------------------------------------------------------------------
......@@ -25,19 +25,10 @@ if __name__ == "__main__":
rv = None
while 1:
#rfds, _, _ = select.select([ospf._sock], [], [], timeout)
rv = ospf.parseMsg(VERBOSE, 0)
#consume_ospf(rv)
#if rv:
# print rv["T"]
#if len(rfds) > 0:
# print "receive OSPF"
# rv = ospf.parseMsg(VERBOSE, 0)
#else:
# print "receiveX"
# ## tx some pkts to form adjacency
# pass
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