xorp

proto_unit.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 
00023 #ifndef __LIBPROTO_PROTO_UNIT_HH__
00024 #define __LIBPROTO_PROTO_UNIT_HH__
00025 
00026 
00027 #include "libxorp/xorp.h"
00028 #include "proto_state.hh"
00029 
00030 
00037 enum xorp_module_id {
00038     XORP_MODULE_MIN     = 0,
00039     XORP_MODULE_NULL        = 0,
00040     XORP_MODULE_FEA     = 1,
00041     XORP_MODULE_MFEA        = 2,
00042     XORP_MODULE_MLD6IGMP    = 3,
00043     XORP_MODULE_PIMSM       = 4,
00044     XORP_MODULE_PIMDM       = 5,
00045     XORP_MODULE_BGMP        = 6,
00046     XORP_MODULE_BGP     = 7,
00047     XORP_MODULE_OSPF        = 8,
00048     XORP_MODULE_RIP     = 9,
00049     XORP_MODULE_CLI     = 10,
00050     XORP_MODULE_RIB     = 11,
00051     XORP_MODULE_RTRMGR      = 12,
00052     XORP_MODULE_STATIC_ROUTES   = 13,
00053     XORP_MODULE_FIB2MRIB    = 14,
00054     XORP_MODULE_MAX
00055 };
00056 
00060 class ProtoUnit : public ProtoState {
00061 public:
00068     ProtoUnit(int init_family, xorp_module_id init_module_id);
00069     
00073     virtual ~ProtoUnit();
00074     
00081     int     family()    const   { return (_family);     }
00082     
00088     xorp_module_id  module_id() const   { return (_module_id);  }
00089     
00095     int     proto_version() const   { return (_proto_version);  }
00096     
00102     void    set_proto_version(int v) { _proto_version = v;      }
00103     
00109     int     proto_version_default() const { return (_proto_version_default); }
00110     
00116     void    set_proto_version_default(int v) { _proto_version_default = v;}
00117     
00123     bool    is_ipv4()   const   { return (_family == AF_INET);  }
00124 
00130     bool    is_ipv6()   const   { return (_family == AF_INET6); }
00131     
00140     const char  *module_name()  const   { return (_module_name.c_str()); }
00141     
00149     int     comm_handler()  const   { return (_comm_handler);   }
00150     
00156     void    set_comm_handler(int v) { _comm_handler = v;        }
00157     
00158     //
00159     // Protocol tests
00160     //
00161     
00167     bool    proto_is_mld6igmp() const { return (_module_id == XORP_MODULE_MLD6IGMP); }
00168     
00174     bool    proto_is_igmp() const { return (proto_is_mld6igmp() && is_ipv4()); }
00175     
00181     bool    proto_is_mld6() const { return (proto_is_mld6igmp() && is_ipv6()); }
00182 
00188     bool    proto_is_pimsm() const { return (_module_id == XORP_MODULE_PIMSM); }
00189     
00195     bool    proto_is_pimdm() const { return (_module_id == XORP_MODULE_PIMDM); }
00196 
00202     bool    proto_is_bgmp() const { return (_module_id == XORP_MODULE_BGMP); }
00203 
00209     bool    proto_is_bgp() const { return (_module_id == XORP_MODULE_BGP); }
00210 
00216     bool    proto_is_ospf() const { return (_module_id == XORP_MODULE_OSPF); }
00217     
00223     bool    proto_is_rip() const { return (_module_id == XORP_MODULE_RIP); }
00224 
00230     bool    proto_is_static_routes() const { return (_module_id == XORP_MODULE_STATIC_ROUTES); }
00231 
00237     bool    proto_is_fib2mrib() const { return (_module_id == XORP_MODULE_FIB2MRIB); }
00238     
00239 private:
00240     int     _family;        // The address family.
00241     xorp_module_id _module_id;      // The module ID (XORP_MODULE_*).
00242     int     _comm_handler;      // The communication handler.
00243     int     _proto_version;     // Protocol version (proto. specific).
00244     int     _proto_version_default; // Default protocol version.
00245     string  _module_name;       // The module name.
00246 };
00247 
00248 //
00249 // Global variables
00250 //
00251 
00252 //
00253 // Global functions prototypes
00254 //
00266 const char  *xorp_module_name(int family, xorp_module_id module_id);
00267 
00277 xorp_module_id  xorp_module_name2id(const char *module_name);
00278 
00288 bool        is_valid_module_id(xorp_module_id module_id);
00289 
00290 #endif // __LIBPROTO_PROTO_UNIT_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations