xorp

command.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2009 XORP, Inc.
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/harness/command.hh,v 1.18 2008/10/02 21:56:26 bms Exp $
00021 
00022 #ifndef __BGP_HARNESS_COMMAND_HH__
00023 #define __BGP_HARNESS_COMMAND_HH__
00024 
00025 #include "libxorp/ref_ptr.hh"
00026 #include "libxorp/tokenize.hh"
00027 #include "peer.hh"
00028 
00029 class TimeVal;
00030 
00031 /*
00032 ** All the commands to the coordinating process come via this class.
00033 ** The commands are delivered either via XRL's or from a file.
00034 */
00035 
00036 class Command {
00037 public:
00038     Command(EventLoop& eventloop, XrlStdRouter& xrlrouter);
00039 
00040     /*
00041     ** Load command map.
00042     */
00043     void load_command_map();
00044 
00045     /*
00046     ** Accept a command for the coordinating process.
00047     */
00048     void command(const string& line) throw(InvalidString);
00049 
00050     /*
00051     ** Show the status of the peers.
00052     */
00053     void status(const string& peer, string& status);
00054 
00055     /*
00056     ** Test to see if there are any uncompleted commands.
00057     */
00058     bool pending();
00059 
00060     /*
00061     ** Data from the test peers.
00062     */
00063     void datain(const string&  peer,  const uint32_t& genid,
00064         const bool& status, const TimeVal& tv,
00065         const vector<uint8_t>&  data);
00066     void datain_error(const string&  peer,  const uint32_t& genid,
00067               const string& reason);
00068     void datain_closed(const string&  peer,  const uint32_t& genid);
00069    
00070     /*
00071     ** All commands to peers sent through here.
00072     */
00073     void peer(const string& line, const vector<string>& v) 
00074     throw(InvalidString);
00075 
00076     void reset(const string& line, const vector<string>& v);
00077     void target(const string& line, const vector<string>& v) 
00078     throw(InvalidString);
00079     void initialise(const string& line, const vector<string>& v) 
00080     throw(InvalidString);
00081     void initialise_callback(const XrlError& error, string peername);
00082 private:
00083     EventLoop& _eventloop;
00084     XrlStdRouter& _xrlrouter;
00085     uint32_t _genid;
00086 
00087     uint32_t _init_count;   // Number of initialisations with
00088                 // test_peers currently in progress.
00089 
00090     /*
00091     ** Supported commands.
00092     */
00093     typedef void (Command::* MEMFUN)(const string& line,
00094                      const vector<string>& v);
00095 
00096     struct PCmd {
00097     PCmd(const Command::MEMFUN& mem_fun) : _mem_fun(mem_fun)
00098     {}
00099 
00100     void dispatch(Command* c, const string& line, const vector<string>&v)
00101     {
00102         (c->*_mem_fun)(line, v);
00103     }
00104     Command::MEMFUN _mem_fun;
00105     };
00106 
00107     typedef map<const string, PCmd> StringCommandMap;
00108     StringCommandMap _commands;
00109 
00110     typedef list<Peer> PeerList;
00111     PeerList _peers;
00112 
00113     string _target_hostname;
00114     string _target_port;
00115 };
00116 
00117 #endif // __BGP_HARNESS_COMMAND_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations