|
5 | 5 | ) |
6 | 6 |
|
7 | 7 | type UpfXdpActionStatistic struct { |
8 | | - BpfObjects *BpfObjects |
9 | | - previous UpfCounters |
| 8 | + BpfObjects *BpfObjects |
| 9 | + upfCountersPrevious UpfCounters |
| 10 | + upfRoutePrevious IpEntrypointRouteStat |
10 | 11 | } |
11 | 12 |
|
12 | 13 | type UpfCounters struct { |
@@ -133,7 +134,73 @@ func (stat *UpfXdpActionStatistic) GetUpfExtStatDelta() UpfCounters { |
133 | 134 | counters.Add(statistic.UpfCounters) |
134 | 135 | } |
135 | 136 |
|
136 | | - delta := stat.previous.Delta(counters) |
137 | | - stat.previous = counters |
| 137 | + delta := stat.upfCountersPrevious.Delta(counters) |
| 138 | + stat.upfCountersPrevious = counters |
| 139 | + return delta |
| 140 | +} |
| 141 | + |
| 142 | +func (current *IpEntrypointRouteStat) Add(new IpEntrypointRouteStat) { |
| 143 | + current.FibLookupIp4Cache += new.FibLookupIp4Cache |
| 144 | + current.FibLookupIp4Ok += new.FibLookupIp4Ok |
| 145 | + current.FibLookupIp4ErrorDrop += new.FibLookupIp4ErrorDrop |
| 146 | + current.FibLookupIp4ErrorPass += new.FibLookupIp4ErrorPass |
| 147 | + |
| 148 | + current.FibLookupIp6Cache += new.FibLookupIp6Cache |
| 149 | + current.FibLookupIp6Ok += new.FibLookupIp6Ok |
| 150 | + current.FibLookupIp6ErrorDrop += new.FibLookupIp6ErrorDrop |
| 151 | + current.FibLookupIp6ErrorPass += new.FibLookupIp6ErrorPass |
| 152 | +} |
| 153 | + |
| 154 | +func (current *IpEntrypointRouteStat) Delta(new IpEntrypointRouteStat) IpEntrypointRouteStat { |
| 155 | + delta := IpEntrypointRouteStat{} |
| 156 | + |
| 157 | + delta.FibLookupIp4Cache = new.FibLookupIp4Cache - current.FibLookupIp4Cache |
| 158 | + delta.FibLookupIp4Ok = new.FibLookupIp4Ok - current.FibLookupIp4Ok |
| 159 | + delta.FibLookupIp4ErrorDrop = new.FibLookupIp4ErrorDrop - current.FibLookupIp4ErrorDrop |
| 160 | + delta.FibLookupIp4ErrorPass = new.FibLookupIp4ErrorPass - current.FibLookupIp4ErrorPass |
| 161 | + |
| 162 | + delta.FibLookupIp6Cache = new.FibLookupIp6Cache - current.FibLookupIp6Cache |
| 163 | + delta.FibLookupIp6Ok = new.FibLookupIp6Ok - current.FibLookupIp6Ok |
| 164 | + delta.FibLookupIp6ErrorDrop = new.FibLookupIp6ErrorDrop - current.FibLookupIp6ErrorDrop |
| 165 | + delta.FibLookupIp6ErrorPass = new.FibLookupIp6ErrorPass - current.FibLookupIp6ErrorPass |
| 166 | + |
| 167 | + return delta |
| 168 | +} |
| 169 | + |
| 170 | +// Getters for the upf_route_stat (route_stat) |
| 171 | +func (stat *UpfXdpActionStatistic) GetUpfRouteStat() IpEntrypointRouteStat { |
| 172 | + var statistics []IpEntrypointRouteStat |
| 173 | + var counters IpEntrypointRouteStat |
| 174 | + |
| 175 | + err := stat.BpfObjects.UpfRouteStat.Lookup(uint32(0), &statistics) |
| 176 | + if err != nil { |
| 177 | + log.Warn().Msgf("failed to get upf_route_stat: %s" + err.Error()) |
| 178 | + return counters |
| 179 | + } |
| 180 | + |
| 181 | + for _, statistic := range statistics { |
| 182 | + counters.Add(statistic) |
| 183 | + } |
| 184 | + |
| 185 | + return counters |
| 186 | +} |
| 187 | + |
| 188 | +// Getters for the upf_route_stat (route_stat) |
| 189 | +func (stat *UpfXdpActionStatistic) GetUpfRouteStatDelta() IpEntrypointRouteStat { |
| 190 | + var statistics []IpEntrypointRouteStat |
| 191 | + var counters IpEntrypointRouteStat |
| 192 | + |
| 193 | + err := stat.BpfObjects.UpfRouteStat.Lookup(uint32(0), &statistics) |
| 194 | + if err != nil { |
| 195 | + log.Warn().Msgf("failed to get upf_route_stat: %s" + err.Error()) |
| 196 | + return counters |
| 197 | + } |
| 198 | + |
| 199 | + for _, statistic := range statistics { |
| 200 | + counters.Add(statistic) |
| 201 | + } |
| 202 | + |
| 203 | + delta := stat.upfRoutePrevious.Delta(counters) |
| 204 | + stat.upfRoutePrevious = counters |
138 | 205 | return delta |
139 | 206 | } |
0 commit comments