Connectivity.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _CONNECTIVITY_H_
00018 #define _CONNECTIVITY_H_
00019 
00020 #include "SimEventHandler.h"
00021 #include <oasys/debug/DebugUtils.h>
00022 #include <oasys/debug/Logger.h>
00023 #include <oasys/util/StringUtils.h>
00024 
00025 namespace dtnsim {
00026 
00027 class Node;
00028 
00029 
00034 struct ConnState {
00039     ConnState(): open_(true), bw_(100000), latency_(10) {}
00040 
00044     ConnState(bool open, int bw, int latency)
00045         : open_(open), bw_(bw), latency_(latency) {}
00046 
00050     bool parse_bw(const char* bw_str, int* bw);
00051 
00055     bool parse_time(const char* time_str, int* time);
00056 
00061     bool parse_options(int argc, const char** argv, const char** invalidp);
00062 
00063     
00064     bool open_;
00065     int  bw_;
00066     int  latency_;
00067 };
00068 
00073 class Connectivity : public oasys::Logger, public SimEventHandler {
00074 public:
00078     static Connectivity* instance()
00079     {
00080         if (!instance_) {
00081             ASSERT(type_ != ""); // type must be set;
00082             instance_ = create_conn();
00083         }
00084         
00085         return instance_;
00086     }
00087 
00091     Connectivity();
00092 
00096     virtual ~Connectivity() {}
00097     
00101     const ConnState* lookup(Node* n1, Node* n2);
00102 
00106     virtual void process(SimEvent *e);
00107 
00111     virtual bool exec(int argc, const char** argv);
00112     
00113 protected:
00114     friend class ConnCommand;
00115     
00121     typedef oasys::StringHashMap<ConnState> StateTable;
00122     StateTable state_;
00123 
00127     static Connectivity* create_conn();
00128 
00132     void set_state(const char* n1, const char* n2, const ConnState& s);
00133     
00134     static std::string type_;           
00135     static Connectivity* instance_;     
00136 };
00137 
00138 } // namespace dtnsim
00139 
00140 #endif /* _CONNECTIVITY_H_ */

Generated on Thu Jun 7 16:56:49 2007 for DTN Reference Implementation by  doxygen 1.5.1