/* $XORP: xorp/xrl/interfaces/bgp.xif,v 1.34 2007/07/12 21:35:26 pavlin Exp $ */

#include <xorp_config.h>

/*
** BGP protocol XRL interface.
*/
interface bgp/0.3 {
	/**
	 *  Get the BGP version currently running.
	 */
	get_bgp_version -> version:u32;

	/**
	 * Get local config
	 *
	 * @param as_num our AS number.
	 * @param id our BGP ID.
	 */

	local_config \
		? \
		as:txt \
		& id:ipv4 \
		& use_4byte_asnums:bool;

	/**
	 * Set the local AS number.
	 *
	 * @param as our AS number.
	 */
	
	set_local_as ? as:txt;

	/**
	 * Allow 4-byte AS numbers.
	 *
	 * @param enable whether this is enabled.
	 */
	
	set_4byte_as_support ? enable:bool;

	/**
	 *  Get the local AS number.
	 */
	get_local_as -> as:txt;

	/**
         * Set the BGP id.
	 *
	 * @param id our BGP ID.
	 */

	set_bgp_id ? id:ipv4;

	/**
	 *  Get the BGP id.
	 */
	get_bgp_id -> id:ipv4;

	/**
	 * Confederation identifier.
	 *
	 * @param as externally visible AS number.
	 * @param disable true if confederations are disabled.
	 */
	set_confederation_identifier \
		? \
		as:txt \
		& disable:bool;

	/**
	 * Route reflection.
	 *
	 * @param cluster_id the route reflection cluster ID.
	 * @param disable if true this router is a router reflector.
	 */
	set_cluster_id \
		? \
		cluster_id:ipv4 \
		& disable:bool;

	/**
	 * Route Flap Damping. RFC 2439
	 *
	 * @param half_life decay half life in minutes.
	 * @param max_suppress maximum time in minutes a route can be held 
	 *         down.
	 * @param supress cutoff threshold, once passed route is damped.
	 * @param reuse threshold, point at which a route can be reused.
	 */
	set_damping \
		? \
		half_life:u32 \
		& max_suppress:u32 \
		& reuse:u32 \
		& suppress:u32 \
	 	& disable:bool;

	/** 
	 * Add peer.
	 *
	 * @param local Interface Name.
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param as the peer's AS number.
	 * @param next_hop the local next hop.
	 * @param holdtime if traffic is not received in holdtime seconds
	 *        a peering is considered down.
	 */
	add_peer \
		? \
		local_dev:txt \
		& local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& as:txt \
		& next_hop:ipv4 \
	        & holdtime:u32;

	/**
	 * Delete peer.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 */
	delete_peer \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32;

	/** 
	 * Enable this peer.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 */
	enable_peer \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32;

	/**
	 * Disable this peer.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 */
	disable_peer \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32;

	/**
	 * Change the local IP address and interface.
	 *
	 * @param local_ip current IP address.
	 * @param local_port server port.
	 * @param peer_ip IP address.
	 * @param peer_port peer port.
	 * @param new_local_ip new IP address.
	 * @param new_local_dev new Interface Name.
	 */
	change_local_ip \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& new_local_ip:txt \
		& new_local_dev:txt;

	/**
	 * Change the local port.
	 *
	 * @param local_ip current IP address.
	 * @param local_port server port.
	 * @param peer_ip IP address.
	 * @param peer_port peer port.
	 * @param new_local_port new local port.
	 */
	change_local_port \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& new_local_port:u32;

	/**
	 * Change the peer port.
	 *
	 * @param local_ip current IP address.
	 * @param local_port server port.
	 * @param peer_ip IP address.
	 * @param peer_port peer port.
	 * @param new_local_port new local port.
	 */
	change_peer_port \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& new_peer_port:u32;

	/**
	 * Set the peer's AS number.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param peer_as the peer's AS number.
	 */
	set_peer_as \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& peer_as:txt;

	/**
	 * Set the holdtime
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param holdtime if traffic is not received in holdtime seconds
	 *        a peering is considered down.
	 */
	set_holdtime \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& holdtime:u32;

	/**
	 * Set the delay open time
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param delay_open_time to wait is seconds before sending an open.
	 *       
	 */
	set_delay_open_time \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& delay_open_time:u32;

	/**
	 * Set the route reflection client state. Is this peer a route
	 * reflector client.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param state true if peer is a route reflector client.
	 */
	set_route_reflector_client \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& state:bool;
		
	/**
	 * Is this peer a confederation member.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param state true if peer is a confederation member.
	 */
	set_confederation_member \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& state:bool;

	/**
	 * Set the prefix limit.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param maximum number of prefixes
	 * @param state true if the prefix limit is being enforced
	 */
	set_prefix_limit \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& maximum:u32 \
		& state:bool;

	/**
	 * Set the peer's AS number.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param next_hop IPv4 nexthop.
	 */
	set_nexthop4 \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& next_hop:ipv4;

	/**
         * Set the peer state enabled or disabled.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
         * @param toggle enabled or disabled.
	 */
	set_peer_state \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& toggle:bool;

	/**
	 * Set the peer md5 password.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param password the password to use for TCP-MD5 authentication.
	 */
	set_peer_md5_password \
		? \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& password:txt;

	/**
         * Enable or disable the peering based on the peer state.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 */
	activate \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32;

	/**
	 * Set which parameters we support per peer
	 */
         set_parameter \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& parameter:txt \
		& toggle:bool;

	/**
	 * Set next hop rewrite filter.
	 *
	 * XXX - This is a temporary hack until we get programmable filters.
	 * 
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param next hop IP value. A value of zero clears filter.
	 *
	 */
	 next_hop_rewrite_filter \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& next_hop:ipv4;

	/**
	 * Originate route IPv4
	 *
	 * @param nlri subnet to announce
	 * @param next_hop to forward to
	 * @param unicast if true install in unicast routing table
	 * @param multicast if true install in multicast routing table
	 */
	originate_route4 \
		? \
		nlri:ipv4net \
		& next_hop:ipv4 \
		& unicast:bool \
		& multicast:bool;

	/**
	 * Withdraw route IPv4
	 *
	 * @param nlri subnet to withdraw
	 * @param unicast if true withdraw from unicast routing table
	 * @param multicast if true withdraw from multicast routing table
	 */
	withdraw_route4 \
		? \
		nlri:ipv4net \
		& unicast:bool \
		& multicast:bool;

        /**
         * Enable/Disable tracing.
         *
         * @param tvar trace variable.
         * @param enable set to true to enable false to disable.
         */
         trace ? tvar:txt \
	     & enable:bool;

	/**
	 * Get the first item of a list of BGP peers
	 * See RFC 1657 (BGP MIB) for full definitions of return values.
	 *	
	 * @param token returned token to be provided when calling 
	 * get_peer_list_next.
	 * @param more returned to indicate whether there are more list items 
	 * remaining.
	 */	
	get_peer_list_start -> \
		token:u32 \
		& more:bool;

	/**
	 * Get the next item of a list of BGP peers
	 *
	 * @param token token from prior call to get_peer_list
	 * @param more returned to indicate whether there are more list items 
	 * remaining.
	 */	
	get_peer_list_next \
		? \
		token:u32 \
		-> \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& more:bool;

         
	get_peer_id \
		? \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		-> \
		peer_id:ipv4; 

	get_peer_status \
		? \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		-> \
		peer_state:u32 \
		& admin_status:u32;

	get_peer_negotiated_version \
		? \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		-> \
		neg_version:i32;

	get_peer_as \
		? \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		-> \
		peer_as:txt;

	get_peer_msg_stats \
		? \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		-> \
		in_updates:u32 \
		& out_updates:u32 \
		& in_msgs:u32 \
		& out_msgs:u32 \
		& last_error:u32 \
		& in_update_elapsed:u32;

	get_peer_established_stats \
		? \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		-> \
		transitions:u32 \
		& established_time:u32;


	get_peer_timer_config \
		? \
		local_ip:txt \
		& local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		-> \
		retry_interval:u32 \
		& hold_time:u32 \
		& keep_alive:u32 \
		& hold_time_conf:u32 \
		& keep_alive_conf:u32 \
		& min_as_orgination_interval:u32 \
		& min_route_adv_interval:u32;

	/**
	 * Register rib.
	 *
	 * @param name rib name.
	 */
	register_rib \
		? \
		name:txt;
	/**
	 * Get the first item of a list of BGP routes
	 * See RFC 1657 (BGP MIB) for full definitions of return values.
	 *
	 * @param net the subtree to examine.
	 *
	 * NB Either unicast or multicast should be set to true, but not both.
	 *
	 * @param unicast request start of unicast routes.
         * @param multicast request start of unicast routes.
	 *
	 * @param token returned token to be provided when calling
	 * get_route_list_next.
	 */
	get_v4_route_list_start \
	        ? \
		net:ipv4net \
		& unicast:bool \
		& multicast:bool \
		-> \
		token:u32;

	/**
         * Get the next route in the list
	 * See RFC 1657 (BGP MIB) for full definitions of return values.
         */
        get_v4_route_list_next \
		? \
		token:u32 \
		-> \
		peer_id:ipv4 \
		& net:ipv4net \
		& best_and_origin:u32 \
		& aspath:binary \
		& nexthop:ipv4 \
		& med:i32 \
		& localpref:i32 \
		& atomic_agg:i32 \
		& aggregator:binary \
		& calc_localpref:i32 \
		& attr_unknown:binary \
		& valid:bool \
	        & unicast:bool \
	        & multicast:bool;

#ifdef HAVE_IPV6
	/**
	 * Set the IPv6 nexthop.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param next_hop IPv6 nexthop
	 */
	set_nexthop6 \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		& next_hop:ipv6;


	/**
	 * Get the IPv6 nexthop.
	 *
	 * @param local IP address.
	 * @param local server port.
	 * @param peer IP address.
	 * @param peer port.
	 * @param next_hop IPv6 nexthop
	 */
	get_nexthop6 \
		? \
		local_ip:txt \
	        & local_port:u32 \
		& peer_ip:txt \
		& peer_port:u32 \
		-> next_hop:ipv6;

	/**
	 * Withdraw route IPv6
	 *
	 * @param nlri subnet to withdraw
	 * @param unicast if true withdraw from unicast routing table
	 * @param multicast if true withdraw from multicast routing table
	 */
	withdraw_route6 \
		? \
		nlri:ipv6net \
		& unicast:bool \
		& multicast:bool;

	/**
	 * Get the first item of a list of BGP routes
	 * See RFC 1657 (BGP MIB) for full definitions of return values.
	 *
	 * @param net the subtree to examine.
	 *
	 * NB Either unicast or multicast should be set to true, but not both.
	 *
	 * @param unicast request start of unicast routes.
         * @param multicast request start of multicast routes.
	 *
	 * @param token returned token to be provided when calling
	 * get_route_list_next.
	 */
	get_v6_route_list_start \
	        ? \
		net:ipv6net \
		& unicast:bool \
		& multicast:bool \
		-> \
		token:u32;

	/**
	 * Originate route IPv6
	 *
	 * @param nlri subnet to announce
	 * @param next_hop to forward to
	 * @param unicast if true install in unicast routing table
	 * @param multicast if true install in multicast routing table
	 */
	originate_route6 \
		? \
		nlri:ipv6net \
		& next_hop:ipv6 \
		& unicast:bool \
		& multicast:bool;

	/**
         * Get the next route in the list
	 * See RFC 1657 (BGP MIB) for full definitions of return values.
         */
        get_v6_route_list_next \
		? \
		token:u32 \
		-> \
		peer_id:ipv4 \
		& net:ipv6net \
		& best_and_origin:u32 \
		& aspath:binary \
		& nexthop:ipv6 \
		& med:i32 \
		& localpref:i32 \
		& atomic_agg:i32 \
		& aggregator:binary \
		& calc_localpref:i32 \
		& attr_unknown:binary \
		& valid:bool \
	        & unicast:bool \
	        & multicast:bool;

#endif
}
