Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

message.hh

Go to the documentation of this file.
00001 // 
00002 // message.hh    : Message definitions
00003 // authors       : Fabio Silva
00004 //
00005 // Copyright (C) 2000-2002 by the University of Southern California
00006 // $Id: message.hh,v 1.6 2002/11/26 22:45:40 haldar 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 //
00022 
00023 // This file defines the Message class, used inside a node to
00024 // represent a diffusion message. It contains all elements from the
00025 // packet header in addition to the packet's attributes. The Message
00026 // class also contains other flags that are not part of diffusion
00027 // packets. new_message_ indicates if this packet/message was seen in
00028 // the past, indicating a loop (this is set by diffusion upon
00029 // receiving the packet). next_port_ is used by the Filter API to
00030 // indicate the packet's next destination.
00031 //
00032 // This file also defines two other attributes (ControlMsgAttr and
00033 // OriginalHdrAttr) and two classes (ControlMessage and
00034 // OriginalHeader). These are used when sending packets/messages from
00035 // the diffusion core to the library API.
00036 //
00037 // The function CopyMessage can be used to copy a message. It returns
00038 // a pointer to the newly created message. The original message is not
00039 // changed.
00040 
00041 #ifndef _MESSAGE_HH_
00042 #define _MESSAGE_HH_
00043 
00044 #ifdef HAVE_CONFIG_H
00045 #include "config.h"
00046 #endif // HAVE_CONFIG_H
00047 
00048 #include "nr/nr.hh"
00049 #include "header.hh"
00050 #include "attrs.hh"
00051 
00052 class Message {
00053 public:
00054   // Read directly from the packet header
00055   int8_t  version_;
00056   int8_t  msg_type_;
00057   u_int16_t source_port_;
00058   int16_t data_len_;
00059   int16_t num_attr_;
00060   int32_t pkt_num_;
00061   int32_t rdm_id_;
00062   int32_t next_hop_;
00063   int32_t last_hop_;
00064 
00065   // Added variables
00066   int new_message_;
00067   u_int16_t next_port_;
00068 
00069   // Message attributes
00070   NRAttrVec *msg_attr_vec_;
00071 
00072   Message(int8_t version, int8_t msg_type, u_int16_t source_port,
00073           u_int16_t data_len, u_int16_t num_attr, int32_t pkt_num,
00074           int32_t rdm_id, int32_t next_hop, int32_t last_hop) :
00075     version_(version),
00076     msg_type_(msg_type),
00077     source_port_(source_port),
00078     data_len_(data_len),
00079     num_attr_(num_attr),
00080     pkt_num_(pkt_num),
00081     rdm_id_(rdm_id),
00082     next_hop_(next_hop),
00083     last_hop_(last_hop)
00084   {
00085     msg_attr_vec_ = NULL;
00086     next_port_ = 0;
00087     new_message_ = 1;             // New message by default, will be changed
00088                                   // later if message is found to be old
00089   }
00090 
00091   ~Message()
00092   {
00093     if (msg_attr_vec_){
00094       ClearAttrs(msg_attr_vec_);
00095       delete msg_attr_vec_;
00096     }
00097   }
00098 };
00099 
00100 extern NRSimpleAttributeFactory<void *> ControlMsgAttr;
00101 extern NRSimpleAttributeFactory<void *> OriginalHdrAttr;
00102 
00103 #define CONTROL_MESSAGE_KEY  1400
00104 #define ORIGINAL_HEADER_KEY  1401
00105 
00106 // Control Message types
00107 typedef enum ctl_t_ {
00108   ADD_UPDATE_FILTER,
00109   REMOVE_FILTER,
00110   SEND_MESSAGE
00111 } ctl_t;
00112 
00113 class ControlMessage {
00114 public:
00115 
00116   ControlMessage(int32_t command, int32_t param1, int32_t param2) :
00117     command_(command), param1_(param1), param2_(param2) {};
00118 
00119   int32_t command_;
00120   int32_t param1_;
00121   int32_t param2_;
00122 };
00123 
00124 class RedirectMessage {
00125 public:
00126 
00127   RedirectMessage(int8_t new_message, int8_t msg_type, u_int16_t source_port,
00128                   u_int16_t data_len, u_int16_t num_attr, int32_t rdm_id,
00129                   int32_t pkt_num, int32_t next_hop, int32_t last_hop,
00130                   int32_t handle, u_int16_t next_port) :
00131     new_message_(new_message), msg_type_(msg_type), source_port_(source_port),
00132     data_len_(data_len), num_attr_(num_attr), rdm_id_(rdm_id),
00133     pkt_num_(pkt_num), next_hop_(next_hop), last_hop_(last_hop),
00134     handle_(handle), next_port_(next_port) {};
00135 
00136   int8_t  new_message_;
00137   int8_t  msg_type_;
00138   u_int16_t source_port_;
00139   u_int16_t data_len_;
00140   u_int16_t num_attr_;
00141   int32_t rdm_id_;
00142   int32_t pkt_num_;
00143   int32_t next_hop_;
00144   int32_t last_hop_;
00145   int32_t handle_;
00146   u_int16_t next_port_;
00147 };
00148 
00149 Message * CopyMessage(Message *msg);
00150 
00151 #endif // !_MESSAGE_HH_

Generated on Tue Apr 20 12:14:24 2004 for NS2.26SourcesOriginal by doxygen 1.3.3