root/vic/trunk/net/pktbuf.h @ 962

Revision 962, 2.9 KB (checked in by piers, 15 years ago)

Added new packet buffer class (from MASH) for layered support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * Copyright (c) 1996 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the MASH Research
16 *      Group at University of California, Berkeley.
17 * 4. Neither the name of the University nor of the Laboratory may be used
18 *    to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#) $Header$ (LBL)
34 */
35
36#ifndef mash_pktbuf_h
37#define mash_pktbuf_h
38
39#ifdef WIN32
40//#include <winsock.h>
41#else
42#include <sys/param.h>
43#include <sys/types.h>
44#include <sys/socket.h>
45#include <sys/uio.h>
46#endif
47//#include "config.h"
48#include "vic_tcl.h"
49//#include "timer.h"
50//#include "inet.h"
51//#include "module.h"
52
53class pktbuf;
54
55class Buffer {
56public:
57        virtual Buffer* copy() = 0;
58        virtual void release();
59};
60
61/*
62 * The base object for performing the outbound path of
63 * the application level protocol.
64 */
65class BufferPool : public TclObject {
66    public:
67        BufferPool();
68        void release(pktbuf*);
69        /*
70         * Buffer allocation hooks.
71         */
72        pktbuf* alloc(int layer = 0);
73    private:
74        static pktbuf* freebufs_;
75        static int nbufs_;
76};
77
78/*XXX*/
79#define MAXHDR 128
80#define PKTBUF_PAD 256
81#define PKTBUF_SIZE (MAXHDR + 1024 + PKTBUF_PAD)
82
83class pktbuf : public Buffer {
84public:
85        pktbuf* next;
86        int layer;
87        int len;
88        int ref;
89        u_int8_t* dp;
90        u_int8_t data[PKTBUF_SIZE];
91        BufferPool* manager;
92        inline void release() {
93                ref--;
94                if (!ref)
95                  manager->release(this);
96        }
97        inline void attach() {
98                ref++;
99        }
100        Buffer* copy();
101};
102
103#endif
Note: See TracBrowser for help on using the browser.