📄 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: /usr/src/mash/repository/vint/ns-2/packet.h,v 1.72 1999/11/23 23:43:31 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 "list.h"#include "packet-stamp.h"#include "ns-process.h"#include "dsr/hdr_sr.h"#define RT_PORT 255 /* port that all route msgs are sent to */#define HDR_CMN(p) ((struct hdr_cmn*)(p)->access(hdr_cmn::offset_))#define HDR_ARP(p) ((struct hdr_arp*)(p)->access(off_arp_))#define HDR_MAC(p) ((struct hdr_mac*)(p)->access(hdr_mac::offset_))#define HDR_MAC802_11(p) ((struct hdr_mac802_11*)(p)->access(hdr_mac::offset_))#define HDR_LL(p) ((struct hdr_ll*)(p)->access(hdr_ll::offset_))#define HDR_IP(p) ((struct hdr_ip*)(p)->access(hdr_ip::offset_))#define HDR_RTP(p) ((struct hdr_rtp*)(p)->access(hdr_rtp::offset_))#define HDR_TCP(p) ((struct hdr_tcp*)(p)->access(hdr_tcp::offset_))#define HDR_SR(p) ((struct hdr_sr*)(p)->access(hdr_sr::offset_))#define HDR_TFRC(p) ((struct hdr_tfrc*)(p)->access(hdr_tfrc::offset_))#define HDR_TORA(p) ((struct hdr_tora*)(p)->access(off_TORA_))#define HDR_IMEP(p) ((struct hdr_imep*)(p)->access(off_IMEP_))#define CIP_DATA 0// Cellular#define CIP_PAGING 1// Cellular#define CIP_PAGE 2// Cellular#define CIP_ROUTE 3// Cellularenum packet_t { PT_TCP, PT_UDP, PT_CBR, PT_AUDIO, PT_VIDEO, PT_ACK, PT_START, PT_STOP, PT_PRUNE, PT_GRAFT, PT_GRAFTACK, PT_JOIN, PT_ASSERT, PT_MESSAGE, PT_RTCP, PT_RTP, PT_RTPROTO_DV, PT_CtrMcast_Encap, PT_CtrMcast_Decap, PT_SRM, /* simple signalling messages */ PT_REQUEST, PT_ACCEPT, PT_CONFIRM, PT_TEARDOWN, PT_LIVE, // packet from live network PT_REJECT, PT_TELNET, // not needed: telnet use TCP PT_FTP, PT_PARETO, PT_EXP, PT_INVAL, PT_HTTP, /* new encapsulator */ PT_ENCAPSULATED, PT_MFTP, /* CMU/Monarch's extnsions */ PT_ARP, PT_MAC, PT_TORA, PT_DSR, PT_AODV, PT_IMEP, // RAP packets PT_RAP_DATA, PT_RAP_ACK, // insert new packet types here PT_TFRC, PT_TFRC_ACK, PT_PING, PT_NTYPE // 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"; 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 \ ); }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 \ )#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 data_ = NULL; } virtual ~PacketData() { if (data_ != NULL) delete []data_; } unsigned char* data() { return data_; } virtual int size() { return datalen_; } virtual AppData* copy() { return new PacketData(*this); }private: unsigned char* data_; int datalen_;};//Monarch exttypedef void (*FailureCallback)(Packet *,void *);class Packet : public Event {private: unsigned char* bits_; // header bits// unsigned char* data_; // variable size buffer for 'data'// unsigned int datalen_; // length of variable size buffer AppData* data_; // variable size buffer for 'data' static void init(Packet*); // initialize pkt hdr bool fflag_;protected: static Packet* free_; // packet free listpublic: Packet* next_; // for queues and the free list static int hdrlen_; Packet() : bits_(0), data_(0), next_(0) { } inline unsigned char* const bits() { return (bits_); } inline Packet* copy() const; static inline Packet* alloc(); static inline Packet* alloc(int); inline void allocdata(int); static inline void free(Packet*); inline unsigned char* access(int off) const { if (off < 0) abort(); return (&bits_[off]); } // This is used for backward compatibility, i.e., assuming user data // is PacketData and return its pointer. inline unsigned char* accessdata() const { if (data_ == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -