Example #1
0
    def get_lsp_by_uids(self, args):

        uids = args['lsp_uids']
        lsps = {}

        sql_str = 'select * from t_lsp where t_lsp.id in (%s)' % ','.join(uids)
        db = mysql_utils('tunnel')
        results = db.exec_sql(sql_str)
        db.close()

        if results is not None:
        for result in results:
            uid = result[0]
            one_lsp = {}
            one_lsp['uid'] = uid
            one_lsp['name'] = result[1]
            one_lsp['from_router_uid'] = result[2]
            one_lsp['to_router_uid'] = result[5]
            one_lsp['bandwidth'] = result[8]
            one_lsp['delay'] = result[9]
            one_lsp['priority'] = result[10]
            one_lsp['status'] = result[13]

            lsps[uid] = one_lsp

        return lsps
Example #2
0
    def get_lsp_by_customer(self, args):
        customers = args['cust_uids']
        lsps = {}

        sql_str = 'select * from t_assigned_flow inner join t_lsp on t_assigned_flow.lsp_id = t_lsp.id ' + \
            'and t_assigned_flow.customer_id in (%s)' % ','.join(str(c) for c in customers)
        # print sql_str
        db = mysql_utils('tunnel')
        results = db.exec_sql(sql_str)
        db.close()
        # print results
        for result in results:
            cust_uid = str(result[6])
            if cust_uid not in lsps:
                lsps[cust_uid] = []

            one_lsp = {}
            one_lsp['lsp_uid'] = str(result[1])
            one_lsp['customer_id'] = str(result[6])
            one_lsp['lsp_name'] = result[11]
            one_lsp['bandwidth'] = result[18]
            one_lsp['delay'] = result[19]
            one_lsp['priority'] = result[20]
            one_lsp['status'] = result[23]
            one_lsp['user_data'] = result[24]
            one_lsp['hop_list'] = result[25]
            one_lsp['path'] = result[26]
            lsps[cust_uid].append(one_lsp)

        return lsps
Example #3
0
    def get_lsp_by_flow(self,args):
        flow_uids = args['flow_uids']
        flow_lsps = {}

        db = mysql_utils('tunnel')
        for fid in flow_uids:
            sql_str = 'select * from t_assigned_flow inner join t_lsp on t_assigned_flow.lsp_id = t_lsp.id ' + \
                'and t_assigned_flow.flow_id=%s' % fid
            # sql_str = 'select * from t_assigned_flow where t_assigned_flow.flow_id=%s' % fid

            # print sql_str
            results = db.exec_sql(sql_str)
            lsps = []
            if results:
                for res in results:
                    one_lsp = {}
                    one_lsp['lsp_uid'] = str(res[1])
                    one_lsp['flow_user_data'] = str(res[9])
                    # one_lsp['ip'] = results[0][3] + '/' + str(results[0][4])
                    # one_lsp['customer_id'] = str(results[0][6])
                    one_lsp['lsp_name'] = res[12]
                    # one_lsp['bandwidth'] = results[0][18]
                    # one_lsp['delay'] = results[0][19]
                    # one_lsp['priority'] = results[0][20]
                    # one_lsp['status'] = results[0][23]
                    one_lsp['lsp_user_data'] = res[25]
                    one_lsp['hop_list'] = res[26]
                    # one_lsp['path'] = results[0][26]
                    lsps.append(one_lsp)
            else:
                pass
            flow_lsps[fid] = lsps
        db.close()
        return flow_lsps
Example #4
0
    def update_flow(self,args):

        if 'flow_uid' in args and 'lsp_uid' in args:
            flow_uid = args['flow_uid']
            lsp_uid = args['lsp_uid']
        else:
            print 'Update_flow: flow_uid and lsp_uid must be specified'
            return {}

        sql_str = 'SELECT * from t_assigned_flow WHERE flow_id = %s and lsp_id = %s' % (flow_uid, lsp_uid)
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)

        if not result:
            print 'Update_flow: Can not find the flow'
            db.close()
            return {}

        flow = result[0]
        status = args['status'] if 'status' in args else flow[8]
        user_data = json.dumps(args['user_data']) if 'user_data' in args else flow[9]

        sql_str = 'UPDATE t_assigned_flow SET status = %s, user_data = \'%s\' WHERE flow_id = %s and lsp_id=%s'\
                  % (status, user_data, flow_uid, lsp_uid)
        db.exec_sql(sql_str)
        db.commit()
        db.close()

        return {}
Example #5
0
    def update_lsp(self, args):
        lsp = args

        lsp_old = self.get_lsp_by_uid(lsp['uid'])['lsps'][0]

        for k in lsp_old:
            if k not in lsp:
                lsp[k]=lsp_old[k]
                if lsp[k] is None:
                    lsp[k] = ''
        num_keys = ['delay', 'priority', 'control_type', 'path_type', 'status']
        for k in num_keys:
            if k in lsp and lsp[k] == '':
                lsp[k] = 'null'


        sql_str = 'update t_lsp set name=\'%s\',from_router_id=\'%s\',to_router_id=\'%s\',bandwidth=%s,delay=%s,priority=%s,status=%s,user_data=\'%s\',path=\'%s\' where t_lsp.id=%s' \
            % (lsp['name'],lsp['from_router_uid'],lsp['to_router_uid'],lsp['bandwidth'],lsp['delay'],lsp['priority'],lsp['status'],json.dumps(lsp['user_data']),
               ','.join((str(lsp['from_router_uid']), str(lsp['to_router_uid']))) if 'path' not in lsp or len(lsp['path']) == 0 else ','.join(lsp['path']),lsp['uid'])
        # print sql_str
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)
        if not result:
            db.commit()
        db.close()
        print result

        pass
Example #6
0
    def get_equips(self, arg):
        equips = {}
        rts = []

        sql_str = 'select * from t_router inner join t_site on t_router.site_id=t_site.id'
        db = mysql_utils('topology')
        results = db.exec_sql(sql_str)
        db.close()

        for result in results:
            one_rt = {}
            one_rt['uid'] = str(result[0])
            one_rt['name'] = result[2]
            #one_rt['model'] = result[2]
            one_rt['community'] = result[5]
            one_rt['vendor'] = result[6]
            #one_rt['pos'] = result[5]
            one_rt['x'] = result[7]
            one_rt['y'] = result[8]
            one_rt['ip_str'] = result[4]
            one_rt['model'] = result[9]
            rts.append(one_rt)

        equips['routers'] = rts
        return equips
Example #7
0
    def add_lsp(self, args):
        lsp = args
        added_lsp = []

        str_keys = ['from_port_uid', 'to_port_uid','from_router_ip', 'to_router_ip','user_data', 'host_list', 'path', 'from_router_name', 'to_router_name']
        num_keys = ['delay', 'priority', 'control_type', 'path_type', 'status']
        for k in str_keys:
            if k not in lsp or lsp[k] is None:
                lsp[k] = ''
        for k in num_keys:
            if k not in lsp or lsp[k] is None:
                lsp[k] = 'null'

        lsp['hop_list'] = ','.join(lsp['hop_list'])
        lsp['path'] = ','.join(lsp['path'])
        #insert into t_lsp values (1, 'lsp-1', 1, '1.1.1.1', 1, 2, '2.2.2.2', 1, 100.0, 20.0, 1, 1, 0);
        sql_str = 'insert into t_lsp(name,from_router_id,from_router_ip,from_port_id,to_router_id,to_router_ip,' \
            + 'to_port_id, bandwidth,delay,priority,control_type,path_type,status,user_data,hop_list,path) values (\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',%s,%s,%s,%s,%s,%s,\'%s\',\'%s\',\'%s\')' \
            % (lsp['name'],lsp['from_router_uid'],lsp['from_router_ip'],lsp['from_port_uid'],lsp['to_router_uid'],lsp['to_router_ip'],lsp['to_port_uid'],\
            lsp['bandwidth'],lsp['delay'],lsp['priority'],lsp['control_type'],lsp['path_type'],lsp['status'],lsp['user_data'],lsp['hop_list'],lsp['path'])
        # print sql_str
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)
        if not result:
            db.commit()
        lsp_id = db.exec_sql('SELECT LAST_INSERT_ID()')[0][0]
        db.close()
        return {'uid':str(lsp_id)}
Example #8
0
    def del_flow(self, args):
        flow_uid = args['flow_uid']
        lsp_uid = args['lsp_uid']

        sql_str = 'delete from t_assigned_flow where flow_id=%s and lsp_id=%s' % (str(flow_uid), str(lsp_uid))
        db = mysql_utils('tunnel')
        db.exec_sql(sql_str)
        db.commit()
        db.close()
        return {}
Example #9
0
    def __init__(self):
        handlers = [(r'/', ms_customer_handler)]
        tornado.web.Application.__init__(self, handlers)
        self.ip_cust_map = {}
        self.db = mysql_utils('customer')
        self.split_bits = 8
        tornado.ioloop.IOLoop.instance().add_timeout(
            datetime.timedelta(milliseconds=500), self.load_ip_cust_map)

        pass
Example #10
0
    def add_customer_to_lsp(self, args):
        cust_uid = args['cust_uid']
        lsp_uid = args['lsp_uid']

        sql_str = 'insert into t_assigned_flow (customer_id, lsp_id) VALUES (%s,%s)' % (cust_uid, lsp_uid)
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)
        if not result:
                db.commit()
        db.close()
        return {}
Example #11
0
    def del_customer_from_lsp(self, args):

        cust_uid = args['cust_uid']
        lsp_uid = args['lsp_uid']

        sql_str = 'delete from t_assigned_flow where t_assigned_flow.customer_id=%s and t_assigned_flow.lsp_id=%s' % (cust_uid, lsp_uid)
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)
        if not result:
                db.commit()
        db.close()
        return {}
Example #12
0
    def set_vlink_delay(self, arg):
        ' args is {"vlinks":[{"uid":"xxx", "delay":123} ] }'
        dlys = arg['vlinks']

        db = mysql_utils('topology')
        for d in dlys:
            sqltxt = 'UPDATE t_link SET t_link.delay = %s WHERE t_link.id = %s' % (
                d['delay'], d['uid'])
            db.exec_sql(sqltxt)
        db.commit()
        db.close()
        return {}
Example #13
0
    def del_lsp(self, args):
        if 'uids' in args:
            uids = args['uids']
        elif 'uid' in args:
            uids = [args['uid']]

        sql_str = 'delete from t_lsp where t_lsp.id in (%s)' % (",".join(str(uid) for uid in uids))
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)
        if not result:
            db.commit()
        db.close()
        return result
Example #14
0
    def update_equip(self, arg):

        if 'uid' in arg:
            uid = str(arg['uid'])
        if 'name' in arg:
            name = arg['name']

        sql_str = 'update t_router set t_router.name = \'%s\' where id=%s' % (
            name, uid)
        db = mysql_utils('topology')
        db.exec_sql(sql_str)
        db.commit()
        db.close()
        return {}
Example #15
0
    def get(self, input):
        resp = {}
        db = mysql_utils('topology')
        if input.startswith('managed-elements'):
            'Get equipments'
            sql_txt = 'SELECT * FROM t_router'
            res = db.exec_sql(sql_txt)
            num = len(res)
            resp['totalNum'] = num
            eles = []
            for e in res:
                one_me = {'id':str(e[0]), 'name':e[2],'ipAddress':e[4], 'community':e[5],
                          'x':e[7], 'y':e[8], 'manufacturer':e[6]}
                eles.append(one_me)
                pass
            resp['managedElements'] = eles
        elif input.startswith('logical-termination-points'):
            meid = input.split('=')[1]
            sql_txt = 'SELECT * FROM t_port where router_id=%s' % str(meid)
            res = db.exec_sql(sql_txt)
            num = len(res)
            resp['totalNum'] = num
            ports = []
            for p in res:
                one_p = {'id':str(p[0]), 'name':p[4], 'portIndex':p[9], 'phyBW':p[5],
                         'macAddress':p[6], 'ipAddress':p[8], 'type':p[2] }
                ports.append(one_p)
            resp['logicalTerminationPoints'] = ports

        elif input.startswith('topological-links'):
            sql_txt = 'SELECT * FROM t_link'
            res = db.exec_sql(sql_txt)
            num = len(res)
            resp['totalNum'] = num
            lks = []
            for lk in res:
                one_lk = {'id':str(lk[0]), 'aEnd':str(lk[1]), 'zEnd':str(lk[2]), 'phyBW':lk[4]}
                lks.append(one_lk)
            resp['topologicalLinks'] = lks
            pass

        self.write(json.dumps(resp))
        self.finish()
        pass
Example #16
0
    def get_vlinks(self, arg):
        vl = {}
        vls = []

        sql_str = 'select * from t_link'
        db = mysql_utils('topology')
        results = db.exec_sql(sql_str)
        db.close()

        for result in results:
            v = {}
            v['uid'] = str(result[0])
            v['sport'] = str(result[1])
            v['dport'] = str(result[2])
            v['bandwidth'] = result[4]
            v['delay'] = result[
                6] if result[6] is not None and result[6] != '' else 0
            vls.append(v)

        vl['vlinks'] = vls
        return vl
