Exemplo n.º 1
0
int console_host_set_property(lua_State *L) {
  const char* name ="";
  const char* prop_id = "";
  const char* prop_value = "";
  lua_ensure(lua_istable(L, -1), "Bad Arguments to create link, Should be a table with named arguments");

  // get Host id
  lua_pushstring(L, "host");
  lua_gettable(L, -2);
  name = lua_tostring(L, -1);
  lua_pop(L, 1);

  // get prop Name
  lua_pushstring(L, "prop");
  lua_gettable(L, -2);
  prop_id = lua_tostring(L, -1);
  lua_pop(L, 1);
  //get args
  lua_pushstring(L,"value");
  lua_gettable(L, -2);
  prop_value = lua_tostring(L,-1);
  lua_pop(L, 1);

  sg_host_t host = sg_host_by_name(name);
  lua_ensure(host, "no host '%s' found",name);
  xbt_dict_t props = sg_host_get_properties(host);
  xbt_dict_set(props,prop_id,xbt_strdup(prop_value),nullptr);

  return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
  xbt_dict_cursor_t cursor = NULL;
  char *key, *data;
  char noexist[] = "NoProp";
  const char *value;
  char exist[] = "Hdd";

  /* SD initialization */
  SD_init(&argc, argv);
  xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s ../../platforms/prop.xml", argv[0], argv[0]);

  SD_create_environment(argv[1]);

  /* init of platform elements */
  sg_host_t h1 = sg_host_by_name("host1");
  sg_host_t h2 = sg_host_by_name("host2");
  const char *name1 = sg_host_get_name(h1);
  const char *name2 = sg_host_get_name(h2);

  /* Get the property list of 'host1' */
  XBT_INFO("Property list for host %s", name1);
  xbt_dict_t props = sg_host_get_properties(h1);

  /* Trying to set a new property */
  xbt_dict_set(props, "NewProp", strdup("newValue"), NULL);

  /* Print the properties of 'host1' */
  xbt_dict_foreach(props, cursor, key, data) {
    XBT_INFO("\tProperty: %s has value: %s", key, data);
  }
Exemplo n.º 3
0
int main(int argc, char **argv)
{
  char *platformFile = NULL;
  unsigned int totalHosts, totalLinks;
  int timings=0;
  int version = 4;
  const char *link_ctn = "link_ctn";
  unsigned int i;
  xbt_dict_t props = NULL;
  xbt_dict_cursor_t cursor = NULL;
  xbt_lib_cursor_t cursor_src = NULL;
  xbt_lib_cursor_t cursor_dst = NULL;
  char *src,*dst,*key,*data;
  sg_netcard_t value1;
  sg_netcard_t value2;

  const sg_host_t *hosts;
  const SD_link_t *links;
  xbt_os_timer_t parse_time = xbt_os_timer_new();

  SD_init(&argc, argv);

  if (parse_cmdline(&timings, &platformFile, argc, argv) || !platformFile) {
    xbt_die("Invalid command line arguments: expected [--timings] platformFile");
  }

  XBT_DEBUG("%d,%s", timings, platformFile);

  create_environment(parse_time, platformFile);

  if (timings) {
    XBT_INFO("Parsing time: %fs (%zu hosts, %d links)", xbt_os_timer_elapsed(parse_time),
             sg_host_count(), sg_link_count());
  } else {
    printf("<?xml version='1.0'?>\n");
    printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n");
    printf("<platform version=\"%d\">\n", version);
    printf("<AS id=\"AS0\" routing=\"Full\">\n");

    // Hosts
    totalHosts = sg_host_count();
    hosts = sg_host_list();
    qsort((void *) hosts, totalHosts, sizeof(sg_host_t), name_compare_hosts);

    for (i = 0; i < totalHosts; i++) {
      printf("  <host id=\"%s\" speed=\"%.0f\"", sg_host_get_name(hosts[i]), sg_host_speed(hosts[i]));
      props = sg_host_get_properties(hosts[i]);
      if (sg_host_core_count(hosts[i])>1) {
        printf(" core=\"%d\"", sg_host_core_count(hosts[i]));
      }
      if (props && !xbt_dict_is_empty(props)) {
        printf(">\n");
        xbt_dict_foreach(props, cursor, key, data) {
          printf("    <prop id=\"%s\" value=\"%s\"/>\n", key, data);
        }
        printf("  </host>\n");
      } else {
Exemplo n.º 4
0
/** @brief Displays debugging information about a host */
void sg_host_dump(sg_host_t host)
{
  xbt_dict_t props;
  xbt_dict_cursor_t cursor=NULL;
  char *key,*data;

  XBT_INFO("Displaying host %s", sg_host_get_name(host));
  XBT_INFO("  - speed: %.0f", host->speed());
  XBT_INFO("  - available speed: %.2f", sg_host_get_available_speed(host));
  props = sg_host_get_properties(host);

  if (!xbt_dict_is_empty(props)){
    XBT_INFO("  - properties:");

    xbt_dict_foreach(props,cursor,key,data) {
      XBT_INFO("    %s->%s",key,data);
    }
Exemplo n.º 5
0
/** \ingroup m_host_management
 * \brief Returns the value of a given host property
 *
 * \param host a host
 * \param name a property name
 * \return value of a property (or NULL if property not set)
*/
const char *sg_host_get_property_value(sg_host_t host, const char *name)
{
  return (const char*) xbt_dict_get_or_null(sg_host_get_properties(host), name);
}
Exemplo n.º 6
0
  /* Trying to set a new property */
  xbt_dict_set(props, "NewProp", strdup("newValue"), NULL);

  /* Print the properties of 'host1' */
  xbt_dict_foreach(props, cursor, key, data) {
    XBT_INFO("\tProperty: %s has value: %s", key, data);
  }

  /* Try to get a property that does not exist */
  value = sg_host_get_property_value(h1, noexist);
  XBT_INFO("\tProperty: %s has value: %s", noexist, value?value:"Undefined (NULL)");

  /* Get the property list of 'host2' */
  XBT_INFO("Property list for host %s", name2);
  props = sg_host_get_properties(h2);

  /* Print the properties of 'host2' */
  xbt_dict_foreach(props, cursor, key, data) {
    XBT_INFO("\tProperty: %s on host: %s", key, data);
  }

  /* Modify an existing property test. First check it exists */
  XBT_INFO("Modify an existing property");

  value = sg_host_get_property_value(h2, exist);
  if (value == NULL)
    XBT_INFO("\tProperty: %s is undefined", exist);
  else {
    XBT_INFO("\tProperty: %s old value: %s", exist, value);
    xbt_dict_set(props, exist, strdup("250"), NULL);