3 * Copyright (C) James R. Leu 2001
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
10 #include "ldp_struct.h"
11 #include "ldp_tunnel.h"
12 #include "ldp_hop_list.h"
13 #include "ldp_resource.h"
14 #include "ldp_outlabel.h"
16 #include "mpls_assert.h"
17 #include "mpls_mm_impl.h"
18 #include "mpls_trace_impl.h"
20 static uint32_t _ldp_tunnel_next_index
= 1;
22 ldp_tunnel
*ldp_tunnel_create()
24 ldp_tunnel
*t
= (ldp_tunnel
*) mpls_malloc(sizeof(ldp_tunnel
));
27 memset(t
, 0, sizeof(ldp_tunnel
));
28 MPLS_REFCNT_INIT(t
, 0);
29 MPLS_LIST_ELEM_INIT(t
, _global
);
30 MPLS_LIST_ELEM_INIT(t
, _outlabel
);
32 t
->index
= _ldp_tunnel_get_next_index();
37 void ldp_tunnel_delete(ldp_tunnel
* t
)
39 // LDP_PRINT(g->user_data,"tunnel delete\n");
40 MPLS_REFCNT_ASSERT(t
, 0);
44 uint32_t _ldp_tunnel_get_next_index()
46 uint32_t retval
= _ldp_tunnel_next_index
;
48 _ldp_tunnel_next_index
++;
49 if (retval
> _ldp_tunnel_next_index
) {
50 _ldp_tunnel_next_index
= 1;
55 mpls_bool
ldp_tunnel_is_active(ldp_tunnel
* t
)
57 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
58 return MPLS_BOOL_TRUE
;
60 return MPLS_BOOL_FALSE
;
63 mpls_bool
ldp_tunnel_is_ready(ldp_tunnel
* t
)
65 return MPLS_BOOL_TRUE
;
68 mpls_return_enum
ldp_tunnel_add_resource(ldp_tunnel
* t
, ldp_resource
* r
)
72 MPLS_ASSERT(t
->resource
== NULL
);
74 _ldp_resource_add_tunnel(r
, t
);
80 mpls_return_enum
ldp_tunnel_del_resource(ldp_tunnel
* t
)
82 if (t
&& t
->resource
) {
83 _ldp_resource_del_tunnel(t
->resource
);
84 MPLS_REFCNT_RELEASE(t
->resource
, ldp_resource_delete
);
91 mpls_return_enum
ldp_tunnel_add_hop_list(ldp_tunnel
* t
, ldp_hop_list
* h
)
95 MPLS_ASSERT(t
->hop_list
== NULL
);
97 _ldp_hop_list_add_tunnel(h
, t
);
103 mpls_return_enum
ldp_tunnel_del_hop_list(ldp_tunnel
* t
)
105 if (t
&& t
->hop_list
) {
106 _ldp_hop_list_del_tunnel(t
->hop_list
);
107 MPLS_REFCNT_RELEASE(t
->hop_list
, ldp_hop_list_delete
);
114 mpls_return_enum
ldp_tunnel_add_outlabel(ldp_tunnel
* t
, ldp_outlabel
* o
)
118 MPLS_ASSERT(t
->outlabel
== NULL
);
120 _ldp_outlabel_add_tunnel(o
, t
);
126 mpls_return_enum
ldp_tunnel_del_outlabel(ldp_tunnel
* t
)
128 if (t
&& t
->outlabel
) {
129 _ldp_outlabel_del_tunnel(t
->outlabel
, t
);
130 MPLS_REFCNT_RELEASE(t
->outlabel
, ldp_outlabel_delete
);
137 mpls_return_enum
ldp_tunnel_startup(ldp_global
* global
, ldp_tunnel
* tunnel
)
142 mpls_return_enum
ldp_tunnel_shutdown(ldp_global
* global
, ldp_tunnel
* tunnel
,