summaryrefslogtreecommitdiffstats
path: root/pathd/path_pcep_pcc.h
blob: 9e712baf16a5ad94b163a9fc02dc468729eaeea9 (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
/*
 * Copyright (C) 2020  NetDEF, Inc.
 *
 * This program 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 of the License, or (at your option)
 * any later version.
 *
 * This program 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 this program; see the file COPYING; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef _PATH_PCEP_PCC_H_
#define _PATH_PCEP_PCC_H_

#include "typesafe.h"
#include "pathd/path_pcep.h"

enum pcc_status {
	PCEP_PCC_INITIALIZED = 0,
	PCEP_PCC_DISCONNECTED,
	PCEP_PCC_CONNECTING,
	PCEP_PCC_SYNCHRONIZING,
	PCEP_PCC_OPERATING
};

PREDECL_HASH(plspid_map);
PREDECL_HASH(nbkey_map);
PREDECL_HASH(req_map);

struct plspid_map_data {
	struct plspid_map_item mi;
	struct lsp_nb_key nbkey;
	uint32_t plspid;
};

struct nbkey_map_data {
	struct nbkey_map_item mi;
	struct lsp_nb_key nbkey;
	uint32_t plspid;
};

struct req_map_data {
	struct req_map_item mi;
	struct lsp_nb_key nbkey;
	uint32_t reqid;
};

struct req_entry {
	RB_ENTRY(req_entry) entry;
	struct thread *t_retry;
	int retry_count;
	bool was_sent;
	struct path *path;
};
RB_HEAD(req_entry_head, req_entry);
RB_PROTOTYPE(req_entry_head, req_entry, entry, req_entry_compare);

struct pcc_state {
	int id;
	char tag[MAX_TAG_SIZE];
	enum pcc_status status;
	uint16_t flags;
#define F_PCC_STATE_HAS_IPV4 0x0002
#define F_PCC_STATE_HAS_IPV6 0x0004
	struct pcc_opts *pcc_opts;
	struct pce_opts *pce_opts;
	struct in_addr pcc_addr_v4;
	struct in6_addr pcc_addr_v6;
	/* PCC transport source address */
	struct ipaddr pcc_addr_tr;
	char *originator;
	pcep_session *sess;
	uint32_t retry_count;
	bool synchronized;
	struct thread *t_reconnect;
	struct thread *t_update_best;
	struct thread *t_session_timeout;
	uint32_t next_reqid;
	uint32_t next_plspid;
	struct plspid_map_head plspid_map;
	struct nbkey_map_head nbkey_map;
	struct req_map_head req_map;
	struct req_entry_head requests;
	struct pcep_caps caps;
	bool is_best;
	bool previous_best;
};

struct pcc_state *pcep_pcc_initialize(struct ctrl_state *ctrl_state,
				      int pcc_id);
void pcep_pcc_finalize(struct ctrl_state *ctrl_state,
		       struct pcc_state *pcc_state);
int pcep_pcc_enable(struct ctrl_state *ctrl_state, struct pcc_state *pcc_state);
int pcep_pcc_disable(struct ctrl_state *ctrl_state,
		     struct pcc_state *pcc_state);
int pcep_pcc_update(struct ctrl_state *ctrl_state, struct pcc_state *pcc_state,
		    struct pcc_opts *pcc_opts, struct pce_opts *pce_opts);
void pcep_pcc_reconnect(struct ctrl_state *ctrl_state,
			struct pcc_state *pcc_state);
void pcep_pcc_pcep_event_handler(struct ctrl_state *ctrl_state,
				 struct pcc_state *pcc_state,
				 pcep_event *event);
void pcep_pcc_pathd_event_handler(struct ctrl_state *ctrl_state,
				  struct pcc_state *pcc_state,
				  enum pcep_pathd_event_type type,
				  struct path *path);
void pcep_pcc_timeout_handler(struct ctrl_state *ctrl_state,
			      struct pcc_state *pcc_state,
			      enum pcep_ctrl_timeout_type type, void *param);
void pcep_pcc_sync_path(struct ctrl_state *ctrl_state,
			struct pcc_state *pcc_state, struct path *path);
void pcep_pcc_sync_done(struct ctrl_state *ctrl_state,
			struct pcc_state *pcc_state);
/* Send a report explicitly. When doing so the PCC may send multiple reports
 * due to expectations from vendors for the first report to be with a DOWN
 * status. The parameter is_stable is used for that purpose as a hint wheter
 * to expect an update for the report */
void pcep_pcc_send_report(struct ctrl_state *ctrl_state,
			  struct pcc_state *pcc_state, struct path *path,
			  bool is_stable);
void pcep_pcc_send_error(struct ctrl_state *ctrl_state,
			 struct pcc_state *pcc_state, struct pcep_error *path,
			 bool is_stable);
int pcep_pcc_multi_pce_sync_path(struct ctrl_state *ctrl_state, int pcc_id,
				 struct pcc_state **pcc_state_list);
int pcep_pcc_multi_pce_remove_pcc(struct ctrl_state *ctrl_state,
				  struct pcc_state **pcc_state_list);
int pcep_pcc_timer_update_best_pce(struct ctrl_state *ctrl_state, int pcc_id);
int pcep_pcc_calculate_best_pce(struct pcc_state **pcc);
int pcep_pcc_get_pcc_id_by_ip_port(struct pcc_state **pcc,
				   struct pce_opts *pce_opts);
int pcep_pcc_get_pcc_id_by_idx(struct pcc_state **pcc, int idx);
struct pcc_state *pcep_pcc_get_pcc_by_id(struct pcc_state **pcc, int id);
struct pcc_state *pcep_pcc_get_pcc_by_name(struct pcc_state **pcc,
					   const char *pce_name);
int pcep_pcc_get_pcc_idx_by_id(struct pcc_state **pcc, int id);
int pcep_pcc_get_free_pcc_idx(struct pcc_state **pcc);
int pcep_pcc_get_pcc_id(struct pcc_state *pcc);
void pcep_pcc_copy_pcc_info(struct pcc_state **pcc,
			    struct pcep_pcc_info *pcc_info);

#endif // _PATH_PCEP_PCC_H_