xorp

vif.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/vif.hh,v 1.23 2008/10/02 21:57:36 bms Exp $
00023 
00024 #ifndef __LIBXORP_VIF_HH__
00025 #define __LIBXORP_VIF_HH__
00026 
00027 
00028 
00029 #include "xorp.h"
00030 #include "ipv4.hh"
00031 #include "ipv6.hh"
00032 #include "ipvx.hh"
00033 #include "ipvxnet.hh"
00034 
00041 class VifAddr {
00042 public:
00048     explicit VifAddr(const IPvX& ipvx_addr);
00049 
00060     VifAddr(const IPvX& ipvx_addr, const IPvXNet& ipvx_subnet_addr,
00061         const IPvX& ipvx_broadcast_addr, const IPvX& ipvx_peer_addr);
00062 
00063 #ifdef XORP_USE_USTL
00064     VifAddr(); // AF_INET
00065 #endif
00066 
00072     const IPvX&     addr()      const   { return (_addr);   }
00073 
00079     const IPvXNet&  subnet_addr()   const   { return (_subnet_addr); }
00080 
00089     const IPvX&     broadcast_addr() const  { return (_broadcast_addr); }
00090 
00098     const IPvX&     peer_addr() const   { return (_peer_addr);  }
00099     
00105     void  set_addr(const IPvX& v)       { _addr = v;        }
00106 
00112     void  set_subnet_addr(const IPvXNet& v) { _subnet_addr = v; }
00113 
00119     void  set_broadcast_addr(const IPvX& v) { _broadcast_addr = v;  }
00120 
00126     void  set_peer_addr(const IPvX& v)      { _peer_addr = v;   }
00127     
00137     bool  is_my_addr(const IPvX& ipvx_addr) const { return (addr() == ipvx_addr); }
00138     
00148     bool  is_same_subnet(const IPvXNet& ipvxnet) const;
00149     
00158     bool  is_same_subnet(const IPvX& ipvx_addr) const;
00159     
00166     string str() const;
00167     
00175     bool operator==(const VifAddr& other) const;
00176     
00177 private:
00178     IPvX    _addr;              // IP address of the vif
00179     IPvXNet _subnet_addr;           // Subnet address on the vif
00180     IPvX    _broadcast_addr;        // Network broadcast address
00181     IPvX    _peer_addr;         // Peer address (on p2p links)
00182 };
00183 
00192 class Vif {
00193 public:
00201     explicit Vif(const string& vifname, const string& ifname = string(""));
00202 
00203 #ifdef XORP_USE_USTL
00204     Vif() { }
00205 #endif
00206     
00212     Vif(const Vif& vif);
00213     
00217     virtual ~Vif();
00218     
00225     string str() const;
00226 
00234     bool operator==(const Vif& other) const;
00235     
00241     const string& name() const { return _name; }
00242 
00248     const string& ifname() const { return _ifname; }
00249 
00255     void set_ifname(const string& ifname) { _ifname = ifname; }
00256 
00262     uint32_t pif_index() const { return (_pif_index); }
00263     
00269     void set_pif_index(uint32_t v) { _pif_index = v; }
00270     
00274     enum {
00275     VIF_INDEX_INVALID   = ((uint32_t)~0),
00276     VIF_INDEX_MAX       = ((uint32_t)~0)
00277     };
00278     
00284     uint32_t vif_index() const { return (_vif_index); }
00285     
00291     void set_vif_index(uint32_t v) { _vif_index = v; }
00292 
00298     bool    is_pim_register()   const   { return _is_pim_register; }
00299     
00305     bool    is_p2p()        const   { return _is_p2p; }
00306     
00312     bool    is_loopback()       const   { return _is_loopback; }
00313     
00319     bool    is_discard()        const   { return _is_discard; }
00320 
00326     bool    is_unreachable()    const   { return _is_unreachable; }
00327 
00333     bool    is_management() const   { return _is_management; }
00334     
00340     bool    is_multicast_capable() const { return _is_multicast_capable; }
00341     
00347     bool    is_broadcast_capable() const { return _is_broadcast_capable; }
00348     
00359     bool    is_underlying_vif_up() const { return _is_underlying_vif_up; }
00360 
00366     uint32_t    mtu() const { return _mtu; }
00367 
00374     void    set_pim_register(bool v)    { _is_pim_register = v; }
00375     
00382     void    set_p2p(bool v)         { _is_p2p = v; }
00383     
00390     void    set_loopback(bool v)        { _is_loopback = v; }
00391     
00398     void    set_discard(bool v)     { _is_discard = v; }
00399 
00406     void    set_unreachable(bool v)     { _is_unreachable = v; }
00407 
00414     void    set_management(bool v)      { _is_management = v; }
00415     
00422     void    set_multicast_capable(bool v)   { _is_multicast_capable = v; }
00423     
00430     void    set_broadcast_capable(bool v)   { _is_broadcast_capable = v; }
00431     
00442     void    set_underlying_vif_up(bool v)   { _is_underlying_vif_up = v; }
00443 
00449     void    set_mtu(uint32_t v) { _mtu = v; }
00450 
00456     const list<VifAddr>& addr_list() const { return _addr_list; }
00457     
00464     const IPvX* addr_ptr() const;
00465     
00474     int add_address(const VifAddr& vif_addr);
00475     
00485     int add_address(const IPvX& ipvx_addr,
00486             const IPvXNet& ipvxnet_subnet_addr,
00487             const IPvX& ipvx_broadcast_addr,
00488             const IPvX& ipvx_peer_addr);
00489     
00496     int add_address(const IPvX& ipvx_addr);
00497     
00503     int delete_address(const IPvX& ipvx_addr);
00504     
00512     VifAddr *find_address(const IPvX& ipvx_addr);
00513 
00521     const VifAddr *find_address(const IPvX& ipvx_addr) const;
00522     
00529     bool is_my_addr(const IPvX& ipvx_addr) const;
00530     
00537     bool is_my_vif_addr(const VifAddr& vif_addr) const;
00538     
00547     bool is_same_subnet(const IPvXNet& ipvxnet) const;
00548     
00557     bool is_same_subnet(const IPvX& ipvx_addr) const;
00558     
00567     bool is_same_p2p(const IPvX& ipvx_addr) const;
00568     
00569 private:
00570     string  _name;      // The vif name
00571     string  _ifname;    // The physical interface name (if applicable)
00572     uint32_t    _pif_index; // Physical interface index (if applicable),
00573                 // or 0 if invalid.
00574     uint32_t    _vif_index; // Virtual interface index
00575     bool    _is_pim_register;   // PIM Register vif
00576     bool    _is_p2p;        // Point-to-point interface
00577     bool    _is_loopback;       // Loopback interface
00578     bool    _is_discard;        // Discard interface
00579     bool    _is_unreachable;    // Unreachable interface
00580     bool    _is_management;     // Management interface
00581     bool    _is_multicast_capable;  // Multicast-capable interface
00582     bool    _is_broadcast_capable;  // Broadcast-capable interface
00583     bool    _is_underlying_vif_up;  // True if underlying vif is up
00584     uint32_t    _mtu;           // The MTU of the vif
00585     
00586     list<VifAddr> _addr_list;       // The list of addresses for this vif
00587 };
00588 
00589 #endif // __LIBXORP_VIF_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations