mrcl-address.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00036 #ifndef _MRCL_ADDRESS_
00037 #define _MRCL_ADDRESS_
00038 
00039 #include <packet.h>
00040 
00041 #define MRCL_ADDRESS_MAX_LEN 288
00042 
00043 #define MRCL_ADDRESS_MAX_ROUTING_TREE_DEPTH 10
00044 
00045 #define HDR_ROUTING(p)          (RoutingHdr::access(p))
00046 
00047 typedef struct RoutingHdr {
00048         char saddr_[MRCL_ADDRESS_MAX_LEN];
00049         char daddr_[MRCL_ADDRESS_MAX_LEN];
00050         char nexthop_[MRCL_ADDRESS_MAX_LEN];
00051         int moduleRoute_[MRCL_ADDRESS_MAX_ROUTING_TREE_DEPTH];
00052         int moduleRouteCount_;
00053         int sendup_;
00054         int ttl_;
00055         
00056         inline char *saddr() { return saddr_; }
00057         inline char *daddr() { return daddr_; }
00058         inline char *nexthop() { return nexthop_; }
00059         inline int &ttl() { return ttl_; }
00060         inline void addModuleRoute(int i, int val) 
00061         {
00062                 assert(i < MRCL_ADDRESS_MAX_ROUTING_TREE_DEPTH);
00063                 moduleRoute_[i] = val;
00064                 if(i >= moduleRouteCount_)
00065                         moduleRouteCount_ = i + 1;
00066         }
00067         inline int moduleRouteCount() { return moduleRouteCount_; }
00068         inline int getModuleRoute(int i) { return moduleRoute_[i]; }
00069         inline void clearModuleRoute()
00070         {
00071                 moduleRouteCount_ = 0;
00072                 memset(moduleRoute_, 0, sizeof(int) * MRCL_ADDRESS_MAX_ROUTING_TREE_DEPTH);
00073                 sendup_ = 0;
00074         }
00075         inline int sendup() { return sendup_; }
00076         inline void setSendup() { sendup_ = 1; }
00077 
00078         
00079         static int offset_;
00080         inline static int& offset() { return offset_; }
00081         inline static struct RoutingHdr* access(const Packet* p) {
00082                 return (struct RoutingHdr*)p->access(offset_);
00083         }
00084 } RoutingHdr;
00085 
00086 
00087 class MrclAddress : public TclObject
00088 {
00089 public:
00090         MrclAddress();
00091         MrclAddress(char *addr);
00092         virtual ~MrclAddress();
00093 
00110         virtual int command(int argc, const char*const* argv);
00118         virtual int toString(char *str, int strlen) = 0;
00122         virtual int strlen() = 0;
00123         
00129         virtual void setAddress(const char *addr) = 0;
00130 
00131         void setAddr(void *addr, int addrlen);
00132 
00133         void getAddr(void *addr, int addrle = MRCL_ADDRESS_MAX_LEN - sizeof(int), int offset = 0);
00134 
00135         char *getAddr();
00136 
00137         void write(void *addr, int addrlen);
00138 
00139         bool operator==(const MrclAddress &a);
00140 
00141         int isEqual(char *addr);
00142 
00143         static int areEqual(char *addr1, char *addr2);
00144         static void storeAddr(char *dst, char *addr);
00145 private:
00146         char addr_[MRCL_ADDRESS_MAX_LEN];
00147 };
00148 
00149 #endif
00150 
00151 

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2