Esempio n. 1
0
int main(int argc, char** argv) {
    int p = 6;
    int s=1<<p;
    while(1) {
        printf("---\n");
        FILE* in = popen("tmux capture-pane -pJ", "r");

        unsigned char buf[s*s+1];
        for(int i=0; i<s*s; i++) buf[i] = '.';
        buf[s*s] = 0;
        
        unsigned char c;
        int i=0;
        while(c = fgetc(in)) {
            if(feof(in)) break;
            int x, y;
            d2xy(s, i, &x, &y);
            if(c=='\n') c='~';
            buf[x+y*s]=c;
            i++;
        }

        for(int y=0; y<32; y++){
           for(int x=0; x<s; x++) {
              printf("%c", buf[x+y*s]);
           }
           printf("\n");
        }

        pclose(in);
        sleep(1);
    }
}
Esempio n. 2
0
void
heatmap_image_hilbert_data_aspath_max_distance (int peer_spec_i)
{
  int peer_index = peer_spec_index[peer_spec_i];
  struct ptree *ptree = peer_ptree[peer_spec_i];

  unsigned int a0, a1, a2;
  struct in_addr addr = { 0 };
  unsigned long val = 0;
  unsigned char *p = (unsigned char *) &addr;
  struct ptree_node *node;
  //unsigned long count = 0;
  unsigned long max = 0;

  unsigned int array[256][256];

  u_int32_t x, y;
  x = y = 0;

  for (a0 = 0; a0 < 256; a0++)
    {
      p[0] = (unsigned char) a0;
      for (a1 = 0; a1 < 256; a1++)
        {
          p[1] = (unsigned char) a1;

          //count = 0;
          max = 0;

          for (a2 = 0; a2 < 256; a2++)
            {
              p[2] = (unsigned char) a2;
              //printf ("heat: addr: %s\n", inet_ntoa (addr));

              node = ptree_search ((char *)&addr, 24, ptree);
              if (node)
                {
                  struct bgp_route *route = node->data;
                  //route_print (route);
                  //count++;
                  if (max < route->path_size)
                    max = route->path_size;
                }
              else
                {
                  //printf ("no route.\n");
                }
            }

          p[2] = 0;
          val = (a0 << 8) + a1;
          d2xy (1ULL << 16, val, &x, &y);
#if 0
          printf ("val: %lu, x: %lu, y: %lu, count: %lu\n",
                  val, (unsigned long) x, (unsigned long) y,
                  (unsigned long) count);
#endif
#if 1
          printf ("val: %lu, x: %lu, y: %lu, max: %lu\n",
                  val, (unsigned long) x, (unsigned long) y,
                  (unsigned long) max);
#endif

          //array[x][y] = count;
          int adjust = 16;
          if (max * adjust > 255)
            array[x][y] = 255;
          else
            array[x][y] = max * adjust;
        }
    }

  //printf ("\n");

  FILE *fp;
  char filename[256];
  snprintf (filename, sizeof (filename), "%s-p%d.dat",
            heatmap_prefix, peer_index);

  fp = fopen (filename, "w+");
  if (! fp)
    {
      fprintf (stderr, "can't open file %s: %s\n",
               filename, strerror (errno));
      return;
    }

  for (a0 = 0; a0 < 256; a0++)
    for (a1 = 0; a1 < 256; a1++)
      fprintf (fp, "%u %u %u\n", a0, a1, array[a0][a1]);

  fclose (fp);
  printf ("%s is written.\n", filename);
}
Esempio n. 3
0
void
heatmap_image_hilbert_gplot (int peer_spec_i)
{
  int peer_index = peer_spec_index[peer_spec_i];

  unsigned int a0;
  unsigned long val = 0;

  u_int32_t x1, y1, x2, y2;
  u_int32_t xs, ys, xe, ye;

  unsigned int index;

  int textxmargin = 1;
  int textymargin = 5;

  FILE *fp;
  char filename[256];
  snprintf (filename, sizeof (filename), "%s-p%d.gp",
            heatmap_prefix, peer_index);
  fp = fopen (filename, "w+");
  if (! fp)
    {
      fprintf (stderr, "can't open file %s: %s\n",
               filename, strerror (errno));
      return;
    }

  fprintf (fp, "set xlabel \"\"\n");
  fprintf (fp, "set ylabel \"\"\n");
  fprintf (fp, "\n");
  fprintf (fp, "unset tics\n");
  fprintf (fp, "\n");
  fprintf (fp, "set cbrange [0:256]\n");
  fprintf (fp, "set cbtics 32\n");
  fprintf (fp, "\n");
  fprintf (fp, "set xrange [-1:256]\n");
  fprintf (fp, "set yrange [256:-1]\n");
  fprintf (fp, "\n");
  fprintf (fp, "set pm3d map\n");
  fprintf (fp, "set palette defined (0 \"black\", 1 \"red\", "
               "128 \"yellow\", 192 \"green\", 255 \"blue\")\n");
  fprintf (fp, "\n");
  fprintf (fp, "set style rect back fs empty border lc rgb \"white\"\n");
  fprintf (fp, "\n");

  for (a0 = 0; a0 < 256; a0++)
    {
      val = (a0 << 8);
      d2xy (1ULL << 16, val, &x1, &y1);
      val = (a0 << 8) + 255;
      d2xy (1ULL << 16, val, &x2, &y2);

      index = a0 + 1;
      //printf ("%u: start (%u,%u) end (%u,%u).\n",
      //        a0, x1, y1, x2, y2);

#ifndef MIN
#define MIN(a,b) (a < b ? a : b)
#endif
#ifndef MAX
#define MAX(a,b) (a > b ? a : b)
#endif
      xs = (MIN (x1, x2)) / 16 * 16;
      ys = (MIN (y1, y2)) / 16 * 16;
      xe = xs + 16;
      ye = ys + 16;

      fprintf (fp, "set label  %u \"%u\" at first %u,%u left "
              "font \",8\" front textcolor rgb \"white\"\n",
              index, a0, xs + textxmargin, ys + textymargin);
      fprintf (fp, "set object %u rect from %u,%u to %u,%u front\n",
              index, xs, ys, xe, ye);
    }

  int asnum;
  char bgpid[32], bgpaddr[32];
  asnum = peer_table[peer_index].asnumber;
  inet_ntop (AF_INET, &peer_table[peer_index].bgp_id,
             bgpid, sizeof (bgpid));
  inet_ntop (AF_INET, &peer_table[peer_index].ipv4_addr,
             bgpaddr, sizeof (bgpaddr));

  char *p, titlename[64];
  p = rindex (heatmap_prefix, '/');
  if (p)
    snprintf (titlename, sizeof (titlename), "%s", ++p);
  else
    snprintf (titlename, sizeof (titlename), "%s", heatmap_prefix);

  fprintf (fp, "\n");
  fprintf (fp, "set title \"%s p%d bgpid:%s addr:%s AS%d\"\n",
           titlename, peer_index, bgpid, bgpaddr, asnum);
  fprintf (fp, "set term postscript eps enhanced color\n");
  fprintf (fp, "set output '%s-p%d.eps'\n", heatmap_prefix, peer_index);
  fprintf (fp, "splot '%s-p%d.dat' u 1:2:3 with image notitle\n",
           heatmap_prefix, peer_index);
  fprintf (fp, "\n");
  fprintf (fp, "set term png\n");
  fprintf (fp, "set output '%s-p%d.png'\n", heatmap_prefix, peer_index);
  fprintf (fp, "replot\n");
  fprintf (fp, "\n");

  fclose (fp);

  printf ("%s is written.\n", filename);
}