ped_ssd.c File Reference

Routines related to talking to SDK Service Daemon. More...

#include <sync/common.h>
#include <jnx/ssd_ipc.h>
#include <jnx/ssd_ipc_msg.h>
#include <limits.h>
#include "ped_ssd.h"

Go to the source code of this file.

Data Structures

struct  ssd_request_t

Defines

#define RT_TBL_NAME   "inet.0"
 routing table we wish to add routes to
#define REQUESTS_BUFFER_SIZE   64
#define UNCONFIRMED_CONTEXT   REQUESTS_BUFFER_SIZE
#define MAX_UNCONFIRMED_CONTEXT   UINT_MAX
#define RETRY_CONNECT   60

Functions

static int ssd_client_connection (int fd)
static void ssd_client_connection_close (int fd, int cause)
static void ssd_client_msg (int fd, struct ssd_ipc_msg *cmsg)
static void connect_ssd (evContext ctx __unused, void *uap __unused, struct timespec due __unused, struct timespec inter __unused)
static int ssd_client_ifa_handler (kcom_ifa_t *msg, void *user_info)
void ped_ssd_init (void)
void ped_ssd_shutdown (void)
boolean get_ssd_ready (void)
boolean get_ssd_idle (void)
boolean ssd_client_add_route_request (policy_route_msg_t *route, ssd_reply_notification_handler func, void *user_data)
boolean ssd_client_del_route_request (policy_route_msg_t *route, ssd_reply_notification_handler func, void *user_data)
void clean_routes (void)

Variables

static boolean ssd_ready = FALSE
 The state of connection.
static int ssd_server_fd = -1
 socket to SSD
static int client_id = 0
 client id with SSD
static uint32_t rt_tbl_id = 0
 routing instance to which we add routes
static evTimerID timer_id
 timer ID for retrying connection to SSD
static struct ssd_ipc_ft ssd_client_ft
 the function table for SSD callbacks
evContext ped_ctx
 Event context for ped.
static ssd_request_t ssd_requests [REQUESTS_BUFFER_SIZE]
 buffer of requests
static uint32_t next_buffer = 0
 index of next buffer to use up for a request
static uint32_t next_unconfirmed = UNCONFIRMED_CONTEXT
 number of requests outstanding in buffer
static int outstanding_requests = 0
 number of requests outstanding in buffer


Detailed Description

Routines related to talking to SDK Service Daemon.

Functions for connecting to SSD and adding or deleting route.

Definition in file ped_ssd.c.


Define Documentation

#define MAX_UNCONFIRMED_CONTEXT   UINT_MAX

Max value for next_unconfirmed where upon we reset it to UNCONFIRMED_CONTEXT

Definition at line 57 of file ped_ssd.c.

Referenced by clean_routes(), and ssd_client_del_route_request().

#define REQUESTS_BUFFER_SIZE   64

Number of requests we accept without responses back from SSD

Definition at line 46 of file ped_ssd.c.

Referenced by ped_ssd_init(), ssd_client_add_route_request(), ssd_client_del_route_request(), and ssd_client_msg().

#define RETRY_CONNECT   60

Retry connecting to SSD every RETRY_CONNECT seconds until connection is made

Definition at line 62 of file ped_ssd.c.

#define UNCONFIRMED_CONTEXT   REQUESTS_BUFFER_SIZE

The client context to give to libssd when a request is to be unconfirmed (which only applies to deletes herein)

Definition at line 52 of file ped_ssd.c.

Referenced by ped_ssd_init(), and ssd_client_del_route_request().


Function Documentation

void clean_routes ( void   ) 

Clean up all routes created and shutdown this module

Definition at line 790 of file ped_ssd.c.

References MAX_UNCONFIRMED_CONTEXT, ssd_ready, and ssd_server_fd.

static void connect_ssd ( evContext ctx  __unused,
void *uap  __unused,
struct timespec due  __unused,
struct timespec inter  __unused 
) [static]

Setup the connection to SSD. This also sets the function table of callbacks to use between ped and libssd. We periodically call this until the connection setup is successful.

Parameters:
[in] ctx The event context for this application
[in] uap The user data for this callback
[in] due The absolute time when the event is due (now)
[in] inter The period; when this will next be called

Definition at line 128 of file ped_ssd.c.

References ped_ctx, ssd_client_ft, ssd_server_fd, and timer_id.

Referenced by ped_ssd_init(), service_route_init(), and ssd_client_connection_close().

boolean get_ssd_idle ( void   ) 

Are there any outstanding requests to SSD for which we soon expect replies

Returns:
TRUE if there are NOT outstanding requests; FALSE if there are outstanding requests

Definition at line 568 of file ped_ssd.c.

References outstanding_requests.

Referenced by policy_table_clean(), and psd_ipc_read().

boolean get_ssd_ready ( void   ) 

Check the state of SSD connection.

Returns:
TRUE if connected to SSD, otherwise FALSE.

Definition at line 554 of file ped_ssd.c.

References ssd_ready.

Referenced by policy_table_clean(), and psd_ipc_read().

void ped_ssd_init ( void   ) 

Initialize client

Definition at line 502 of file ped_ssd.c.

References client_id, connect_ssd(), next_buffer, next_unconfirmed, outstanding_requests, ped_ctx, REQUESTS_BUFFER_SIZE, RETRY_CONNECT, rt_tbl_id, ssd_requests, ssd_server_fd, timer_id, UNCONFIRMED_CONTEXT, and ssd_request_t::user_data.

Referenced by ped_init().

void ped_ssd_shutdown ( void   ) 

Shutdown client

Definition at line 539 of file ped_ssd.c.

References ssd_server_fd.

boolean ssd_client_add_route_request ( policy_route_msg_t route,
ssd_reply_notification_handler  func,
void *  user_data 
)

Send message to SSD to add a route.

Parameters:
[in] route Pointer to route data.
[in] func function to callback when result is available
[in] user_data user data to echo in callback
Returns:
TRUE if request was accepted; FALSE if not due to no more buffers to store the request, or a KCOM problem, or ssd_request_route_add fails

Definition at line 591 of file ped_ssd.c.

References policy_route_msg_s::af, policy_route_msg_s::ifname, next_buffer, outstanding_requests, ssd_request_t::reply_handler, REQUESTS_BUFFER_SIZE, ssd_client_ifa_handler(), ssd_ready, ssd_requests, and ssd_request_t::user_data.

Referenced by add_route().

static int ssd_client_connection ( int  fd  )  [static]

The callback function called after first connecting to SSD. We also ask SSD for a client ID.

Definition at line 162 of file ped_ssd.c.

static void ssd_client_connection_close ( int fd  __unused,
int cause  __unused 
) [static]

The callback function to handle the connection close from SSD

Parameters:
[in] fd SSD server socket
[in] cause The cause of the connection close

Definition at line 191 of file ped_ssd.c.

References connect_ssd(), ped_ctx, RETRY_CONNECT, ssd_ready, ssd_server_fd, and timer_id.

boolean ssd_client_del_route_request ( policy_route_msg_t route,
ssd_reply_notification_handler  func,
void *  user_data 
)

Send message to SSD to delete a route. This should be done with confirmation (func should handle the result). However, if our SSD confirmation-of-request buffers run out, then we return FALSE. In case of this, the caller can try calling the function again with func and user_data both NULL, but beware that no confirmation of the result will be provided, and the function will return TRUE unless libssd fails to accept it.

Parameters:
[in] route Pointer to route data.
[in] func function to callback when result is available. NULL if trying to delete without confirmation (caller will never know result if SSD accepts the reqest)
[in] user_data user data to echo in callback
Returns:
TRUE if request was accepted; FALSE if not due to no more buffers to store the request, or a KCOM problem, or ssd_request_route_delete fails

Definition at line 700 of file ped_ssd.c.

References MAX_UNCONFIRMED_CONTEXT, next_buffer, next_unconfirmed, outstanding_requests, ssd_request_t::reply_handler, REQUESTS_BUFFER_SIZE, policy_route_msg_s::route_addr, policy_route_msg_s::route_addr_prefix, rt_tbl_id, ssd_ready, ssd_requests, ssd_server_fd, UNCONFIRMED_CONTEXT, and ssd_request_t::user_data.

Referenced by remove_route(), and ssd_request_status().

static int ssd_client_ifa_handler ( kcom_ifa_t *  msg,
void *  user_info 
) [static]

A callback/handler passed into junos_kcom_ifa_get_all from ssd_client_add_route_request

Parameters:
[in] msg message with ifa info
[in] user_info user data passed to junos_kcom_ifa_get_all
Returns:
SUCCESS or 1 if there's an SSD issue

Definition at line 411 of file ped_ssd.c.

References policy_route_msg_s::metrics, next_buffer, policy_route_msg_s::nh_addr, policy_route_msg_s::nh_type, policy_route_msg_s::preferences, policy_route_msg_s::route_addr, policy_route_msg_s::route_addr_prefix, rt_tbl_id, and ssd_server_fd.

Referenced by ssd_client_add_route_request().

static void ssd_client_msg ( int  fd,
struct ssd_ipc_msg *  cmsg 
) [static]

The callback function to handle getting messages from SSD

Parameters:
[in] fd SSD server fd.
[in] cmsg The pointer to the message from SSD.

Definition at line 230 of file ped_ssd.c.

References ADD_FAILED, ADD_SUCCESS, client_id, DELETE_FAILED, DELETE_SUCCESS, outstanding_requests, ssd_request_t::reply_handler, REQUESTS_BUFFER_SIZE, rt_tbl_id, RT_TBL_NAME, ssd_ready, ssd_requests, and ssd_request_t::user_data.


Variable Documentation

struct ssd_ipc_ft ssd_client_ft [static]

Initial value:

the function table for SSD callbacks

Definition at line 82 of file ped_ssd.c.


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:27:06 2010 for SDK Your Net Corporation Policy Manager Example: Policy Enforcement Daemon 1.0 by Doxygen 1.5.1