xorp

nexthop.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU Lesser General Public License, Version
00008 // 2.1, June 1999 as published by the Free Software Foundation.
00009 // Redistribution and/or modification of this program under the terms of
00010 // any other version of the GNU Lesser General Public License is not
00011 // permitted.
00012 // 
00013 // This program is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00016 // see the GNU Lesser General Public License, Version 2.1, a copy of
00017 // which can be found in the XORP LICENSE.lgpl file.
00018 // 
00019 // XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00020 // http://xorp.net
00021 
00022 // $XORP: xorp/libxorp/nexthop.hh,v 1.11 2008/10/02 21:57:32 bms Exp $
00023 
00024 #ifndef __LIBXORP_NEXTHOP_HH__
00025 #define __LIBXORP_NEXTHOP_HH__
00026 
00027 #include "xorp.h"
00028 #include "ipv4.hh"
00029 #include "ipv6.hh"
00030 #include "ipvx.hh"
00031 
00032 // NextHop is a generic next hop object.
00033 // PeerNextHop is for next hops that are local peers.
00034 // EncapsNextHop is for "next hops" that are non-local, and require 
00035 //  encapsulation to reach.  Eg. PIM Register Encaps.
00036 // ExternalNextHop An IP nexthop that is not an intermediate neighbor.
00037 // DiscardNextHop is a discard interface.
00038 // UnreachableNextHop is an unreachable interface.
00039 //
00040 // there will probably be more needed at some point
00041 
00042 #define GENERIC_NEXTHOP     0
00043 #define PEER_NEXTHOP        1
00044 #define ENCAPS_NEXTHOP      2
00045 #define EXTERNAL_NEXTHOP    3
00046 #define DISCARD_NEXTHOP     4
00047 #define UNREACHABLE_NEXTHOP 5
00048 
00059 class NextHop {
00060 public:
00064     NextHop() {}
00065 
00069     virtual ~NextHop() {}
00070 
00084     virtual int type() = 0;
00085 
00092     virtual string str() const = 0;
00093 };
00094 
00095 
00101 template<class A>
00102 class IPNextHop : public NextHop {
00103 public:
00110     IPNextHop(const A &from_ipaddr);
00111 
00112 #ifdef XORP_USE_USTL
00113     IPNextHop() { }
00114 #endif
00115     
00121     const A& addr() const { return _addr; }
00122     
00123 protected:
00124     A _addr;
00125 };
00126 
00127 typedef IPNextHop<IPv4> IPv4NextHop;
00128 typedef IPNextHop<IPv6> IPv6NextHop;
00129 typedef IPNextHop<IPvX> IPvXNextHop;
00130 
00131 
00138 template<class A>
00139 class IPPeerNextHop : public IPNextHop<A> {
00140 public:
00147     IPPeerNextHop(const A &from_addr);
00148 
00149 #ifdef XORP_USE_USTL
00150     IPPeerNextHop() { }
00151 #endif
00152 
00158     int type() { return PEER_NEXTHOP; }
00159 
00166     string str() const;
00167     
00168 private:
00169     
00170 };
00171 
00172 typedef IPPeerNextHop<IPv4> IPv4PeerNextHop;
00173 typedef IPPeerNextHop<IPv6> IPv6PeerNextHop;
00174 typedef IPPeerNextHop<IPvX> IPvXPeerNextHop;
00175 
00176 
00183 template<class A>
00184 class IPEncapsNextHop : public IPNextHop<A> {
00185 public:
00192     IPEncapsNextHop(const A &from_addr);
00193     
00199     int type() { return ENCAPS_NEXTHOP; }
00200 
00207     string str() const;
00208     
00209 private:
00210     //_cached_peer is the cached copy of the local peer we send the 
00211     //encapsulated packet to.
00212     IPPeerNextHop<A> *_cached_peer;
00213 };
00214 
00215 typedef IPEncapsNextHop<IPv4> IPv4EncapsNextHop;
00216 typedef IPEncapsNextHop<IPv6> IPv6EncapsNextHop;
00217 typedef IPEncapsNextHop<IPvX> IPvXEncapsNextHop;
00218 
00219 
00231 template<class A>
00232 class IPExternalNextHop : public IPNextHop<A> {
00233 public:
00240     IPExternalNextHop(const A &from_addr);
00241 
00242 #ifdef XORP_USE_USTL
00243     IPExternalNextHop() { }
00244 #endif
00245     
00251     int type() { return EXTERNAL_NEXTHOP; }
00252 
00259     string str() const;
00260     
00261 private:
00262     
00263 };
00264 
00265 typedef IPExternalNextHop<IPv4> IPv4ExternalNextHop;
00266 typedef IPExternalNextHop<IPv6> IPv6ExternalNextHop;
00267 typedef IPExternalNextHop<IPvX> IPvXExternalNextHop;
00268 
00269 
00275 class DiscardNextHop : public NextHop {
00276 public:
00280     DiscardNextHop();
00281     
00287     int type() { return DISCARD_NEXTHOP; }
00288 
00295     string str() const;
00296     
00297 private:
00298     
00299 };
00300 
00307 class UnreachableNextHop : public NextHop {
00308 public:
00312     UnreachableNextHop();
00313     
00319     int type() { return UNREACHABLE_NEXTHOP; }
00320 
00327     string str() const;
00328     
00329 private:
00330     
00331 };
00332 
00333 #endif // __LIBXORP_NEXTHOP_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations