def get_flow(dpid): info = json.loads( send_req(SERVER_IP + URL_REST_DB['flow'].format(dpid=dpid))) if None == info: return None tmp = { 'DPID': 0, 'PRIORITY': 0, 'TABLE_ID': 0, 'DTIME': 0, 'ITIME': 0, 'HTIME': 0, 'MATCH': 'a', 'ACTIONS': 'a' } tmp['DPID'] = dpid table = [] for flow in info[str(dpid)]: tmp['PRIORITY'] = flow['priority'] tmp['TABLE_ID'] = flow['table_id'] tmp['DTIME'] = flow['duration_sec'] tmp['ITIME'] = flow['idle_timeout'] tmp['HTIME'] = flow['hard_timeout'] tmp['MATCH'] = json.dumps(flow['match']) tmp['ACTIONS'] = json.dumps(flow['actions']) table.append(dict(tmp)) return table
def get_gateway(): gws = json.loads(send_req(SERVER_IP+URL_REST_DB['gateway'])) if None == gws: return None for gw in gws: gw['dpid'] = gw['more']['dpid'] gw['port'] = gw['more']['port'] return gws
def get_gateway(): gws = json.loads(send_req(SERVER_IP + URL_REST_DB['gateway'])) if None == gws: return None for gw in gws: gw['dpid'] = gw['more']['dpid'] gw['port'] = gw['more']['port'] return gws
def flow_visit_gw(url,vlan_id): flows = list(VGW) info = [] for flow in flows: flow['match']['vlan_vid'] = 4096 + vlan_id content = json.dumps(flow) rst = send_req(url,content) info.append(rst) return info
def flow_push_vlan(url,mac_addr,vlan_id,user_id): flow = dict(PUSH_VLAN) flow['match']['eth_src'] = mac_addr flow['actions'][1]['value'] = 4096 + vlan_id flow['mobileVlan']['MAC_ADDR'] = mac_addr flow['mobileVlan']['VLAN_ID'] = vlan_id flow['mobileVlan']['USER_ID'] = user_id content = json.dumps(flow) info = send_req(url,content) return info
def get_dpid_all(): db = database('modules/USERDATA.db') dpall = json.loads(send_req(SERVER_IP + URL_REST_DB['dpid_all'])) if None == dpall: return None for dev in dpall: rcd_user = db.findUSERByX('USER_ID', dev['user']) for user in rcd_user: dev['more'] = {} dev['more']['depart'] = user[2].encode('utf-8') dev['more']['position'] = user[3].encode('utf-8') dev['more']['name'] = user[4].encode('utf-8') return dpall
def get_dpid_all(): db = database('modules/USERDATA.db') dpall = json.loads(send_req(SERVER_IP+URL_REST_DB['dpid_all'])) if None == dpall: return None for dev in dpall: rcd_user = db.findUSERByX('USER_ID',dev['user']) for user in rcd_user: dev['more'] = {} dev['more']['depart'] = user[2].encode('utf-8') dev['more']['position'] = user[3].encode('utf-8') dev['more']['name'] = user[4].encode('utf-8') return dpall
def get_dpid(dpid): dpid = dpid_lib.dpid_to_str(dpid) db = database('modules/USERDATA.db') table_dpid = json.loads(send_req(SERVER_IP+URL_REST_DB['dpid'].format(dpid=dpid))) if None == table_dpid: return None for dev in table_dpid: rcd_user = db.findUSERByX('USER_ID',dev['user']) for user in rcd_user: dev['more'] = {} dev['more']['depart'] = user[2].encode('utf-8') dev['more']['position'] = user[3].encode('utf-8') dev['more']['name'] = user[4].encode('utf-8') return table_dpid
def get_device(): db = database('modules/USERDATA.db') devs = json.loads(send_req(SERVER_IP + URL_REST_DB['device'])) if None == devs: return None for dev in devs: rcd_user = db.findUSERByX('USER_ID', dev['user'])[0] dev['ip'] = dev['more']['ip'].encode('utf-8') dev['dpid'] = dev['more']['dpid'] dev['port'] = dev['more']['port'] dev['more']['depart'] = rcd_user[2].encode('utf-8') dev['more']['position'] = rcd_user[3].encode('utf-8') dev['more']['name'] = rcd_user[4].encode('utf-8') return devs
def get_device(): db = database('modules/USERDATA.db') devs = json.loads(send_req(SERVER_IP+URL_REST_DB['device'])) if None == devs: return None for dev in devs: rcd_user = db.findUSERByX('USER_ID',dev['user'])[0] dev['ip'] = dev['more']['ip'].encode('utf-8') dev['dpid'] = dev['more']['dpid'] dev['port'] = dev['more']['port'] dev['more']['depart'] = rcd_user[2].encode('utf-8') dev['more']['position'] = rcd_user[3].encode('utf-8') dev['more']['name'] = rcd_user[4].encode('utf-8') return devs
def get_dpid(dpid): dpid = dpid_lib.dpid_to_str(dpid) db = database('modules/USERDATA.db') table_dpid = json.loads( send_req(SERVER_IP + URL_REST_DB['dpid'].format(dpid=dpid))) if None == table_dpid: return None for dev in table_dpid: rcd_user = db.findUSERByX('USER_ID', dev['user']) for user in rcd_user: dev['more'] = {} dev['more']['depart'] = user[2].encode('utf-8') dev['more']['position'] = user[3].encode('utf-8') dev['more']['name'] = user[4].encode('utf-8') return table_dpid
def get_flow(dpid): info = json.loads(send_req(SERVER_IP+URL_REST_DB['flow'].format(dpid=dpid))) if None == info: return None tmp = {'DPID':0,'PRIORITY':0,'TABLE_ID':0,'DTIME':0,'ITIME':0,'HTIME':0,'MATCH':'a','ACTIONS':'a'} tmp['DPID'] = dpid table = [] for flow in info[str(dpid)]: tmp['PRIORITY'] = flow['priority'] tmp['TABLE_ID'] = flow['table_id'] tmp['DTIME'] = flow['duration_sec'] tmp['ITIME'] = flow['idle_timeout'] tmp['HTIME'] = flow['hard_timeout'] tmp['MATCH'] = json.dumps(flow['match']) tmp['ACTIONS'] = json.dumps(flow['actions']) table.append(dict(tmp)) return table
def get_switches(): return json.loads(send_req(SERVER_IP+URL_REST_TOPO['switches']))
def get_dpid_list(): return json.loads(send_req(SERVER_IP + URL_REST_DB['dpid_list']))
def get_hosts(): return json.loads(send_req(SERVER_IP+URL_REST_TOPO['hosts_all']))
def get_mac(ip_addr): return json.loads(send_req(SERVER_IP+URL_REST_DB['mac'].format(ip_addr=ip_addr)))
def get_mac(ip_addr): return json.loads( send_req(SERVER_IP + URL_REST_DB['mac'].format(ip_addr=ip_addr)))
def get_dpid_list(): return json.loads(send_req(SERVER_IP+URL_REST_DB['dpid_list']))
def get_links(): return json.loads(send_req(SERVER_IP+URL_REST_TOPO['links_all']))