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

ipv4.h

Go to the documentation of this file.
00001 // GENERAL PUBLIC LICENSE AGREEMENT
00002 // 
00003 // PLEASE READ THIS DOCUMENT CAREFULLY BEFORE UTILIZING THE PROGRAM
00004 // 
00005 // BY UTILIZING THIS PROGRAM, YOU AGREE TO BECOME BOUND BY THE TERMS OF
00006 // THIS LICENSE.  IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE, DO
00007 // NOT USE THIS PROGRAM OR ANY PORTION THEREOF IN ANY FORM OR MANNER.
00008 // 
00009 // This Program is licensed, not sold to you by GEORGIA TECH RESEARCH
00010 // CORPORATION ("GTRC"), owner of all code and accompanying documentation
00011 // (hereinafter "Program"), for use only under the terms of this License,
00012 // and GTRC reserves any rights not expressly granted to you.
00013 // 
00014 // 1.  This License allows you to:
00015 // 
00016 // (a) make copies and distribute copies of the Program's source code
00017 // provide that any such copy clearly displays any and all appropriate
00018 // copyright notices and disclaimer of warranty as set forth in Article 5
00019 // and 6 of this License.  All notices that refer to this License and to
00020 // the absence of any warranty must be kept intact at all times.  A copy
00021 // of this License must accompany any and all copies of the Program
00022 // distributed to third parties.
00023 // 
00024 // A fee may be charged to cover the cost associated with the physical
00025 // act of transferring a copy to a third party.  At no time shall the
00026 // program be sold for commercial gain either alone or incorporated with
00027 // other program(s) without entering into a separate agreement with GTRC.
00028 //  
00029 // 
00030 // (b) modify the original copy or copies of the Program or any portion
00031 // thereof ("Modification(s)").  Modifications may be copied and
00032 // distributed under the terms and conditions as set forth above,
00033 // provided the following conditions are met:
00034 // 
00035 //     i) any and all modified files must be affixed with prominent
00036 // notices that you have changed the files and the date that the changes
00037 // occurred.
00038 //              
00039 //     ii) any work that you distribute, publish, or make available, that
00040 // in whole or in part contains portions of the Program or derivative
00041 // work thereof, must be licensed at no charge to all third parties under
00042 // the terms of this License.
00043 // 
00044 //    iii) if the modified program normally reads commands interactively
00045 // when run, you must cause it, when started running for such interactive
00046 // use in the most ordinary way, to display and/or print an announcement
00047 // with all appropriate copyright notices and disclaimer of warranty as
00048 // set forth in Article 5 and 6 of this License to be clearly displayed.
00049 // In addition, you must provide reasonable access to this License to the
00050 // user.
00051 // 
00052 // Any portion of a Modification that can be reasonably considered
00053 // independent of the Program and separate work in and of itself is not
00054 // subject to the terms and conditions set forth in this License as long
00055 // as it is not distributed with the Program or any portion thereof.
00056 // 
00057 // 
00058 // 2. This License further allows you to copy and distribute the Program
00059 //    or a work based on it, as set forth in Article 1 Section b in
00060 //    object code or executable form under the terms of Article 1 above
00061 //    provided that you also either:
00062 // 
00063 //    i) accompany it with complete corresponding machine-readable source
00064 // code, which must be distributed under the terms of Article 1, on a
00065 // medium customarily used for software interchange; or,
00066 // 
00067 //   ii) accompany it with a written offer, valid for no less than three
00068 // (3) years from the time of distribution, to give any third party, for
00069 // no consideration greater than the cost of physical transfer, a
00070 // complete machine-readable copy of the corresponding source code, to be
00071 // distributed under the terms of Article 1 on a medium customarily used
00072 // for software interchange; or,
00073 // 
00074 // 
00075 // 3.  Export Law Assurance.
00076 // 
00077 // You agree that the Software will not be shipped, transferred or
00078 // exported, directly into any country prohibited by the United States
00079 // Export Administration Act and the regulations thereunder nor will be
00080 // used for any purpose prohibited by the Act.
00081 //  
00082 // 4.  Termination.
00083 // 
00084 // If at anytime you are unable to comply with any portion of this
00085 // License you must immediately cease use of the Program and all
00086 // distribution activities involving the Program or any portion thereof.
00087 // 
00088 // 
00089 // 5.  Disclaimer of Warranties and Limitation on Liability.
00090 // 
00091 // YOU ACCEPT THE PROGRAM ON AN "AS IS" BASIS.  GTRC MAKES NO WARRANTY
00092 // THAT ALL ERRORS CAN BE OR HAVE BEEN ELIMINATED FROM PROGRAM.  GTRC
00093 // SHALL NOT BE RESPONSIBLE FOR LOSSES OF ANY KIND RESULTING FROM THE USE
00094 // OF PROGRAM AND ITS ACCOMPANYING DOCUMENT(S), AND CAN IN NO WAY PROVIDE
00095 // COMPENSATION FOR ANY LOSSES SUSTAINED, INCLUDING BUT NOT LIMITED TO
00096 // ANY OBLIGATION, LIABILITY, RIGHT, CLAIM OR REMEDY FOR TORT, OR FOR ANY
00097 // ACTUAL OR ALLEGED INFRINGEMENT OF PATENTS, COPYRIGHTS, TRADE SECRETS,
00098 // OR SIMILAR RIGHTS OF THIRD PARTIES, NOR ANY BUSINESS EXPENSE, MACHINE
00099 // DOWNTIME OR DAMAGES CAUSED TO YOU BY ANY DEFICIENCY, DEFECT OR ERROR
00100 // IN PROGRAM OR MALFUNCTION THEREOF, NOR ANY INCIDENTAL OR CONSEQUENTIAL
00101 // DAMAGES, HOWEVER CAUSED.  GTRC DISCLAIMS ALL WARRANTIES, BOTH EXPRESS
00102 // AND IMPLIED RESPECTING THE USE AND OPERATION OF PROGRAM AND ITS
00103 // ACCOMPANYING DOCUMENTATION, INCLUDING ALL IMPLIED WARRANTIES OF
00104 // MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE AND ANY IMPLIED
00105 // WARRANTY ARISING FROM COURSE OF PERFORMANCE, COURSE OF DEALING OR
00106 // USAGE OF TRADE.  GTRC MAKES NO WARRANTY THAT PROGRAM IS ADEQUATELY OR
00107 // COMPLETELY DESCRIBED IN, OR BEHAVES IN ACCORDANCE WITH ANY
00108 // ACCOMPANYING DOCUMENTATION.  THE USER OF PROGRAM IS EXPECTED TO MAKE
00109 // THE FINAL EVALUATION OF PROGRAM'S USEFULNESS IN USER'S OWN
00110 // ENVIRONMENT.
00111 // 
00112 // GTRC represents that, to the best of its knowledge, the software
00113 // furnished hereunder does not infringe any copyright or patent.
00114 // 
00115 // GTRC shall have no obligation for support or maintenance of Program.
00116 // 
00117 // 6.  Copyright Notice.
00118 // 
00119 // THE SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE COPYRIGHTED WITH ALL
00120 // RIGHTS RESERVED BY GTRC.  UNDER UNITED STATES COPYRIGHT LAWS, THE
00121 // SOFTWARE AND ITS ACCOMPANYING DOCUMENTATION MAY NOT BE COPIED EXCEPT
00122 // AS GRANTED HEREIN.
00123 // 
00124 // You acknowledge that GTRC is the sole owner of Program, including all
00125 // copyrights subsisting therein.  Any and all copies or partial copies
00126 // of Program made by you shall bear the copyright notice set forth below
00127 // and affixed to the original version or such other notice as GTRC shall
00128 // designate.  Such notice shall also be affixed to all improvements or
00129 // enhancements of Program made by you or portions thereof in such a
00130 // manner and location as to give reasonable notice of GTRC's copyright
00131 // as set forth in Article 1.
00132 // 
00133 // Said copyright notice shall read as follows:
00134 // 
00135 // Copyright 2004
00136 // Dr. George F. Riley
00137 // Georgia Tech Research Corporation
00138 // Atlanta, Georgia 30332-0415
00139 // All Rights Reserved
00140 //
00141 // $Id: ipv4.h 446 2005-11-15 20:48:03Z riley $
00142 
00143 
00144 
00145 // Georgia Tech Network Simulator - Internet Protocol base class
00146 // George F. Riley.  Georgia Tech, Spring 2002
00147 
00148 // Implements the Internet Protocol Version 4, Layer 3
00149 
00150 #ifndef __ipv4_h__
00151 #define __ipv4_h__
00152 
00153 #include <list>
00154 
00155 #include "common-defs.h"
00156 #include "l3protocol.h"
00157 #include "pdu.h"
00158 #include "ipaddr.h"
00159 #include "node.h"
00160 #include "backplane.h"
00161 
00162 class IPV4Header;
00163 
00164 class IPV4ReqInfo;
00165 //Doc:ClassXRef
00166 class IPV4 : public L3Protocol {
00167 //Doc:Class The class {\tt IPV4} implements the Internet Protocol Version 4
00168 //Doc:Class It derives  from the class {\tt L3Protocol}. Since IPV4 is a
00169 //Doc:Class a static instance of this is enough for a simulation that uses
00170 //Doc:Class IPv4.
00171         
00172 public:
00173   typedef enum { DefaultTTL = 64 } DefTTL_t;
00174   typedef enum { VERSION, HEADERLENGTH, SERVICETYPE,
00175                  TOTALLENGTH, IDENTIFICATION,
00176                  FLAGS, FRAGMENTOFFSET,
00177                  TTL, PROTOCOL, HEADERCHECKSUM,
00178                  SRC, DST, UID, OPTIONS } IPV4Trace_t; // Tracing options
00179   //Doc:Method
00180   IPV4();
00181   //Doc:Desc Default constructor
00182 
00183   //Doc:Method
00184   void DataRequest(Node*, Packet*, void*);     // From upper layer
00185   //Doc:Desc This method is used by layer 4 protocols like udp/tcp to
00186   //Doc:Desc hand a packet to IP.
00187   //Doc:Arg1 Pointer to the node requesting the data transfer
00188   //Doc:Arg2 Pointer to the packet to be transmitted
00189   //Doc:Arg3 Any auxiliary information that layer 4 might want to convey
00190   
00191   //Doc:Method
00192   void DataIndication(Interface*, Packet*);    // From lower layer
00193   //Doc:Desc This method is used to pass on a packet from any layer 2 protocol
00194   //Doc:Desc up the stack.
00195   //Doc:Arg1 A pointer to the interface at which this packet is received
00196   //Doc:Arg2 A pointer to the packet that was received
00197   
00198   //Doc:Method
00199   Interface* PeekInterface(Node*, void*);      // Find forwarding interface
00200   //Doc:Desc This method returns the interface pointer. This interface is
00201   //Doc:Desc chosen based on the node pointer and some arbitrary data
00202   //Doc:Desc passed to it.
00203   //Doc:Arg1 the pointer to the assocaited node
00204   //Doc:Arg2 the data based on which we return the address
00205   //Doc:Return the pointer to the interface object
00206   
00207   //Doc:Method
00208   virtual Count_t Version() { return 4;}       // Get IP version number
00209   //Doc:Desc This method returns the version of Internet Protocol
00210   //DOc:Return returns the version
00211   
00212   //Doc:Method
00213   virtual Proto_t Proto()   { return 0x800;}   // Get the protocol number
00214   //Doc:Desc This method returns the IANA assigned protocol number
00215   //Doc:Return the protocol number
00216   
00217 private:
00218   void Broadcast(Node*, Packet*, IPV4ReqInfo*);// Network layer broadcast
00219 private:
00220   static IPV4* instance; // Points to single instance of proto object
00221 public:
00222   //Doc:Method
00223   static IPV4* Instance();   // Get a pointer to the single global instance
00224   //Doc:Desc This method returns the pointer to the global instance
00225   //Doc:Desc of the IPV4 object
00226   //Doc:Return the pointer to the global instance
00227 
00228   // Register data items with the dynamic simulation backplane
00229   static void  RegisterBackplane(DSHandle_t);
00230   static int   IPV4ExportQuery(char*, int, void*);
00231   static int   IPV4DefaultCallback(char*, void*);
00232   static int   IPV4ExportCallback(char*, char*, int, void*);
00233   static int   IPV4ImportCallback(char*, int, char*, void*);
00234 public:
00235   // Static members
00236   static IPV4Header* bpHeader; // IPV4 header imported from backplane
00237   
00238   bool route_locally; // Allows transport layer protocols on the same
00239                       // node to communicate with each other. Off by
00240                       // default.
00241 };
00242 
00243 //Doc:ClassXRef
00244 class IPV4Header : public L3PDU {
00245 //Doc:Class     
00246 public :
00247   //Doc:Method
00248   IPV4Header();
00249   //Doc:Desc This is the default constructor
00250  
00251   //Doc:Method 
00252   IPV4Header(const IPV4Header& r);
00253   //Doc:Desc This constructor takes the reference to an IPV4 header
00254   
00255   //Doc:Method
00256   IPV4Header(char*, Size_t&, Packet*); // Construct from serialized buffer
00257   //Doc:Desc This method creates a PDU and inserts in the packet from
00258   //Doc:Desc a serialized buffer
00259   //Doc:Arg1 pointer to the buffer
00260   //Doc:Arg2 size of the buffer
00261   //Doc:Arg3 the pointer to the packet
00262   
00263   //Doc:Method
00264   virtual ~IPV4Header();
00265   //Doc:Desc Destructor
00266   
00267   //Doc:Method
00268   Size_t  Size() const;
00269   //Doc:Desc This method returns the size of the PDU
00270   //Doc:Return the size of the PDU
00271   
00272   //Doc:Method
00273   PDU*    Copy() const{ return new IPV4Header(*this);}
00274   //Doc:Desc This method creates a copy of this PDU
00275   //Doc:Return A pointer to the copy of this PDU
00276   
00277   //Doc:Method
00278   Count_t Version() { return 4;}       // Indicate IPV4
00279   //Doc:Desc Returns the version number of the protocol
00280   //Doc:Return version 4 of IP
00281   
00282   //Doc:Method
00283   Proto_t Proto() { return 0x800;}        // IPV4 is protocol 0x800
00284   //Doc:Method Return the IPV4 protocol number
00285   //Doc:Return 0x800 for IPV4
00286 
00287   //Doc:Method
00288   Priority_t Priority();
00289   //Doc:Desc   Get the priority for this header. For IPV4, it is the
00290   //Doc:Desc diffserv codepoint field, which overlays the
00291   //Doc:Desc type-of-service field.
00292   //Doc:Return Priority for this packet.
00293 
00294   void    Trace(Tfstream&, Bitmap_t,  // Trace the contents of this pdu
00295                      Packet* = nil, const char* = nil);
00296   //Doc:Desc This method traces the contents of the PDU
00297   //Doc:Arg1 File output stream descriptor
00298   //Doc:Arg2 Bitmap that specifies the level of detail of the trace
00299   //Doc:Arg3 Packet that contains this PDU (optional)
00300   //Doc:Arg4 Extra text information for trace file (optional)
00301   
00302   // Serialization
00303   //Doc:Method
00304   Size_t SSize();                   // Size needed for serialization
00305   //Doc:Desc The actual size of all the PDU contents in terms of bytes for
00306   //Doc:Desc serialization of the contents.
00307   //Doc:Return the size
00308   
00309   //Doc:Method
00310   char*  Serialize(char*, Size_t&); // Serialize to a buffer
00311   //Doc:Desc This method is used to serialize the contents of the PDU
00312   //Doc:Desc into a serialized character buffer b . the size of this buffer is
00313   //Doc:Desc in the size arguement
00314   //Doc:Arg1 This is the pointer to the character buffer
00315   //Doc:Arg2 a reference to the size variable
00316   //Doc:Return the pointer to the updated character buffer
00317   
00318   //Doc:Method
00319   char*  Construct(char*, Size_t&); // Construct from buffer
00320   //Doc:Desc This method is the reverse of the Serialize . It constructs the
00321   //Doc:Desc PDU object from the character buffer that has been received over
00322   //Doc:Desc the network
00323   //Doc:Arg1 This is the pointer to the character buffer
00324   //Doc:Arg2 a reference to the size variable
00325   //Doc:Return the pointer to the character buffer of the remaining data
00326 
00327   // Inherited from L3PDU
00328   //Doc:Method
00329   virtual IPAddr_t GetSrcIP(){return src;}
00330   //Doc:Desc Return the source IP address.
00331   //Doc:Return source IP Address
00332 
00333   //Doc:Method
00334   virtual IPAddr_t GetDstIP() { return dst;}
00335   //Doc:Desc Return the destination IP address.
00336   //Doc:Return destination IP Address
00337 
00338 public:
00339   Byte_t   version;
00340   Byte_t   headerLength;
00341   Byte_t   serviceType;
00342   Word_t   totalLength;
00343   Word_t   identification;
00344   Byte_t   flags;
00345   Word_t   fragmentOffset;
00346   Byte_t   ttl;       // Time to live
00347   Byte_t   protocol;  // Layer 4 protocols
00348   Word_t   headerChecksum;
00349   IPAddr   src;
00350   IPAddr   dst;
00351   PDUVec_t options;   // IP Options
00352 };
00353 
00354 //Doc:ClassXRef
00355 class IPV4Options : public PDU { // Base class for ipv4 options
00356 //Doc:Class The Class {\tt IPV4Options } defines the IP options part
00357 //Doc:Class of the IP Header. As all other headers this is also derived from
00358 //Doc:Class the class {\tt PDU}
00359 public:
00360   //Doc:Method
00361   IPV4Options(Byte_t o) : optionNumber(o) { }
00362   //Doc:Desc Constructor takes a byte as the arguement
00363   
00364 public:
00365   //Doc:Method
00366   virtual Size_t  Size() const { return 0;}
00367   //Doc:Desc Returns the size of the PDU
00368   //Doc:Return size of the PDU
00369   
00370   //Doc:Method  
00371   virtual PDU*    Copy() const { return new IPV4Options(*this);}
00372   //Doc:Desc This method creates a copy of this PDU
00373   //Doc:Return A pointer to the copy of this PDU
00374   
00375   //Doc:Method
00376   virtual void  Trace(Tfstream&, Bitmap_t,     // Trace this pdu 
00377                      Packet* = nil, const char* = nil) { }
00378   //Doc:Desc This method traces the contents of the PDU
00379   //Doc:Arg1 File output stream descriptor
00380   //Doc:Arg2 Bitmap that specifies the level of detail of the trace
00381   //Doc:Arg3 Packet that contains this PDU (optional)
00382   //Doc:Arg4 Extra text information for trace file (optional)
00383   
00384   //Doc:Method
00385   Byte_t  Option() { return optionNumber;}
00386   //Doc:Desc returns the options of the PDU
00387   //Doc:Return the options
00388 public:
00389   Byte_t  optionNumber;
00390 };
00391 
00392 //Doc:ClassXRef
00393 class IPV4ReqInfo {  // Information passed from L4 for IP Data Request
00394 //Doc:Class This class defines the data structure that defines the information
00395 //Doc:Class that is passed from layer 4 to layer 3
00396 public:
00397   IPV4ReqInfo() : dst(IPADDR_NONE), src(IPADDR_NONE) { };
00398   IPV4ReqInfo(IPAddr_t d, IPAddr_t s, Count_t t, Proto_t p) 
00399       : dst(d), src(s), ttl(t), l4proto(p), tos(0) { }
00400   IPV4ReqInfo(IPAddr_t d, IPAddr_t s, Count_t t, Proto_t p, Byte_t ts) 
00401       : dst(d), src(s), ttl(t), l4proto(p), tos(ts) { }
00402   IPAddr   dst;    // Destination
00403   IPAddr   src;    // Src IP (if spoofed, 0 if normal lookup)
00404   Count_t  ttl;    // Time to Live
00405   Proto_t  l4proto;// Layer 4 protocol
00406   Byte_t   tos;    // Value for l3 Type-of-Service field
00407   // Probably need more later
00408 };
00409 
00410 #endif
00411 

Generated on Wed Aug 27 16:17:13 2008 for Georgia Tech Network Simulator (GTNetS) by  doxygen 1.3.9.1