1 .\" Copyright (c) 2001-2003 International Computer Science Institute
3 .\" Permission is hereby granted, free of charge, to any person obtaining a
4 .\" copy of this software and associated documentation files (the "Software"),
5 .\" to deal in the Software without restriction, including without limitation
6 .\" the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 .\" and/or sell copies of the Software, and to permit persons to whom the
8 .\" Software is furnished to do so, subject to the following conditions:
10 .\" The above copyright notice and this permission notice shall be included in
11 .\" all copies or substantial portions of the Software.
13 .\" The names and trademarks of copyright holders may not be used in
14 .\" advertising or publicity pertaining to the software without specific
15 .\" prior permission. Title to copyright in this software and any associated
16 .\" documentation will at all times remain with the copyright holders.
18 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 .\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 .\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 .\" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 .\" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 .\" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 .\" DEALINGS IN THE SOFTWARE.
26 .\" $FreeBSD: /repoman/r/ncvs/src/share/man/man4/multicast.4,v 1.1 2003/10/17 15:12:01 bmah Exp $
27 .\" $DragonFly: src/share/man/man4/multicast.4,v 1.4 2006/05/26 19:39:39 swildner Exp $
38 .Cd "options MROUTING"
43 .In net/ip_mroute/ip_mroute.h
44 .In netinet6/ip6_mroute.h
46 .Fn getsockopt "int s" IPPROTO_IP MRT_INIT "void *optval" "socklen_t *optlen"
48 .Fn setsockopt "int s" IPPROTO_IP MRT_INIT "const void *optval" "socklen_t optlen"
50 .Fn getsockopt "int s" IPPROTO_IPV6 MRT6_INIT "void *optval" "socklen_t *optlen"
52 .Fn setsockopt "int s" IPPROTO_IPV6 MRT6_INIT "const void *optval" "socklen_t optlen"
54 .Tn "Multicast routing"
55 is used to efficiently propagate data
56 packets to a set of multicast listeners in multipoint networks.
57 If unicast is used to replicate the data to all listeners,
58 then some of the network links may carry multiple copies of the same
60 With multicast routing, the overhead is reduced to one copy
61 (at most) per network link.
63 All multicast-capable routers must run a common multicast routing
65 The Distance Vector Multicast Routing Protocol (DVMRP)
66 was the first developed multicast routing protocol.
67 Later, other protocols such as Multicast Extensions to OSPF (MOSPF),
68 Core Based Trees (CBT),
69 Protocol Independent Multicast - Sparse Mode (PIM-SM),
70 and Protocol Independent Multicast - Dense Mode (PIM-DM)
71 were developed as well.
73 To start multicast routing,
74 the user must enable multicast forwarding in the kernel
77 about the kernel configuration options),
78 and must run a multicast routing capable user-level process.
79 From developer's point of view,
80 the programming guide described in the
81 .Sx "Programming Guide"
82 section should be used to control the multicast forwarding in the kernel.
85 This section provides information about the basic multicast routing API.
87 .Dq advanced multicast API
89 .Sx "Advanced Multicast API Programming Guide"
92 First, a multicast routing socket must be open.
93 That socket would be used
94 to control the multicast forwarding in the kernel.
95 Note that most operations below require certain privilege
96 (i.e., root privilege):
101 mrouter_s4 = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP);
106 mrouter_s6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
109 Note that if the router needs to open an IGMP or ICMPv6 socket
110 (in case of IPv4 and IPv6 respectively)
111 for sending or receiving of IGMP or MLD multicast group membership messages,
112 then the same mrouter_s4 or mrouter_s6 sockets should be used
113 for sending and receiving respectively IGMP or MLD messages.
114 In case of BSD-derived kernel, it may be possible to open separate sockets
115 for IGMP or MLD messages only.
116 However, some other kernels (e.g., Linux) require that the multicast
117 routing socket must be used for sending and receiving of IGMP or MLD
119 Therefore, for portability reason the multicast
120 routing socket should be reused for IGMP and MLD messages as well.
122 After the multicast routing socket is open, it can be used to enable
123 or disable multicast forwarding in the kernel:
126 int v = 1; /* 1 to enable, or 0 to disable */
127 setsockopt(mrouter_s4, IPPROTO_IP, MRT_INIT, (void *)&v, sizeof(v));
132 int v = 1; /* 1 to enable, or 0 to disable */
133 setsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_INIT, (void *)&v, sizeof(v));
135 /* If necessary, filter all ICMPv6 messages */
136 struct icmp6_filter filter;
137 ICMP6_FILTER_SETBLOCKALL(&filter);
138 setsockopt(mrouter_s6, IPPROTO_ICMPV6, ICMP6_FILTER, (void *)&filter,
142 After multicast forwarding is enabled, the multicast routing socket
143 can be used to enable PIM processing in the kernel if we are running PIM-SM or
148 For each network interface (e.g., physical or a virtual tunnel)
149 that would be used for multicast forwarding, a corresponding
150 multicast interface must be added to the kernel:
154 memset(&vc, 0, sizeof(vc));
155 /* Assign all vifctl fields as appropriate */
156 vc.vifc_vifi = vif_index;
157 vc.vifc_flags = vif_flags;
158 vc.vifc_threshold = min_ttl_threshold;
159 vc.vifc_rate_limit = max_rate_limit;
160 memcpy(&vc.vifc_lcl_addr, &vif_local_address, sizeof(vc.vifc_lcl_addr));
161 if (vc.vifc_flags & VIFF_TUNNEL)
162 memcpy(&vc.vifc_rmt_addr, &vif_remote_address,
163 sizeof(vc.vifc_rmt_addr));
164 setsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_VIF, (void *)&vc,
170 must be unique per vif.
176 .In net/ip_mroute/ip_mroute.h .
178 .Dq min_ttl_threshold
179 contains the minimum TTL a multicast data packet must have to be
180 forwarded on that vif.
181 Typically, it would have value of 1.
184 contains the maximum rate (in bits/s) of the multicast data packets forwarded
186 Value of 0 means no limit.
188 .Dq vif_local_address
189 contains the local IP address of the corresponding local interface.
191 .Dq vif_remote_address
192 contains the remote IP address in case of DVMRP multicast tunnels.
197 memset(&mc, 0, sizeof(mc));
198 /* Assign all mif6ctl fields as appropriate */
199 mc.mif6c_mifi = mif_index;
200 mc.mif6c_flags = mif_flags;
201 mc.mif6c_pifi = pif_index;
202 setsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_ADD_MIF, (void *)&mc,
208 must be unique per vif.
214 .In netinet6/ip6_mroute.h .
217 is the physical interface index of the corresponding local interface.
219 A multicast interface is deleted by:
222 vifi_t vifi = vif_index;
223 setsockopt(mrouter_s4, IPPROTO_IP, MRT_DEL_VIF, (void *)&vifi,
229 mifi_t mifi = mif_index;
230 setsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_DEL_MIF, (void *)&mifi,
234 After the multicast forwarding is enabled, and the multicast virtual
236 added, the kernel may deliver upcall messages (also called signals
237 later in this text) on the multicast routing socket that was open
242 The IPv4 upcalls have
245 .In net/ip_mroute/ip_mroute.h )
249 Note that this header follows the structure of
251 with the protocol field
254 The IPv6 upcalls have
257 .In netinet6/ip6_mroute.h )
261 Note that this header follows the structure of
263 with the next header field
267 The upcall header contains field
271 with the type of the upcall
275 for IPv4 and IPv6 respectively.
276 The values of the rest of the upcall header fields
277 and the body of the upcall message depend on the particular upcall type.
279 If the upcall message type is
282 .Dq MRT6MSG_NOCACHE ,
283 this is an indication that a multicast packet has reached the multicast
284 router, but the router has no forwarding state for that packet.
285 Typically, the upcall would be a signal for the multicast routing
286 user-level process to install the appropriate Multicast Forwarding
287 Cache (MFC) entry in the kernel.
289 A MFC entry is added by:
293 memset(&mc, 0, sizeof(mc));
294 memcpy(&mc.mfcc_origin, &source_addr, sizeof(mc.mfcc_origin));
295 memcpy(&mc.mfcc_mcastgrp, &group_addr, sizeof(mc.mfcc_mcastgrp));
296 mc.mfcc_parent = iif_index;
297 for (i = 0; i < maxvifs; i++)
298 mc.mfcc_ttls[i] = oifs_ttl[i];
299 setsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_MFC,
300 (void *)&mc, sizeof(mc));
306 memset(&mc, 0, sizeof(mc));
307 memcpy(&mc.mf6cc_origin, &source_addr, sizeof(mc.mf6cc_origin));
308 memcpy(&mc.mf6cc_mcastgrp, &group_addr, sizeof(mf6cc_mcastgrp));
309 mc.mf6cc_parent = iif_index;
310 for (i = 0; i < maxvifs; i++)
312 IF_SET(i, &mc.mf6cc_ifset);
313 setsockopt(mrouter_s4, IPPROTO_IPV6, MRT6_ADD_MFC,
314 (void *)&mc, sizeof(mc));
321 are the source and group address of the multicast packet (as set
322 in the upcall message).
325 is the virtual interface index of the multicast interface the multicast
326 packets for this specific source and group address should be received on.
329 array contains the minimum TTL (per interface) a multicast packet
330 should have to be forwarded on an outgoing interface.
331 If the TTL value is zero, the corresponding interface is not included
332 in the set of outgoing interfaces.
333 Note that in case of IPv6 only the set of outgoing interfaces can
336 A MFC entry is deleted by:
340 memset(&mc, 0, sizeof(mc));
341 memcpy(&mc.mfcc_origin, &source_addr, sizeof(mc.mfcc_origin));
342 memcpy(&mc.mfcc_mcastgrp, &group_addr, sizeof(mc.mfcc_mcastgrp));
343 setsockopt(mrouter_s4, IPPROTO_IP, MRT_DEL_MFC,
344 (void *)&mc, sizeof(mc));
350 memset(&mc, 0, sizeof(mc));
351 memcpy(&mc.mf6cc_origin, &source_addr, sizeof(mc.mf6cc_origin));
352 memcpy(&mc.mf6cc_mcastgrp, &group_addr, sizeof(mf6cc_mcastgrp));
353 setsockopt(mrouter_s4, IPPROTO_IPV6, MRT6_DEL_MFC,
354 (void *)&mc, sizeof(mc));
357 The following method can be used to get various statistics per
358 installed MFC entry in the kernel (e.g., the number of forwarded
359 packets per source and group address):
362 struct sioc_sg_req sgreq;
363 memset(&sgreq, 0, sizeof(sgreq));
364 memcpy(&sgreq.src, &source_addr, sizeof(sgreq.src));
365 memcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp));
366 ioctl(mrouter_s4, SIOCGETSGCNT, &sgreq);
371 struct sioc_sg_req6 sgreq;
372 memset(&sgreq, 0, sizeof(sgreq));
373 memcpy(&sgreq.src, &source_addr, sizeof(sgreq.src));
374 memcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp));
375 ioctl(mrouter_s6, SIOCGETSGCNT_IN6, &sgreq);
378 The following method can be used to get various statistics per
379 multicast virtual interface in the kernel (e.g., the number of forwarded
380 packets per interface):
383 struct sioc_vif_req vreq;
384 memset(&vreq, 0, sizeof(vreq));
385 vreq.vifi = vif_index;
386 ioctl(mrouter_s4, SIOCGETVIFCNT, &vreq);
391 struct sioc_mif_req6 mreq;
392 memset(&mreq, 0, sizeof(mreq));
393 mreq.mifi = vif_index;
394 ioctl(mrouter_s6, SIOCGETMIFCNT_IN6, &mreq);
396 .Ss Advanced Multicast API Programming Guide
397 If we want to add new features in the kernel, it becomes difficult
398 to preserve backward compatibility (binary and API),
399 and at the same time to allow user-level processes to take advantage of
400 the new features (if the kernel supports them).
402 One of the mechanisms that allows us to preserve the backward
403 compatibility is a sort of negotiation
404 between the user-level process and the kernel:
407 The user-level process tries to enable in the kernel the set of new
408 features (and the corresponding API) it would like to use.
410 The kernel returns the (sub)set of features it knows about
411 and is willing to be enabled.
413 The user-level process uses only that set of features
414 the kernel has agreed on.
418 To support backward compatibility, if the user-level process doesn't
419 ask for any new features, the kernel defaults to the basic
420 multicast API (see the
421 .Sx "Programming Guide"
423 .\" XXX: edit as appropriate after the advanced multicast API is
424 .\" supported under IPv6
425 Currently, the advanced multicast API exists only for IPv4;
426 in the future there will be IPv6 support as well.
428 Below is a summary of the expandable API solution.
429 Note that all new options and structures are defined
431 .In net/ip_mroute/ip_mroute.h
433 .In netinet6/ip6_mroute.h ,
434 unless stated otherwise.
436 The user-level process uses new get/setsockopt() options to
437 perform the API features negotiation with the kernel.
438 This negotiation must be performed right after the multicast routing
440 The set of desired/allowed features is stored in a bitset
441 (currently, in uint32_t; i.e., maximum of 32 new features).
442 The new get/setsockopt() options are
449 getsockopt(sock, IPPROTO_IP, MRT_API_SUPPORT, (void *)&v, sizeof(v));
454 the pre-defined bits that the kernel API supports.
455 The eight least significant bits in uint32_t are same as the
460 as part of the new definition of
462 (see below about those flags), which leaves 24 flags for other new features.
463 The value returned by getsockopt(MRT_API_SUPPORT) is read-only; in other
464 words, setsockopt(MRT_API_SUPPORT) would fail.
466 To modify the API, and to set some specific feature in the kernel, then:
468 uint32_t v = MRT_MFC_FLAGS_DISABLE_WRONGVIF;
469 if (setsockopt(sock, IPPROTO_IP, MRT_API_CONFIG, (void *)&v, sizeof(v))
473 if (v & MRT_MFC_FLAGS_DISABLE_WRONGVIF)
474 return (OK); /* Success */
479 In other words, when setsockopt(MRT_API_CONFIG) is called, the
480 argument to it specifies the desired set of features to
481 be enabled in the API and the kernel.
484 is the actual (sub)set of features that were enabled in the kernel.
485 To obtain later the same set of features that were enabled, then:
487 getsockopt(sock, IPPROTO_IP, MRT_API_CONFIG, (void *)&v, sizeof(v));
490 The set of enabled features is global.
491 In other words, setsockopt(MRT_API_CONFIG)
492 should be called right after setsockopt(MRT_INIT).
494 Currently, the following set of new features is defined:
496 #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */
497 #define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) /* border vif */
498 #define MRT_MFC_RP (1 << 8) /* enable RP address */
499 #define MRT_MFC_BW_UPCALL (1 << 9) /* enable bw upcalls */
502 .\" In the future there might be:
504 .\" #define MRT_MFC_GROUP_SPECIFIC (1 << 10) /* allow (*,G) MFC entries */
507 .\" to allow (*,G) MFC entries (i.e., group-specific entries) in the kernel.
508 .\" For now this is left-out until it is clear whether
509 .\" (*,G) MFC support is the preferred solution instead of something more generic
510 .\" solution for example.
512 .\" 2. The newly defined struct mfcctl2.
515 The advanced multicast API uses a newly defined
517 instead of the traditional
527 * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays
528 * and extends the old struct mfcctl.
531 /* the mfcctl fields */
532 struct in_addr mfcc_origin; /* ip origin of mcasts */
533 struct in_addr mfcc_mcastgrp; /* multicast group associated*/
534 vifi_t mfcc_parent; /* incoming vif */
535 u_char mfcc_ttls[MAXVIFS];/* forwarding ttls on vifs */
537 /* extension fields */
538 uint8_t mfcc_flags[MAXVIFS];/* the MRT_MFC_FLAGS_* flags*/
539 struct in_addr mfcc_rp; /* the RP address */
544 .Dq mfcc_flags[MAXVIFS]
547 Note that for compatibility reasons they are added at the end.
550 .Dq mfcc_flags[MAXVIFS]
551 field is used to set various flags per
552 interface per (S,G) entry.
553 Currently, the defined flags are:
555 #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */
556 #define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) /* border vif */
560 .Dq MRT_MFC_FLAGS_DISABLE_WRONGVIF
561 flag is used to explicitly disable the
563 kernel signal at the (S,G) granularity if a multicast data packet
564 arrives on the wrong interface.
565 Usually, this signal is used to
566 complete the shortest-path switch in case of PIM-SM multicast routing,
567 or to trigger a PIM assert message.
568 However, it should not be delivered for interfaces that are not in
569 the outgoing interface set, and that are not expecting to
570 become an incoming interface.
572 .Dq MRT_MFC_FLAGS_DISABLE_WRONGVIF
573 flag is set for some of the
574 interfaces, then a data packet that arrives on that interface for
575 that MFC entry will NOT trigger a WRONGVIF signal.
576 If that flag is not set, then a signal is triggered (the default action).
579 .Dq MRT_MFC_FLAGS_BORDER_VIF
580 flag is used to specify whether the Border-bit in PIM
581 Register messages should be set (in case when the Register encapsulation
582 is performed inside the kernel).
583 If it is set for the special PIM Register kernel virtual interface
586 the Border-bit in the Register messages sent to the RP will be set.
588 The remaining six bits are reserved for future usage.
592 field is used to specify the RP address (in case of PIM-SM multicast routing)
594 group G if we want to perform kernel-level PIM Register encapsulation.
597 field is used only if the
599 advanced API flag/capability has been successfully set by
600 setsockopt(MRT_API_CONFIG).
603 .\" 3. Kernel-level PIM Register encapsulation
607 flag was successfully set by
608 setsockopt(MRT_API_CONFIG), then the kernel will attempt to perform
609 the PIM Register encapsulation itself instead of sending the
610 multicast data packets to user level (inside IGMPMSG_WHOLEPKT
611 upcalls) for user-level encapsulation.
612 The RP address would be taken from the
619 flag was successfully set, if the
624 kernel will still deliver an IGMPMSG_WHOLEPKT upcall with the
625 multicast data packet to the user-level process.
627 In addition, if the multicast data packet is too large to fit within
628 a single IP packet after the PIM Register encapsulation (e.g., if
629 its size was on the order of 65500 bytes), the data packet will be
630 fragmented, and then each of the fragments will be encapsulated
632 Note that typically a multicast data packet can be that
633 large only if it was originated locally from the same hosts that
634 performs the encapsulation; otherwise the transmission of the
635 multicast data packet over Ethernet for example would have
636 fragmented it into much smaller pieces.
638 .\" Note that if this code is ported to IPv6, we may need the kernel to
639 .\" perform MTU discovery to the RP, and keep those discoveries inside
640 .\" the kernel so the encapsulating router may send back ICMP
641 .\" Fragmentation Required if the size of the multicast data packet is
642 .\" too large (see "Encapsulating data packets in the Register Tunnel"
643 .\" in Section 4.4.1 in the PIM-SM spec
644 .\" draft-ietf-pim-sm-v2-new-05.{txt,ps}).
645 .\" For IPv4 we may be able to get away without it, but for IPv6 we need
648 .\" 4. Mechanism for "multicast bandwidth monitoring and upcalls".
651 Typically, a multicast routing user-level process would need to know the
652 forwarding bandwidth for some data flow.
653 For example, the multicast routing process may want to timeout idle MFC
654 entries, or in case of PIM-SM it can initiate (S,G) shortest-path switch if
655 the bandwidth rate is above a threshold for example.
657 The original solution for measuring the bandwidth of a dataflow was
658 that a user-level process would periodically
659 query the kernel about the number of forwarded packets/bytes per
660 (S,G), and then based on those numbers it would estimate whether a source
661 has been idle, or whether the source's transmission bandwidth is above a
663 That solution is far from being scalable, hence the need for a new
664 mechanism for bandwidth monitoring.
666 Below is a description of the bandwidth monitoring mechanism.
669 If the bandwidth of a data flow satisfies some pre-defined filter,
670 the kernel delivers an upcall on the multicast routing socket
671 to the multicast routing process that has installed that filter.
673 The bandwidth-upcall filters are installed per (S,G). There can be
674 more than one filter per (S,G).
676 Instead of supporting all possible comparison operations
677 (i.e., < <= == != > >= ), there is support only for the
678 <= and >= operations,
679 because this makes the kernel-level implementation simpler,
680 and because practically we need only those two.
681 Further, the missing operations can be simulated by secondary
682 user-level filtering of those <= and >= filters.
683 For example, to simulate !=, then we need to install filter
684 .Dq bw <= 0xffffffff ,
686 upcall is received, we need to check whether
687 .Dq measured_bw != expected_bw .
689 The bandwidth-upcall mechanism is enabled by
690 setsockopt(MRT_API_CONFIG) for the MRT_MFC_BW_UPCALL flag.
692 The bandwidth-upcall filters are added/deleted by the new
693 setsockopt(MRT_ADD_BW_UPCALL) and setsockopt(MRT_DEL_BW_UPCALL)
694 respectively (with the appropriate
699 From application point of view, a developer needs to know about
703 * Structure for installing or delivering an upcall if the
704 * measured bandwidth is above or below a threshold.
706 * User programs (e.g. daemons) may have a need to know when the
707 * bandwidth used by some data flow is above or below some threshold.
708 * This interface allows the userland to specify the threshold (in
709 * bytes and/or packets) and the measurement interval. Flows are
710 * all packet with the same source and destination IP address.
711 * At the moment the code is only used for multicast destinations
712 * but there is nothing that prevents its use for unicast.
714 * The measurement interval cannot be shorter than some Tmin (currently, 3s).
715 * The threshold is set in packets and/or bytes per_interval.
717 * Measurement works as follows:
719 * For >= measurements:
720 * The first packet marks the start of a measurement interval.
721 * During an interval we count packets and bytes, and when we
722 * pass the threshold we deliver an upcall and we are done.
723 * The first packet after the end of the interval resets the
724 * count and restarts the measurement.
726 * For <= measurement:
727 * We start a timer to fire at the end of the interval, and
728 * then for each incoming packet we count packets and bytes.
729 * When the timer fires, we compare the value with the threshold,
730 * schedule an upcall if we are below, and restart the measurement
731 * (reschedule timer and zero counters).
735 struct timeval b_time;
741 struct in_addr bu_src; /* source address */
742 struct in_addr bu_dst; /* destination address */
743 uint32_t bu_flags; /* misc flags (see below) */
744 #define BW_UPCALL_UNIT_PACKETS (1 << 0) /* threshold (in packets) */
745 #define BW_UPCALL_UNIT_BYTES (1 << 1) /* threshold (in bytes) */
746 #define BW_UPCALL_GEQ (1 << 2) /* upcall if bw >= threshold */
747 #define BW_UPCALL_LEQ (1 << 3) /* upcall if bw <= threshold */
748 #define BW_UPCALL_DELETE_ALL (1 << 4) /* delete all upcalls for s,d*/
749 struct bw_data bu_threshold; /* the bw threshold */
750 struct bw_data bu_measured; /* the measured bw */
753 /* max. number of upcalls to deliver together */
754 #define BW_UPCALLS_MAX 128
755 /* min. threshold time interval for bandwidth measurement */
756 #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC 3
757 #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC 0
762 structure is used as an argument to
763 setsockopt(MRT_ADD_BW_UPCALL) and setsockopt(MRT_DEL_BW_UPCALL).
764 Each setsockopt(MRT_ADD_BW_UPCALL) installs a filter in the kernel
765 for the source and destination address in the
768 and that filter will trigger an upcall according to the following
771 if (bw_upcall_oper IS ">=") {
772 if (((bw_upcall_unit & PACKETS == PACKETS) &&
773 (measured_packets >= threshold_packets)) ||
774 ((bw_upcall_unit & BYTES == BYTES) &&
775 (measured_bytes >= threshold_bytes)))
776 SEND_UPCALL("measured bandwidth is >= threshold");
778 if (bw_upcall_oper IS "<=" && measured_interval >= threshold_interval) {
779 if (((bw_upcall_unit & PACKETS == PACKETS) &&
780 (measured_packets <= threshold_packets)) ||
781 ((bw_upcall_unit & BYTES == BYTES) &&
782 (measured_bytes <= threshold_bytes)))
783 SEND_UPCALL("measured bandwidth is <= threshold");
789 the unit can be specified in both BYTES and PACKETS.
790 However, the GEQ and LEQ flags are mutually exclusive.
792 Basically, an upcall is delivered if the measured bandwidth is >= or
793 <= the threshold bandwidth (within the specified measurement
795 For practical reasons, the smallest value for the measurement
796 interval is 3 seconds.
797 If smaller values are allowed, then the bandwidth
798 estimation may be less accurate, or the potentially very high frequency
799 of the generated upcalls may introduce too much overhead.
800 For the >= operation, the answer may be known before the end of
801 .Dq threshold_interval ,
802 therefore the upcall may be delivered earlier.
803 For the <= operation however, we must wait
804 until the threshold interval has expired to know the answer.
808 struct bw_upcall bw_upcall;
809 /* Assign all bw_upcall fields as appropriate */
810 memset(&bw_upcall, 0, sizeof(bw_upcall));
811 memcpy(&bw_upcall.bu_src, &source, sizeof(bw_upcall.bu_src));
812 memcpy(&bw_upcall.bu_dst, &group, sizeof(bw_upcall.bu_dst));
813 bw_upcall.bu_threshold.b_data = threshold_interval;
814 bw_upcall.bu_threshold.b_packets = threshold_packets;
815 bw_upcall.bu_threshold.b_bytes = threshold_bytes;
816 if (is_threshold_in_packets)
817 bw_upcall.bu_flags |= BW_UPCALL_UNIT_PACKETS;
818 if (is_threshold_in_bytes)
819 bw_upcall.bu_flags |= BW_UPCALL_UNIT_BYTES;
822 bw_upcall.bu_flags |= BW_UPCALL_GEQ;
826 bw_upcall.bu_flags |= BW_UPCALL_LEQ;
831 setsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_BW_UPCALL,
832 (void *)&bw_upcall, sizeof(bw_upcall));
835 To delete a single filter, then use MRT_DEL_BW_UPCALL,
836 and the fields of bw_upcall must be set
837 exactly same as when MRT_ADD_BW_UPCALL was called.
839 To delete all bandwidth filters for a given (S,G), then
846 need to be set, and then just set only the
847 .Dq BW_UPCALL_DELETE_ALL
849 .Dq bw_upcall.bu_flags .
851 The bandwidth upcalls are received by aggregating them in the new upcall
854 #define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */
857 This message is an array of
859 elements (up to BW_UPCALLS_MAX = 128).
861 delivered when there are 128 pending upcalls, or when 1 second has
862 expired since the previous upcall (whichever comes first).
867 field is filled-in to
868 indicate the particular measured values.
869 However, because of the way
870 the particular intervals are measured, the user should be careful how
871 bu_measured.b_time is used.
873 filter is installed to trigger an upcall if the number of packets
876 may have a value of zero in the upcalls after the
877 first one, because the measured interval for >= filters is
879 by the forwarded packets.
880 Hence, this upcall mechanism should not be used for measuring
881 the exact value of the bandwidth of the forwarded data.
882 To measure the exact bandwidth, the user would need to
883 get the forwarded packets statistics with the ioctl(SIOCGETSGCNT)
886 .Sx Programming Guide
889 Note that the upcalls for a filter are delivered until the specific
890 filter is deleted, but no more frequently than once per
891 .Dq bu_threshold.b_time .
892 For example, if the filter is specified to
893 deliver a signal if bw >= 1 packet, the first packet will trigger a
894 signal, but the next upcall will be triggered no earlier than
895 .Dq bu_threshold.b_time
896 after the previous upcall.
913 The original multicast code was written by David Waitzman (BBN Labs),
914 and later modified by the following individuals:
915 Steve Deering (Stanford), Mark J. Steiglitz (Stanford),
916 Van Jacobson (LBL), Ajit Thyagarajan (PARC),
918 The IPv6 multicast support was implemented by the KAME project
919 (http://www.kame.net), and was based on the IPv4 multicast code.
920 The advanced multicast API and the multicast bandwidth
921 monitoring were implemented by Pavlin Radoslavov (ICSI)
922 in collaboration with Chris Brown (NextHop).
924 This manual page was written by Pavlin Radoslavov (ICSI).