📄 packet.h
字号:
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- *//* * Copyright (c) 1997 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Computer Systems * Engineering Group at Lawrence Berkeley Laboratory. * 4. Neither the name of the University nor of the Laboratory may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/common/packet.h,v 1.96 2004/04/22 20:12:30 haldar Exp $ (LBL) */#ifndef ns_packet_h#define ns_packet_h#include <string.h>#include <assert.h>#include "config.h"#include "scheduler.h"#include "object.h"#include "lib/bsd-list.h"#include "packet-stamp.h"#include "ns-process.h"// Used by wireless routing code to attach routing agent#define RT_PORT 255 /* port that all route msgs are sent to */#define HDR_CMN(p) (hdr_cmn::access(p)) #define HDR_ARP(p) (hdr_arp::access(p))#define HDR_MAC(p) (hdr_mac::access(p))#define HDR_MAC802_11(p) ((hdr_mac802_11 *)hdr_mac::access(p))#define HDR_MAC802_16(p) ((hdr_mac802_16 *)hdr_mac802_16::access(p))#define HDR_MAC802_16_DCD(p) ((DCD_MSG *)DCD_MSG::access(p)) #define HDR_MAC802_16_UCD(p) ((UCD_MSG *)UCD_MSG::access(p))#define HDR_MAC802_16_DL_MAP(p) ((DL_MAP *)DL_MAP::access(p))#define HDR_MAC802_16_UL_MAP(p) ((UL_MAP *)UL_MAP::access(p)) #define HDR_MAC802_16_RNGREQ(p) ((rng_req_t*)rng_req_t::access(p)) //banish#define HDR_MAC802_16_RNGRSP(p) ((rng_rsp_t*)rng_rsp_t::access(p)) //banish#define HDR_MAC802_16_BWREQ(p) ((bw_req_t*)bw_req_t::access(p)) //banish#define sub_HDR_MAC802_16_pack(p) ((pack_subheader_t*)pack_subheader_t::access(p)) //banish#define sub_HDR_MAC802_16_frag(p) ((frag_subheader_t*)frag_subheader_t::access(p)) //banish#define HDR_MAC_TDMA(p) ((hdr_mac_tdma *)hdr_mac::access(p))#define HDR_SMAC(p) ((hdr_smac *)hdr_mac::access(p))#define HDR_LL(p) (hdr_ll::access(p))#define HDR_IP(p) (hdr_ip::access(p))#define HDR_RTP(p) (hdr_rtp::access(p))#define HDR_TCP(p) (hdr_tcp::access(p))#define HDR_SCTP(p) (hdr_sctp::access(p))#define HDR_SR(p) (hdr_sr::access(p))#define HDR_TFRC(p) (hdr_tfrc::access(p))#define HDR_TORA(p) (hdr_tora::access(p))#define HDR_IMEP(p) (hdr_imep::access(p))#define HDR_CDIFF(p) (hdr_cdiff::access(p)) /* chalermak's diffusion*///#define HDR_DIFF(p) (hdr_diff::access(p)) /* SCADD's diffusion ported into ns */#define HDR_LMS(p) (hdr_lms::access(p))/* --------------------------------------------------------------------*/enum packet_t { PT_TCP=0, PT_UDP=1, PT_CBR=2, PT_AUDIO=3, PT_VIDEO=4, PT_ACK=5, PT_START=6, PT_STOP=7, PT_PRUNE=8, PT_GRAFT=9, PT_GRAFTACK=10, PT_JOIN=11, PT_ASSERT=12, PT_MESSAGE=13, PT_RTCP=14, PT_RTP=15, PT_RTPROTO_DV=16, PT_CtrMcast_Encap=17, PT_CtrMcast_Decap=18, PT_SRM=19, /* simple signalling messages */ PT_REQUEST=20, PT_ACCEPT=21, PT_CONFIRM=22, PT_TEARDOWN=23, PT_LIVE=24, // packet from live network PT_REJECT=25, PT_TELNET=26, // not needed: telnet use TCP PT_FTP=27, PT_PARETO=28, PT_EXP=29, PT_INVAL=30, PT_HTTP=31, /* new encapsulator */ PT_ENCAPSULATED=32, PT_MFTP=33, /* CMU/Monarch's extnsions */ PT_ARP=34, PT_MAC=35, PT_TORA=36, PT_DSR=37, PT_AODV=38, PT_IMEP=39, // RAP packets PT_RAP_DATA=40, PT_RAP_ACK=41, PT_TFRC=42, PT_TFRC_ACK=43, PT_PING=44, // Diffusion packets - Chalermek PT_DIFF=45, // LinkState routing update packets PT_RTPROTO_LS=46, // MPLS LDP header PT_LDP=47, // GAF packet PT_GAF=48, // ReadAudio traffic PT_REALAUDIO=49, // Pushback Messages PT_PUSHBACK=50,#ifdef HAVE_STL // Pragmatic General Multicast PT_PGM=51,#endif //STL // LMS packets PT_LMS=52, PT_LMS_SETUP=53, PT_SCTP=54, PT_SCTP_APP1=55, // SMAC packet PT_SMAC=56, // XCP packet PT_XCP=57, //---------------ieee802.16--------------- PT_UGS=58, PT_rtPS=59, PT_ertPS=60, PT_nrtPS=61, PT_BE=62, PT_RNGREQ=63, PT_RNGRSP=64, PT_BWREQ=65, PT_ULMAP=66, PT_DLMAP=67, // insert new packet types here PT_NTYPE=68 // This MUST be the LAST one};class p_info {public: p_info() { name_[PT_TCP]= "tcp"; name_[PT_UDP]= "udp"; name_[PT_CBR]= "cbr"; name_[PT_AUDIO]= "audio"; name_[PT_VIDEO]= "video"; name_[PT_ACK]= "ack"; name_[PT_START]= "start"; name_[PT_STOP]= "stop"; name_[PT_PRUNE]= "prune"; name_[PT_GRAFT]= "graft"; name_[PT_GRAFTACK]= "graftAck"; name_[PT_JOIN]= "join"; name_[PT_ASSERT]= "assert"; name_[PT_MESSAGE]= "message"; name_[PT_RTCP]= "rtcp"; name_[PT_RTP]= "rtp"; name_[PT_RTPROTO_DV]= "rtProtoDV"; name_[PT_CtrMcast_Encap]= "CtrMcast_Encap"; name_[PT_CtrMcast_Decap]= "CtrMcast_Decap"; name_[PT_SRM]= "SRM"; name_[PT_REQUEST]= "sa_req"; name_[PT_ACCEPT]= "sa_accept"; name_[PT_CONFIRM]= "sa_conf"; name_[PT_TEARDOWN]= "sa_teardown"; name_[PT_LIVE]= "live"; name_[PT_REJECT]= "sa_reject"; name_[PT_TELNET]= "telnet"; name_[PT_FTP]= "ftp"; name_[PT_PARETO]= "pareto"; name_[PT_EXP]= "exp"; name_[PT_INVAL]= "httpInval"; name_[PT_HTTP]= "http"; name_[PT_ENCAPSULATED]= "encap"; name_[PT_MFTP]= "mftp"; name_[PT_ARP]= "ARP"; name_[PT_MAC]= "MAC"; name_[PT_TORA]= "TORA"; name_[PT_DSR]= "DSR"; name_[PT_AODV]= "AODV"; name_[PT_IMEP]= "IMEP"; name_[PT_RAP_DATA] = "rap_data"; name_[PT_RAP_ACK] = "rap_ack"; name_[PT_TFRC]= "tcpFriend"; name_[PT_TFRC_ACK]= "tcpFriendCtl"; name_[PT_PING]="ping"; /* For diffusion : Chalermek */ name_[PT_DIFF] = "diffusion"; // Link state routing updates name_[PT_RTPROTO_LS] = "rtProtoLS"; // MPLS LDP packets name_[PT_LDP] = "LDP"; // for GAF name_[PT_GAF] = "gaf"; // RealAudio packets name_[PT_REALAUDIO] = "ra"; //pushback name_[PT_PUSHBACK] = "pushback";#ifdef HAVE_STL // for PGM name_[PT_PGM] = "PGM";#endif //STL // LMS entries name_[PT_LMS]="LMS"; name_[PT_LMS_SETUP]="LMS_SETUP"; name_[PT_SCTP]= "sctp"; name_[PT_SCTP_APP1] = "sctp_app1"; // smac name_[PT_SMAC]="smac"; name_[PT_XCP]="xcp"; //==========francis 2006/05/04========== name_[PT_UGS]= "UGS"; name_[PT_rtPS]= "rtPS"; name_[PT_ertPS]= "ertPS"; name_[PT_nrtPS]= "nrtPS"; name_[PT_BE]= "BE"; name_[PT_RNGREQ]= "RNGREQ"; name_[PT_RNGRSP]="RNGRSP"; name_[PT_BWREQ]="BWREQ"; name_[PT_ULMAP]="ULMAP"; name_[PT_DLMAP]="DLMAP"; //====================================== name_[PT_NTYPE]= "undefined"; } const char* name(packet_t p) const { if ( p <= PT_NTYPE ) return name_[p]; return 0; } static bool data_packet(packet_t type) { return ( (type) == PT_TCP || \ (type) == PT_TELNET || \ (type) == PT_CBR || \ (type) == PT_AUDIO || \ (type) == PT_VIDEO || \ (type) == PT_ACK || \ (type) == PT_SCTP || \ (type) == PT_SCTP_APP1 \ ); }private: static char* name_[PT_NTYPE+1];};extern p_info packet_info; /* map PT_* to string name *///extern char* p_info::name_[];#define DATA_PACKET(type) ( (type) == PT_TCP || \ (type) == PT_TELNET || \ (type) == PT_CBR || \ (type) == PT_AUDIO || \ (type) == PT_VIDEO || \ (type) == PT_ACK || \ (type) == PT_SCTP || \ (type) == PT_SCTP_APP1 \ )#define OFFSET(type, field) ((int) &((type *)0)->field)class PacketData : public AppData {public: PacketData(int sz) : AppData(PACKET_DATA) { datalen_ = sz; if (datalen_ > 0) data_ = new unsigned char[datalen_]; else data_ = NULL; } PacketData(PacketData& d) : AppData(d) { datalen_ = d.datalen_; if (datalen_ > 0) { data_ = new unsigned char[datalen_]; memcpy(data_, d.data_, datalen_); } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -