|
xorp
|
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 __LIBFEACLIENT_IFMGR_ATOMS_HH__ 00024 #define __LIBFEACLIENT_IFMGR_ATOMS_HH__ 00025 00026 #include "libxorp/xorp.h" 00027 00028 00029 00030 00031 #include "libxorp/ipv4.hh" 00032 #include "libxorp/ipv6.hh" 00033 #include "libxorp/ipvx.hh" 00034 #include "libxorp/ipv4net.hh" 00035 #include "libxorp/ipv6net.hh" 00036 #include "libxorp/ipvxnet.hh" 00037 #include "libxorp/mac.hh" 00038 #include "libxorp/vif.hh" 00039 00040 class IfMgrIfAtom; 00041 class IfMgrVifAtom; 00042 class IfMgrIPv4Atom; 00043 class IfMgrIPv6Atom; 00044 00053 class IfMgrIfTree { 00054 public: 00055 typedef map<string, IfMgrIfAtom> IfMap; 00056 00057 public: 00058 00062 const IfMap& interfaces() const { return _interfaces; } 00063 00067 IfMap& interfaces() { return _interfaces; } 00068 00072 void clear(); 00073 00079 const IfMgrIfAtom* find_interface(const string& ifname) const; 00080 00086 IfMgrIfAtom* find_interface(const string& ifname); 00087 00094 const IfMgrVifAtom* find_vif(const string& ifname, 00095 const string& vifname) const; 00096 00103 IfMgrVifAtom* find_vif(const string& ifname, 00104 const string& vifname); 00105 00113 const IfMgrIPv4Atom* find_addr(const string& ifname, 00114 const string& vifname, 00115 const IPv4& addr) const; 00116 00124 IfMgrIPv4Atom* find_addr(const string& ifname, 00125 const string& vifname, 00126 const IPv4& addr); 00127 00135 const IfMgrIPv6Atom* find_addr(const string& ifname, 00136 const string& vifname, 00137 const IPv6& addr) const; 00138 00146 IfMgrIPv6Atom* find_addr(const string& ifname, 00147 const string& vifname, 00148 const IPv6& addr); 00149 00155 bool operator==(const IfMgrIfTree& o) const; 00156 00170 bool is_my_addr(const IPv4& addr, string& ifname, string& vifname) const; 00171 00185 bool is_my_addr(const IPv6& addr, string& ifname, string& vifname) const; 00186 00200 bool is_my_addr(const IPvX& addr, string& ifname, string& vifname) const; 00201 00217 bool is_directly_connected(const IPv4& addr, string& ifname, 00218 string& vifname) const; 00219 00235 bool is_directly_connected(const IPv6& addr, string& ifname, 00236 string& vifname) const; 00237 00253 bool is_directly_connected(const IPvX& addr, string& ifname, 00254 string& vifname) const; 00255 00256 /* Print this thing out for debugging purposes. */ 00257 string toString() const; 00258 00259 protected: 00260 IfMap _interfaces; // The interface configuration state 00261 }; 00262 00263 00272 class IfMgrIfAtom { 00273 public: 00274 typedef map<string, IfMgrVifAtom> VifMap; 00275 00276 public: 00277 IfMgrIfAtom(const string& name); 00278 00279 const string& name() const { return _name; } 00280 00281 bool enabled() const { return _enabled; } 00282 void set_enabled(bool v) { _enabled = v; } 00283 00284 bool discard() const { return _discard; } 00285 void set_discard(bool v) { _discard = v; } 00286 00287 bool unreachable() const { return _unreachable; } 00288 void set_unreachable(bool v) { _unreachable = v; } 00289 00290 bool management() const { return _management; } 00291 void set_management(bool v) { _management = v; } 00292 00293 uint32_t mtu() const { return _mtu; } 00294 void set_mtu(uint32_t v) { _mtu = v; } 00295 00296 const Mac& mac() const { return _mac; } 00297 void set_mac(const Mac& v) { _mac = v; } 00298 00299 uint32_t pif_index() const { return _pif_index; } 00300 void set_pif_index(uint32_t v) { _pif_index = v; } 00301 00302 bool no_carrier() const { return _no_carrier; } 00303 void set_no_carrier(bool v) { _no_carrier = v; } 00304 00305 uint64_t baudrate() const { return _baudrate; } 00306 void set_baudrate(uint64_t v) { _baudrate = v; } 00307 00308 const string& parent_ifname() const { return _parent_ifname; } 00309 void set_parent_ifname(const string& v) { _parent_ifname = v; } 00310 00311 const string& iface_type() const { return _iface_type; } 00312 void set_iface_type(const string& v) { _iface_type = v; } 00313 00314 const string& vid() const { return _vid; } 00315 void set_vid(const string& v) { _vid = v; } 00316 00317 const VifMap& vifs() const { return _vifs; } 00318 VifMap& vifs() { return _vifs; } 00319 const IfMgrVifAtom* find_vif(const string& vifname) const; 00320 IfMgrVifAtom* find_vif(const string& vifname); 00321 00322 bool operator==(const IfMgrIfAtom& o) const; 00323 00324 // Print this thing out for debugging purposes. 00325 string toString() const; 00326 00327 #ifndef XORP_USE_USTL 00328 private: 00329 IfMgrIfAtom(); // not implemented 00330 #else 00331 IfMgrIfAtom() { } 00332 #endif 00333 00334 protected: 00335 string _name; // The interface name 00336 00337 bool _enabled; // True if enabled 00338 bool _discard; // True if a discard interface 00339 bool _unreachable; // True if an unreachable interface 00340 bool _management; // True if a management interface 00341 uint32_t _mtu; // The interface MTU (in bytes) 00342 Mac _mac; // The interface MAC address 00343 uint32_t _pif_index; // Physical interface index 00344 bool _no_carrier; // True if no carrier 00345 uint64_t _baudrate; // The link baudrate 00346 string _parent_ifname; 00347 string _iface_type; 00348 string _vid; 00349 VifMap _vifs; // The vif configuration state 00350 }; 00351 00352 00358 class IfMgrVifAtom { 00359 public: 00360 typedef map<IPv4, IfMgrIPv4Atom> IPv4Map; 00361 typedef map<IPv6, IfMgrIPv6Atom> IPv6Map; 00362 00363 public: 00364 IfMgrVifAtom(const string& name); 00365 00366 const string& name() const { return _name; } 00367 00368 bool enabled() const { return _enabled; } 00369 void set_enabled(bool v) { _enabled = v; } 00370 00371 bool multicast_capable() const { return _multicast_capable; } 00372 void set_multicast_capable(bool v) { _multicast_capable = v; } 00373 00374 bool broadcast_capable() const { return _broadcast_capable; } 00375 void set_broadcast_capable(bool v) { _broadcast_capable = v; } 00376 00377 bool p2p_capable() const { return _p2p_capable; } 00378 void set_p2p_capable(bool v) { _p2p_capable = v; } 00379 00380 bool loopback() const { return _loopback; } 00381 void set_loopback(bool v) { _loopback = v; } 00382 00383 bool pim_register() const { return _pim_register; } 00384 void set_pim_register(bool v) { _pim_register = v; } 00385 00386 uint32_t pif_index() const { return _pif_index; } 00387 void set_pif_index(uint32_t v) { _pif_index = v; } 00388 00389 uint32_t vif_index() const { return _vif_index; } 00390 void set_vif_index(uint32_t v) { _vif_index = v; } 00391 00392 const IPv4Map& ipv4addrs() const { return _ipv4addrs; } 00393 IPv4Map& ipv4addrs() { return _ipv4addrs; } 00394 const IfMgrIPv4Atom* find_addr(const IPv4& addr) const; 00395 IfMgrIPv4Atom* find_addr(const IPv4& addr); 00396 00397 const IPv6Map& ipv6addrs() const { return _ipv6addrs; } 00398 IPv6Map& ipv6addrs() { return _ipv6addrs; } 00399 const IfMgrIPv6Atom* find_addr(const IPv6& addr) const; 00400 IfMgrIPv6Atom* find_addr(const IPv6& addr); 00401 00402 bool operator==(const IfMgrVifAtom& o) const; 00403 00404 // Print this thing out for debugging purposes. 00405 string toString() const; 00406 00407 #ifndef XORP_USE_USTL 00408 private: 00409 IfMgrVifAtom(); // Not implemented 00410 #else 00411 IfMgrVifAtom() { } 00412 #endif 00413 00414 protected: 00415 string _name; // The vif name 00416 00417 bool _enabled; // True if enabled 00418 bool _multicast_capable; // True if multicast capable 00419 bool _broadcast_capable; // True if broadcast capable 00420 bool _p2p_capable; // True if point-to-point capable 00421 bool _loopback; // True if loopback vif 00422 bool _pim_register; // True if PIM Register vif 00423 uint32_t _pif_index; // Physical interface index 00424 uint32_t _vif_index; // Virtual interface index 00425 00426 IPv4Map _ipv4addrs; // The IPv4 addresses 00427 IPv6Map _ipv6addrs; // The IPv6 addresses 00428 }; 00429 00430 00437 class IfMgrIPv4Atom { 00438 public: 00439 IfMgrIPv4Atom(const IPv4& addr); 00440 00441 const IPv4& addr() const { return _addr; } 00442 00443 uint32_t prefix_len() const { return _prefix_len; } 00444 void set_prefix_len(uint32_t v) { _prefix_len = v; } 00445 00446 bool enabled() const { return _enabled; } 00447 void set_enabled(bool v) { _enabled = v; } 00448 00449 bool multicast_capable() const { return _multicast_capable; } 00450 void set_multicast_capable(bool v) { _multicast_capable = v; } 00451 00452 bool loopback() const { return _loopback; } 00453 void set_loopback(bool v) { _loopback = v; } 00454 00455 bool has_broadcast() const { return _broadcast; } 00456 void remove_broadcast() { _broadcast = false; } 00457 void set_broadcast_addr(const IPv4& baddr); 00458 const IPv4& broadcast_addr() const; 00459 00460 bool has_endpoint() const { return _p2p; } 00461 void remove_endpoint() { _p2p = false; } 00462 void set_endpoint_addr(const IPv4& endpoint); 00463 const IPv4& endpoint_addr() const; 00464 00465 bool operator==(const IfMgrIPv4Atom& o) const; 00466 00467 // Debugging info 00468 string toString() const; 00469 00470 #ifndef XORP_USE_USTL 00471 private: 00472 IfMgrIPv4Atom(); // Not implemented 00473 #else 00474 IfMgrIPv4Atom() { } 00475 #endif 00476 00477 protected: 00478 IPv4 _addr; // The address 00479 uint32_t _prefix_len; // The network prefix length 00480 bool _enabled; // True if enabled 00481 bool _multicast_capable; // True if multicast capable 00482 bool _loopback; // True if a loopback address 00483 bool _broadcast; // True if _other_addr is a broadcast address 00484 bool _p2p; // True if _other_addr is a p2p address 00485 00486 IPv4 _other_addr; // The "other" address [broadcast | p2p] 00487 static const IPv4 _ZERO_ADDR; // IPv4::ZERO() address 00488 }; 00489 00490 00498 class IfMgrIPv6Atom { 00499 public: 00500 IfMgrIPv6Atom(const IPv6& addr); 00501 00502 const IPv6& addr() const { return _addr; } 00503 00504 bool enabled() const { return _enabled; } 00505 void set_enabled(bool v) { _enabled = v; } 00506 00507 uint32_t prefix_len() const { return _prefix_len; } 00508 void set_prefix_len(uint32_t v) { _prefix_len = v; } 00509 00510 bool multicast_capable() const { return _multicast_capable; } 00511 void set_multicast_capable(bool v) { _multicast_capable = v; } 00512 00513 bool loopback() const { return _loopback; } 00514 void set_loopback(bool v) { _loopback = v; } 00515 00516 bool has_endpoint() const { return _p2p; } 00517 void remove_endpoint() { _p2p = false; } 00518 void set_endpoint_addr(const IPv6& endpoint); 00519 const IPv6& endpoint_addr() const; 00520 00521 bool operator==(const IfMgrIPv6Atom& o) const; 00522 00523 // Debugging info 00524 string toString() const; 00525 00526 #ifndef XORP_USE_USTL 00527 private: 00528 IfMgrIPv6Atom(); // Not implemented 00529 #else 00530 IfMgrIPv6Atom() { } 00531 #endif 00532 00533 protected: 00534 IPv6 _addr; // The address 00535 uint32_t _prefix_len; // The network prefix length 00536 bool _enabled; // True if enabled 00537 bool _multicast_capable; // True if multicast capable 00538 bool _loopback; // True if a loopback address 00539 bool _p2p; // True if _other_addr is a p2p2 address 00540 00541 IPv6 _other_addr; // The "other" address [p2p] 00542 static const IPv6 _ZERO_ADDR; // IPv6::ZERO() address 00543 }; 00544 00545 00561 template <typename A> 00562 struct IfMgrIP 00563 { 00564 }; 00565 00566 template <> 00567 struct IfMgrIP<IPv4> 00568 { 00569 typedef IfMgrIPv4Atom Atom; 00570 }; 00571 00572 template <> 00573 struct IfMgrIP<IPv6> 00574 { 00575 typedef IfMgrIPv6Atom Atom; 00576 }; 00577 00578 00579 // ---------------------------------------------------------------------------- 00580 // Inline IfMgrIfTree methods 00581 00582 inline void 00583 IfMgrIfTree::clear() 00584 { 00585 _interfaces.clear(); 00586 } 00587 00588 00589 // ---------------------------------------------------------------------------- 00590 // Inline IfMgrIfAtom methods 00591 00592 inline 00593 IfMgrIfAtom::IfMgrIfAtom(const string& name) 00594 : _name(name), 00595 _enabled(false), 00596 _discard(false), 00597 _unreachable(false), 00598 _management(false), 00599 _mtu(0), 00600 _pif_index(0), 00601 _no_carrier(false), 00602 _baudrate(0) 00603 { 00604 } 00605 00606 00607 // ---------------------------------------------------------------------------- 00608 // Inline IfMgrVifAtom methods 00609 00610 inline 00611 IfMgrVifAtom::IfMgrVifAtom(const string& name) 00612 : _name(name), 00613 _enabled(false), 00614 _multicast_capable(false), 00615 _broadcast_capable(false), 00616 _p2p_capable(false), 00617 _loopback(false), 00618 _pim_register(false), 00619 _pif_index(0), 00620 _vif_index(Vif::VIF_INDEX_INVALID) 00621 { 00622 } 00623 00624 // ---------------------------------------------------------------------------- 00625 // Inline IfMgrIPv4Atom methods 00626 00627 inline 00628 IfMgrIPv4Atom::IfMgrIPv4Atom(const IPv4& addr) 00629 : _addr(addr), 00630 _prefix_len(0), 00631 _enabled(false), 00632 _multicast_capable(false), 00633 _loopback(false), 00634 _broadcast(false), 00635 _p2p(false) 00636 { 00637 } 00638 00639 inline void 00640 IfMgrIPv4Atom::set_broadcast_addr(const IPv4& broadcast_addr) 00641 { 00642 if (broadcast_addr == IPv4::ZERO()) { 00643 _broadcast = false; 00644 } else { 00645 _broadcast = true; 00646 _p2p = false; 00647 _other_addr = broadcast_addr; 00648 } 00649 } 00650 00651 inline const IPv4& 00652 IfMgrIPv4Atom::broadcast_addr() const 00653 { 00654 return _broadcast ? _other_addr : _ZERO_ADDR; 00655 } 00656 00657 inline void 00658 IfMgrIPv4Atom::set_endpoint_addr(const IPv4& p2p_addr) 00659 { 00660 if (p2p_addr == IPv4::ZERO()) { 00661 _p2p = false; 00662 } else { 00663 _p2p = true; 00664 _broadcast = false; 00665 _other_addr = p2p_addr; 00666 } 00667 } 00668 00669 inline const IPv4& 00670 IfMgrIPv4Atom::endpoint_addr() const 00671 { 00672 return _p2p ? _other_addr : _ZERO_ADDR; 00673 } 00674 00675 00676 // ---------------------------------------------------------------------------- 00677 // Inline IfMgrIPv6Atom methods 00678 00679 inline 00680 IfMgrIPv6Atom::IfMgrIPv6Atom(const IPv6& addr) 00681 : _addr(addr), 00682 _prefix_len(0), 00683 _enabled(false), 00684 _multicast_capable(false), 00685 _loopback(false), 00686 _p2p(false) 00687 { 00688 } 00689 00690 inline void 00691 IfMgrIPv6Atom::set_endpoint_addr(const IPv6& p2p_addr) 00692 { 00693 if (p2p_addr == IPv6::ZERO()) { 00694 _p2p = false; 00695 } else { 00696 _p2p = true; 00697 _other_addr = p2p_addr; 00698 } 00699 } 00700 00701 inline const IPv6& 00702 IfMgrIPv6Atom::endpoint_addr() const 00703 { 00704 return _p2p ? _other_addr : _ZERO_ADDR; 00705 } 00706 00707 #endif // __LIBFEACLIENT_IFMGR_ATOMS_HH__