xorp

xrl_pf_stcp_ph.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2009 XORP, Inc.
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU Lesser General Public License, Version
00008 // 2.1, June 1999 as published by the Free Software Foundation.
00009 // Redistribution and/or modification of this program under the terms of
00010 // any other version of the GNU Lesser General Public License is not
00011 // permitted.
00012 // 
00013 // This program is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00016 // see the GNU Lesser General Public License, Version 2.1, a copy of
00017 // which can be found in the XORP LICENSE.lgpl file.
00018 // 
00019 // XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00020 // http://xorp.net
00021 
00022 // $XORP: xorp/libxipc/xrl_pf_stcp_ph.hh,v 1.19 2008/10/02 21:57:25 bms Exp $
00023 
00024 #ifndef __LIBXIPC_XRL_PF_STCP_PH_HH__
00025 #define __LIBXIPC_XRL_PF_STCP_PH_HH__
00026 
00027 // major and minor maybe defined on system, undefine them
00028 #ifdef major
00029 #undef major
00030 #endif
00031 
00032 #ifdef minor
00033 #undef minor
00034 #endif
00035 
00036 // STCP Packet Type enumerations
00037 
00038 enum STCPPacketType {
00039     STCP_PT_HELO    = 0x00,
00040     STCP_PT_HELO_ACK    = 0x01,
00041     STCP_PT_REQUEST = 0x02,
00042     STCP_PT_RESPONSE    = 0x03
00043 };
00044 
00045 // Flag masks
00046 #define FLAG_BATCH_MASK  0x1
00047 #define FLAG_BATCH_SHIFT   0
00048 
00049 // STCP Packet Header.
00050 class STCPPacketHeader {
00051 public:
00052     STCPPacketHeader(uint8_t* data);
00053 
00054     static const size_t SIZE = 24;  // STCP Packet Header size
00055 
00056     void initialize(uint32_t        seqno,
00057             STCPPacketType  type,
00058             const XrlError& err,
00059             uint32_t        xrl_data_bytes);
00060 
00061     static size_t header_size()     { return STCPPacketHeader::SIZE; }
00062 
00063     bool is_valid() const;
00064 
00065     uint32_t fourcc() const;
00066 
00067     uint8_t  major() const;
00068 
00069     uint8_t  minor() const;
00070 
00071     STCPPacketType type() const;
00072 
00073     uint32_t seqno() const;
00074 
00075     uint32_t error_code() const;
00076 
00077     uint32_t error_note_bytes() const;
00078 
00079     uint32_t xrl_data_bytes() const;
00080 
00081     uint32_t payload_bytes() const;
00082 
00083     // Sum of header, error note, and payload bytes.
00084     uint32_t frame_bytes() const;
00085 
00086     bool batch() const;
00087     void set_batch(bool batch);
00088 
00089 private:
00090     //
00091     // The STCP packet header has the following content:
00092     //
00093     // fourcc (4 bytes): fourcc 'S' 'T' 'C' 'P'
00094     // major  (1 byte):  Major version
00095     // minor  (1 byte):  Minor version
00096     // seqno  (4 bytes): Sequence number
00097     // flags  (1 byte):  Bit 0 = batch.
00098     // type   (1 byte):  Bits [0:1] hello/req./resp.
00099     // error_code (4 bytes): XrlError code
00100     // error_note_bytes (4 bytes): Length of note (if any) assoc. w/ code
00101     // xrl_data_bytes (4 bytes): Xrl return args data bytes
00102     //
00103 
00104     uint8_t* _data;     // The buffer data with the header
00105 
00106     // Pointers to the header fields
00107     uint8_t* _fourcc;       // fourcc 'S' 'T' 'C' 'P'
00108     uint8_t* _major;        // Major version
00109     uint8_t* _minor;        // Minor version
00110     uint8_t* _seqno;        // Sequence number
00111     uint8_t* _flags;        // Flags
00112     uint8_t* _type;     // [0:1] hello/req./resp.
00113     uint8_t* _error_code;   // XrlError code
00114     uint8_t* _error_note_bytes; // Length of note (if any) assoc. w/ code
00115     uint8_t* _xrl_data_bytes;   // Xrl return args data bytes
00116 
00117     // Sizes of the header fields
00118     static const size_t _fourcc_sizeof = 4;
00119     static const size_t _major_sizeof = 1;
00120     static const size_t _minor_sizeof = 1;
00121     static const size_t _seqno_sizeof = 4;
00122     static const size_t _flags_sizeof = 1;
00123     static const size_t _type_sizeof = 1;
00124     static const size_t _error_code_sizeof = 4;
00125     static const size_t _error_note_bytes_sizeof = 4;
00126     static const size_t _xrl_data_bytes_sizeof = 4;
00127 
00128     // Offsets for the header fields
00129     static const size_t _fourcc_offset = 0;
00130     static const size_t _major_offset = _fourcc_offset + _fourcc_sizeof;
00131     static const size_t _minor_offset = _major_offset + _major_sizeof;
00132     static const size_t _seqno_offset = _minor_offset + _minor_sizeof;
00133     static const size_t _flags_offset = _seqno_offset + _seqno_sizeof;
00134     static const size_t _type_offset = _flags_offset + _flags_sizeof;
00135     static const size_t _error_code_offset = _type_offset + _type_sizeof;
00136     static const size_t _error_note_bytes_offset = _error_code_offset + _error_code_sizeof;
00137     static const size_t _xrl_data_bytes_offset = _error_note_bytes_offset + _error_note_bytes_sizeof;
00138 };
00139 
00140 #endif // __LIBXIPC_XRL_PF_STCP_PH_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations