summaryrefslogtreecommitdiff
path: root/ospf6d/ospf6_top.c
blob: a8a058f2c254e1c3f3c05ba01bfdff50ac807a6d (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*
 * OSPFv3 Top Level Data Structure
 * Copyright (C) 1999 Yasuhiro Ohara
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * GNU Zebra is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Zebra; see the file COPYING.  If not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA 02111-1307, USA.  
 */

#include <zebra.h>

#include "log.h"
#include "memory.h"
#include "vty.h"
#include "linklist.h"
#include "prefix.h"
#include "table.h"
#include "thread.h"
#include "command.h"

#include "ospf6_hook.h"
#include "ospf6_proto.h"
#include "ospf6_prefix.h"
#include "ospf6_lsa.h"
#include "ospf6_lsdb.h"

#include "ospf6_message.h"
#include "ospf6_neighbor.h"
#include "ospf6_interface.h"
#include "ospf6_area.h"
#include "ospf6_top.h"

#include "ospf6_route.h"
#include "ospf6_zebra.h"

#include "ospf6_nsm.h"
#include "ospf6_asbr.h"
#include "ospf6_abr.h"

#define HEADER_DEPENDENCY
#include "ospf6d.h"
#undef HEADER_DEPENDENCY

/* global ospf6d variable */
struct ospf6 *ospf6;

static void
ospf6_top_foreach_area (struct ospf6 *o6, void *arg, int val,
                        void (*func) (void *, int, void *))
{
  listnode node;
  struct ospf6_area *o6a;

  for (node = listhead (o6->area_list); node; nextnode (node))
    {
      o6a = (struct ospf6_area *) getdata (node);
      (*func) (arg, val, o6a);
    }
}

static void
ospf6_top_foreach_interface (struct ospf6 *o6, void *arg, int val,
                             void (*func) (void *, int, void *))
{
  listnode node;
  struct ospf6_area *o6a;

  for (node = listhead (o6->area_list); node; nextnode (node))
    {
      o6a = (struct ospf6_area *) getdata (node);
      (*o6a->foreach_if) (o6a, arg, val, func);
    }
}

static void
ospf6_top_foreach_neighbor (struct ospf6 *o6, void *arg, int val,
                            void (*func) (void *, int, void *))
{
  listnode node;
  struct ospf6_area *o6a;

  for (node = listhead (o6->area_list); node; nextnode (node))
    {
      o6a = (struct ospf6_area *) getdata (node);
      (*o6a->foreach_nei) (o6a, arg, val, func);
    }
}

static int
ospf6_top_maxage_remover (struct thread *t)
{
  int count;
  struct ospf6 *o6 = (struct ospf6 *) THREAD_ARG (t);

  o6->maxage_remover = (struct thread *) NULL;

  count = 0;
  o6->foreach_nei (o6, &count, NBS_EXCHANGE, ospf6_count_state);
  o6->foreach_nei (o6, &count, NBS_LOADING, ospf6_count_state);
  if (count != 0)
    return 0;

  ospf6_lsdb_remove_maxage (o6->lsdb);
  return 0;
}

void
ospf6_top_schedule_maxage_remover (void *arg, int val, struct ospf6 *o6)
{
  if (o6->maxage_remover != NULL)
    return;

  o6->maxage_remover =
    thread_add_event (master, ospf6_top_maxage_remover, o6, 0);
}

void
ospf6_show (struct vty *vty)
{
  listnode n;
  struct ospf6_area *area;
  char id_string[32];
  unsigned long day, hour, min, sec;
  struct timeval now, running;

  /* process id, router id */
  inet_ntop (AF_INET, &ospf6->router_id, id_string, sizeof (id_string));
  vty_out (vty, " Routing Process (%lu) with ID %s%s",
           ospf6->process_id, id_string, VTY_NEWLINE);

  /* running time */
  gettimeofday (&now, (struct timezone *)NULL);
  ospf6_timeval_sub (&now, &ospf6->starttime, &running);
  ospf6_timeval_decode (&running, &day, &hour, &min, &sec, NULL, NULL);
  vty_out (vty, " Running %ld days %ld hours %ld minutes %ld seconds%s",
           day, hour, min, sec, VTY_NEWLINE);

  vty_out (vty, " Supports only single TOS(TOS0) routes%s", VTY_NEWLINE);

  /* Redistribute config */
  ospf6_redistribute_show_config (vty);

  /* LSAs */
  vty_out (vty, " Number of AS scoped LSAs is %u%s",
           ospf6->lsdb->count, VTY_NEWLINE);
  vty_out (vty, " Route calculation executed %d times%s",
           ospf6->stat_route_calculation_execed, VTY_NEWLINE);

  /* Route Statistics */
#if 0
  ospf6_route_statistics_show (vty, ospf6->route_table);
#endif

  /* Areas */
  vty_out (vty, " Number of areas in this router is %u%s",
           listcount (ospf6->area_list), VTY_NEWLINE);
  for (n = listhead (ospf6->area_list); n; nextnode (n))
    {
      area = (struct ospf6_area *) getdata (n);
      ospf6_area_show (vty, area);
    }
}

void
ospf6_statistics_show (struct vty *vty, struct ospf6 *o6)
{
  listnode node;
  struct ospf6_area *o6a;
  char running_time[128];
  struct timeval now, running;

  gettimeofday (&now, (struct timezone *) NULL);
  ospf6_timeval_sub (&now, &o6->starttime, &running);
  ospf6_timeval_string (&running, running_time, sizeof (running_time));

  vty_out (vty, "Statistics of OSPF process %ld%s",
           o6->process_id, VTY_NEWLINE);
  vty_out (vty, "  Running: %s%s", running_time, VTY_NEWLINE);

#if 0
  ospf6_route_statistics_show (vty, o6->route_table);
#endif

  for (node = listhead (o6->area_list); node; nextnode (node))
    {
      o6a = (struct ospf6_area *) getdata (node);
      ospf6_area_statistics_show (vty, o6a);
    }
}

static struct ospf6 *
ospf6_new ()
{
  struct ospf6 *new;
  new = XMALLOC (MTYPE_OSPF6_TOP, sizeof (struct ospf6));
  if (new)
    memset (new, 0, sizeof (struct ospf6));
  return new;
}

void
ospf6_free (struct ospf6 *ospf6)
{
  XFREE (MTYPE_OSPF6_TOP, ospf6);
}

void
ospf6_top_topology_add (struct ospf6_route_req *request)
{
  assert (request->route.type == OSPF6_DEST_TYPE_ROUTER);
  if (CHECK_FLAG (request->path.router_bits, OSPF6_ROUTER_LSA_BIT_E))
    ospf6_asbr_asbr_entry_add (request);
}

void
ospf6_top_topology_remove (struct ospf6_route_req *request)
{
  assert (request->route.type == OSPF6_DEST_TYPE_ROUTER);
  if (CHECK_FLAG (request->path.router_bits, OSPF6_ROUTER_LSA_BIT_E))
    ospf6_asbr_asbr_entry_remove (request);
}

struct ospf6 *
ospf6_create (unsigned long process_id)
{
  struct ospf6 *o6;
  char namebuf[64];

  o6 = ospf6_new ();

  /* initialize */
  gettimeofday (&o6->starttime, (struct timezone *)NULL);
  o6->process_id = process_id;
  o6->version = OSPF6_VERSION;
  o6->area_list = list_new ();

  o6->lsdb = ospf6_lsdb_create ();

  o6->foreach_area = ospf6_top_foreach_area;
  o6->foreach_if = ospf6_top_foreach_interface;
  o6->foreach_nei = ospf6_top_foreach_neighbor;

  snprintf (namebuf, sizeof (namebuf), "InterTopology table");
  o6->topology_table = ospf6_route_table_create (namebuf);
  ospf6_route_hook_register (ospf6_top_topology_add,
                             ospf6_top_topology_add,
                             ospf6_top_topology_remove,
                             o6->topology_table);

#if 0
  snprintf (namebuf, sizeof (namebuf), "External table");
  o6->external_table = ospf6_route_table_create (namebuf);
  ospf6_route_hook_register (ospf6_asbr_external_route_add,
                             ospf6_asbr_external_route_add,
                             ospf6_asbr_external_route_remove,
                             o6->external_table);
#endif /*0*/

  snprintf (namebuf, sizeof (namebuf), "Top route table");
  o6->route_table = ospf6_route_table_create (namebuf);
  ospf6_route_hook_register (ospf6_zebra_route_update_add,
                             ospf6_zebra_route_update_add,
                             ospf6_zebra_route_update_remove,
                             o6->route_table);
  ospf6_route_hook_register (ospf6_abr_route_add,
                             ospf6_abr_route_add,
                             ospf6_abr_route_remove,
                             o6->route_table);

  return o6;
}

void
ospf6_delete (struct ospf6 *ospf6)
{
  ospf6_route_remove_all (ospf6->route_table);
  ospf6_free (ospf6);
}

struct ospf6 *
ospf6_start ()
{
  if (ospf6)
    return ospf6;

  ospf6 = ospf6_create (0);
  return ospf6;
}

void
ospf6_stop ()
{
  if (!ospf6)
    return;

  ospf6_delete (ospf6);
  ospf6 = NULL;
}

int
ospf6_is_asbr (struct ospf6 *o6)
{
  int i = 0;
  i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_SYSTEM);
  i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_CONNECT);
  i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_STATIC);
  i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_KERNEL);
  i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_RIPNG);
  i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_BGP);
  return (i);
}

DEFUN (show_ipv6_ospf6_route,
       show_ipv6_ospf6_route_cmd,
       "show ipv6 ospf6 route",
       SHOW_STR
       IP6_STR
       OSPF6_STR
       "Routing table\n"
       )
{
  OSPF6_CMD_CHECK_RUNNING ();
  return ospf6_route_table_show (vty, argc, argv, ospf6->route_table);
}

ALIAS (show_ipv6_ospf6_route,
       show_ipv6_ospf6_route_prefix_cmd,
       "show ipv6 ospf6 route (X::X|detail)",
       SHOW_STR
       IP6_STR
       OSPF6_STR
       "Routing table\n"
       "match IPv6 prefix\n"
       )

DEFUN (show_ipv6_ospf6_topology,
       show_ipv6_ospf6_topology_cmd,
       "show ipv6 ospf6 topology",
       SHOW_STR
       IP6_STR
       OSPF6_STR
       "Inter Area topology information\n"
       )
{
  OSPF6_CMD_CHECK_RUNNING ();
  return ospf6_route_table_show (vty, argc, argv, ospf6->topology_table);
}

ALIAS (show_ipv6_ospf6_topology,
       show_ipv6_ospf6_topology_router_cmd,
       "show ipv6 ospf6 topology (A.B.C.D|<0-4294967295>|detail)",
       SHOW_STR
       IP6_STR
       OSPF6_STR
       "Inter Area topology information\n"
       OSPF6_ROUTER_ID_STR
       OSPF6_ROUTER_ID_STR
       "Detailed information\n"
       )

ALIAS (show_ipv6_ospf6_topology,
       show_ipv6_ospf6_topology_router_lsid_cmd,
       "show ipv6 ospf6 topology (A.B.C.D|<0-4294967295>) (A.B.C.D|<0-4294967295>)",
       SHOW_STR
       IP6_STR
       OSPF6_STR
       "Inter Area topology information\n"
       OSPF6_ROUTER_ID_STR
       OSPF6_ROUTER_ID_STR
       OSPF6_LS_ID_STR
       OSPF6_LS_ID_STR
       )

void
ospf6_top_init ()
{
  install_element (VIEW_NODE, &show_ipv6_ospf6_route_cmd);
  install_element (VIEW_NODE, &show_ipv6_ospf6_route_prefix_cmd);
  install_element (VIEW_NODE, &show_ipv6_ospf6_topology_cmd);
  install_element (VIEW_NODE, &show_ipv6_ospf6_topology_router_cmd);
  install_element (VIEW_NODE, &show_ipv6_ospf6_topology_router_lsid_cmd);
  install_element (ENABLE_NODE, &show_ipv6_ospf6_route_cmd);
  install_element (ENABLE_NODE, &show_ipv6_ospf6_route_prefix_cmd);
  install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_cmd);
  install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_router_cmd);
  install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_router_lsid_cmd);
}