xorp

nexthop_port_mapper.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/fea/nexthop_port_mapper.hh,v 1.15 2008/10/02 21:56:50 bms Exp $
00022 
00023 #ifndef __FEA_NEXTHOP_PORT_MAPPER_HH__
00024 #define __FEA_NEXTHOP_PORT_MAPPER_HH__
00025 
00026 
00027 
00028 
00029 #include "libxorp/ipv4.hh"
00030 #include "libxorp/ipv6.hh"
00031 #include "libxorp/ipv4net.hh"
00032 #include "libxorp/ipv6net.hh"
00033 
00034 
00035 class NexthopPortMapperObserver;
00036 
00049 class NexthopPortMapper {
00050 public:
00051     NexthopPortMapper();
00052     ~NexthopPortMapper();
00053 
00057     void clear();
00058 
00065     int add_observer(NexthopPortMapperObserver* observer);
00066 
00073     int delete_observer(NexthopPortMapperObserver* observer);
00074 
00078     void notify_observers();
00079 
00088     int lookup_nexthop_interface(const string& ifname,
00089                  const string& vifname) const;
00090 
00097     int lookup_nexthop_ipv4(const IPv4& ipv4) const;
00098 
00105     int lookup_nexthop_ipv6(const IPv6& ipv6) const;
00106 
00117     int add_interface(const string& ifname, const string& vifname, int port);
00118 
00126     int delete_interface(const string& ifname, const string& vifname);
00127 
00137     int add_ipv4(const IPv4& ipv4, int port);
00138 
00145     int delete_ipv4(const IPv4& ipv4);
00146 
00156     int add_ipv6(const IPv6& ipv6, int port);
00157 
00164     int delete_ipv6(const IPv6& ipv6);
00165 
00175     int add_ipv4net(const IPv4Net& ipv4net, int port);
00176 
00183     int delete_ipv4net(const IPv4Net& ipv4net);
00184 
00194     int add_ipv6net(const IPv6Net& ipv6net, int port);
00195 
00202     int delete_ipv6net(const IPv6Net& ipv6net);
00203 
00204 private:
00205     bool is_mapping_changed() const;
00206 
00207     // The maps with the lookup info
00208     map<pair<string, string>, int>  _interface_map;
00209     map<IPv4, int>          _ipv4_map;
00210     map<IPv6, int>          _ipv6_map;
00211     map<IPv4Net, int>           _ipv4net_map;
00212     map<IPv6Net, int>           _ipv6net_map;
00213 
00214     // The maps with the old info
00215     map<pair<string, string>, int>  _old_interface_map;
00216     map<IPv4, int>          _old_ipv4_map;
00217     map<IPv6, int>          _old_ipv6_map;
00218     map<IPv4Net, int>           _old_ipv4net_map;
00219     map<IPv6Net, int>           _old_ipv6net_map;
00220 
00221     list<NexthopPortMapperObserver *>   _observers;
00222 };
00223 
00227 class NexthopPortMapperObserver {
00228 public:
00232     virtual ~NexthopPortMapperObserver() {}
00233 
00240     virtual void nexthop_port_mapper_event(bool is_mapping_changed) = 0;
00241 };
00242 
00243 #endif // __FEA_NEXTHOP_PORT_MAPPER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations