xorp

peer_handler.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/bgp/peer_handler.hh,v 1.31 2008/11/08 06:14:37 mjh Exp $
00021 
00022 #ifndef __BGP_PEER_HANDLER_HH__
00023 #define __BGP_PEER_HANDLER_HH__
00024 
00025 class BGPMain;
00026 class BGPPeer;
00027 class BGPPlumbing;
00028 
00029 #include "libxorp/debug.h"
00030 #include "internal_message.hh"
00031 #include "packet.hh"
00032 #include "peer.hh"
00033 #include "parameter.hh"
00034 
00040 class PeerHandler {
00041 public:
00042     PeerHandler(const string &peername, BGPPeer *peer,
00043         BGPPlumbing *plumbing_unicast,
00044         BGPPlumbing *plumbing_multicast);
00045     virtual ~PeerHandler();
00046 
00047     void stop();
00048     void peering_went_down();
00049     void peering_came_up();
00050     bool peering_is_up() const { return _peering_is_up; }
00051 
00056     int process_update_packet(UpdatePacket *p);
00057     
00067     template <typename A> 
00068     bool add(const UpdatePacket *p,
00069          ref_ptr<FastPathAttributeList<IPv4> >& original_pa_list,
00070          ref_ptr<FastPathAttributeList<A> >& pa_list,
00071          Safi safi);
00081     template <typename A> 
00082     bool withdraw(const UpdatePacket *p, 
00083           ref_ptr<FastPathAttributeList<IPv4> >& original_pa_list,
00084           Safi safi);
00085 
00086     template <typename A> bool multiprotocol(Safi safi, 
00087                          BGPPeerData::Direction d) const;
00088 
00089 
00094     virtual int start_packet();
00095 
00096     virtual int add_route(const SubnetRoute<IPv4> &rt, 
00097               FPAList4Ref& pa_list,
00098               bool ibgp, Safi safi);
00099     virtual int replace_route(const SubnetRoute<IPv4> &old_rt, bool old_ibgp,
00100                   const SubnetRoute<IPv4> &new_rt, bool new_ibgp,
00101                   FPAList4Ref& pa_list,
00102                   Safi safi);
00103     virtual int delete_route(const SubnetRoute<IPv4> &rt,  
00104                  FPAList4Ref& pa_list,
00105                  bool new_ibgp,
00106                  Safi safi);
00107     virtual PeerOutputState push_packet();
00108     virtual void output_no_longer_busy();
00109 
00113     AsNum my_AS_number() const      {
00114     return _peer->peerdata()->my_AS_number();
00115     }
00116 
00120     AsNum AS_number() const     { return _peer->peerdata()->as(); }
00121 
00122 
00126     bool use_4byte_asnums() const {
00127     return _peer->peerdata()->use_4byte_asnums();
00128     }
00129 
00130     virtual PeerType get_peer_type() const { 
00131     return _peer->peerdata()->get_peer_type(); 
00132     }
00133 
00134     const string& peername() const  { return _peername; }
00135     bool ibgp() const           {
00136     if (0 == _peer) {
00137         XLOG_ASSERT(originate_route_handler());
00138         return false;
00139     }
00140     return _peer->peerdata()->ibgp();
00141     }
00142 
00146     virtual bool originate_route_handler() const {return false;}
00147 
00151     virtual uint32_t get_unique_id() const { return _peer->get_unique_id(); }
00152 
00156     virtual const IPv4& id() const { return _peer->peerdata()->id(); }
00157 
00162     uint32_t neighbour_address() const  {
00163     //return ntohl(_peer->peerdata()->iptuple().get_peer_addr().s_addr);
00164     return id().addr();
00165     }
00166 
00167     const IPv4& my_v4_nexthop() const   {
00168     return _peer->peerdata()->get_v4_local_addr();
00169     }
00170 
00174     string get_local_addr() const {
00175     return _peer->peerdata()->iptuple().get_local_addr();
00176     }
00177 
00181     string get_peer_addr() const {
00182     return _peer->peerdata()->iptuple().get_peer_addr();
00183     }
00184 
00189     bool get_peer_addr(IPv4& addr) const {
00190     return _peer->peerdata()->iptuple().get_peer_addr(addr);
00191     }
00192 
00196     uint32_t get_prefix_count() const;
00197 
00198     virtual EventLoop& eventloop() const;
00199 
00200 
00201 #ifdef HAVE_IPV6
00202 
00203     virtual int add_route(const SubnetRoute<IPv6> &rt, 
00204               FPAList6Ref& pa_list,
00205               bool ibgp, Safi safi);
00206     virtual int replace_route(const SubnetRoute<IPv6> &old_rt, bool old_ibgp,
00207                   const SubnetRoute<IPv6> &new_rt, bool new_ibgp,
00208                   FPAList6Ref& pa_list,
00209                   Safi safi);
00210     virtual int delete_route(const SubnetRoute<IPv6> &rt,  
00211                  FPAList6Ref& pa_list,
00212                  bool new_ibgp,
00213                  Safi safi);
00214     const IPv6& my_v6_nexthop() const   {
00215     return _peer->peerdata()->get_v6_local_addr();
00216     }
00217 
00222     bool get_peer_addr(IPv6& addr) const {
00223     return _peer->peerdata()->iptuple().get_peer_addr(addr);
00224     }
00225 
00226 
00227 #endif //ipv6
00228 
00229 protected:
00230     BGPPlumbing *_plumbing_unicast;
00231     BGPPlumbing *_plumbing_multicast;
00232 private:
00233     string _peername;
00234     BGPPeer *_peer;
00235     bool _peering_is_up; /*whether we still think it's up (it may be
00236                            down, but the FSM hasn't told us yet) */
00237     UpdatePacket *_packet; /* this is a packet we construct to send */
00238 
00239     /*stats*/
00240     uint32_t _nlri_total;
00241     uint32_t _packets;
00242 };
00243 
00244 #endif // __BGP_PEER_HANDLER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations