def path_show_route_path(self, conf, version, src_dpid, src_port, dst_dpid, dst_port): src_sw = None dst_sw = None src_alias = None dst_alias = None path = None try: src_sw = mul_nbapi.get_switch(int(src_dpid, 0)) dst_sw = mul_nbapi.get_switch(int(dst_dpid, 0)) src_alias = mul_nbapi.get_switch_alias_from_switch_info(src_sw) dst_alias = mul_nbapi.get_switch_alias_from_switch_info(dst_sw) path = mul_nbapi.get_simple_path(src_alias,int(src_port, 0),dst_alias,int(dst_port, 0)) except: return None return {'hops':self.json_serializer.nbapi_path_elem_list_t_serialization(path,self.alias_map)}
def __init__(self): self.json_serializer = mlapi_json_serialization() self.json_deserializer = mlapi_json_deserialization() self.flow_tbl={} self.fab_host_tbl={} self.alias_map = {} self.db_client = MongoClient(DB_HOST, DB_PORT) self.db = self.db_client[DB_NAME] self.err = Error() ''' Make API and DB mapping table ''' ServiceChainMgr_package = __import__('kulcloud.api.v1') ServiceChainMgr_module = getattr(ServiceChainMgr_package, 'ServiceChainManager') ServiceChainMgr_validator = getattr(ServiceChainMgr_module, 'input_validation') NFVTopologyMgr_package = __import__('kulcloud.api.v1') NFVTopologyMgr_module = getattr(NFVTopologyMgr_package, 'NFVTopologyManager') NFVTopologyMgr_validator = getattr(NFVTopologyMgr_module, 'input_validation') ServiceChainDefaultRuleMgr_package = __import__('kulcloud.api.v1') ServiceChainDefaultRuleMgr_module = getattr(ServiceChainDefaultRuleMgr_package, 'ServiceChainDefaultRuleManager') ServiceChainDefaultRuleMgr_validator = getattr(ServiceChainDefaultRuleMgr_module, 'input_validation') self.db_collection['NFVGroupMgr']={'name':'NFVGroupMgr', 'keys':['name'], 'validator':None} self.db_collection['NFVTopologyMgr']={'name':'NFVTopologyMgr', 'keys':['dpid','in_port','out_port','name'], 'validator':NFVTopologyMgr_validator} self.db_collection['ServiceChainDefaultRuleMgr']={'name':'ServiceChainDefaultRuleMgr', 'keys':['service_id', 'service_level'], 'validator':ServiceChainDefaultRuleMgr_validator} self.db_collection['ServiceChainMgr']={'name':'ServiceChainMgr', 'keys':['ip','service_id'], 'validator':ServiceChainMgr_validator} self.db_collection['ServiceMgr']={'name':'ServiceMgr', 'keys':['name', 'vlan'], 'validator':None} self.db_collection['UserMgr']={'name':'UserMgr', 'keys':['mdn', 'ip'], 'validator':None} resp =[] # TODO : Threading to check the switch pull status and alias_map try: resp = mul_nbapi.get_switch_all() except: print 'error' for s in resp: sw_info = mul_nbapi.get_switch(s.switch_id.datapath_id) self.alias_map[mul_nbapi.get_switch_alias_from_switch_info(sw_info)]='0x%lx' % s.switch_id.datapath_id
def get_switch(self, conf, dpid): resp = None try: con = mdb.connect("localhost", "root", "of#123", "skdemo") cur = con.cursor(mdb.cursors.DictCursor) except: print "[ERROR] Fail to connect DB" pass cur.execute("SELECT * FROM logicswitch WHERE logical_dpid = %s", dpid) logic = cur.fetchone() real_dpid = str(logic["dpid"]) cur.close() con.close() try: resp = mul_nbapi.get_switch(int(real_dpid, 0)) except: return None return self.json_serializer.ofp_switch_fetures_serialization(resp)