summaryrefslogtreecommitdiffstats
path: root/src/plugins/ioam/analyse/ip6/ip6_ioam_analyse.c
blob: 9db0485da616ab81355d893be41db1390f9826fa (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Copyright (c) 2017 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 <vnet/ethernet/ethernet.h>
#include <ioam/analyse/ioam_analyse.h>
#include <ioam/export-common/ioam_export.h>
#include <ioam/analyse/ip6/ip6_ioam_analyse.h>
#include <ioam/analyse/ioam_summary_export.h>
#include <vnet/ip/ip.h>
#include <ioam/ipfixcollector/ipfixcollector.h>

extern ioam_export_main_t ioam_export_main;
static clib_error_t *
ioam_analyse_enable_disable (vlib_main_t * vm,
			     int is_add, int is_export, int remote_listen)
{
  ipfix_client_add_del_t ipfix_reg;
  clib_error_t *rv = 0;

  ipfix_reg.client_name = format (0, "ip6-hbh-analyse-remote");
  ipfix_reg.client_node = analyse_node_remote.index;
  ipfix_reg.ipfix_setid = IPFIX_IOAM_EXPORT_ID;

  if (is_export)
    {
      rv = ioam_flow_create (!is_add);
      if (rv)
	goto ret;
    }

  if (is_add)
    {
      ip6_ioam_analyse_register_handlers ();
      if (remote_listen)
	{
	  ipfix_reg.del = 0;
	  ipfix_collector_reg_setid (vm, &ipfix_reg);
	}
      else
	{
	  ioam_export_set_next_node (&ioam_export_main,
				     (u8 *) "ip6-hbh-analyse-local");
	}
    }
  else
    {
      ip6_ioam_analyse_unregister_handlers ();
      if (remote_listen)
	{
	  ipfix_reg.del = 1;
	  ipfix_collector_reg_setid (vm, &ipfix_reg);
	}
      else
	ioam_export_reset_next_node (&ioam_export_main);
    }

ret:
  vec_free (ipfix_reg.client_name);
  return rv;
}

static clib_error_t *
set_ioam_analyse_command_fn (vlib_main_t * vm, unformat_input_t * input,
			     vlib_cli_command_t * cmd)
{
  int is_export = 0;
  int is_add = 1;
  int remote_listen = 0;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "export-ipfix-collector"))
	is_export = 1;
      else if (unformat (input, "disable"))
	is_add = 0;
      else if (unformat (input, "listen-ipfix"))
	remote_listen = 1;
      else
	break;
    }

  return (ioam_analyse_enable_disable (vm, is_add, is_export, remote_listen));
}

VLIB_CLI_COMMAND (set_ioam_analyse_command, static) = {
  .path = "set ioam analyse",
  .short_help = "set ioam analyse [export-ipfix-collector] [disable] [listen-ipfix]",
  .function = set_ioam_analyse_command_fn,
};

static clib_error_t *
show_ioam_analyse_cmd_fn (vlib_main_t * vm, unformat_input_t * input,
			  vlib_cli_command_t * cmd)
{
  ip6_ioam_analyser_main_t *am = &ioam_analyser_main;
  ioam_analyser_data_t *record = NULL;
  u8 i;
  u8 *s = 0;

  vec_reset_length (s);
  s = format (0, "iOAM Analyse Information: \n");
  vec_foreach_index (i, am->aggregated_data)
  {
    record = am->aggregated_data + i;
    if (record->is_free)
      continue;

    s = format (s, "Flow Number: %u\n", i);
    s = print_analyse_flow (s, record);
    s = format (s, "\n");
  }
  vlib_cli_output (vm, "%v", s);

  vec_free (s);

  return 0;
}

VLIB_CLI_COMMAND (ip6_show_ioam_ipfix_cmd, static) = {
  .path = "show ioam analyse ",
  .short_help = "show ioam analyser information",
  .function = show_ioam_analyse_cmd_fn,
};

static clib_error_t *
ioam_analyse_init (vlib_main_t * vm)
{
  ip6_ioam_analyser_main_t *am = &ioam_analyser_main;
  u16 i;

  vec_validate_aligned (am->aggregated_data, 50, CLIB_CACHE_LINE_BYTES);
  vec_foreach_index (i, am->aggregated_data)
  {
    ioam_analyse_init_data (am->aggregated_data + i);
  }

  return 0;
}

VLIB_INIT_FUNCTION (ioam_analyse_init);

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