00001 /* 00002 * Copyright 2004-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 _LINK_STATE_GRAPH_H_ 00018 #define _LINK_STATE_GRAPH_H_ 00019 00020 #include <set> 00021 #include <oasys/debug/Logger.h> 00022 00023 #include "BundleRouter.h" 00024 #include "LinkScheduleEstimator.h" 00025 00026 00027 #define MAX_EID 255 00028 00029 namespace dtn { 00030 00064 class LinkStateGraph : public oasys::Logger { 00065 public: 00066 LinkStateGraph(); 00067 00068 class Vertex; 00069 class Edge; 00070 00071 typedef int cost_t; 00072 typedef std::set<Vertex*> VertexSet; 00073 typedef std::set<Edge*> EdgeSet; 00074 00080 VertexSet vertices_; 00081 00088 EdgeSet edges_; 00089 00093 Edge* addEdge(Vertex* from, Vertex* to, cost_t cost); 00094 00095 /* 00096 * Returns the edge between from and to, if such an edge exists. 00097 */ 00098 Edge* getEdge(Vertex* from, Vertex* to); 00099 00103 void removeEdge(Edge *to); 00104 00110 Vertex* getVertex(const char* eid); 00111 00116 Vertex* getMatchingVertex(const char* eid); 00117 00122 Vertex* findNextHop(Vertex* from, Vertex *to); 00123 00125 void dumpGraph(oasys::StringBuffer* buf); 00126 00127 EdgeSet edges(); 00128 00129 /* A time-varying connection between two vertices in the graph */ 00130 class Edge { 00131 public: 00132 Edge(Vertex *from, Vertex *to, cost_t cost); 00133 00134 Vertex* from_; 00135 Vertex* to_; 00136 00137 cost_t cost_; 00138 00139 // log of all the up/down events this edge has seen 00140 LinkScheduleEstimator::Log log_; 00141 LinkScheduleEstimator::LogEntry contact_; 00142 }; 00143 00144 00145 /* 00146 A vertex in the graph is an EID 00147 XXX/jakob - is it? 00148 */ 00149 class Vertex { 00150 public: 00151 Vertex(const char * eid); 00152 00153 char eid_[MAX_EID]; 00154 int dijkstra_distance_; 00155 00156 std::map<Vertex*,Edge*> incoming_edges_; 00157 std::map<Vertex*,Edge*> outgoing_edges_; 00158 00159 int operator<(Vertex* a) { 00160 ASSERT(a); 00161 return strcmp(eid_,a->eid_); 00162 } 00163 }; 00164 }; 00165 00166 } // namespace dtn 00167 00168 #endif /* _LINK_STATE_GRAPH_H_ */