xorp

vertex.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8 sw=4:
00003 
00004 // Copyright (c) 2001-2009 XORP, Inc.
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License, Version 2, June
00008 // 1991 as published by the Free Software Foundation. Redistribution
00009 // and/or modification of this program under the terms of any other
00010 // version of the GNU General Public License is not permitted.
00011 // 
00012 // This program is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00015 // see the GNU General Public License, Version 2, a copy of which can be
00016 // found in the XORP LICENSE.gpl file.
00017 // 
00018 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00019 // http://xorp.net
00020 
00021 // $XORP: xorp/contrib/olsr/vertex.hh,v 1.3 2008/10/02 21:56:36 bms Exp $
00022 
00023 #ifndef __OLSR_VERTEX_HH__
00024 #define __OLSR_VERTEX_HH__
00025 
00029 class Vertex {
00030  public:
00031     Vertex();
00032 
00033     explicit Vertex(const Neighbor& n);
00034 
00035     explicit Vertex(const TwoHopNeighbor& n2);
00036 
00037     explicit Vertex(const IPv4& main_addr);
00038 
00039     explicit Vertex(const TopologyEntry& tc);
00040 
00055     inline bool operator<(const Vertex& other) const {
00056 #if 0
00057     if (_main_addr == other.main_addr()) {
00058         if (_is_origin == other.is_origin())
00059         return _t < other.type();
00060         return _is_origin > other.is_origin();
00061     }
00062 #endif
00063     return _main_addr < other.main_addr();
00064     }
00065 
00075     inline bool operator==(const Vertex& other) const {
00076     return _main_addr == other.main_addr();
00077     }
00078 
00079     inline void set_main_addr(const IPv4& main_addr) {
00080     _main_addr = main_addr;
00081     }
00082 
00083     inline IPv4 main_addr() const {
00084     return _main_addr;
00085     }
00086 
00087     void set_nodeid(uint32_t nid) {
00088     _nodeid = nid;
00089     }
00090 
00091     uint32_t nodeid() const {
00092     return _nodeid;
00093     }
00094 
00095     void set_is_origin(bool v) {
00096     _is_origin = v;
00097     }
00098 
00102     bool is_origin() const {
00103     return _is_origin;
00104     }
00105 
00106     void set_producer(const IPv4& producer) {
00107     _producer = producer;
00108     }
00109 
00110     IPv4 producer() const {
00111     return _producer;
00112     }
00113 
00114     void set_faceid(const OlsrTypes::FaceID fid) {
00115     _faceid = fid;
00116     }
00117 
00118     OlsrTypes::FaceID faceid() const {
00119     return _faceid;
00120     }
00121 
00125     const LogicalLink* link() const {
00126     return _link;
00127     }
00128 
00129     void set_link(const LogicalLink* l) {
00130     XLOG_ASSERT(_t == OlsrTypes::VT_NEIGHBOR);
00131     _link = l;
00132     }
00133 
00137     const TwoHopLink* twohop_link() const {
00138     return _twohop_link;
00139     }
00140 
00141     void set_twohop_link(const TwoHopLink* l2) {
00142     XLOG_ASSERT(_t == OlsrTypes::VT_TWOHOP);
00143     _twohop_link = l2;
00144     }
00145 
00146     void set_type(const OlsrTypes::VertexType t) {
00147     _t = t;
00148     }
00149 
00150     OlsrTypes::VertexType type() const {
00151     return _t;
00152     }
00153 
00154     string str() const {
00155     string output = "OLSR";
00156     output += c_format(" Node %s", cstring(_main_addr));
00157     output += c_format(" Type %u", XORP_UINT_CAST(type()));
00158     output += c_format(" ID %u", XORP_UINT_CAST(nodeid()));
00159     return output;
00160     }
00161 
00162  private:
00166     bool    _is_origin;
00167 
00172     OlsrTypes::VertexType _t;
00173 
00178     uint32_t    _nodeid;
00179 
00184     IPv4    _main_addr;
00185 
00191     IPv4    _producer;
00192 
00193     // XXX: union candidate.
00194 
00200     OlsrTypes::FaceID   _faceid;
00201 
00206     const LogicalLink*  _link;
00207 
00212     const TwoHopLink*   _twohop_link;
00213 };
00214 
00218 inline
00219 Vertex::Vertex()
00220  : _is_origin(false),
00221    _t(OlsrTypes::VT_UNKNOWN),
00222    _nodeid(OlsrTypes::UNUSED_NEIGHBOR_ID),
00223    _faceid(OlsrTypes::UNUSED_FACE_ID)
00224 {
00225 }
00226 
00227 // There are several explicit constructors for Vertex. These are used
00228 // to populate Vertex with the information which we will need when
00229 // plumbing routes to the policy engine for redistribution, after the
00230 // SPT computation.
00231 
00241 inline
00242 Vertex::Vertex(const Neighbor& n)
00243  : _is_origin(false),
00244    _t(OlsrTypes::VT_NEIGHBOR),
00245    _nodeid(n.id()),
00246    _main_addr(n.main_addr()),
00247    _producer(n.main_addr()),
00248    _faceid(OlsrTypes::UNUSED_FACE_ID)
00249 {
00250 }
00251 
00266 inline
00267 Vertex::Vertex(const TwoHopNeighbor& n2)
00268  : _is_origin(false),
00269    _t(OlsrTypes::VT_TWOHOP),
00270    _nodeid(n2.id()),
00271    _main_addr(n2.main_addr()),
00272    _faceid(OlsrTypes::UNUSED_FACE_ID)
00273 {
00274 }
00275 
00283 inline
00284 Vertex::Vertex(const IPv4& main_addr)
00285  : _is_origin(false),
00286    _t(OlsrTypes::VT_TOPOLOGY),
00287    _main_addr(main_addr)
00288 {
00289 }
00290 
00298 inline
00299 Vertex::Vertex(const TopologyEntry& tc)
00300  : _is_origin(false),
00301    _t(OlsrTypes::VT_TOPOLOGY),
00302    _nodeid(tc.id()),
00303    _main_addr(tc.destination()),
00304    _producer(tc.lasthop())
00305 {
00306 }
00307 
00308 #endif // __OLSR_VERTEX_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations