mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 17:51:53 +00:00
marking time with 1 and 4 tag
This commit is contained in:
parent
cbd5e4b415
commit
1c4995f9d2
@ -13,15 +13,63 @@ void print_with_size(byte *string, int len)
|
||||
}
|
||||
}
|
||||
|
||||
void print_as_time(long int t)
|
||||
|
||||
void print_time(int64_t time)
|
||||
{
|
||||
int t1 = t TO_S;
|
||||
int t2 = t - t1 S;
|
||||
while (t2 > 999)
|
||||
t2 = t2/10;
|
||||
printf("%i.%i", t1, t2);
|
||||
struct tm tm = *localtime(&time);
|
||||
printf("%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
}
|
||||
|
||||
void print_epoch_time(struct buff_reader *buf_read)
|
||||
{
|
||||
struct value val = get_value(buf_read); // tag time
|
||||
ASSERT(val.val == 1);
|
||||
val = get_value(buf_read); // tag decimal
|
||||
val = get_value(buf_read); // array
|
||||
val = get_value(buf_read);
|
||||
int shift = val.val;
|
||||
val = get_value(buf_read);
|
||||
while (shift > 0)
|
||||
{
|
||||
shift --;
|
||||
val.val *= 10;
|
||||
}
|
||||
int milisec = 0;
|
||||
while (shift < 0)
|
||||
{
|
||||
shift ++;
|
||||
milisec *= 10;
|
||||
milisec += val.val % 10;
|
||||
val.val /= 10;
|
||||
}
|
||||
print_time(val.val);
|
||||
printf(":%i", milisec);
|
||||
}
|
||||
|
||||
void print_relativ_time(struct buff_reader *buf_read)
|
||||
{
|
||||
struct value val = get_value(buf_read); // tag decimal
|
||||
val = get_value(buf_read); // array
|
||||
val = get_value(buf_read);
|
||||
int shift = val.val;
|
||||
val = get_value(buf_read);
|
||||
while (shift > 0)
|
||||
{
|
||||
shift --;
|
||||
val.val *= 10;
|
||||
}
|
||||
int milisec = 0;
|
||||
while (shift < 0)
|
||||
{
|
||||
shift ++;
|
||||
milisec *= 10;
|
||||
milisec += val.val % 10;
|
||||
val.val /= 10;
|
||||
}
|
||||
printf("%li.%i s", val.val, milisec);
|
||||
}
|
||||
|
||||
|
||||
void print_with_size_(byte *string, int len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
@ -121,12 +169,6 @@ void discard_key(struct buff_reader *buf_read)
|
||||
buf_read->pt+=val.val;
|
||||
}
|
||||
|
||||
void print_time(int64_t time)
|
||||
{
|
||||
struct tm tm = *localtime(&time);
|
||||
printf("%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
|
||||
}
|
||||
|
||||
void print_string_string(struct buff_reader *buf_read, char *str)
|
||||
{
|
||||
@ -565,18 +607,6 @@ void print_show_memory(struct buff_reader *buf_read)
|
||||
|
||||
void print_show_status(struct buff_reader *buf_read)
|
||||
{
|
||||
/*
|
||||
print("BIRD", answer["show_status:message"]["version"])
|
||||
for key in answer["show_status:message"]["body"].keys():
|
||||
name = key.replace("_", " ")
|
||||
if key == "router_id":
|
||||
print(name, self.addr_to_str( answer["show_status:message"]["body"][key]))
|
||||
elif key in "server_time last_reboot last_reconfiguration":
|
||||
print(name, datetime.datetime.fromtimestamp(answer["show_status:message"]["body"][key]))
|
||||
else:
|
||||
print(name, answer["show_status:message"]["body"][key])
|
||||
print(answer["show_status:message"]["state"])
|
||||
*/
|
||||
struct value val = get_value(buf_read);
|
||||
ASSERT(val.major == BLOCK);
|
||||
val = get_value(buf_read);
|
||||
@ -617,13 +647,27 @@ void print_show_status(struct buff_reader *buf_read)
|
||||
print_with_size(&buf_read->buff[buf_read->pt], val.val);
|
||||
buf_read->pt+=val.val;
|
||||
printf(": ");
|
||||
val = get_value(buf_read);
|
||||
ASSERT(val.major == UINT);
|
||||
print_time(val.val);
|
||||
print_epoch_time(buf_read);
|
||||
printf("\n");
|
||||
}
|
||||
val = get_value(buf_read);
|
||||
if (val.major != TEXT)
|
||||
if (val.major == TEXT)
|
||||
{
|
||||
buf_read->pt+=val.val;
|
||||
printf("Graceful restart recovery in progress\n");
|
||||
val = get_value(buf_read); // open 2 block
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
printf(" Waiting for %ld channels to recover\n", val.val);
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read); // open 2 block
|
||||
discard_key(buf_read);
|
||||
printf(" Wait timer is ");
|
||||
print_relativ_time(buf_read);
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
printf("/%lu", val.val);
|
||||
}
|
||||
val = get_value(buf_read);
|
||||
ASSERT(val.major == TEXT); // state
|
||||
printf("state: ");
|
||||
@ -854,9 +898,8 @@ void print_rpki_show_proto_info_timer(struct buff_reader *buf_read)
|
||||
if (!val_is_break(val))
|
||||
{
|
||||
buf_read->pt += val.val;
|
||||
val = get_value(buf_read);
|
||||
printf(": ");
|
||||
print_as_time(val.val);
|
||||
print_relativ_time(buf_read);
|
||||
printf("/");
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
@ -918,9 +961,8 @@ void print_show_protocols_rpki(struct buff_reader *buf_read)
|
||||
val = get_value(buf_read);
|
||||
printf(" Serial number: %lu\n", val.val);
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
printf(" Last update: before ");
|
||||
print_as_time(val.val);
|
||||
print_relativ_time(buf_read);
|
||||
printf(" s\n");
|
||||
}
|
||||
else
|
||||
@ -1043,8 +1085,9 @@ void print_bgp_capabilities(struct buff_reader *buf_read)
|
||||
{
|
||||
buf_read->pt += val.val;
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
printf(" Restart time: %lu", val.val);
|
||||
printf(" Restart time: ");
|
||||
print_epoch_time(buf_read);
|
||||
printf("\n");
|
||||
val = get_value(buf_read);
|
||||
if (compare_buff_str(buf_read, val.val, "restart_recovery"))
|
||||
{
|
||||
@ -1095,8 +1138,9 @@ void print_bgp_capabilities(struct buff_reader *buf_read)
|
||||
if (compare_buff_str(buf_read, val.val, "ll_stale_time"))
|
||||
{
|
||||
buf_read->pt += val.val;
|
||||
val = get_value(buf_read);
|
||||
printf(" LL stale time: %lu\n", val.val);
|
||||
printf(" LL stale time: ");
|
||||
print_epoch_time(buf_read);
|
||||
printf("\n");
|
||||
discard_key(buf_read);
|
||||
printf(" AF supported:\n");
|
||||
print_bgp_show_afis(buf_read);
|
||||
@ -1185,9 +1229,8 @@ void print_show_protocols_bgp(struct buff_reader *buf_read)
|
||||
if (compare_buff_str(buf_read, val.val, "error_wait_remains"))
|
||||
{
|
||||
buf_read->pt += val.val;
|
||||
val = get_value(buf_read);
|
||||
printf(" Error wait: ");
|
||||
print_as_time(val.val);
|
||||
print_relativ_time(buf_read);
|
||||
printf("/");
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
@ -1197,21 +1240,19 @@ void print_show_protocols_bgp(struct buff_reader *buf_read)
|
||||
if (compare_buff_str(buf_read, val.val, "connect_remains"))
|
||||
{
|
||||
buf_read->pt += val.val;
|
||||
val = get_value(buf_read);
|
||||
printf(" Connect delay: ");
|
||||
print_as_time(val.val);
|
||||
print_relativ_time(buf_read);
|
||||
printf("/");
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
printf("%lu\n", val.val);
|
||||
val = get_value(buf_read);
|
||||
}
|
||||
if (compare_buff_str(buf_read, val.val, "connect_remains"))
|
||||
if (compare_buff_str(buf_read, val.val, "restart_time"))
|
||||
{
|
||||
buf_read->pt += val.val;
|
||||
val = get_value(buf_read);
|
||||
printf(" Connect delay: ");
|
||||
print_as_time(val.val);
|
||||
printf(" Restart timer: ");
|
||||
print_relativ_time(buf_read);
|
||||
printf("/-\n");
|
||||
val = get_value(buf_read);
|
||||
}
|
||||
@ -1243,18 +1284,16 @@ void print_show_protocols_bgp(struct buff_reader *buf_read)
|
||||
printf("\n");
|
||||
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
printf(" Hold timer: ");
|
||||
print_as_time(val.val);
|
||||
print_relativ_time(buf_read);
|
||||
printf("/");
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
printf("%lu\n", val.val);
|
||||
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
printf(" Keepalive timer: ");
|
||||
print_as_time(val.val);
|
||||
print_relativ_time(buf_read);
|
||||
printf("/");
|
||||
discard_key(buf_read);
|
||||
val = get_value(buf_read);
|
||||
@ -1302,9 +1341,8 @@ void print_show_protocols_bgp(struct buff_reader *buf_read)
|
||||
if (compare_buff_str(buf_read, val.val, "llstale_timer"))
|
||||
{
|
||||
buf_read->pt += val.val;
|
||||
val = get_value(buf_read);
|
||||
printf(" LL stale timer: ");
|
||||
print_as_time(val.val);
|
||||
print_relativ_time(buf_read);
|
||||
printf("/-");
|
||||
val = get_value(buf_read);
|
||||
}
|
||||
@ -1392,8 +1430,7 @@ void print_show_protocols(struct buff_reader *buf_read)
|
||||
print_with_size_add_space(&buf_read->buff[buf_read->pt], val.val, 7);
|
||||
buf_read->pt += val.val;
|
||||
discard_key(buf_read); // since
|
||||
val = get_value(buf_read);
|
||||
print_time(val.val);
|
||||
print_epoch_time(buf_read);
|
||||
printf(" ");
|
||||
discard_key(buf_read); //info
|
||||
val = get_value(buf_read);
|
||||
|
14
nest/cbor.c
14
nest/cbor.c
@ -60,6 +60,20 @@ void cbor_add_int(struct cbor_writer *writer, int64_t item)
|
||||
}
|
||||
}
|
||||
|
||||
void cbor_epoch_time(struct cbor_writer *writer, int64_t time, int shift)
|
||||
{
|
||||
write_item(writer, 6, 1); // 6 is TAG, 1 is tag number for epoch time
|
||||
cbor_relativ_time(writer, time, shift);
|
||||
}
|
||||
|
||||
void cbor_relativ_time(struct cbor_writer *writer, int64_t time, int shift)
|
||||
{
|
||||
write_item(writer, 6, 4); // 6 is TAG, 4 is tag number for decimal fraction
|
||||
cbor_open_list_with_length(writer, 2);
|
||||
cbor_add_int(writer, shift);
|
||||
cbor_add_int(writer, time);
|
||||
}
|
||||
|
||||
void cbor_add_ipv4(struct cbor_writer *writer, uint32_t addr)
|
||||
{
|
||||
write_item(writer, 6, 52); // 6 is TAG, 52 is tag number for ipv4
|
||||
|
@ -31,6 +31,10 @@ void cbor_add_ipv4(struct cbor_writer *writer, uint32_t addr);
|
||||
|
||||
void cbor_add_ipv6(struct cbor_writer *writer, uint32_t addr[4]);
|
||||
|
||||
void cbor_epoch_time(struct cbor_writer *writer, int64_t time, int shift);
|
||||
|
||||
void cbor_relativ_time(struct cbor_writer *writer, int64_t time, int shift);
|
||||
|
||||
void cbor_add_ipv4_prefix(struct cbor_writer *writer, net_addr_ip4 *n);
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ cmd_show_protocols_cbor(byte *tbuf, uint capacity, struct arg_list *args, struct
|
||||
cbor_string_string(w, "proto", p->proto->name);
|
||||
cbor_string_string(w, "table", p->main_channel ? p->main_channel->table->name : "---");
|
||||
cbor_string_string(w, "state", proto_state_name_stolen_for_cbor(p));
|
||||
cbor_string_int(w, "since", preprocess_time(p->last_state_change));
|
||||
cbor_string_epoch_time(w, "since", tm_get_real_time(p->last_state_change), -6);
|
||||
byte buf[256];
|
||||
buf[0] = 0;
|
||||
if (p->proto->get_status)
|
||||
@ -171,19 +171,18 @@ cmd_show_status_cbor(byte *tbuf, uint capacity, struct linpool *lp)
|
||||
cbor_open_block(w);
|
||||
cbor_string_ipv4(w, "router_id", config->router_id);
|
||||
cbor_string_string(w, "hostname", config->hostname);
|
||||
cbor_string_int(w, "server_time", preprocess_time(current_time()));
|
||||
cbor_string_int(w, "last_reboot", preprocess_time(boot_time));
|
||||
cbor_string_int(w, "last_reconfiguration", preprocess_time(config->load_time));
|
||||
cbor_string_epoch_time(w, "server_time", tm_get_real_time(current_time()), -6);
|
||||
cbor_string_epoch_time(w, "last_reboot", tm_get_real_time(boot_time), -6);
|
||||
cbor_string_epoch_time(w, "last_reconfiguration", tm_get_real_time(config->load_time), -6);
|
||||
if (is_gr_active())
|
||||
{
|
||||
log("graceful restart");
|
||||
cbor_add_string(w, "gr_restart");
|
||||
cbor_open_block_with_length(w, 2);
|
||||
cbor_string_int(w, "waiting_for_n_channels_to_recover", get_graceful_restart_locks_num());
|
||||
cbor_add_string(w, "wait_timer");
|
||||
cbor_open_block_with_length(w, 2);
|
||||
cbor_string_int(w, "remains", get_tm_remains_gr_wait_timer());
|
||||
cbor_string_int(w, "count_time", get_config_gr_wait());
|
||||
cbor_string_relativ_time(w, "remains", get_tm_remains_gr_wait_timer(), -6);
|
||||
cbor_string_relativ_time(w, "count_time", get_config_gr_wait(), -6);
|
||||
}
|
||||
cbor_close_block_or_list(w);
|
||||
cbor_add_string(w, "state");
|
||||
@ -194,7 +193,6 @@ cmd_show_status_cbor(byte *tbuf, uint capacity, struct linpool *lp)
|
||||
else
|
||||
cbor_add_string(w, "Daemon is up and running");
|
||||
cbor_write_to_file(w, "test.cbor");
|
||||
log("leaving show status");
|
||||
return w->pt;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,16 @@ void cbor_string_uint(struct cbor_writer *writer, char *key, u64 value) {
|
||||
cbor_add_uint(writer, value);
|
||||
}
|
||||
|
||||
void cbor_string_epoch_time(struct cbor_writer *writer, char *key, int64_t time, int shift) {
|
||||
cbor_add_string(writer, key);
|
||||
cbor_epoch_time(writer, time, shift);
|
||||
}
|
||||
|
||||
void cbor_string_relativ_time(struct cbor_writer *writer, char *key, int64_t time, int shift) {
|
||||
cbor_add_string(writer, key);
|
||||
cbor_relativ_time(writer, time, shift);
|
||||
}
|
||||
|
||||
void cbor_string_ip(struct cbor_writer *writer, char *key, ip_addr addr) {
|
||||
cbor_add_string(writer, key);
|
||||
if (ipa_is_ip4(addr))
|
||||
|
@ -12,6 +12,8 @@ void cbor_string_string(struct cbor_writer *writer, char *key, const char *value
|
||||
|
||||
void cbor_string_int(struct cbor_writer *writer, char *key, int64_t value);
|
||||
|
||||
void cbor_string_epoch_time(struct cbor_writer *writer, char *key, int64_t time, int shift);
|
||||
void cbor_string_relativ_time(struct cbor_writer *writer, char *key, int64_t time, int shift);
|
||||
void cbor_string_uint(struct cbor_writer *writer, char *key, u64 value);
|
||||
void cbor_string_ip(struct cbor_writer *writer, char *key, ip_addr addr);
|
||||
void cbor_string_ipv4(struct cbor_writer *writer, char *key, u32 value);
|
||||
|
@ -2634,7 +2634,7 @@ bgp_show_capabilities_cbor(struct cbor_writer *w, struct bgp_proto *p UNUSED, st
|
||||
if (any_gr_able)
|
||||
{
|
||||
/* Continues from gr_aware */
|
||||
cbor_string_int(w, "restart_time", caps->gr_time);
|
||||
cbor_string_epoch_time(w, "restart_time", caps->gr_time, -6);
|
||||
if (caps->gr_flags & BGP_GRF_RESTART)
|
||||
{
|
||||
cbor_add_string(w, "restart_recovery");
|
||||
@ -2706,7 +2706,7 @@ bgp_show_capabilities_cbor(struct cbor_writer *w, struct bgp_proto *p UNUSED, st
|
||||
}
|
||||
|
||||
/* Continues from llgr_aware */
|
||||
cbor_string_int(w, "ll_stale_time", stale_time);
|
||||
cbor_string_epoch_time(w, "ll_stale_time", stale_time, -6);
|
||||
|
||||
bgp_show_afis_cbor(w, "AF_supported", afl1, afn1);
|
||||
bgp_show_afis_cbor(w, "AF_preserved", afl2, afn2);
|
||||
@ -2877,19 +2877,19 @@ bgp_show_proto_info_cbor(struct cbor_writer *w, struct proto *P)
|
||||
if ((p->start_state < BSS_CONNECT) &&
|
||||
(tm_active(p->startup_timer)))
|
||||
{
|
||||
cbor_string_int(w, "error_wait_remains", tm_remains(p->startup_timer));
|
||||
cbor_string_relativ_time(w, "error_wait_remains", tm_remains(p->startup_timer), -6);
|
||||
cbor_string_int(w, "error_delay", p->startup_delay);
|
||||
}
|
||||
|
||||
if ((oc->state == BS_ACTIVE) &&
|
||||
(tm_active(oc->connect_timer)))
|
||||
{
|
||||
cbor_string_int(w, "connect_remains", tm_remains(oc->connect_timer));
|
||||
cbor_string_relativ_time(w, "connect_remains", tm_remains(oc->connect_timer), -6);
|
||||
cbor_string_int(w, "connect_delay", p->cf->connect_delay_time);
|
||||
}
|
||||
|
||||
if (p->gr_active_num && tm_active(p->gr_timer))
|
||||
cbor_string_int(w, "restart_time", tm_remains(p->gr_timer));
|
||||
cbor_string_relativ_time(w, "restart_time", tm_remains(p->gr_timer), -6);
|
||||
}
|
||||
else if (P->proto_state == PS_UP)
|
||||
{
|
||||
@ -2918,10 +2918,10 @@ bgp_show_proto_info_cbor(struct cbor_writer *w, struct proto *P)
|
||||
|
||||
cbor_string_ip(w, "source_address", p->local_ip);
|
||||
|
||||
cbor_string_int(w, "hold_timer", tm_remains(p->conn->hold_timer));
|
||||
cbor_string_relativ_time(w, "hold_timer", tm_remains(p->conn->hold_timer), -6);
|
||||
cbor_string_int(w, "hold_t_base", p->conn->hold_time);
|
||||
|
||||
cbor_string_int(w, "keepalive_timer", tm_remains(p->conn->keepalive_timer));
|
||||
cbor_string_relativ_time(w, "keepalive_timer", tm_remains(p->conn->keepalive_timer), -6);
|
||||
cbor_string_int(w, "keepalive_t_base", p->conn->keepalive_time);
|
||||
}
|
||||
|
||||
@ -2953,7 +2953,7 @@ bgp_show_proto_info_cbor(struct cbor_writer *w, struct proto *P)
|
||||
cbor_string_string(w, "neighbor_gr", bgp_gr_states[c->gr_active]);
|
||||
|
||||
if (c->stale_timer && tm_active(c->stale_timer))
|
||||
cbor_string_int(w, "llstale_timer", tm_remains(c->stale_timer));
|
||||
cbor_string_relativ_time(w, "llstale_timer", tm_remains(c->stale_timer), -6);
|
||||
|
||||
if (c->c.channel_state == CS_UP)
|
||||
{
|
||||
|
@ -898,7 +898,7 @@ rpki_show_proto_info_timer_cbor(struct cbor_writer *w, const char *name, uint nu
|
||||
cbor_open_block(w);
|
||||
if (tm_active(t))
|
||||
{
|
||||
cbor_string_int(w, "time", tm_remains(t));
|
||||
cbor_string_relativ_time(w, "time", tm_remains(t), -6);
|
||||
cbor_string_int(w, "num", num);
|
||||
}
|
||||
cbor_close_block_or_list(w);
|
||||
@ -953,7 +953,7 @@ rpki_show_proto_info_cbor(struct cbor_writer *w, struct proto *P)
|
||||
if (cache->last_update)
|
||||
{
|
||||
cbor_string_int(w, "serial_num", cache->serial_num);
|
||||
cbor_string_int(w, "last_update", tm_get_real_time(current_time() - cache->last_update) TO_S);
|
||||
cbor_string_relativ_time(w, "last_update", tm_get_real_time(current_time() - cache->last_update), -6);
|
||||
}
|
||||
|
||||
rpki_show_proto_info_timer_cbor(w, "Refresh timer", cache->refresh_interval, cache->refresh_timer);
|
||||
|
Loading…
Reference in New Issue
Block a user