mactime: add a "top" command to watch device stats
[vpp.git] / src / vnet / dhcp / dhcp6_pd_client_dp.h
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef included_vnet_dhcp6_pd_client_dp_h
17 #define included_vnet_dhcp6_pd_client_dp_h
18
19 #include <vlib/vlib.h>
20 #include <vnet/dhcp/dhcp6_client_common_dp.h>
21
22 typedef struct
23 {
24   u32 preferred_lt;
25   u32 valid_lt;
26   ip6_address_t prefix;
27   u8 prefix_length;
28 } dhcp6_pd_send_client_message_params_prefix_t;
29
30 typedef struct
31 {
32   u32 sw_if_index;
33   u32 server_index;
34   u32 irt;
35   u32 mrt;
36   u32 mrc;
37   u32 mrd;
38   u8 msg_type;
39   u32 T1;
40   u32 T2;
41   dhcp6_pd_send_client_message_params_prefix_t *prefixes;
42 } dhcp6_pd_send_client_message_params_t;
43
44 typedef struct
45 {
46   u8 entry_valid;
47   u8 keep_sending_client_message;       /* when true then next fields are valid */
48   dhcp6_pd_send_client_message_params_t params;
49   f64 transaction_start;
50   f64 sleep_interval;
51   f64 due_time;
52   u32 n_left;
53   f64 start_time;
54   u32 transaction_id;
55   vlib_buffer_t *buffer;
56   u32 elapsed_pos;
57   u32 adj_index;
58 } dhcp6_pd_client_state_t;
59
60 typedef struct
61 {
62   dhcp6_pd_client_state_t *client_state_by_sw_if_index;
63
64   uword publisher_node;
65   uword publisher_et;
66
67   u32 seed;
68
69   /* convenience */
70   vlib_main_t *vlib_main;
71   vnet_main_t *vnet_main;
72 } dhcp6_pd_client_main_t;
73
74 extern dhcp6_pd_client_main_t dhcp6_pd_client_main;
75
76 typedef struct
77 {
78   ip6_address_t prefix;
79   u8 prefix_length;
80   u32 valid_time;
81   u32 preferred_time;
82   u16 status_code;
83 } dhcp6_prefix_info_t;
84
85 typedef struct
86 {
87   dhcp6_report_common_t body;
88   u32 n_prefixes;
89   dhcp6_prefix_info_t *prefixes;
90 } prefix_report_t;
91
92 #define vl_typedefs             /* define message structures */
93 #include <vnet/vnet_all_api_h.h>
94 #undef vl_typedefs
95
96 void dhcp6_pd_send_client_message (vlib_main_t * vm, u32 sw_if_index, u8 stop,
97                                    dhcp6_pd_send_client_message_params_t *
98                                    params);
99 void dhcp6_pd_set_publisher_node (uword node_index, uword event_type);
100 int dhcp6_pd_publish_report (prefix_report_t * r);
101
102 void
103   vl_api_want_dhcp6_pd_reply_events_t_handler
104   (vl_api_want_dhcp6_pd_reply_events_t * mp);
105 void
106   vl_api_dhcp6_pd_send_client_message_t_handler
107   (vl_api_dhcp6_pd_send_client_message_t * mp);
108 void
109   vl_api_dhcp6_clients_enable_disable_t_handler
110   (vl_api_dhcp6_clients_enable_disable_t * mp);
111
112 extern vlib_node_registration_t dhcp6_pd_reply_process_node;
113
114 enum
115 { DHCP6_PD_DP_REPLY_REPORT, DHCP6_PD_DP_REPORT_MAX };
116
117 typedef struct _vnet_dhcp6_pd_reply_function_list_elt
118 {
119   struct _vnet_dhcp6_pd_reply_function_list_elt
120     *next_dhcp6_pd_reply_event_function;
121   clib_error_t *(*fp) (vl_api_dhcp6_pd_reply_event_t * mp);
122 } _vnet_dhcp6_pd_reply_event_function_list_elt_t;
123
124 typedef struct
125 {
126   _vnet_dhcp6_pd_reply_event_function_list_elt_t *functions;
127 } dhcp6_pd_client_public_main_t;
128
129 extern dhcp6_pd_client_public_main_t dhcp6_pd_client_public_main;
130
131 #define VNET_DHCP6_PD_REPLY_EVENT_FUNCTION(f)                             \
132                                                                           \
133 static void __vnet_dhcp6_pd_reply_event_function_init_##f (void)          \
134     __attribute__((__constructor__)) ;                                    \
135                                                                           \
136 static void __vnet_dhcp6_pd_reply_event_function_init_##f (void)          \
137 {                                                                         \
138  dhcp6_pd_client_public_main_t * nm = &dhcp6_pd_client_public_main;       \
139  static _vnet_dhcp6_pd_reply_event_function_list_elt_t init_function;     \
140  init_function.next_dhcp6_pd_reply_event_function = nm->functions;        \
141  nm->functions = &init_function;                                          \
142  init_function.fp = (void *) &f;                                          \
143 }                                                                         \
144                                                                           \
145 static void __vnet_dhcp6_pd_reply_event_function_deinit_##f (void)        \
146     __attribute__((__destructor__)) ;                                     \
147                                                                           \
148 static void __vnet_dhcp6_pd_reply_event_function_deinit_##f (void)        \
149 {                                                                         \
150  dhcp6_pd_client_public_main_t * nm = &dhcp6_pd_client_public_main;       \
151  _vnet_dhcp6_pd_reply_event_function_list_elt_t *next;                    \
152  if (nm->functions->fp == (void *) &f)                                    \
153     {                                                                     \
154       nm->functions =                                                     \
155         nm->functions->next_dhcp6_pd_reply_event_function;                \
156       return;                                                             \
157     }                                                                     \
158   next = nm->functions;                                                   \
159   while (next->next_dhcp6_pd_reply_event_function)                        \
160     {                                                                     \
161       if (next->next_dhcp6_pd_reply_event_function->fp == (void *) &f)    \
162         {                                                                 \
163           next->next_dhcp6_pd_reply_event_function =                      \
164             next->next_dhcp6_pd_reply_event_function->next_dhcp6_pd_reply_event_function; \
165           return;                                                         \
166         }                                                                 \
167       next = next->next_dhcp6_pd_reply_event_function;                    \
168     }                                                                     \
169 }
170
171 #endif /* included_vnet_dhcp6_pd_client_dp_h */
172
173 /*
174  * fd.io coding-style-patch-verification: ON
175  *
176  * Local Variables:
177  * eval: (c-set-style "gnu")
178  * End:
179  */