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 _ROUTING_MODULE_ 00037 #define _ROUTING_MODULE_ 00038 00039 #include <module.h> 00040 #include <clmessage.h> 00041 #include <cltracer.h> 00042 #include "mrcl-address.h" 00043 #include "metric.h" 00044 #include "utility.h" 00045 #include "routing-queue.h" 00046 00047 extern ClMessage_t CL_ROUTEMESSAGE; 00048 00049 #define ROUTEREACHABLE_VERBOSITY 5 00050 #define ROUTE_REACHABLE_ALLOC_INFO_PER_TIME 10 00051 00052 #define CTRL_PKT_DROP_VERBOSITY 10 00053 #define CTRL_PKT_DROP_MSG "CTRL" 00054 00059 class RouteReachable : public ClMessage 00060 { 00061 public: 00067 RouteReachable(int source); 00071 virtual ~RouteReachable(); 00077 void setAddress(char *a); 00081 char *getAddress(); 00088 void addRouteInfo(RouteInfo *i); 00092 int length(); 00101 RouteInfo *getRouteInfo(int id); 00105 RouteInfo **getRouteInfo(); 00109 void empty(); 00110 int isMyIP(); 00111 void setMyIP(); 00112 void processed(int value); 00113 int processed(); 00114 int getIndex(int id); 00115 private: 00119 RouteInfo **info_; 00123 int nInfo_; 00127 int *modules_; 00131 int nModules_; 00135 int infoLen_; 00139 char addr_[MRCL_ADDRESS_MAX_LEN]; 00140 int myIP_; 00141 int processed_; 00142 }; 00143 00144 00145 00146 // class RouteReachableTracer : public ClMessageTracer 00147 // { 00148 // public: 00149 // RouteReachableTracer(); 00150 // void format(ClMessage *m, ClSAP *sap); 00151 // }; 00152 00153 00154 struct ModuleRoute 00155 { 00156 DinArray modules; 00157 double w; 00158 Reachability reachability; 00159 }; 00160 00164 class MrclRouting : public Module 00165 { 00166 friend class RoutingQueue; 00167 public: 00171 MrclRouting(); 00175 virtual ~MrclRouting(); 00186 virtual int command(int argc, const char*const* argv); 00193 virtual int recvSyncClMsg(ClMessage *m); 00194 void recv(Packet* p); 00195 protected: 00204 virtual int controlPacket(Packet *p) = 0; 00212 virtual char *getNextHop(Packet *p) = 0; 00213 int getRoute(MrclAddress *a, Packet *p, int i); 00214 int getRoute(char *addr, Packet *p, int i); 00226 virtual int canIReach(char *a, Metric ***m)=0; 00227 virtual void forward(Packet *p) = 0; 00228 virtual void resolve(Packet *p) = 0; 00229 void addAddress(MrclAddress *a); 00230 MrclAddress *getAddress(int i); 00231 int nAddresses(); 00232 int isMyAddress(char *addr); 00233 int overheadLength_; 00234 private: 00249 int getConfiguration(char *a, int source = -1); 00250 int findNextLeaf(int i = -1); 00254 MrclAddress **addresses_; 00258 int nAddresses_; 00264 RouteReachable *rr_; 00268 double lastGetConfiguration_; 00272 DinArray routes_; 00276 double delayUp_; 00280 double delayDown_; 00281 }; 00282 00283 00284 #endif