xorp

IfTree Class Reference

Container class for FEA Interface objects in a system. More...

#include <iftree.hh>

Inheritance diagram for IfTree:
IfTreeItem NONCOPYABLE

List of all members.

Public Types

typedef map< string,
IfTreeInterface * > 
IfMap
typedef map< uint32_t,
IfTreeInterface * > 
IfIndexMap
typedef multimap< uint32_t,
IfTreeVif * > 
VifIndexMap

Public Member Functions

 IfTree (const char *tree_name)
 Default constructor.
 IfTree (const IfTree &other)
 Constructor from another IfTree.
virtual ~IfTree ()
 Destructor.
IfTreeoperator= (const IfTree &other)
 Assignment operator.
void clear ()
 Remove all interface state from the interface tree.
void registerListener (IfTreeListener *l) const
 Not really const, but better than having to pass non-const references to other classes.
void unregisterListener (IfTreeListener *l) const
 Not really const, but better than having to pass non-const references to other classes.
void add_recursive_interface (const IfTreeInterface &other_iface, bool mark_state)
 Add recursively a new interface.
int add_interface (const string &ifname)
 Create a new interface.
int remove_interface (const string &ifname)
 Label interface as ready for deletion.
int update_interface (const IfTreeInterface &other_iface)
 Recursively create a new interface or update its state if it already exists.
IfTreeInterfacefind_interface (const string &ifname)
 Find an interface.
const IfTreeInterfacefind_interface (const string &ifname) const
 Find a const interface.
IfTreeInterfacefind_interface (uint32_t pif_index)
 Find an interface for a given physical index.
const IfTreeInterfacefind_interface (uint32_t pif_index) const
 Find a const interface for a given physical index.
IfTreeViffind_vif (const string &ifname, const string &vifname)
 Find a vif.
const IfTreeViffind_vif (const string &ifname, const string &vifname) const
 Find a const vif.
IfTreeViffind_vif (uint32_t pif_index)
 Find a vif for a given physical index.
const IfTreeViffind_vif (uint32_t pif_index) const
 Find a const vif for a given physical index.
IfTreeAddr4find_addr (const string &ifname, const string &vifname, const IPv4 &addr)
 Find an IPv4 address.
const IfTreeAddr4find_addr (const string &ifname, const string &vifname, const IPv4 &addr) const
 Find a const IPv4 address.
IfTreeAddr6find_addr (const string &ifname, const string &vifname, const IPv6 &addr)
 Find an IPv6 address.
const IfTreeAddr6find_addr (const string &ifname, const string &vifname, const IPv6 &addr) const
 Find a const IPv6 address.
bool find_interface_vif_by_addr (const IPvX &addr, const IfTreeInterface *&ifp, const IfTreeVif *&vifp) const
 Find an interface and a vif by an address that belongs to that interface and vif.
bool find_interface_vif_same_subnet_or_p2p (const IPvX &addr, const IfTreeInterface *&ifp, const IfTreeVif *&vifp) const
 Find an interface and a vif by an address that shares the same subnet or p2p address.
IfMap & interfaces ()
 Get the map with the stored interfaces.
const IfMap & interfaces () const
 Get the const map with the stored interfaces.
IfTreealign_with_pulled_changes (const IfTree &other, const IfTree &user_config)
 Align system-user merged configuration with the pulled changes in the system configuration.
IfTreealign_with_observed_changes (const IfTree &other, const IfTree &user_config)
 Align system-user merged configuration with the observed changes in the system configuration.
IfTreealign_with_user_config (const IfTree &other)
 Align system-user merged configuration with the user configuration changes.
IfTreeprepare_replacement_state (const IfTree &other)
 Prepare configuration for pushing and replacing previous configuration.
IfTreeprune_bogus_deleted_state (const IfTree &old_iftree)
 Prune bogus deleted state.
void finalize_state ()
 Delete interfaces labelled as ready for deletion, call finalize_state() on remaining interfaces, and set state to NO_CHANGE.
string str () const
const string & getName () const
void markVifDeleted (IfTreeVif *ifp)
void markIfaceDeleted (IfTreeInterface *ifp)

Protected Member Functions

void insert_ifindex (IfTreeInterface *ifp)
void erase_ifindex (IfTreeInterface *ifp)
void insert_vifindex (IfTreeVif *vifp)
void erase_vifindex (IfTreeVif *vifp)
void sendEvent (IfTreeVifEventE e, IfTreeVif *vifp)
void sendEvent (IfTreeIfaceEventE e, IfTreeInterface *ifp)

Private Attributes

string name
IfMap _interfaces
IfIndexMap _ifindex_map
VifIndexMap _vifindex_map
list< IfTreeListener * > listeners

Friends

class IfTreeInterface
class IfTreeVif

Detailed Description

Container class for FEA Interface objects in a system.


Constructor & Destructor Documentation

IfTree::IfTree ( const IfTree other)

Constructor from another IfTree.

Parameters:
otherthe other IfTree.

Member Function Documentation

int IfTree::add_interface ( const string &  ifname)

Create a new interface.

Parameters:
ifnamethe interface name.
Returns:
XORP_OK on success, otherwise XORP_ERROR.
void IfTree::add_recursive_interface ( const IfTreeInterface other_iface,
bool  mark_state 
)

Add recursively a new interface.

Parameters:
other_ifacethe interface to add recursively.
mark_stateif true, then mark the state same as the state from the other interface, otherwise the state will be CREATED.
IfTree & IfTree::align_with_observed_changes ( const IfTree other,
const IfTree user_config 
)

Align system-user merged configuration with the observed changes in the system configuration.

Inside the FEA there may be multiple configuration representations, typically one the user modifies, one that mirrors the hardware, and one that merges those two (e.g., some of the merged information comes from the user configuration while other might come from the underlying system). On certain systems there could be asynchronous updates originated by the system that are captured by the FEA interface observer (e.g., a cable is unplugged, a tunnel interface is added/deleted, etc).

This method is used to align those updates with the merged configuration.

1. If an interface in the other tree is not in the local tree, it is tested whether is in the user configuration tree. If not, the rest of the processing is not applied and the interface is ignored. Otherwise it is created, its state is merged from the user config and other tree, and is marked as "CREATED". 2. If an interface in the local tree is marked as "soft", its state is not modified and the rest of the processing is ignored. 3. If an interface in the local tree is marked as "default_system_config", the rest of the processing is not applied, and its state (and the subtree below it) is copied as-is from the other tree. 4. If an item in the other tree is not in the local tree, it is tested whether is in the user configuration tree. If not, the rest of the processing is not applied and the item is ignored. Otherwise it is created, its state is merged from the user config and the other tree, and is marked as "CREATED". 5. If an item in the other tree is marked as: (a) "NO_CHANGE": The state of the entry in the other tree is not propagated to the local tree, but its subtree entries are processed. (b) "DELETED": The item in the local tree is disabled, and the subtree entries are ignored. (c) "CREATED" or "CHANGED": If the state of the entry is different in the other and the local tree, it is copied to the local tree, and the item in the local tree is marked as "CREATED" or "CHANGED". unless it was marked earlier as "CREATED". Also, if the item is disabled in the user config tree, it is marked as "disabled" in the local tree.

Parameters:
otherthe configuration tree to align state with.
user_configthe user configuration tree to reference during the alignment.
Returns:
modified configuration structure.

Inside the FEA there may be multiple configuration representations, typically one the user modifies, one that mirrors the hardware, and one that merges those two (e.g., some of the merged information comes from the user configuration while other might come from the underlying system). On certain systems there could be asynchronous updates originated by the system that are captured by the FEA interface observer (e.g., a cable is unplugged, a tunnel interface is added/deleted, etc).

This method is used to align those updates with the merged configuration.

The alignment works as follows: 1. If an interface in the other tree is not in the local tree, it is tested whether is in the user configuration tree. If not, the rest of the processing is not applied and the interface is ignored. Otherwise it is created, its state is merged from the user config and other tree, and is marked as "CREATED". 2. If an interface in the local tree is marked as "soft", its state is not modified and the rest of the processing is ignored. 3. If an interface in the local tree is marked as "default_system_config", the rest of the processing is not applied, and its state (and the subtree below it) is copied as-is from the other tree. 4. If an item in the other tree is not in the local tree, it is tested whether is in the user configuration tree. If not, the rest of the processing is not applied and the item is ignored. Otherwise it is created, its state is merged from the user config and the other tree, and is marked as "CREATED". 5. If an item in the other tree is marked as: (a) "NO_CHANGE": The state of the entry in the other tree is not propagated to the local tree, but its subtree entries are processed. (b) "DELETED": The item in the local tree is disabled, and the subtree entries are ignored. (c) "CREATED" or "CHANGED": If the state of the entry is different in the other and the local tree, it is copied to the local tree, and the item in the local tree is marked as "CREATED" or "CHANGED". Also, if the item is disabled in the user config tree, it is marked as "disabled" in the local tree.

Parameters:
otherthe configuration tree to align state with.
user_configthe user configuration tree to reference during the alignment.
Returns:
modified configuration structure.
IfTree & IfTree::align_with_pulled_changes ( const IfTree other,
const IfTree user_config 
)

Align system-user merged configuration with the pulled changes in the system configuration.

Inside the FEA there may be multiple configuration representations, typically one the user modifies, one that mirrors the hardware, and one that merges those two (e.g., some of the merged information comes from the user configuration while other might come from the underlying system). Errors may occur pushing the user config down onto the hardware and we need a method to update the merged config from the h/w config that exists after the config push. We can't just copy the h/w config since the user config is restricted to configuration set by the user.

The alignment works as follows: 1. If an interface in the local tree is marked as "soft", its state is not modified and the rest of the processing is ignored. 2. If an interface in the local tree is marked as "default_system_config", the rest of the processing is not applied, and the following rules are used instead: (a) If the interface is not in the other tree, it is marked as "disabled" and its vifs are marked for deletion. (b) Otherwise, its state (and the subtree below it) is copied as-is from the other tree. 3. If an item in the local tree is not in the other tree, it is marked as "disabled" in the local tree. 4. If an item in the local tree is in the other tree, and its state is different in the local and the other tree, the state is copied from the other tree to the local tree. Also, if the item is disabled in the user config tree, it is marked as "disabled" in the local tree.

Parameters:
otherthe configuration tree to align state with.
user_configthe user configuration tree to reference during the alignment.
Returns:
modified configuration structure.
IfTree & IfTree::align_with_user_config ( const IfTree other)

Align system-user merged configuration with the user configuration changes.

Inside the FEA there may be multiple configuration representations, typically one the user modifies, one that mirrors the hardware, and one that merges those two (e.g., some of the merged information comes from the user configuration while other might come from the underlying system).

This method is used to align the user configuration changes with the merged configuration.

The alignment works as follows: 1. If an item in the other tree is not in the local tree, it is created in the local tree and its state (and the subtree below it) is copied as-is from the other tree, and the rest of the processing is ignored. 2. If an item in the other tree is marked as: (a) "DELETED": The item in the local tree is marked as "DELETED", and the subtree entries are ignored. (b) All other: If the state of the item is different in the other and the local tree, it is copied to the local tree. Note that we compare the state even for "NO_CHANGE" items in case a previous change to a parent item in the merged tree has affected the entry (e.g., disabled interface would disable the vifs and addresses as well).

Parameters:
otherthe configuration tree to align state with.
Returns:
modified configuration structure.
const IfTreeAddr4 * IfTree::find_addr ( const string &  ifname,
const string &  vifname,
const IPv4 addr 
) const

Find a const IPv4 address.

Parameters:
ifnamethe interface name to search for.
vifnamethe vif name to search for.
addrthe address to search for.
Returns:
a const pointer to the vif (IfTreeAddr4) or NULL if not found.
IfTreeAddr4 * IfTree::find_addr ( const string &  ifname,
const string &  vifname,
const IPv4 addr 
)

Find an IPv4 address.

Parameters:
ifnamethe interface name to search for.
vifnamethe vif name to search for.
addrthe address to search for.
Returns:
a pointer to the vif (IfTreeAddr4) or NULL if not found.
const IfTreeAddr6 * IfTree::find_addr ( const string &  ifname,
const string &  vifname,
const IPv6 addr 
) const

Find a const IPv6 address.

Parameters:
ifnamethe interface name to search for.
vifnamethe vif name to search for.
addrthe address to search for.
Returns:
a pointer to the vif (IfTreeAddr6) or NULL if not found.
IfTreeAddr6 * IfTree::find_addr ( const string &  ifname,
const string &  vifname,
const IPv6 addr 
)

Find an IPv6 address.

Parameters:
ifnamethe interface name to search for.
vifnamethe vif name to search for.
addrthe address to search for.
Returns:
a pointer to the vif (IfTreeAddr6) or NULL if not found.
IfTreeInterface * IfTree::find_interface ( const string &  ifname)

Find an interface.

Parameters:
ifnamethe interface name to search for.
Returns:
a pointer to the interface (IfTreeInterface) or NULL if not found.
const IfTreeInterface * IfTree::find_interface ( const string &  ifname) const

Find a const interface.

Parameters:
ifnamethe interface name to search for.
Returns:
a const pointer to the interface (IfTreeInterface) or NULL if not found.
IfTreeInterface * IfTree::find_interface ( uint32_t  pif_index)

Find an interface for a given physical index.

Parameters:
pif_indexthe physical interface index to search for.
Returns:
a pointer to the interface (IfTreeInterface) or NULL if not found.
const IfTreeInterface * IfTree::find_interface ( uint32_t  pif_index) const

Find a const interface for a given physical index.

Parameters:
pif_indexthe physical interface index to search for.
Returns:
a const pointer to the interface (IfTreeInterface) or NULL if not found.
bool IfTree::find_interface_vif_by_addr ( const IPvX addr,
const IfTreeInterface *&  ifp,
const IfTreeVif *&  vifp 
) const

Find an interface and a vif by an address that belongs to that interface and vif.

Parameters:
addrthe address.
ifpreturn-by-reference a pointer to the interface.
vifpreturn-by-reference a pointer to the vif.
Returns:
true if a match is found, otherwise false.
bool IfTree::find_interface_vif_same_subnet_or_p2p ( const IPvX addr,
const IfTreeInterface *&  ifp,
const IfTreeVif *&  vifp 
) const

Find an interface and a vif by an address that shares the same subnet or p2p address.

Parameters:
addrthe address.
ifpreturn-by-reference a pointer to the interface.
vifpreturn-by-reference a pointer to the vif.
Returns:
true if a match is found, otherwise false.
const IfTreeVif * IfTree::find_vif ( uint32_t  pif_index) const

Find a const vif for a given physical index.

Parameters:
pif_indexthe physical interface index to search for.
Returns:
a const pointer to the vif (IfTreeVif) or NULL if not found.
IfTreeVif * IfTree::find_vif ( const string &  ifname,
const string &  vifname 
)

Find a vif.

Parameters:
ifnamethe interface name to search for.
vifnamethe vif name to search for.
Returns:
a pointer to the vif (IfTreeVif) or NULL if not found.
const IfTreeVif * IfTree::find_vif ( const string &  ifname,
const string &  vifname 
) const

Find a const vif.

Parameters:
ifnamethe interface name to search for.
vifnamethe vif name to search for.
Returns:
a const pointer to the vif (IfTreeVif) or NULL if not found.
IfTreeVif * IfTree::find_vif ( uint32_t  pif_index)

Find a vif for a given physical index.

Parameters:
pif_indexthe physical interface index to search for.
Returns:
a pointer to the vif (IfTreeVif) or NULL if not found.
IfMap& IfTree::interfaces ( ) [inline]

Get the map with the stored interfaces.

Returns:
the map with the stored interfaces.
const IfMap& IfTree::interfaces ( ) const [inline]

Get the const map with the stored interfaces.

Returns:
the const map with the stored interfaces.
IfTree & IfTree::operator= ( const IfTree other)

Assignment operator.

Parameters:
otherthe other IfTree.
IfTree & IfTree::prepare_replacement_state ( const IfTree other)

Prepare configuration for pushing and replacing previous configuration.

If the previous configuration is to be replaced with new configuration, we need to prepare the state that will delete, update, and add the new state as appropriate. The preparation works as follows:

  • All items in the local tree are preserved and marked as created.
  • All items in the other tree that are not in the local tree are added to the local tree and are marked as deleted.
Parameters:
otherthe configuration tree to be used to prepare the replacement state.
Returns:
modified configuration structure.

If the previous configuration is to be replaced with new configuration, we need to prepare the state that will delete, update, and add the new state as appropriate. The preparation works as follows:

  • All items in the local tree are preserved and are marked as created.
  • All items in the other tree that are not in the local tree are added to the local tree and are marked as deleted.
Parameters:
otherthe configuration tree to be used to prepare the replacement state.
Returns:
modified configuration structure.
IfTree & IfTree::prune_bogus_deleted_state ( const IfTree old_iftree)

Prune bogus deleted state.

If an item in the local tree is marked as deleted, but is not in the other tree, then it is removed.

Parameters:
old_iftreethe old tree with the state that is used as reference.
Returns:
the modified configuration tree.
int IfTree::remove_interface ( const string &  ifname)

Label interface as ready for deletion.

Deletion does not occur until finalize_state() is called.

Parameters:
ifnamethe name of the interface to be labelled.
Returns:
XORP_OK on success, otherwise XORP_ERROR.
string IfTree::str ( ) const
Returns:
string representation of IfTree.

Reimplemented from IfTreeItem.

int IfTree::update_interface ( const IfTreeInterface other_iface)

Recursively create a new interface or update its state if it already exists.

Parameters:
other_ifacethe interface with the state to copy from.
Returns:
XORP_OK on success, otherwise XORP_ERROR.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations