hellopics-mgmt_conn.c File Reference

Relating to managing the connections. More...

#include <string.h>
#include <jnx/aux_types.h>
#include <jnx/trace.h>
#include <jnx/junos_trace.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <jnx/pconn.h>
#include <ddl/ddl.h>
#include <sync/hellopics_ipc.h>
#include "hellopics-mgmt_logging.h"
#include "hellopics-mgmt_conn.h"
#include "hellopics-mgmt_ha.h"

Go to the source code of this file.

Defines

#define evInitID(id)   ((id)->opaque = NULL)
 initialize the evTimerID
#define evTestID(id)   ((id).opaque != NULL)
 Test if the evTimerID has been initialized.
#define HELLOPICS_MGMT_SERVER_MAX_CONN   2
 max # cnxs (1-4-ctrl & 1-4-data)
#define HELLOPICS_HELLO_MSG_INTERVAL   60
 # of seconds between sending HELLOs

Functions

static void sendHelloMessage (evContext ctx __unused, void *uap __unused, struct timespec due __unused, struct timespec inter __unused)
static void startMessageCycle (void)
static void stopMessageCycle (void)
static status_t send_peer_info (pconn_session_t *to_session, pconn_session_t *for_session)
static void receive_connection (pconn_session_t *session, pconn_event_t event, void *cookie __unused)
static status_t receive_message (pconn_session_t *session, ipc_msg_t *msg, void *cookie __unused)
void init_connection_stats (void)
status_t start_server (evContext ctx)
status_t init_server (evContext ctx)
void close_connections (void)

Variables

volatile boolean is_master
hellopics_stats_t hellopics_stats
 global message stats
static pconn_server_t * mgmt_server
 the server connection info
static pconn_session_t * ctrl_session
 the session to the control component
static pconn_session_t * data_session
 the session to the data component
static boolean ctrl_ready
 the control component is ready
static boolean data_ready
 the data component is ready
static evTimerID timer_id
 timer ID used for setting off a HELLO
static uint32_t hello_seq_num
 Next HELLO sequence number.
static boolean received
 received the last sent hello back
static evContext ev_ctx
 event context


Detailed Description

Relating to managing the connections.

These functions and types will manage the connections.

Definition in file hellopics-mgmt_conn.c.


Function Documentation

void close_connections ( void   ) 

Close existing connections and shutdown server

Definition at line 653 of file hellopics-mgmt_conn.c.

References ctrl_session, data_session, HELLOPICS_PORT_NUM, and mgmt_server.

void init_connection_stats ( void   ) 

Initialize the statistic variables

Definition at line 574 of file hellopics-mgmt_conn.c.

References hellopics_stats.

Referenced by hellopics_init().

status_t init_server ( evContext  ctx  ) 

Initialize the server if it is the master.

Parameters:
[in] ctx event context
Returns:
SUCCESS if successful;

Definition at line 638 of file hellopics-mgmt_conn.c.

References is_master, and start_server().

Referenced by hellopics_init().

static void receive_connection ( pconn_session_t *  session,
pconn_event_t  event,
void *cookie  __unused 
) [static]

Connection handler for new and dying connections

Parameters:
[in] session The session information for the source peer
[in] event The event (established, or shutdown are the ones we care about)
[in] cookie The cookie we passed in. This is the eventlib context here.

Definition at line 247 of file hellopics-mgmt_conn.c.

References ctrl_session, data_session, and stopMessageCycle().

Referenced by start_server().

static status_t receive_message ( pconn_session_t *  session,
ipc_msg_t *  msg,
void *cookie  __unused 
) [static]

Message handler for open connections. We receive all kinds of messages (msg_type_e) except MSG_PEER.

Parameters:
[in] session The session information for the source peer
[in] msg The inbound message
[in] cookie The cookie we passed in. This is the eventlib context here.
Returns:
SUCCESS if successful; otherwise EFAIL with an error message.

Definition at line 351 of file hellopics-mgmt_conn.c.

References ctrl_ready, ctrl_session, data_ready, data_session, hello_seq_num, HELLOPICS_ID_CTRL, HELLOPICS_ID_DATA, hellopics_stats, MSG_GET_PEER, MSG_HELLO, MSG_ID, MSG_READY, hellopics_stats_s::msgs_badorder, hellopics_stats_s::msgs_received, received, send_peer_info(), startMessageCycle(), and update_replication_entry().

Referenced by start_server().

static status_t send_peer_info ( pconn_session_t *  to_session,
pconn_session_t *  for_session 
) [static]

A helper function to send PIC peer information to the other PIC. Either ctrl component info is sent to the data component or vice versa.

Parameters:
[in] to_session The peer to which we are send the information to
[in] for_session The established session for which we will extract the connection information, for sending to the to_session peer
Returns:
SUCCESS if successful; otherwise EFAIL with an error message.

Definition at line 196 of file hellopics-mgmt_conn.c.

References MSG_PEER.

Referenced by receive_message().

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

Send a HELLO message to the ctrl or data component. The component it is sent to alternates each time this is called starting with the data component.

Parameters:
[in] ctx The event context
[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 92 of file hellopics-mgmt_conn.c.

References ctrl_session, data_session, hello_seq_num, HELLOPICS_ID_CTRL, HELLOPICS_ID_DATA, hellopics_stats, MSG_HELLO, hellopics_stats_s::msgs_missed, hellopics_stats_s::msgs_sent, received, and update_replication_entry().

Referenced by startMessageCycle().

status_t start_server ( evContext  ctx  ) 

Create the server socket connection

Parameters:
[in] ctx event context
Returns:
SUCCESS if successful; otherwise EFAIL with an error message.

Definition at line 588 of file hellopics-mgmt_conn.c.

References ctrl_ready, ctrl_session, data_ready, data_session, ev_ctx, evInitID, hello_seq_num, HELLOPICS_MGMT_SERVER_MAX_CONN, HELLOPICS_PORT_NUM, mgmt_server, receive_connection(), receive_message(), received, and timer_id.

Referenced by init_server().

static void startMessageCycle ( void   )  [static]

Start the event timer which will generate HELLO messages periodically

Parameters:
[in] ctx The event context

Definition at line 150 of file hellopics-mgmt_conn.c.

References ev_ctx, evInitID, evTestID, HELLOPICS_HELLO_MSG_INTERVAL, sendHelloMessage(), and timer_id.

Referenced by receive_message().

static void stopMessageCycle ( void   )  [static]

Stop the event timer which is generating HELLO messages

Parameters:
[in] ctx The event context

Definition at line 172 of file hellopics-mgmt_conn.c.

References ev_ctx, evInitID, evTestID, and timer_id.

Referenced by receive_connection().


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:26:58 2010 for SDK Your Net Corporation Hellopics Example: hellopics-mgmt 1.0 by Doxygen 1.5.1