Example #17
0
    def add_flow(self, args):
        flow_uid = args['flow_uid']
        lsp_uid = args['lsp_uid']
        status = args['status'] if 'status' in args else 0
        user_data = args['user_data'] if 'user_data' in args else ''

        #insert into t_assigned_flow values (1, 1, 16843265, 16843266, '1.1.2.1', '1.1.2.2');
        # ip = customer['ips'].split('/')[0]
        # print ip
        # mask = int(customer['ips'].split('/')[1])
        # print mask

        sql_str = 'insert into t_assigned_flow(lsp_id,flow_id,status, user_data) values (%s,%s,%s,\'%s\')' \
            % (lsp_uid,flow_uid, status, user_data)
        print sql_str
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)
        if not result:
            db.commit()
        db.close()
        return {}
Example #18
0
    def get_ports(self, arg):
        uid = arg['uid']
        port = {}
        ps = []

        sql_str = 'select * from t_port where t_port.router_id=%s' % uid
        print sql_str
        db = mysql_utils('topology')
        results = db.exec_sql(sql_str)
        db.close()

        for result in results:
            one_port = {}
            one_port['uid'] = str(result[0])
            one_port['type'] = result[2]
            one_port['mac'] = result[6]
            one_port['ip_str'] = result[8]
            one_port['if_index'] = result[9]
            one_port['if_name'] = result[4]
            ps.append(one_port)

        port['ports'] = ps
        return port
Example #19
0
    def get_lsp_by_uid(self, uid):
        lsps = {}
        lsp = []

        sql_str = 'select * from t_lsp where t_lsp.id = %s' % uid
        print sql_str
        db = mysql_utils('tunnel')
        results = db.exec_sql(sql_str)
        db.close()

        for result in results:
            one_lsp = {}
            one_lsp['uid'] = uid
            one_lsp['name'] = result[1]
            one_lsp['from_router_uid'] = result[2]
            one_lsp['to_router_uid'] = result[5]
            one_lsp['bandwidth'] = result[8]
            one_lsp['delay'] = result[9]
            one_lsp['priority'] = result[10]

            lsp.append(one_lsp)

        lsps['lsps'] = lsp
        return lsps
Example #20
0
    def get_customer_by_lsp(self, args):

        if 'lsp_uids' in args:
            lsps = args['lsp_uids']
            sql_str = 'select * from t_assigned_flow where t_assigned_flow.lsp_id in (%s) and t_assigned_flow.customer_id is not null'\
                      % ','.join(str(p) for p in lsps)
        else:
            sql_str = 'select * from t_assigned_flow  t_assigned_flow.customer_id is not null'

        db = mysql_utils('tunnel')
        results = db.exec_sql(sql_str)
        db.close()
        customers = {}
	if results is not None:
        for result in results:
            lsp_uid = str(result[1])
            cust_uid = str(result[6])
            if lsp_uid not in customers:
                customers[lsp_uid] = []
            customers[lsp_uid].append(cust_uid)

        return customers

    def add_customer_to_lsp(self, args):
        cust_uid = args['cust_uid']
        lsp_uid = args['lsp_uid']

        sql_str = 'insert into t_assigned_flow (customer_id, lsp_id) VALUES (%s,%s)' % (cust_uid, lsp_uid)
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)
        if not result:
                db.commit()
        db.close()
        return {}

    def del_customer_from_lsp(self, args):

        cust_uid = args['cust_uid']
        lsp_uid = args['lsp_uid']

        sql_str = 'delete from t_assigned_flow where t_assigned_flow.customer_id=%s and t_assigned_flow.lsp_id=%s' % (cust_uid, lsp_uid)
        db = mysql_utils('tunnel')
        result = db.exec_sql(sql_str)
        if not result:
                db.commit()
        db.close()
        return {}

    def get_lsp_by_uids(self, args):

        uids = args['lsp_uids']
        lsps = {}

        sql_str = 'select * from t_lsp where t_lsp.id in (%s)' % ','.join(uids)
        db = mysql_utils('tunnel')
        results = db.exec_sql(sql_str)
        db.close()

        if results is not None:
        for result in results:
            uid = result[0]
            one_lsp = {}
            one_lsp['uid'] = uid
            one_lsp['name'] = result[1]
            one_lsp['from_router_uid'] = result[2]
            one_lsp['to_router_uid'] = result[5]
            one_lsp['bandwidth'] = result[8]
            one_lsp['delay'] = result[9]
            one_lsp['priority'] = result[10]
            one_lsp['status'] = result[13]

            lsps[uid] = one_lsp

        return lsps