xorp

output.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 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/rip/output.hh,v 1.15 2008/10/02 21:58:16 bms Exp $
00022 
00023 #ifndef __RIP_OUTPUT_HH__
00024 #define __RIP_OUTPUT_HH__
00025 
00026 // #define DEBUG_LOGGING
00027 // #define DEBUG_PRINT_FUNCTION_NAME
00028 
00029 #include "libxorp/xorp.h"
00030 #include "libxorp/debug.h"
00031 #include "libxorp/eventloop.hh"
00032 
00033 
00034 
00035 #include "policy/backend/policy_filters.hh"
00036 
00037 #include "port.hh"
00038 #include "system.hh"
00039 #include "rip_varrw.hh"
00040 
00041 template <typename A>
00042 class PacketQueue;
00043 
00053 template <typename A>
00054 class OutputBase :
00055     public NONCOPYABLE
00056 {
00057 public:
00058     typedef A       Addr;
00059     typedef IPNet<A>    Net;
00060 
00061 public:
00062     OutputBase(EventLoop&   e,
00063            Port<A>&     port,
00064            PacketQueue<A>&  pkt_queue,
00065            const A&     ip_addr,
00066            uint16_t     ip_port);
00067 
00068     virtual ~OutputBase() {};
00069 
00073     const A& ip_addr() const            { return _ip_addr; }
00074 
00078     uint16_t ip_port() const            { return _ip_port; }
00079 
00083     bool running() const;
00084 
00090     void start();
00091 
00095     void stop();
00096 
00100     void packets_sent() const           { return _pkts_out; }
00101 
00102 protected:
00107     uint32_t interpacket_gap_ms() const;
00108 
00113     virtual void start_output_processing() = 0;
00114 
00119     virtual void stop_output_processing() = 0;
00120 
00128     virtual void output_packet() = 0;
00129 
00130     void incr_packets_sent()            { _pkts_out++; }
00131 
00138     bool do_filtering(RouteEntry<A>* r);
00139 
00140 protected:
00141     EventLoop&      _e;
00142     Port<A>&        _port;      // Port associated with output
00143     PacketQueue<A>& _pkt_queue; // Place for generated packets to go
00144     const A     _ip_addr;   // IP address for output packets
00145     const uint16_t  _ip_port;   // IP port for output packets
00146     XorpTimer       _op_timer;  // Timer invoking output_packet()
00147     uint32_t        _pkts_out;  // Packets sent
00148 
00149     PolicyFilters&  _policy_filters;    // Global policy filters
00150 };
00151 
00152 template <typename A>
00153 OutputBase<A>::OutputBase(EventLoop&      e,
00154               Port<A>&    port,
00155               PacketQueue<A>& pkt_queue,
00156               const A&    ip_addr,
00157               uint16_t    ip_port)
00158     : _e(e), _port(port), _pkt_queue(pkt_queue),
00159       _ip_addr(ip_addr), _ip_port(ip_port), _pkts_out(0),
00160       _policy_filters(port.port_manager().system().policy_filters())
00161 {
00162 }
00163 
00164 template <typename A>
00165 inline bool
00166 OutputBase<A>::running() const
00167 {
00168     return _op_timer.scheduled();
00169 }
00170 
00171 template <typename A>
00172 inline void
00173 OutputBase<A>::start()
00174 {
00175     if (running() == false)
00176     start_output_processing();
00177 }
00178 
00179 template <typename A>
00180 inline void
00181 OutputBase<A>::stop()
00182 {
00183     stop_output_processing();
00184 }
00185 
00186 template <typename A>
00187 inline uint32_t
00188 OutputBase<A>::interpacket_gap_ms() const
00189 {
00190     return _port.constants().interpacket_delay_ms();
00191 }
00192 
00193 
00194 template <typename A>
00195 bool
00196 OutputBase<A>::do_filtering(RouteEntry<A>* route)
00197 {
00198     try {
00199     RIPVarRW<A> varrw(*route);
00200     
00201     debug_msg("[RIP] Running export filter on route: %s\n",
00202           route->net().str().c_str());
00203 
00204     bool accepted = _policy_filters.run_filter(filter::EXPORT,
00205                            varrw);
00206 
00207     return accepted;
00208     } catch(const PolicyException& e) {
00209     XLOG_FATAL("PolicyException: %s", e.str().c_str());
00210     XLOG_UNFINISHED();
00211     }
00212 }
00213 
00214 #endif // __RIP_OUTPUT_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations