]>
git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_tx_queue.c
507fd489bc621fb3e50bd9f73f1d39e665bf1c46
2 * IS-IS Rout(e)ing protocol - LSP TX Queuing logic
4 * Copyright (C) 2018 Christian Franke
6 * This file is part of FreeRangeRouting (FRR)
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "isisd/isisd.h"
28 #include "isisd/isis_memory.h"
29 #include "isisd/isis_flags.h"
30 #include "isisd/isis_circuit.h"
31 #include "isisd/isis_lsp.h"
32 #include "isisd/isis_misc.h"
33 #include "isisd/isis_tx_queue.h"
35 DEFINE_MTYPE_STATIC(ISISD
, TX_QUEUE
, "ISIS TX Queue")
36 DEFINE_MTYPE_STATIC(ISISD
, TX_QUEUE_ENTRY
, "ISIS TX Queue Entry")
38 struct isis_tx_queue
{
39 struct isis_circuit
*circuit
;
40 void (*send_event
)(struct isis_circuit
*circuit
,
41 struct isis_lsp
*, enum isis_tx_type
);
45 struct isis_tx_queue_entry
{
47 enum isis_tx_type type
;
50 struct isis_tx_queue
*queue
;
53 static unsigned tx_queue_hash_key(const void *p
)
55 const struct isis_tx_queue_entry
*e
= p
;
57 uint32_t id_key
= jhash(e
->lsp
->hdr
.lsp_id
,
58 ISIS_SYS_ID_LEN
+ 2, 0x55aa5a5a);
60 return jhash_1word(e
->lsp
->level
, id_key
);
63 static bool tx_queue_hash_cmp(const void *a
, const void *b
)
65 const struct isis_tx_queue_entry
*ea
= a
, *eb
= b
;
67 if (ea
->lsp
->level
!= eb
->lsp
->level
)
70 if (memcmp(ea
->lsp
->hdr
.lsp_id
, eb
->lsp
->hdr
.lsp_id
,
77 struct isis_tx_queue
*isis_tx_queue_new(
78 struct isis_circuit
*circuit
,
79 void(*send_event
)(struct isis_circuit
*circuit
,
83 struct isis_tx_queue
*rv
= XCALLOC(MTYPE_TX_QUEUE
, sizeof(*rv
));
85 rv
->circuit
= circuit
;
86 rv
->send_event
= send_event
;
88 rv
->hash
= hash_create(tx_queue_hash_key
, tx_queue_hash_cmp
, NULL
);
92 static void tx_queue_element_free(void *element
)
94 struct isis_tx_queue_entry
*e
= element
;
97 thread_cancel(e
->retry
);
99 XFREE(MTYPE_TX_QUEUE_ENTRY
, e
);
102 void isis_tx_queue_free(struct isis_tx_queue
*queue
)
104 hash_clean(queue
->hash
, tx_queue_element_free
);
105 hash_free(queue
->hash
);
106 XFREE(MTYPE_TX_QUEUE
, queue
);
109 static struct isis_tx_queue_entry
*tx_queue_find(struct isis_tx_queue
*queue
,
110 struct isis_lsp
*lsp
)
112 struct isis_tx_queue_entry e
= {
116 return hash_lookup(queue
->hash
, &e
);
119 static int tx_queue_send_event(struct thread
*thread
)
121 struct isis_tx_queue_entry
*e
= THREAD_ARG(thread
);
122 struct isis_tx_queue
*queue
= e
->queue
;
125 thread_add_timer(master
, tx_queue_send_event
, e
, 5, &e
->retry
);
128 queue
->circuit
->area
->lsp_rxmt_count
++;
132 queue
->send_event(queue
->circuit
, e
->lsp
, e
->type
);
133 /* Don't access e here anymore, send_event might have destroyed it */
138 void _isis_tx_queue_add(struct isis_tx_queue
*queue
,
139 struct isis_lsp
*lsp
,
140 enum isis_tx_type type
,
141 const char *func
, const char *file
,
147 if (isis
->debugs
& DEBUG_TX_QUEUE
) {
148 zlog_debug("Add LSP %s to %s queue as %s LSP. (From %s %s:%d)",
149 rawlspid_print(lsp
->hdr
.lsp_id
),
150 queue
->circuit
->interface
->name
,
151 (type
== TX_LSP_CIRCUIT_SCOPED
) ?
152 "circuit scoped" : "regular",
156 struct isis_tx_queue_entry
*e
= tx_queue_find(queue
, lsp
);
158 e
= XCALLOC(MTYPE_TX_QUEUE_ENTRY
, sizeof(*e
));
162 struct isis_tx_queue_entry
*inserted
;
163 inserted
= hash_get(queue
->hash
, e
, hash_alloc_intern
);
164 assert(inserted
== e
);
170 thread_cancel(e
->retry
);
171 thread_add_event(master
, tx_queue_send_event
, e
, 0, &e
->retry
);
176 void _isis_tx_queue_del(struct isis_tx_queue
*queue
, struct isis_lsp
*lsp
,
177 const char *func
, const char *file
, int line
)
182 struct isis_tx_queue_entry
*e
= tx_queue_find(queue
, lsp
);
186 if (isis
->debugs
& DEBUG_TX_QUEUE
) {
187 zlog_debug("Remove LSP %s from %s queue. (From %s %s:%d)",
188 rawlspid_print(lsp
->hdr
.lsp_id
),
189 queue
->circuit
->interface
->name
,
194 thread_cancel(e
->retry
);
196 hash_release(queue
->hash
, e
);
197 XFREE(MTYPE_TX_QUEUE_ENTRY
, e
);
200 unsigned long isis_tx_queue_len(struct isis_tx_queue
*queue
)
205 return hashcount(queue
->hash
);
208 void isis_tx_queue_clean(struct isis_tx_queue
*queue
)
210 hash_clean(queue
->hash
, tx_queue_element_free
);