aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/vagrant
AgeCommit message (Expand)AuthorFilesLines
2018-03-21HC Tests: adapt sub-interface tests to recent api changes (HC2VPP-289)Marek Gradzki1-0/+29
2016-07-01CSIT-186: Add multilink to Vagrant fileMatej Klotton1-22/+31
2016-06-09Fix Vagrant config for multi-user environmentAurélien Degeorges1-4/+9
2016-06-02CSIT-117: CSIT Vagrant+Virtualbox dev environment inoperative on UbuntuDave Wallace2-27/+19
2016-06-02CSIT-117: CSIT Vagrant+Virtualbox dev environment inoperative on UbuntuDave Wallace2-11/+24
2016-04-08Add Vagrantfile for local testing.Stefan Kobza2-0/+123
ht .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 *------------------------------------------------------------------
 * persist.c - persistent data structure storage test / demo code
 *
 * Copyright (c) 2013 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <signal.h>
#include <pthread.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <vppinfra/clib.h>
#include <vppinfra/vec.h>
#include <vppinfra/hash.h>
#include <vppinfra/bitmap.h>
#include <vppinfra/fifo.h>
#include <vppinfra/time.h>
#include <vppinfra/mheap.h>
#include <vppinfra/heap.h>
#include <vppinfra/pool.h>
#include <vppinfra/format.h>
#include <vppinfra/serialize.h>
#include <svmdb.h>

typedef struct
{
  svmdb_client_t *c;
} persist_main_t;

persist_main_t persist_main;

typedef struct
{
  u8 *string1;
  u8 *string2;
} demo_struct2_t;

typedef struct
{
  demo_struct2_t *demo2;
  u8 *name;
} demo_struct1_t;

/*
 * Data structures in persistent shared memory, all the time
 */
clib_error_t *
persist_malloc (persist_main_t * pm)
{
  demo_struct2_t *demo2;
  demo_struct1_t *demo1;
  time_t starttime = time (0);
  char *datestring = ctime (&starttime);
  void *oldheap;

  /* Get back the root pointer */
  demo1 = svmdb_local_get_variable_reference
    (pm->c, SVMDB_NAMESPACE_VEC, "demo1_location");

  /* It doesnt exist create our data structures */
  if (demo1 == 0)
    {
      /* If you want MP / thread safety, lock the region... */
      pthread_mutex_lock (&pm->c->db_rp->mutex);

      /* Switch to the shared memory region heap */
      oldheap = svm_push_data_heap (pm->c->db_rp);

      /* Allocate the top-level structure as a single element vector */
      vec_validate (demo1, 0);

      /* Allocate the next-level structure as a plain old memory obj */
      demo2 = clib_mem_alloc (sizeof (*demo2));

      demo1->demo2 = demo2;
      demo1->name = format (0, "My name is Ishmael%c", 0);
      demo2->string1 = format (0, "Here is string1%c", 0);
      demo2->string2 = format (0, "Born at %s%c", datestring, 0);

      /* Back to the process-private heap */
      svm_pop_heap (oldheap);
      pthread_mutex_unlock (&pm->c->db_rp->mutex);

      /*
       * Set the root pointer. Note: this guy switches heaps, locks, etc.
       * We allocated demo1 as a vector to make this "just work..."
       */
      svmdb_local_set_vec_variable (pm->c, "demo1_location",
				    demo1, sizeof (demo1));

    }
  else
    {
      /* retrieve and print data from shared memory */
      demo2 = demo1->demo2;
      fformat (stdout, "name: %s\n", demo1->name);
      fformat (stdout, "demo2 location: %llx\n", demo2);
      fformat (stdout, "string1: %s\n", demo2->string1);
      fformat (stdout, "string2: %s\n", demo2->string2);
    }
  return 0;
}

void
unserialize_demo1 (serialize_main_t * sm, va_list * args)
{
  demo_struct1_t **result = va_arg (*args, demo_struct1_t **);
  demo_struct1_t *demo1;
  demo_struct2_t *demo2;

  /* Allocate data structures in process private memory */
  demo1 = clib_mem_alloc (sizeof (*demo1));
  demo2 = clib_mem_alloc (sizeof (*demo2));
  demo1->demo2 = demo2;

  /* retrieve data from shared memory checkpoint */
  unserialize_cstring (sm, (char **) &demo1->name);
  unserialize_cstring (sm, (char **) &demo2->string1);
  unserialize_cstring (sm, (char **) &demo2->string2);
  *result = demo1;
}

void
serialize_demo1 (serialize_main_t * sm, va_list * args)
{
  demo_struct1_t *demo1 = va_arg (*args, demo_struct1_t *);
  demo_struct2_t *demo2 = demo1->demo2;

  serialize_cstring (sm, (char *) demo1->name);
  serialize_cstring (sm, (char *) demo2->string1);
  serialize_cstring (sm, (char *) demo2->string2);
}

/* Serialize / unserialize variant */
clib_error_t *
persist_serialize (persist_main_t * pm)
{
  u8 *checkpoint;
  serialize_main_t sm;

  demo_struct2_t *demo2;
  demo_struct1_t *demo1;
  time_t starttime = time (0);
  char *datestring = ctime (&starttime);

  /* Get back the root pointer */
  checkpoint = svmdb_local_get_vec_variable (pm->c, "demo1_checkpoint",
					     sizeof (u8));

  /* It doesnt exist create our data structures */
  if (checkpoint == 0)
    {
      /* Allocate data structures in process-private memory */
      demo1 = clib_mem_alloc (sizeof (*demo2));
      vec_validate (demo1, 0);
      demo2 = clib_mem_alloc (sizeof (*demo2));

      demo1->demo2 = demo2;
      demo1->name = format (0, "My name is Ishmael%c", 0);
      demo2->string1 = format (0, "Here is string1%c", 0);
      demo2->string2 = format (0, "Born at %s%c", datestring, 0);

      /* Create checkpoint */
      serialize_open_vector (&sm, checkpoint);
      serialize (&sm, serialize_demo1, demo1);
      checkpoint = serialize_close_vector (&sm);

      /* Copy checkpoint into shared memory */
      svmdb_local_set_vec_variable (pm->c, "demo1_checkpoint",
				    checkpoint, sizeof (u8));
      /* Toss the process-private-memory original.. */
      vec_free (checkpoint);
    }
  else
    {
      /* Open the checkpoint */
      unserialize_open_data (&sm, checkpoint, vec_len (checkpoint));
      unserialize (&sm, unserialize_demo1, &demo1);

      /* Toss the process-private-memory checkpoint copy */
      vec_free (checkpoint);

      /* Off we go... */
      demo2 = demo1->demo2;
      fformat (stdout, "name: %s\n", demo1->name);
      fformat (stdout, "demo2 location: %llx\n", demo2);
      fformat (stdout, "string1: %s\n", demo2->string1);
      fformat (stdout, "string2: %s\n", demo2->string2);
    }
  return 0;
}


int
main (int argc, char **argv)
{
  unformat_input_t _input, *input = &_input;
  persist_main_t *pm = &persist_main;
  clib_error_t *error = 0;

  /* Make a 4mb database arena, chroot so it's truly private */
  pm->c = svmdb_map_chroot_size ("/ptest", 4 << 20);

  ASSERT (pm->c);

  unformat_init_command_line (input, argv);

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "malloc"))
	error = persist_malloc (pm);
      else if (unformat (input, "serialize"))
	error = persist_serialize (pm);
      else
	{
	  error = clib_error_return (0, "Unknown flavor '%U'",
				     format_unformat_error, input);
	  break;
	}
    }

  svmdb_unmap (pm->c);

  if (error)
    {
      clib_error_report (error);
      exit (1);
    }
  return 0;
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */