Beispiel #1
0
int
main(int argc, char** argv)
{
    if (argc != 3) {
        fprintf(stderr, "usage: ./test-wire <name> <pipeline>\n\n");
        fprintf(stderr, " Arguments:\n");
        fprintf(stderr, "    name       the symbolic name of the dataplane\n");
        fprintf(stderr, "    pipeline   the absolute path to a pipeline module\n");
        return -1;
    }

    char const* name = argv[1];
    char const* path = argv[2];

    fp_error_t err;
    struct fp_dataplane* dp = fp_dataplane_create(name, path, &err);
    if (fp_error(err)) {
        fprintf(stderr, "error: %s\n", fp_strerror(err));
        return -1;
    }


    /* Create the ports. */
    struct fp_port* port1 = add_port(dp, 5000);
    if (!port1)
        return -1;
    struct fp_port* port2 = add_port(dp, 5001);
    if (!port2)
        return -1;

    /* Start the data plane. */
    bool ok = true;
    err = fp_dataplane_start(dp);
    if (fp_error(err)) {
        fprintf(stderr, "error: %s\n", fp_strerror(err));
        ok = false;
    }

    /* Stop the data plane. */
    err = fp_dataplane_stop(dp);
    if (fp_error(err)) {
        fprintf(stderr, "error: %s\n", fp_strerror(err));
        ok = false;
    }

    /* Clean up the data plane. */
    fp_dataplane_delete(dp, &err);

    return ok ? 0 : -1;
}
Beispiel #2
0
double sinh(double x)
{
    int sign;
    ip_number ix,r;

    ix=_d2e(x);
    if (fp_uncommon(ix)) goto dom_error;
    sign=fp_sign(ix);
    fp_abs(ix);

    if (fp_grpow(ix,0)) {
        /* _sinh_lnv is REQUIRED to read in as a number with the lower part of   */
        /* its floating point representation zero.                               */
        ip_number w,z,z2;

        w=_esub(ix,&sinh_lnv);
        z=_exp(w);
        if (fp_error(z)) goto range_error;
        if (!fp_grpow(z,32)) {
            ip_number t;
            z2=z;
            t=_erdv(z,&sinh_vm2);
            fp_negate(t);
            z=_eadd(t,&z2);
        }
        z2=z;
        r=_eadd(_emul(z,&sinh_v2m1),&z2);
        fp_abs(r);
        r.word.hi|=sign;
    } else if (!fp_grpow(ix,-32)) return x;
    else {
        ip_number g,t,ix2;
        ix2=ix;
        g=_esquare(ix);
        /* Use a (minimax) rational approximation. See Cody & Waite.     */
        t=__fp_poly1(g,4,sinhp_poly);
        r=_erdv(__fp_poly0(g,3,sinhq_poly),&t);

        ix2.word.hi|=sign;           /* put sign back */
        r=__fp_spike(r,&ix2);        /* r=r*ix+ix */
    }
    if (fp_error(r)) goto range_error;
    return _e2d(r);

dom_error:
    return __fp_edom(sign_bit, TRUE);
range_error:
    return __fp_erange(ix.word.hi, TRUE);
}
Beispiel #3
0
double tanh(double x)
{
  /* The first two exits avoid premature overflow as well as needless use  */
  /* of the exp() function.                                                */
  int sign;
  dp_number fx;

  fx.d=x;

  sign=fp_sign(fx); fp_abs(fx);

  if (fx.d<=27.0) {
    ip_number ix=_d2e(fx.d);
    if (fp_uncommon(ix)) goto uncommon;

    if (_egr(ix,&log3_by_2)) {
      ix=_emul(ix,&two);
      ix=_exp(ix);
      if (fp_error(ix)) goto error;
      ix=_erdv(_eadd(ix,&one),&two); fp_negate(ix); ix=_eadd(ix,&one);
    } else {
      if (fp_grpow(ix,-32)) {
        ip_number g,t,r1,r2,ix2;
        ix2=ix;
        g=_esquare(ix2);
        r1=__fp_poly1(g,3,tanhp_poly);
        r2=__fp_poly0(g,3,tanhq_poly);
        t=_erdv(r2,&r1);
        ix=__fp_spike(t,&ix2);   /* ix=g*ix+ix */
      }
    }
    ix.word.hi|=sign;
    if (fp_error(ix)) goto error;
    return _e2d(ix);
  } else {
    dp_number result;
    result.word.hi=0x3ff00000 | sign;
    result.word.lo=0;
    return result.d;
  }

 error: return __fp_erange(sign, TRUE);
 uncommon: return __fp_edom(0, TRUE);
}
Beispiel #4
0
/* Create a UDP port. */
struct fp_port*
make_port(short p)
{
    fp_error_t err = 0;
    struct fp_device* dev = fp_udp_open_port(p, &err);
    if (fp_error(err)) {
        fprintf(stderr, "error: %s\n", fp_strerror(err));
        return NULL;
    }
    struct fp_port* port = fp_port_create(dev);
    return port;
}
Beispiel #5
0
/* Create a UDP port and add it ot the data plane. Returns
   the port. */
struct fp_port*
add_port(struct fp_dataplane* dp, short p)
{
    /* Make the port. */
    struct fp_port* port = make_port(p);
    if (!port)
        return NULL;

    /* Add the port ot the data plane. */
    fp_error_t err;
    fp_dataplane_add_port(dp, port, &err);
    if (fp_error(err)) {
        fprintf(stderr, "%s\n", fp_strerror(err));
        return NULL;
    }

    return port;
}
Beispiel #6
0
int 
main(int argc, char** argv)
{
  if (argc != 5) {
    fprintf(stderr, "usage: ./test-nadk <name> <pipeline>\n\n");
    fprintf(stderr, " Arguments:\n");
    fprintf(stderr, "    name       the symbolic name of the dataplane\n");
    fprintf(stderr, "    pipeline   the absolute path to a pipeline module\n");
    fprintf(stderr, "    dprc       the name of the NADK resource container\n");
    fprintf(stderr, "    test_type  0: Reflect; 1: XRefelct; "
                    "2:Loopback, 3:XLoopback, 4: Dataplane\n");
    return -1;
  }

  char const* name = argv[1];
  char const* path = argv[2];
  char const* dprc = argv[3];
  const test_type_t test = atoi(argv[4]);

  /* Asynchronous signals that result in attempted graceful exit */
  install_signal_handler();

  fp_error_t err;
  struct fp_dataplane* dp = fp_dataplane_create(name, path, &err);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    return -1;
  }

  /* Hack to initialize NADK framework with passed-in DPRC */
  fp_nadk_init(dprc);

  /* Add ports to the dataplane. */
  struct fp_port* port1 = add_port(dp, 0);
  if (!port1)
    return -1;
  struct fp_port* port2 = add_port(dp, 1);
  if (!port2)
    return -1;

  /* Start the data plane. */
  bool ok = true;
  err = fp_dataplane_start(dp);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    ok = false;
  }

  /* Enter test loop until Ctrl-C (SIGINT) is received */
  printf("Entering packet I/O loop until Ctrl-C (SIGINT) is received\n");
  int i = 0;
  while(!received_sigint) {
    // choose which test to run by run-time parameter:
    switch(test) {
    case TEST_REFLECT:
      reflect_test(port1, port2);
      break;
    case TEST_XREFLECT:
      xreflect_test(port1, port2);
      break;
    case TEST_LOOPBACK:
      loopback_test(port1, port2);
      break;
    case TEST_XLOOPBACK:
      xloopback_test(port1, port2);
      break;
    case TEST_DATAPLANE:
      dataplane_test(dp, port1, port2);
      break;
    default:
      printf("Invalid test_type: %d...\n", test);
      received_sigint = 1;
      break;
    }
  }
  printf("Broke out of processing loop\n");
  
  /* Stop the data plane. */
  err = fp_dataplane_stop(dp);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    ok = false;
  }

  /* Clean up the data plane. */
  fp_dataplane_delete(dp, &err);

  return ok ? 0 : -1;
}