00001 // 00002 // message.hh : Message definitions 00003 // authors : Fabio Silva 00004 // 00005 // Copyright (C) 2000-2003 by the University of Southern California 00006 // $Id: message.hh,v 1.8 2005/09/13 04:53:50 tomh Exp $ 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License, 00010 // version 2, as published by the Free Software Foundation. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License along 00018 // with this program; if not, write to the Free Software Foundation, Inc., 00019 // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00020 // 00021 // Linking this file statically or dynamically with other modules is making 00022 // a combined work based on this file. Thus, the terms and conditions of 00023 // the GNU General Public License cover the whole combination. 00024 // 00025 // In addition, as a special exception, the copyright holders of this file 00026 // give you permission to combine this file with free software programs or 00027 // libraries that are released under the GNU LGPL and with code included in 00028 // the standard release of ns-2 under the Apache 2.0 license or under 00029 // otherwise-compatible licenses with advertising requirements (or modified 00030 // versions of such code, with unchanged license). You may copy and 00031 // distribute such a system following the terms of the GNU GPL for this 00032 // file and the licenses of the other code concerned, provided that you 00033 // include the source code of that other code when and as the GNU GPL 00034 // requires distribution of source code. 00035 // 00036 // Note that people who make modified versions of this file are not 00037 // obligated to grant this special exception for their modified versions; 00038 // it is their choice whether to do so. The GNU General Public License 00039 // gives permission to release a modified version without this exception; 00040 // this exception also makes it possible to release a modified version 00041 // which carries forward this exception. 00042 00043 // This file defines the Message class, used inside a node to 00044 // represent a diffusion message. It contains all elements from the 00045 // packet header in addition to the packet's attributes. The Message 00046 // class also contains other flags that are not part of diffusion 00047 // packets. new_message_ indicates if this packet/message was seen in 00048 // the past, indicating a loop (this is set by diffusion upon 00049 // receiving the packet). next_port_ is used by the Filter API to 00050 // indicate the packet's next destination. 00051 // 00052 // This file also defines two other attributes (ControlMsgAttr and 00053 // OriginalHdrAttr) and two classes (ControlMessage and 00054 // OriginalHeader). These are used when sending packets/messages from 00055 // the diffusion core to the library API. 00056 // 00057 // The function CopyMessage can be used to copy a message. It returns 00058 // a pointer to the newly created message. The original message is not 00059 // changed. 00060 00061 #ifndef _MESSAGE_HH_ 00062 #define _MESSAGE_HH_ 00063 00064 #ifdef HAVE_CONFIG_H 00065 #include "config.h" 00066 #endif // HAVE_CONFIG_H 00067 00068 #include "nr/nr.hh" 00069 #include "header.hh" 00070 #include "attrs.hh" 00071 00072 class Message { 00073 public: 00074 // Read directly from the packet header 00075 int8_t version_; 00076 int8_t msg_type_; 00077 u_int16_t source_port_; 00078 int16_t data_len_; 00079 int16_t num_attr_; 00080 int32_t pkt_num_; 00081 int32_t rdm_id_; 00082 int32_t next_hop_; 00083 int32_t last_hop_; 00084 00085 // Added variables 00086 int new_message_; 00087 u_int16_t next_port_; 00088 00089 // Message attributes 00090 NRAttrVec *msg_attr_vec_; 00091 00092 Message(int8_t version, int8_t msg_type, u_int16_t source_port, 00093 u_int16_t data_len, u_int16_t num_attr, int32_t pkt_num, 00094 int32_t rdm_id, int32_t next_hop, int32_t last_hop) : 00095 version_(version), 00096 msg_type_(msg_type), 00097 source_port_(source_port), 00098 data_len_(data_len), 00099 num_attr_(num_attr), 00100 pkt_num_(pkt_num), 00101 rdm_id_(rdm_id), 00102 next_hop_(next_hop), 00103 last_hop_(last_hop) 00104 { 00105 msg_attr_vec_ = NULL; 00106 next_port_ = 0; 00107 new_message_ = 1; // New message by default, will be changed 00108 // later if message is found to be old 00109 } 00110 00111 ~Message() 00112 { 00113 if (msg_attr_vec_){ 00114 ClearAttrs(msg_attr_vec_); 00115 delete msg_attr_vec_; 00116 } 00117 } 00118 }; 00119 00120 extern NRSimpleAttributeFactory<void *> ControlMsgAttr; 00121 extern NRSimpleAttributeFactory<void *> OriginalHdrAttr; 00122 00123 #define CONTROL_MESSAGE_KEY 1400 00124 #define ORIGINAL_HEADER_KEY 1401 00125 00126 // Control Message types 00127 typedef enum ctl_t_ { 00128 ADD_UPDATE_FILTER, 00129 REMOVE_FILTER, 00130 SEND_MESSAGE, 00131 ADD_TO_BLACKLIST, 00132 CLEAR_BLACKLIST 00133 } ctl_t; 00134 00135 class ControlMessage { 00136 public: 00137 00138 ControlMessage(int32_t command, int32_t param1, int32_t param2) : 00139 command_(command), param1_(param1), param2_(param2) {}; 00140 00141 int32_t command_; 00142 int32_t param1_; 00143 int32_t param2_; 00144 }; 00145 00146 class RedirectMessage { 00147 public: 00148 00149 RedirectMessage(int8_t new_message, int8_t msg_type, u_int16_t source_port, 00150 u_int16_t data_len, u_int16_t num_attr, int32_t rdm_id, 00151 int32_t pkt_num, int32_t next_hop, int32_t last_hop, 00152 int32_t handle, u_int16_t next_port) : 00153 new_message_(new_message), msg_type_(msg_type), source_port_(source_port), 00154 data_len_(data_len), num_attr_(num_attr), rdm_id_(rdm_id), 00155 pkt_num_(pkt_num), next_hop_(next_hop), last_hop_(last_hop), 00156 handle_(handle), next_port_(next_port) {}; 00157 00158 int8_t new_message_; 00159 int8_t msg_type_; 00160 u_int16_t source_port_; 00161 u_int16_t data_len_; 00162 u_int16_t num_attr_; 00163 int32_t rdm_id_; 00164 int32_t pkt_num_; 00165 int32_t next_hop_; 00166 int32_t last_hop_; 00167 int32_t handle_; 00168 u_int16_t next_port_; 00169 }; 00170 00171 Message * CopyMessage(Message *msg); 00172 00173 #endif // !_MESSAGE_HH_
1.7.1