MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_ppp_mp_strategy

Function ng_ppp_mp_strategy

freebsd/netgraph/ng_ppp.c:2261–2400  ·  view source on GitHub ↗

* Computing the optimal fragmentation * ----------------------------------- * * This routine tries to compute the optimal fragmentation pattern based * on each link's latency, bandwidth, and calculated additional latency. * The latter quantity is the additional latency caused by previously * written data that has not been transmitted yet. * * This algorithm is only useful when not all of t

Source from the content-addressed store, hash-verified

2259 * same latency and bandwidth.
2260 */
2261static void
2262ng_ppp_mp_strategy(node_p node, int len, int *distrib)
2263{
2264 const priv_p priv = NG_NODE_PRIVATE(node);
2265 int latency[NG_PPP_MAX_LINKS];
2266 int sortByLatency[NG_PPP_MAX_LINKS];
2267 int activeLinkNum;
2268 int t0, total, topSum, botSum;
2269 struct timeval now;
2270 int i, numFragments;
2271
2272 /* If only one link, this gets real easy */
2273 if (priv->numActiveLinks == 1) {
2274 distrib[0] = len;
2275 return;
2276 }
2277
2278 /* Get current time */
2279 getmicrouptime(&now);
2280
2281 /* Compute latencies for each link at this point in time */
2282 for (activeLinkNum = 0;
2283 activeLinkNum < priv->numActiveLinks; activeLinkNum++) {
2284 struct ng_ppp_link *alink;
2285 struct timeval diff;
2286 int xmitBytes;
2287
2288 /* Start with base latency value */
2289 alink = &priv->links[priv->activeLinks[activeLinkNum]];
2290 latency[activeLinkNum] = alink->latency;
2291 sortByLatency[activeLinkNum] = activeLinkNum; /* see below */
2292
2293 /* Any additional latency? */
2294 if (alink->bytesInQueue == 0)
2295 continue;
2296
2297 /* Compute time delta since last write */
2298 diff = now;
2299 timevalsub(&diff, &alink->lastWrite);
2300
2301 /* alink->bytesInQueue will be changed, mark change time. */
2302 alink->lastWrite = now;
2303
2304 if (now.tv_sec < 0 || diff.tv_sec >= 10) { /* sanity */
2305 alink->bytesInQueue = 0;
2306 continue;
2307 }
2308
2309 /* How many bytes could have transmitted since last write? */
2310 xmitBytes = (alink->conf.bandwidth * 10 * diff.tv_sec)
2311 + (alink->conf.bandwidth * (diff.tv_usec / 1000)) / 100;
2312 alink->bytesInQueue -= xmitBytes;
2313 if (alink->bytesInQueue < 0)
2314 alink->bytesInQueue = 0;
2315 else
2316 latency[activeLinkNum] +=
2317 (100 * alink->bytesInQueue) / alink->conf.bandwidth;
2318 }

Callers 1

ng_ppp_mp_xmitFunction · 0.85

Calls 2

getmicrouptimeFunction · 0.85
timevalsubFunction · 0.50

Tested by

no test coverage detected