ng_source.c (137136) | ng_source.c (137138) |
---|---|
1/* 2 * ng_source.c 3 * 4 * Copyright 2002 Sandvine Inc. 5 * All rights reserved. 6 * 7 * Subject to the following obligations and disclaimer of warranty, use and 8 * redistribution of this software, in source or object code forms, with or --- 22 unchanged lines hidden (view full) --- 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH 33 * DAMAGE. 34 * 35 * Author: Dave Chapeskie <dchapeskie@sandvine.com> 36 */ 37 38#include <sys/cdefs.h> | 1/* 2 * ng_source.c 3 * 4 * Copyright 2002 Sandvine Inc. 5 * All rights reserved. 6 * 7 * Subject to the following obligations and disclaimer of warranty, use and 8 * redistribution of this software, in source or object code forms, with or --- 22 unchanged lines hidden (view full) --- 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH 33 * DAMAGE. 34 * 35 * Author: Dave Chapeskie <dchapeskie@sandvine.com> 36 */ 37 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/sys/netgraph/ng_source.c 137136 2004-11-02 20:26:41Z glebius $"); | 39__FBSDID("$FreeBSD: head/sys/netgraph/ng_source.c 137138 2004-11-02 21:24:30Z glebius $"); |
40 41/* 42 * This node is used for high speed packet geneneration. It queues 43 * all data recieved on it's 'input' hook and when told to start via 44 * a control message it sends the packets out it's 'output' hook. In 45 * this way this node can be preloaded with a packet stream which is 46 * continuously sent. 47 * --- 34 unchanged lines hidden (view full) --- 82/* Per node info */ 83struct privdata { 84 node_p node; 85 struct source_hookinfo input; 86 struct source_hookinfo output; 87 struct ng_source_stats stats; 88 struct ifqueue snd_queue; /* packets to send */ 89 struct ifnet *output_ifp; | 40 41/* 42 * This node is used for high speed packet geneneration. It queues 43 * all data recieved on it's 'input' hook and when told to start via 44 * a control message it sends the packets out it's 'output' hook. In 45 * this way this node can be preloaded with a packet stream which is 46 * continuously sent. 47 * --- 34 unchanged lines hidden (view full) --- 82/* Per node info */ 83struct privdata { 84 node_p node; 85 struct source_hookinfo input; 86 struct source_hookinfo output; 87 struct ng_source_stats stats; 88 struct ifqueue snd_queue; /* packets to send */ 89 struct ifnet *output_ifp; |
90 struct callout_handle intr_ch; | 90 struct callout intr_ch; |
91 u_int64_t packets; /* packets to send */ 92 u_int32_t queueOctets; 93}; 94typedef struct privdata *sc_p; 95 96/* Node flags */ 97#define NG_SOURCE_ACTIVE (NGF_TYPE1) 98 --- 115 unchanged lines hidden (view full) --- 214 215 sc = malloc(sizeof(*sc), M_NETGRAPH, M_NOWAIT | M_ZERO); 216 if (sc == NULL) 217 return (ENOMEM); 218 219 NG_NODE_SET_PRIVATE(node, sc); 220 sc->node = node; 221 sc->snd_queue.ifq_maxlen = 2048; /* XXX not checked */ | 91 u_int64_t packets; /* packets to send */ 92 u_int32_t queueOctets; 93}; 94typedef struct privdata *sc_p; 95 96/* Node flags */ 97#define NG_SOURCE_ACTIVE (NGF_TYPE1) 98 --- 115 unchanged lines hidden (view full) --- 214 215 sc = malloc(sizeof(*sc), M_NETGRAPH, M_NOWAIT | M_ZERO); 216 if (sc == NULL) 217 return (ENOMEM); 218 219 NG_NODE_SET_PRIVATE(node, sc); 220 sc->node = node; 221 sc->snd_queue.ifq_maxlen = 2048; /* XXX not checked */ |
222 callout_handle_init(&sc->intr_ch); /* XXX fix.. will 223 cause problems. */ | 222 ng_callout_init(&sc->intr_ch); 223 |
224 return (0); 225} 226 227/* 228 * Add a hook 229 */ 230static int 231ng_source_newhook(node_p node, hook_p hook, const char *name) --- 94 unchanged lines hidden (view full) --- 326 /* TODO validation of packets */ 327 sc->packets = packets; 328 sc->output_ifp = NULL; 329 330 sc->node->nd_flags |= NG_SOURCE_ACTIVE; 331 timevalclear(&sc->stats.elapsedTime); 332 timevalclear(&sc->stats.endTime); 333 getmicrotime(&sc->stats.startTime); | 224 return (0); 225} 226 227/* 228 * Add a hook 229 */ 230static int 231ng_source_newhook(node_p node, hook_p hook, const char *name) --- 94 unchanged lines hidden (view full) --- 326 /* TODO validation of packets */ 327 sc->packets = packets; 328 sc->output_ifp = NULL; 329 330 sc->node->nd_flags |= NG_SOURCE_ACTIVE; 331 timevalclear(&sc->stats.elapsedTime); 332 timevalclear(&sc->stats.endTime); 333 getmicrotime(&sc->stats.startTime); |
334 sc->intr_ch = ng_timeout(node, NULL, 0, | 334 ng_timeout(&sc->intr_ch, node, NULL, 0, |
335 ng_source_intr, sc, 0); 336 } 337 break; 338 case NGM_SOURCE_STOP: 339 ng_source_stop(sc); 340 break; 341 case NGM_SOURCE_CLR_DATA: 342 ng_source_clr_data(sc); --- 11 unchanged lines hidden (view full) --- 354 switch (msg->header.cmd) { 355 case NGM_ETHER_GET_IFINDEX: 356 if (ng_source_store_output_ifp(sc, msg) == 0) { 357 ng_source_set_autosrc(sc, 0); 358 sc->node->nd_flags |= NG_SOURCE_ACTIVE; 359 timevalclear(&sc->stats.elapsedTime); 360 timevalclear(&sc->stats.endTime); 361 getmicrotime(&sc->stats.startTime); | 335 ng_source_intr, sc, 0); 336 } 337 break; 338 case NGM_SOURCE_STOP: 339 ng_source_stop(sc); 340 break; 341 case NGM_SOURCE_CLR_DATA: 342 ng_source_clr_data(sc); --- 11 unchanged lines hidden (view full) --- 354 switch (msg->header.cmd) { 355 case NGM_ETHER_GET_IFINDEX: 356 if (ng_source_store_output_ifp(sc, msg) == 0) { 357 ng_source_set_autosrc(sc, 0); 358 sc->node->nd_flags |= NG_SOURCE_ACTIVE; 359 timevalclear(&sc->stats.elapsedTime); 360 timevalclear(&sc->stats.endTime); 361 getmicrotime(&sc->stats.startTime); |
362 sc->intr_ch = ng_timeout(node, NULL, 0, | 362 ng_timeout(&sc->intr_ch, node, NULL, 0, |
363 ng_source_intr, sc, 0); 364 } 365 break; 366 default: 367 error = EINVAL; 368 } 369 break; 370 default: --- 210 unchanged lines hidden (view full) --- 581 582/* 583 * Stop sending queued data out the output hook 584 */ 585static void 586ng_source_stop (sc_p sc) 587{ 588 if (sc->node->nd_flags & NG_SOURCE_ACTIVE) { | 363 ng_source_intr, sc, 0); 364 } 365 break; 366 default: 367 error = EINVAL; 368 } 369 break; 370 default: --- 210 unchanged lines hidden (view full) --- 581 582/* 583 * Stop sending queued data out the output hook 584 */ 585static void 586ng_source_stop (sc_p sc) 587{ 588 if (sc->node->nd_flags & NG_SOURCE_ACTIVE) { |
589 ng_untimeout(sc->intr_ch, sc->node); | 589 ng_untimeout(&sc->intr_ch, sc->node); |
590 sc->node->nd_flags &= ~NG_SOURCE_ACTIVE; 591 getmicrotime(&sc->stats.endTime); 592 sc->stats.elapsedTime = sc->stats.endTime; 593 timevalsub(&sc->stats.elapsedTime, &sc->stats.startTime); 594 /* XXX should set this to the initial value instead */ 595 ng_source_set_autosrc(sc, 1); 596 } 597} --- 7 unchanged lines hidden (view full) --- 605ng_source_intr(node_p node, hook_p hook, void *arg1, int arg2) 606{ 607 sc_p sc = (sc_p)arg1; 608 struct ifqueue *ifq; 609 int packets; 610 611 KASSERT(sc != NULL, ("%s: null node private", __func__)); 612 | 590 sc->node->nd_flags &= ~NG_SOURCE_ACTIVE; 591 getmicrotime(&sc->stats.endTime); 592 sc->stats.elapsedTime = sc->stats.endTime; 593 timevalsub(&sc->stats.elapsedTime, &sc->stats.startTime); 594 /* XXX should set this to the initial value instead */ 595 ng_source_set_autosrc(sc, 1); 596 } 597} --- 7 unchanged lines hidden (view full) --- 605ng_source_intr(node_p node, hook_p hook, void *arg1, int arg2) 606{ 607 sc_p sc = (sc_p)arg1; 608 struct ifqueue *ifq; 609 int packets; 610 611 KASSERT(sc != NULL, ("%s: null node private", __func__)); 612 |
613 callout_handle_init(&sc->intr_ch); | |
614 if (sc->packets == 0 || sc->output.hook == NULL 615 || (sc->node->nd_flags & NG_SOURCE_ACTIVE) == 0) { 616 ng_source_stop(sc); 617 return; 618 } 619 620 if (sc->output_ifp != NULL) { 621 ifq = &sc->output_ifp->if_snd; 622 packets = ifq->ifq_maxlen - ifq->ifq_len; 623 } else 624 packets = sc->snd_queue.ifq_len; 625 626 ng_source_send(sc, packets, NULL); 627 if (sc->packets == 0) 628 ng_source_stop(sc); 629 else | 613 if (sc->packets == 0 || sc->output.hook == NULL 614 || (sc->node->nd_flags & NG_SOURCE_ACTIVE) == 0) { 615 ng_source_stop(sc); 616 return; 617 } 618 619 if (sc->output_ifp != NULL) { 620 ifq = &sc->output_ifp->if_snd; 621 packets = ifq->ifq_maxlen - ifq->ifq_len; 622 } else 623 packets = sc->snd_queue.ifq_len; 624 625 ng_source_send(sc, packets, NULL); 626 if (sc->packets == 0) 627 ng_source_stop(sc); 628 else |
630 sc->intr_ch = ng_timeout(node, NULL, NG_SOURCE_INTR_TICKS, | 629 ng_timeout(&sc->intr_ch, node, NULL, NG_SOURCE_INTR_TICKS, |
631 ng_source_intr, sc, 0); 632} 633 634/* 635 * Send packets out our output hook 636 */ 637static int 638ng_source_send (sc_p sc, int tosend, int *sent_p) --- 58 unchanged lines hidden --- | 630 ng_source_intr, sc, 0); 631} 632 633/* 634 * Send packets out our output hook 635 */ 636static int 637ng_source_send (sc_p sc, int tosend, int *sent_p) --- 58 unchanged lines hidden --- |