3 * Copyright (C) James R. Leu 2002
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
10 #include "lsr_struct.h"
11 #include "lsr_insegment.h"
12 #include "lsr_xconnect.h"
14 #include "mpls_assert.h"
15 #include "mpls_mm_impl.h"
16 #include "mpls_trace_impl.h"
18 uint32_t _lsr_insegment_next_index
= 1;
20 lsr_insegment
*lsr_insegment_create()
22 lsr_insegment
*i
= (lsr_insegment
*) mpls_malloc(sizeof(lsr_insegment
));
25 memset(i
, 0, sizeof(lsr_insegment
));
26 MPLS_REFCNT_INIT(i
, 0);
27 MPLS_LIST_ELEM_INIT(i
, _outsegment
);
28 MPLS_LIST_ELEM_INIT(i
, _global
);
29 MPLS_LIST_INIT(&i
->xconnect_root
,lsr_xconnect
);
30 i
->index
= _lsr_insegment_get_next_index();
35 void lsr_insegment_delete(lsr_insegment
* i
)
37 // LSR_PRINT(g->user_data,"if delete\n");
38 MPLS_REFCNT_ASSERT(i
, 0);
42 uint32_t _lsr_insegment_get_next_index()
44 uint32_t retval
= _lsr_insegment_next_index
;
46 _lsr_insegment_next_index
++;
47 if (retval
> _lsr_insegment_next_index
) {
48 _lsr_insegment_next_index
= 1;
53 mpls_return_enum
lsr_insegment_add_xconnect(lsr_insegment
*in
, lsr_xconnect
*x
) {
56 MPLS_LIST_ADD_HEAD(&in
->xconnect_root
, x
, _insegment
, lsr_xconnect
);
57 _lsr_xconnect_add_insegment(x
, in
);
63 mpls_return_enum
lsr_insegment_del_xconnect(lsr_insegment
*in
, lsr_xconnect
*x
) {
65 MPLS_LIST_REMOVE(&in
->xconnect_root
, x
, _insegment
);
66 _lsr_xconnect_del_insegment(x
);
67 MPLS_REFCNT_RELEASE(x
, lsr_xconnect_delete
);