hellopics-mgmt_ha.c File Reference

High Availability module. More...

#include <stdlib.h>
#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 "hellopics-mgmt_logging.h"
#include "hellopics-mgmt_conn.h"
#include "hellopics-mgmt_ha.h"
#include <jnx/junos_sync.h>

Go to the source code of this file.

Defines

#define HELLOPICS_HA_REPLICATION_PORT   39089
 port # to use for messaging
#define HELLOPICS_HA_REPLICATION_KA   30
 keepalive message interval

Functions

void update_hellopics_statistics (hellopics_stats_t *data)
static void replication_data_hton (hellopics_stats_t *data)
static void replication_data_ntoh (hellopics_stats_t *data)
static void ack_notify (junos_sync_tlv_t *data UNUSED, size_t len UNUSED)
static void decode (void *data, size_t len)
static void * get_next (void *current __unused, junos_sync_getnext_data_t *gndata __unused)
static void conn_status_change (junos_sync_conn_status_t conn_status)
static void init_sync_done (size_t num_of_entries_synced)
static void bind_done (in_port_t port)
static void log_msg (const char *format,...)
static void db_clear (void)
status_t init_replication (in_addr_t master_address)
void update_replication_entry (hellopics_stats_t *data)
void stop_replication (void)
void set_mastership (boolean state, in_addr_t master_addr)

Variables

static junos_sync_state_t rep_state
 replication state
static junos_sync_callbacks_t rep_callbacks
 replication callbacks
static junos_sync_context_t * rep_ctx
 replication API context
volatile boolean is_master
hellopics_stats_t hellopics_stats
 global message stats
evContext present_ctx


Detailed Description

High Availability module.

These functions will manage the packet statistics replication for a master/slave management component.

Definition in file hellopics-mgmt_ha.c.


Function Documentation

static void ack_notify ( junos_sync_tlv_t *data  UNUSED,
size_t len  UNUSED 
) [static]

Callback when an acknolewedgement is received

Parameters:
[in] data The TLV data ack'd
[in] len The TLV data's length

Definition at line 96 of file hellopics-mgmt_ha.c.

References LOG.

Referenced by init_replication().

static void bind_done ( in_port_t  port  )  [static]

Callback to notify application that the master finished binding

Parameters:
[in] port Free port on which it bound itself

Definition at line 176 of file hellopics-mgmt_ha.c.

References HELLOPICS_HA_REPLICATION_PORT, and LOG.

Referenced by init_replication().

static void conn_status_change ( junos_sync_conn_status_t  conn_status  )  [static]

Callback to notify that the connection's status has changed

Parameters:
[in] conn_status Number of entries / messages passed in initial replication

Definition at line 148 of file hellopics-mgmt_ha.c.

References LOG.

Referenced by init_replication().

static void db_clear ( void   )  [static]

Callback to clean up the backup database

Definition at line 209 of file hellopics-mgmt_ha.c.

References LOG.

Referenced by init_replication().

static void decode ( void *  data,
size_t  len 
) [static]

Callback when a data record is received and need to be decoded and added to the backup database

Parameters:
[in] data data to be decoded
[out] len length of data

Definition at line 113 of file hellopics-mgmt_ha.c.

References LOG, rep_state, replication_data_ntoh(), and update_hellopics_statistics().

Referenced by init_replication().

static void* get_next ( void *current  __unused,
junos_sync_getnext_data_t *gndata  __unused 
) [static]

Iterator callback to get the next data in application's database. Called during the initial (re-)sync.

Parameters:
[in] current Null for first item, otherwise the item before the next one returned This could be the last item returned (works iterator-style).
[out] gndata The struct containing the TLV. We popluate data with an allocated copy of the replication data to send

Definition at line 135 of file hellopics-mgmt_ha.c.

Referenced by init_replication().

status_t init_replication ( in_addr_t  master_address  ) 

Init the data structures that will store configuration info

Parameters:
[in] master_address Address of master, or 0 if this is the master
Returns:
SUCCESS if successful; otherwise EFAIL with an error message.

Definition at line 228 of file hellopics-mgmt_ha.c.

References ack_notify(), bind_done(), conn_status_change(), db_clear(), decode(), get_next(), HELLOPICS_HA_REPLICATION_KA, HELLOPICS_HA_REPLICATION_PORT, init_sync_done(), LOG, log_msg(), present_ctx, rep_callbacks, rep_ctx, and rep_state.

Referenced by set_mastership().

static void init_sync_done ( size_t  num_of_entries_synced  )  [static]

Callback to notify that the initial synchronization is done

Parameters:
[in] num_of_entries_synced Number of entries / messages passed in initial replication

Definition at line 162 of file hellopics-mgmt_ha.c.

References LOG.

Referenced by init_replication().

static void log_msg ( const char *  format,
  ... 
) [static]

Callback to log a message

Parameters:
[in] format message to log

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

Referenced by init_replication().

static void replication_data_hton ( hellopics_stats_t data  )  [static]

Perform necessary host to network byte-order swaps

Parameters:
[in,out] data replication data

Definition at line 60 of file hellopics-mgmt_ha.c.

References hellopics_stats_s::msgs_badorder, hellopics_stats_s::msgs_missed, hellopics_stats_s::msgs_received, and hellopics_stats_s::msgs_sent.

Referenced by update_replication_entry().

static void replication_data_ntoh ( hellopics_stats_t data  )  [static]

Perform necessary network to host byte-order swaps

Parameters:
[in,out] data replication data

Definition at line 76 of file hellopics-mgmt_ha.c.

References hellopics_stats_s::msgs_badorder, hellopics_stats_s::msgs_missed, hellopics_stats_s::msgs_received, and hellopics_stats_s::msgs_sent.

Referenced by decode().

void set_mastership ( boolean  state,
in_addr_t  master_addr 
)

Configure mastership of this data component

Parameters:
[in] state Mastership state (T=Master, F=Slave)
[in] master_addr Master address (only present if state=F/slave)

Definition at line 353 of file hellopics-mgmt_ha.c.

References init_replication(), and is_master.

Referenced by init_config().

void stop_replication ( void   ) 

Stop and shutdown all the replication subsystem

Definition at line 319 of file hellopics-mgmt_ha.c.

References rep_ctx.

void update_hellopics_statistics ( hellopics_stats_t data  ) 

Function called in backup daemon to update the state received from the master

Parameters:
[in] data Data received from the master

Definition at line 331 of file hellopics-mgmt_ha.c.

References hellopics_stats, LOG, hellopics_stats_s::msgs_badorder, hellopics_stats_s::msgs_missed, hellopics_stats_s::msgs_received, and hellopics_stats_s::msgs_sent.

Referenced by decode().

void update_replication_entry ( hellopics_stats_t data  ) 

Pass replication data to add or update to the slave

Parameters:
[in] data The data to replicate to the slave

Definition at line 287 of file hellopics-mgmt_ha.c.

References LOG, rep_ctx, and replication_data_hton().

Referenced by receive_message(), and sendHelloMessage().


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