void adm_init() { DTNMP_DEBUG_ENTRY("adm_init","()", NULL); gAdmData = lyst_create(); gAdmCtrls = lyst_create(); gAdmLiterals = lyst_create(); gAdmOps = lyst_create(); adm_bp_init(); #ifdef _HAVE_LTP_ADM_ adm_ltp_init(); #endif /* _HAVE_LTP_ADM_ */ #ifdef _HAVE_ION_ADM_ adm_ion_init(); #endif /* _HAVE_ION_ADM_ */ adm_agent_init(); //initBpAdm(); //initLtpAdm(); //initIonAdm(); DTNMP_DEBUG_EXIT("adm_init","->.", NULL); }
/****************************************************************************** * * \par Function Name: midcol_copy * * \par Purpose: Copies a MID collection * * \retval NULL - Failure * !NULL - The copied MID collection * * \param[in] mids MID collection to be copied. * * \par Notes: * 1. This is a deep copy. * * Modification History: * MM/DD/YY AUTHOR DESCRIPTION * -------- ------------ --------------------------------------------- * 11/14/12 E. Birrane Initial implementation, *****************************************************************************/ Lyst midcol_copy(Lyst mids) { Lyst result = NULL; LystElt elt; mid_t *cur_mid = NULL; mid_t *new_mid = NULL; DTNMP_DEBUG_ENTRY("midcol_copy","(%#llx)",(unsigned long) mids); /* Step 0: Sanity Check. */ if(mids == NULL) { DTNMP_DEBUG_ERR("midcol_copy","Bad Args.",NULL); DTNMP_DEBUG_EXIT("midcol_copy","->NULL.",NULL); return NULL; } /* Build the Lyst. */ if((result = lyst_create()) == NULL) { DTNMP_DEBUG_ERR("midcol_copy","Unable to create lyst.",NULL); DTNMP_DEBUG_EXIT("midcol_copy","->NULL.",NULL); return NULL; } /* Walking copy. */ int success = 1; for(elt = lyst_first(mids); elt; elt = lyst_next(elt)) { cur_mid = (mid_t *) lyst_data(elt); if((new_mid = mid_copy(cur_mid)) == NULL) { DTNMP_DEBUG_ERR("midcol_copy","Fsiled to copy MID.",NULL); midcol_destroy(&result); DTNMP_DEBUG_EXIT("midcol_copy","->NULL.",NULL); return NULL; } else { lyst_insert_last(result,mid_copy(cur_mid)); } } DTNMP_DEBUG_EXIT("midcol_copy","->%#llx.",(unsigned long) result); return result; }
/****************************************************************************** * * \par Function Name: midcol_deserialize * * \par Purpose: Deserialize a MID collection into a Lyst. * * \retval NULL - Failure * !NULL - The created Lyst. * * \param[in] buffer The buffer holding the MC. * \param[in] buffer_size The size of the buffer, in bytes. * \param[out] bytes_used The # bytes consumed in the deserialization. * * \par Notes: * 1. The created Lyst must be freed when done. * 2. Reminder: A Lyst is a pointer to a LystStruct. * * Modification History: * MM/DD/YY AUTHOR DESCRIPTION * -------- ------------ --------------------------------------------- * 11/14/12 E. Birrane Initial implementation, * 06/17/13 E. Birrane Updated to ION 3.1.3, moved to uvast *****************************************************************************/ Lyst midcol_deserialize(unsigned char *buffer, uint32_t buffer_size, uint32_t *bytes_used) { unsigned char *cursor = NULL; Lyst result = NULL; uint32_t bytes = 0; uvast num = 0; mid_t *cur_mid = NULL; uint32_t i = 0; DTNMP_DEBUG_ENTRY("midcol_deserialize","(%#llx,%d,%#llx)", (unsigned long) buffer, buffer_size, (unsigned long) bytes_used); /* Step 0: Sanity Check. */ if((buffer == NULL) || (buffer_size == 0) || (bytes_used == NULL)) { DTNMP_DEBUG_ERR("mid_deserialize_mc","Bad Args", NULL); DTNMP_DEBUG_EXIT("mid_deserialize_mc","->NULL",NULL); return NULL; } *bytes_used = 0; cursor = buffer; /* Step 1: Create the Lyst. */ if((result = lyst_create()) == NULL) { DTNMP_DEBUG_ERR("midcol_deserialize","Can't create lyst.", NULL); DTNMP_DEBUG_EXIT("midcol_deserialize","->NULL",NULL); return NULL; } /* Step 2: Grab # MIDs in the collection. */ if((bytes = utils_grab_sdnv(cursor, buffer_size, &num)) == 0) { DTNMP_DEBUG_ERR("midcol_deserialize","Can't parse SDNV.", NULL); lyst_destroy(result); DTNMP_DEBUG_EXIT("midcol_deserialize","->NULL",NULL); return NULL; } else { cursor += bytes; buffer_size -= bytes; *bytes_used += bytes; } /* Step 3: Grab Mids. */ for(i = 0; i < num; i++) { /* Deserialize ith MID. */ if((cur_mid = mid_deserialize(cursor, buffer_size, &bytes)) == NULL) { DTNMP_DEBUG_ERR("mid_deserialize_mc","Can't grab MID #%d.", i); midcol_destroy(&result); DTNMP_DEBUG_EXIT("mid_deserialize_mc","->NULL",NULL); return NULL; } else { cursor += bytes; buffer_size -= bytes; *bytes_used += bytes; } /* Drop it in the lyst in order. */ lyst_insert_last(result, cur_mid); } DTNMP_DEBUG_EXIT("midcol_deserialize","->%#llx",(unsigned long)result); return result; }
/* * We need to find out a description for the entry so we can print it out. * So, if entry is <RPT MID> <int d1><int d2><int d3> we need to match the items * to elements of the report definition. * */ void ui_print_entry(rpt_entry_t *entry, uvast *mid_sizes, uvast *data_sizes) { LystElt elt = NULL; def_gen_t *cur_def = NULL; uint8_t del_def = 0; if((entry == NULL) || (mid_sizes == NULL) || (data_sizes == NULL)) { AMP_DEBUG_ERR("ui_print_entry","Bad Args.", NULL); return; } /* Step 1: Calculate sizes...*/ *mid_sizes = *mid_sizes + entry->id->raw_size; for(elt = lyst_first(entry->contents->datacol); elt; elt = lyst_next(elt)) { blob_t *cur = lyst_data(elt); *data_sizes = *data_sizes + cur->length; } *data_sizes = *data_sizes + entry->contents->hdr.length; /* Step 1: Print the MID associated with the Entry. */ printf(" ("); ui_print_mid(entry->id); printf(") has %d values.", entry->contents->hdr.length); /* * Step 2: Try and find the metadata associated with each * value in the TDC. Since the TDC is already typed, the * needed meta-data information is simply the * "name" of the data. * * i Only computed data definitions, reports, and macros * need names. Literals, controls, and atomic data do * not (currently) define extra meta-data for their * definitions. * * \todo: Consider printing names for each return * value from a control. */ cur_def = NULL; if(MID_GET_FLAG_ID(entry->id->flags) == MID_ATOMIC) { adm_datadef_t *ad_entry = adm_find_datadef(entry->id); /* Fake a def_gen_t for now. */ if(ad_entry != NULL) { Lyst tmp = lyst_create(); lyst_insert(tmp,mid_copy(ad_entry->mid)); cur_def = def_create_gen(mid_copy(ad_entry->mid), ad_entry->type, tmp); del_def = 1; } } else if(MID_GET_FLAG_ID(entry->id->flags) == MID_COMPUTED) { var_t *cd = NULL; if(MID_GET_FLAG_ISS(entry->id->flags) == 0) { cd = var_find_by_id(gAdmComputed, NULL, entry->id); } else { cd = var_find_by_id(gMgrVDB.compdata, &(gMgrVDB.compdata_mutex), entry->id); } // Fake a def_gen just for this CD item. if(cd != NULL) { Lyst tmp = lyst_create(); lyst_insert(tmp,mid_copy(cd->id)); cur_def = def_create_gen(mid_copy(cd->id), cd->value.type, tmp); del_def = 1; } } else if(MID_GET_FLAG_ID(entry->id->flags) == MID_REPORT) { if(MID_GET_FLAG_ISS(entry->id->flags) == 0) { cur_def = def_find_by_id(gAdmRpts, NULL, entry->id); } else { cur_def = def_find_by_id(gMgrVDB.reports, &(gMgrVDB.reports_mutex), entry->id); } } else if(MID_GET_FLAG_ID(entry->id->flags) == MID_MACRO) { if(MID_GET_FLAG_ISS(entry->id->flags) == 0) { cur_def = def_find_by_id(gAdmMacros, NULL, entry->id); } else { cur_def = def_find_by_id(gMgrVDB.macros, &(gMgrVDB.macros_mutex), entry->id); } } /* Step 3: Print the TDC holding data for the entry. */ ui_print_tdc(entry->contents, cur_def); if(del_def) { def_release_gen(cur_def); } return; }
/****************************************************************************** * * \par Function Name: mgr_init * * \par Initialize the manager... * * \par Notes: * * Modification History: * MM/DD/YY AUTHOR DESCRIPTION * -------- ------------ --------------------------------------------- ** 09/01/11 V. Ramachandran Initial Implementation ** 08/20/13 E. Birrane Code Review Updates *****************************************************************************/ int mgr_init(char *argv[]) { DTNMP_DEBUG_ENTRY("mgr_init","(0x%x)",(unsigned long) argv); strcpy((char *) manager_eid.name, argv[1]); if(iif_register_node(&ion_ptr, manager_eid) == 0) { DTNMP_DEBUG_ERR("mgr_init","Unable to register BP Node. Exiting.", NULL); DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL); return -1; } if (iif_is_registered(&ion_ptr)) { DTNMP_DEBUG_INFO("mgr_init", "Mgr registered with ION, EID: %s", iif_get_local_eid(&ion_ptr).name); } else { DTNMP_DEBUG_ERR("mgr_init","Failed to register mgr with ION, EID %s", iif_get_local_eid(&ion_ptr).name); DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL); return -1; } g_sdr = getIonsdr(); if((known_agents = lyst_create()) == NULL) { DTNMP_DEBUG_ERR("mgr_init","Failed to create known agents list.",NULL); //MRELEASE(ion_ptr); DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL); return -1; } if (initResourceLock(&agents_mutex)) { DTNMP_DEBUG_ERR("mgr_init","Can't initialize rcv rpt list. . errno = %s", strerror(errno)); //MRELEASE(ion_ptr); DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL); return -1; } if((macro_defs = lyst_create()) == NULL) { DTNMP_DEBUG_ERR("mgr_init","Failed to create macro def list.%s",NULL); //MRELEASE(ion_ptr); DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL); return -1; } if (initResourceLock(¯o_defs_mutex)) { DTNMP_DEBUG_ERR("mgr_init","Cant init macro def list mutex. errno = %s", strerror(errno)); //MRELEASE(ion_ptr); DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL); return -1; } adm_init(); #ifdef HAVE_MYSQL db_mgt_init("localhost", "root", "NetworkManagement", "dtnmp", 1); #endif DTNMP_DEBUG_EXIT("mgr_init","->0.",NULL); return 0; }
agent_t* mgr_agent_create(eid_t *in_eid) { Object *entry = NULL; agent_t *agent = NULL; DTNMP_DEBUG_ENTRY("mgr_agent_create", "(%s)", in_eid->name); /* Step 0: Sanity Check. */ if(in_eid == NULL) { DTNMP_DEBUG_ENTRY("mgr_agent_create", "(NULL)", NULL); DTNMP_DEBUG_EXIT("mgr_agent_create", "->NULL", NULL); return NULL; } /* Step 1: Allocate space for the new agent. */ if((agent = (agent_t*)MTAKE(sizeof(agent_t))) == NULL) { DTNMP_DEBUG_ERR("mgr_agent_create", "Unable to allocate %d bytes for new agent %s", sizeof(agent_t), in_eid->name); DTNMP_DEBUG_EXIT("mgr_agent_create", "->NULL", NULL); return NULL; } /* Step 2: Copy over the name. */ strncpy(agent->agent_eid.name, in_eid->name, MAX_EID_LEN); /* Step 3: Create associated lists. */ if((agent->custom_defs = lyst_create()) == NULL) { DTNMP_DEBUG_ERR("mgr_agent_create","Unable to create custom definition lyst for agent %s", in_eid->name); MRELEASE(agent); DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL); return NULL; } if((agent->reports = lyst_create()) == NULL) { DTNMP_DEBUG_ERR("mgr_agent_create","Unable to create report lyst for agent %s", in_eid->name); lyst_destroy(agent->custom_defs); MRELEASE(agent); DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL); return NULL; } if(lyst_insert(known_agents, agent) == NULL) { DTNMP_DEBUG_ERR("mgr_agent_create","Unable to insert agent %s into known agents lyst", in_eid->name); lyst_destroy(agent->custom_defs); lyst_destroy(agent->reports); MRELEASE(agent); DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL); return NULL; } initResourceLock(&(agent->mutex)); DTNMP_DEBUG_EXIT("mgr_agent_create", "->New Agent %s", agent->agent_eid.name); return agent; }