aboutsummaryrefslogtreecommitdiffstats
path: root/doxygen/dir.dox.sample
blob: ccdd095abb2d68a7e4fa7795a9909060d5451f4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * Copyright (c) <YEAR> <YOUR AFFILIATION HERE>
 *
 * 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.
 */

/* Doxygen directory documentation */

/**
@dir
@brief Someone please fix this description.
@todo This directory needs a description.

This is where you would document the contents of a directory.

This looks like a C file but it is not part of the build; it is purely
for documentation.
*/
/*? %%clicmd:group_label CLI section description%% ?*/
/*? %%syscfg:group_label Startup config section description%% ?*/
eyword.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 */
/*
 * Copyright (c) 2015 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.
 */
/*
 *------------------------------------------------------------------
 * srv6_localsid_sample.c - Simple SRv6 LocalSID
 *------------------------------------------------------------------
 */

#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <srv6-localsid/srv6_localsid_sample.h>

#include <vlibapi/api.h>
#include <vlibmemory/api.h>

unsigned char srv6_localsid_name[32] = "Sample-SRv6-LocalSID-plugin";
unsigned char keyword_str[32] = "new_srv6_localsid";
unsigned char def_str[64] = "This is a definition of a sample new_srv6_localsid";
unsigned char params_str[32] = "<fib_table>";

/*****************************************/
/* SRv6 LocalSID instantiation and removal functions */
static int
srv6_localsid_creation_fn (ip6_sr_localsid_t *localsid)
{
  /* 
   * Do you want to do anything fancy upon localsid instantiation?
   * You can do it here
   * (If return != 0 the localsid creation will be cancelled.)
   */
  /* As an example Im going to do a +1 to the fib table inserted by the user */
  srv6_localsid_sample_per_sid_memory_t *ls_mem = localsid->plugin_mem;
  ls_mem->fib_table += 1;
  return 0;
}

static int
srv6_localsid_removal_fn (ip6_sr_localsid_t *localsid)
{
  /* Do you want to do anything fancy upon localsid removal?
   * You can do it here
   * (If return != 0 the localsid removal will be cancelled.)
   */
  /* 
   * BTW if you stored something in localsid->plugin_mem you should clean it now
   */

  //In this example we are only cleaning the memory allocated per localsid
  clib_mem_free(localsid->plugin_mem);
  return 0;
}

/**********************************/
/* SRv6 LocalSID format functions */
/*
 * Prints nicely the parameters of a localsid
 * Example: print "Table 5"
 */
u8 *
format_srv6_localsid_sample (u8 * s, va_list * args)
{
  srv6_localsid_sample_per_sid_memory_t *ls_mem = va_arg (*args, void *);
  return (format (s, "Table: %u", ls_mem->fib_table));
}

/*
 * Process the parameters of a localsid
 * Example: process from:
 * sr localsid address cafe::1 behavior new_srv6_localsid 5
 * everything from behavior on... so in this case 'new_srv6_localsid 5'
 * Notice that it MUST match the keyword_str and params_str defined above.
 */
uword
unformat_srv6_localsid_sample (unformat_input_t * input, va_list * args)
{
  void **plugin_mem = va_arg (*args, void **);
  srv6_localsid_sample_per_sid_memory_t *ls_mem;
  u32 table_id;
  if (unformat (input, "new_srv6_localsid %u", &table_id))
    {
      /* Allocate a portion of memory */
      ls_mem = clib_mem_alloc_aligned_at_offset (
        sizeof(srv6_localsid_sample_per_sid_memory_t), 0, 0, 1);

      /* Set to zero the memory */
      clib_memset (ls_mem, 0, sizeof(srv6_localsid_sample_per_sid_memory_t));

      /* Our brand-new car is ready */
      ls_mem->fib_table = table_id;

      /* Dont forget to add it to the localsid */
      *plugin_mem = ls_mem;
      return 1;
    }
  return 0;
}

/*************************/
/* SRv6 LocalSID FIB DPO */
static u8 *
format_srv6_localsid_sample_dpo (u8 * s, va_list * args)
{
  index_t index = va_arg (*args, index_t);
  CLIB_UNUSED (u32 indent) = va_arg (*args, u32);

  return (format (s, "SR: localsid_sample_index:[%u]", index));
}

void
srv6_localsid_sample_dpo_lock (dpo_id_t * dpo)
{
}

void
srv6_localsid_sample_dpo_unlock (dpo_id_t * dpo)
{
}

const static dpo_vft_t srv6_localsid_sample_vft = {
  .dv_lock = srv6_localsid_sample_dpo_lock,
  .dv_unlock = srv6_localsid_sample_dpo_unlock,
  .dv_format = format_srv6_localsid_sample_dpo,
};

const static char *const srv6_localsid_sample_ip6_nodes[] = {
  "srv6-localsid-sample",
  NULL,
};

const static char *const *const srv6_localsid_sample_nodes[DPO_PROTO_NUM] = {
  [DPO_PROTO_IP6] = srv6_localsid_sample_ip6_nodes,
};

/**********************/
static clib_error_t * srv6_localsid_sample_init (vlib_main_t * vm)
{
  srv6_localsid_sample_main_t * sm = &srv6_localsid_sample_main;
  int rv = 0;
  /* Create DPO */
  sm->srv6_localsid_sample_dpo_type = dpo_register_new_type (
    &srv6_localsid_sample_vft, srv6_localsid_sample_nodes);

  /* Register SRv6 LocalSID */
  rv = sr_localsid_register_function (vm, 
                                  srv6_localsid_name,
                                  keyword_str,
                                  def_str,
                                  params_str,
                                  &sm->srv6_localsid_sample_dpo_type,
                                  format_srv6_localsid_sample, 
                                  unformat_srv6_localsid_sample, 
                                  srv6_localsid_creation_fn, 
                                  srv6_localsid_removal_fn);
  if (rv < 0)
    clib_error_return (0, "SRv6 LocalSID function could not be registered.");
  else
    sm->srv6_localsid_behavior_id = rv;

  return 0;
}

VLIB_INIT_FUNCTION (srv6_localsid_sample_init);

VLIB_PLUGIN_REGISTER () = {
  .version = "1.0",
};