[En-Nut-Discussion] Proposed Enhancement to NutOS (PPP) - Tracking PPP data volume and cellular costs.

Brett Abbott Brett.Abbott at digital-telemetry.com
Wed Apr 13 22:17:15 CEST 2005


Hi

re: Proposed addition to NutOS/PPP

Please find attached a few simple changes that we use in the 3.9.5 
kernel which allow the simple tracking of packets and bytes over PPP 
adapters.  It is reset each time the adapter is reset but allows a 
simple mechanism to track/monitor costs.  When you are working with CDMA 
and GPRS, they charge like wounded bulls, typically by bytes, which 
includes the packet and IP overheads. 

This change allows the application to interogate progressive data 
volumes put through the PPP adapter, even unsolicited and network 
packets (which you still pay for).  We've found it useful also for 
tracking faults and latency issues.

A few notes:
1. Perhaps the changes could be added with #ifdef to keep sturcutres 
streamlined for those who dont need it.
2. Should the additional variables be defined as volatile?

Regards
Brett

-----------------------------------------------------------------

Add to include/dev/ppp.h:

    /*! \brief Current authentication state.
     */
    u_char dcb_auth_state;

    /*! \brief File descriptor of physical device.
     */
    int dcb_fd;

/* Start of Change April 2005, Brett Abbott */
    /* Packet and Byte Monitoring, excludes ppp headers and escape bytes */
    u_long sent_packets;
    u_long sent_databytes;
    u_long recv_packets;
    u_long recv_databytes;
/* End of Change April 2005, Brett Abbott */

};

-----------------------------------------------------------------

// Change to net/pppout.c

int NutPppOutput(NUTDEVICE * dev, u_short type, u_char * ha, NETBUF * nb)
{
    PPPHDR *ph;
    IFNET *nif = dev->dev_icb;
    PPPDCB *dcb = dev->dev_dcb;

    /*
     * Allocate and set the HDLC header.
     */
    if (NutNetBufAlloc(nb, NBAF_DATALINK, sizeof(PPPHDR)) == 0)
        return -1;

    ph = (PPPHDR *) nb->nb_dl.vp;
    ph->address = AHDLC_ALLSTATIONS;
    ph->control = AHDLC_UI;
    ph->prot_type = htons(type);

#ifdef NUTDEBUG
    if (__ppp_trf) {
        fputs("\nPPP<", __ppp_trs);
        NutDumpPpp(__ppp_trs, nb);
    }
#elif defined(__IMAGECRAFT__)
    /*
     * No idea what this is, but ICCAVR fails if this call isn't there.
     */
    NutSleep(100);
#endif


/* Start of Change April 2005, Brett Abbott */
    // Added to count outgoing data
    dcb->sent_packets++;
    dcb->sent_databytes+=nb->nb_nw.sz + nb->nb_tp.sz + nb->nb_ap.sz;
/* End of Change April 2005, Brett Abbott */

    /*
     * Call the physical device output routine.
     */
    if (nif->if_send && (*nif->if_send) ((((NUTFILE *) (uptr_t) 
(dcb->dcb_fd)))->nf_dev, nb) == 0) {
        return 0;
    }
    NutNetBufFree(nb);
    return -1;
}
-----------------------------------------------------------------

// Change to net/pppin.c
/* Start of Change April 2005, Brett Abbott */
    /*
     * We count the bytes and packets - we count the discarded packets as well as we still have to pay
     * Added to count data from incoming ppp packets
     */
    
    dcb->recv_packets++;
    dcb->recv_databytes+=nb->nb_nw.sz;

/* End of Change April 2005, Brett Abbott */

    /*
     * Toss all non-LCP packets unless LCP is OPEN.
     */
    if (protocol != PPP_LCP && dcb->dcb_lcp_state != PPPS_OPENED) {
        NutNetBufFree(nb);
        return;
    }

-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------

-- 
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: Brett.Abbott at digital-telemetry.com
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860  Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.egnite.de/pipermail/en-nut-discussion/attachments/20050414/b57434ca/attachment.html>


More information about the En-Nut-Discussion mailing list