]> git.proxmox.com Git - mirror_frr.git/blame - eigrpd/eigrp_metric.c
Merge pull request #7676 from ton31337/fix/show_ip_bgp_summary_description_truncate
[mirror_frr.git] / eigrpd / eigrp_metric.c
CommitLineData
e9f1847e
DS
1/*
2 * EIGRP Metric Math Functions.
3 * Copyright (C) 2013-2016
4 * Authors:
5 * Donnie Savage
6 *
7 * This file is part of GNU Zebra.
8 *
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include "eigrpd/eigrp_structs.h"
25#include "eigrpd/eigrpd.h"
26#include "eigrpd/eigrp_types.h"
27#include "eigrpd/eigrp_metric.h"
28
29eigrp_scaled_t eigrp_bandwidth_to_scaled(eigrp_bandwidth_t bandwidth)
30{
31 eigrp_bandwidth_t scaled = EIGRP_BANDWIDTH_MAX;
32
33 if (bandwidth != EIGRP_BANDWIDTH_MAX) {
34 scaled = (EIGRP_CLASSIC_SCALER * EIGRP_BANDWIDTH_SCALER);
35 scaled = scaled / bandwidth;
36
37 scaled = scaled ? scaled : EIGRP_BANDWIDTH_MIN;
38 }
39
40 scaled = (scaled < EIGRP_METRIC_MAX) ? scaled : EIGRP_METRIC_MAX;
41 return (eigrp_scaled_t)scaled;
42}
43
44eigrp_bandwidth_t eigrp_scaled_to_bandwidth(eigrp_scaled_t scaled)
45{
46 eigrp_bandwidth_t bandwidth = EIGRP_BANDWIDTH_MAX;
47
48 if (scaled != EIGRP_CLASSIC_MAX) {
49 bandwidth = (EIGRP_CLASSIC_SCALER * EIGRP_BANDWIDTH_SCALER);
50 bandwidth = scaled * bandwidth;
51 bandwidth = (bandwidth < EIGRP_METRIC_MAX)
52 ? bandwidth
53 : EIGRP_BANDWIDTH_MAX;
54 }
55
56 return bandwidth;
57}
58
59eigrp_scaled_t eigrp_delay_to_scaled(eigrp_delay_t delay)
60{
61 delay = delay ? delay : EIGRP_DELAY_MIN;
62 return delay * EIGRP_CLASSIC_SCALER;
63}
64
65eigrp_delay_t eigrp_scaled_to_delay(eigrp_scaled_t scaled)
66{
67 scaled = scaled / EIGRP_CLASSIC_SCALER;
68 scaled = scaled ? scaled : EIGRP_DELAY_MIN;
69
70 return scaled;
71}
72
73eigrp_metric_t eigrp_calculate_metrics(struct eigrp *eigrp,
74 struct eigrp_metrics metric)
75{
76 eigrp_metric_t composite = 0;
77
78 if (metric.delay == EIGRP_MAX_METRIC)
79 return EIGRP_METRIC_MAX;
80
81 /*
82 * EIGRP Composite =
83 * {K1*BW+[(K2*BW)/(256-load)]+(K3*delay)}*{K5/(reliability+K4)}
84 */
85
86 if (eigrp->k_values[0])
87 composite += (eigrp->k_values[0] * metric.bandwidth);
88 if (eigrp->k_values[1])
89 composite += ((eigrp->k_values[1] * metric.bandwidth)
90 / (256 - metric.load));
91 if (eigrp->k_values[2])
92 composite += (eigrp->k_values[2] * metric.delay);
93 if (eigrp->k_values[3] && !eigrp->k_values[4])
94 composite *= eigrp->k_values[3];
95 if (!eigrp->k_values[3] && eigrp->k_values[4])
96 composite *= (eigrp->k_values[4] / metric.reliability);
97 if (eigrp->k_values[3] && eigrp->k_values[4])
98 composite *= ((eigrp->k_values[4] / metric.reliability)
99 + eigrp->k_values[3]);
100
101 composite =
102 (composite <= EIGRP_METRIC_MAX) ? composite : EIGRP_METRIC_MAX;
103
104 return composite;
105}
106
107eigrp_metric_t
108eigrp_calculate_total_metrics(struct eigrp *eigrp,
109 struct eigrp_route_descriptor *entry)
110{
111 struct eigrp_interface *ei = entry->ei;
112 eigrp_delay_t temp_delay;
113 eigrp_bandwidth_t bw;
114
115 entry->total_metric = entry->reported_metric;
116 temp_delay = entry->total_metric.delay
117 + eigrp_delay_to_scaled(ei->params.delay);
118
119 entry->total_metric.delay = temp_delay > EIGRP_METRIC_MAX_CLASSIC
120 ? EIGRP_METRIC_MAX_CLASSIC
121 : temp_delay;
122
123 bw = eigrp_bandwidth_to_scaled(ei->params.bandwidth);
124 entry->total_metric.bandwidth = entry->total_metric.bandwidth > bw
125 ? bw
126 : entry->total_metric.bandwidth;
127
128 return eigrp_calculate_metrics(eigrp, entry->total_metric);
129}
130
131bool eigrp_metrics_is_same(struct eigrp_metrics metric1,
132 struct eigrp_metrics metric2)
133{
134 if ((metric1.bandwidth == metric2.bandwidth)
135 && (metric1.delay == metric2.delay)
136 && (metric1.hop_count == metric2.hop_count)
137 && (metric1.load == metric2.load)
138 && (metric1.reliability == metric2.reliability)
139 && (metric1.mtu[0] == metric2.mtu[0])
140 && (metric1.mtu[1] == metric2.mtu[1])
141 && (metric1.mtu[2] == metric2.mtu[2])) {
142 return true;
143 }
144
145 return false; /* if different */
146}