while (NULL != attrib) {
#if LOG_MMRP
- printf("MMRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MMRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MMRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_TXLA);
mrp_registrar_fsm(&(attrib->registrar),
while (NULL != attrib) {
#if LOG_MMRP
- printf("MMRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MMRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MMRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_RLA);
mrp_registrar_fsm(&(attrib->registrar),
while (NULL != attrib) {
#if LOG_MMRP
- printf("MMRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MMRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MMRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_TX);
attrib = attrib->next;
while (NULL != attrib) {
#if LOG_MMRP
- printf("MMRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MMRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MMRP_db->mrp_db), &(attrib->applicant),
MRP_EVENT_PERIODIC);
}
#if LOG_MMRP
- printf("MMRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MMRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MMRP_db->mrp_db), &(attrib->applicant), event);
/* remap local requests into registrar events */
msgbuf_len = mrpdu_msg_ptr - msgbuf;
bytes = mrpd_send(mmrp_socket, msgbuf, msgbuf_len, 0);
+#if LOG_MMRP
+ mrpd_log_printf("MMRP send PDU\n");
+#endif
if (bytes <= 0)
goto out;
{
int rc;
int err_index;
- char respbuf[8];
+ char respbuf[12];
int mrp_event;
uint8_t svcreq_param;
uint8_t macvec_param[6];
if (NULL == MMRP_db) {
- snprintf(respbuf, sizeof(respbuf) - 1, "ERC %s", buf);
+ snprintf(respbuf, sizeof(respbuf) - 1, "ERC %s\n", buf);
mrpd_send_ctl_msg(client, respbuf, sizeof(respbuf));
goto out;
}
mmrp_socket = INVALID_SOCKET;
/* XXX */
return -1;
-
- return 0;
}
int mmrp_reclaim(void)
{
switch (e) {
case MRP_EVENT_BEGIN:
- return "BEGIN";
+ return "Begin!";
case MRP_EVENT_NEW:
- return "NEW";
+ return "New!";
case MRP_EVENT_JOIN:
- return "JOIN";
+ return "Join!";
case MRP_EVENT_LV:
- return "LV";
+ return "Lv!";
case MRP_EVENT_TX:
- return "TX";
+ return "tx!";
case MRP_EVENT_TXLA:
- return "TXLA";
+ return "txLA!";
case MRP_EVENT_TXLAF:
- return "TXLAF";
+ return "txLAF!";
case MRP_EVENT_RNEW:
- return "RNEW";
+ return "rNew!";
case MRP_EVENT_RJOININ:
- return "RJOININ";
+ return "rJoinIn!";
case MRP_EVENT_RIN:
- return "RIN";
+ return "rIn!";
case MRP_EVENT_RJOINMT:
- return "RJOINMT";
+ return "rJoinMt!";
case MRP_EVENT_RMT:
- return "RMT";
+ return "rMt!";
case MRP_EVENT_RLV:
- return "RLV";
+ return "rLv!";
case MRP_EVENT_RLA:
- return "RLA";
+ return "rLA!";
case MRP_EVENT_FLUSH:
- return "FLUSH";
+ return "Flush!";
case MRP_EVENT_REDECLARE:
- return "REDECLARE";
+ return "Re-Declare!";
case MRP_EVENT_PERIODIC:
- return "PERIODIC";
+ return "periodic!";
case MRP_EVENT_PERIODIC_ENABLE:
return "ENABLE";
case MRP_EVENT_PERIODIC_DISABLE:
return "DISABLE";
case MRP_EVENT_LVTIMER:
- return "LVTIMER";
+ return "leavetimer!";
case MRP_EVENT_LVATIMER:
- return "LVATIMER";
+ return "leavealltimer!";
default:
return "UNKNOWN";
}
case MRP_VO_STATE:
return "VO";
case MRP_VP_STATE:
- return "VO";
+ return "VP";
case MRP_VN_STATE:
- return "VO";
+ return "VN";
case MRP_AN_STATE:
- return "VO";
+ return "AN";
case MRP_AA_STATE:
- return "VO";
+ return "AA";
case MRP_QA_STATE:
- return "VO";
+ return "QA";
case MRP_LA_STATE:
- return "VO";
+ return "LA";
case MRP_AO_STATE:
- return "VO";
+ return "AO";
case MRP_QO_STATE:
- return "VO";
+ return "QO";
case MRP_AP_STATE:
- return "VO";
+ return "AP";
case MRP_QP_STATE:
- return "VO";
+ return "QP";
case MRP_LO_STATE:
- return "VO";
+ return "LO";
case MRP_IN_STATE:
- return "VO";
+ return "IN";
case MRP_LV_STATE:
- return "VO";
+ return "LV";
case MRP_MT_STATE:
- return "VO";
+ return "MT";
default:
- return"??";
+ return "??";
}
}
+static char *mrp_lvatimer_state_string(int s)
+{
+ if (s == MRP_TIMER_PASSIVE)
+ return "PASSIVE";
+ else if (s == MRP_TIMER_ACTIVE)
+ return "ACTIVE";
+ else
+ return "??";
+}
+
static int client_lookup(client_t * list, struct sockaddr_in *newclient)
{
client_t *client_item;
/* 10.7.4.1 - interval between transmit opportunities
* for applicant state machine
*/
+#if LOG_TIMERS
+ mrpd_log_printf("MRP start join timer\n");
+#endif
return mrpd_timer_start(mrp_db->join_timer, MRP_JOINTIMER_VAL);
}
int mrp_jointimer_stop(struct mrp_database *mrp_db)
{
+#if LOG_TIMERS
+ mrpd_log_printf("MRP stop join timer\n");
+#endif
return mrpd_timer_stop(mrp_db->join_timer);
}
* controls how long the Registrar state machine stays in the
* LV state before transitioning to the MT state.
*/
+#if LOG_TIMERS
+ mrpd_log_printf("MRP start leave timer\n");
+#endif
return mrpd_timer_start(mrp_db->lv_timer, MRP_LVTIMER_VAL);
}
int mrp_lvtimer_stop(struct mrp_database *mrp_db)
{
+#if LOG_TIMERS
+ mrpd_log_printf("MRP stop leave timer\n");
+#endif
return mrpd_timer_stop(mrp_db->lv_timer);
}
int mrp_lvatimer_start(struct mrp_database *mrp_db)
{
+ int timeout = 0;
/* leavealltimer has expired. (10.7.5.22)
* on expire, sends a LEAVEALL message
* value is RANDOM in range (LeaveAllTime , 1.5xLeaveAllTime)
* timer is for all attributes of a given application and port, but
* expires each listed attribute individually (per application)
*/
- return mrpd_timer_start(mrp_db->lva_timer,
- MRP_LVATIMER_VAL +
- (random() % (MRP_LVATIMER_VAL / 2)));
+ timeout = MRP_LVATIMER_VAL + (random() % (MRP_LVATIMER_VAL / 2));
+#if LOG_TIMERS
+ mrpd_log_printf("MRP start leaveAll timer (%d ms)\n", timeout);
+#endif
+ return mrpd_timer_start(mrp_db->lva_timer, timeout);
}
int mrp_lvatimer_stop(struct mrp_database *mrp_db)
{
+#if LOG_TIMERS
+ mrpd_log_printf("MRP stop leaveAll timer\n");
+#endif
return mrpd_timer_stop(mrp_db->lva_timer);
}
return -1;
break;
}
+#if LOG_MVRP || LOG_MSRP || LOG_MMRP
+ if (mrp_db->lva.state != la_state) {
+ mrpd_log_printf("mrp_lvatimer_fsm event %s state %s -> %s\n",
+ mrp_event_string(event),
+ mrp_lvatimer_state_string(mrp_db->lva.state),
+ mrp_lvatimer_state_string(la_state));
+ } else {
+ mrpd_log_printf("mrp_lvatimer_fsm event %s state %s\n",
+ mrp_event_string(event),
+ mrp_lvatimer_state_string(la_state));
+ }
+#endif
mrp_db->lva.state = la_state;
mrp_db->lva.sndmsg = sndmsg;
mrp_db->lva.tx = tx;
int mrp_state = attrib->mrp_state;
int sndmsg = MRP_SND_NULL;
-#if LOG_MVRP || LOG_MSRP || LOG_MMRP
- printf("APP FSM evt %s, state %s\n", mrp_event_string(event), mrp_state_string(mrp_state));
-#endif
switch (event) {
case MRP_EVENT_BEGIN:
mrp_state = MRP_VO_STATE;
default:
break;
}
+ }
#if LOG_MVRP || LOG_MSRP || LOG_MMRP
- printf("APP FSM state transition to %s\n", mrp_state_string(mrp_state));
-#endif
+ if (attrib->mrp_state != mrp_state) {
+ mrpd_log_printf("mrp_applicant_fsm event %s, state %s -> %s\n",
+ mrp_event_string(event),
+ mrp_state_string(attrib->mrp_state),
+ mrp_state_string(mrp_state));
+ } else {
+ mrpd_log_printf("mrp_applicant_fsm event %s, state %s\n",
+ mrp_event_string(event),
+ mrp_state_string(mrp_state));
}
+#endif
+
attrib->mrp_state = mrp_state;
attrib->sndmsg = sndmsg;
attrib->encode = (optional ? MRP_ENCODE_OPTIONAL : MRP_ENCODE_YES);
break;
case MRP_LV_STATE:
/* should stop leavetimer - but we have only 1 lvtimer
- * for all attributes, and recieving a LVTIMER event
+ * for all attributes, and receiving a LVTIMER event
* is a don't-care if the attribute is in the IN state.
*/
notify = MRP_NOTIFY_JOIN;
return -1;
break;
}
-
+#if LOG_MVRP || LOG_MSRP || LOG_MMRP
+ if (attrib->mrp_state != mrp_state) {
+ mrpd_log_printf("mrp_registrar_fsm event %s, state %s -> %s\n",
+ mrp_event_string(event),
+ mrp_state_string(attrib->mrp_state),
+ mrp_state_string(mrp_state));
+
+ } else {
+ mrpd_log_printf("mrp_registrar_fsm event %s, state %s\n",
+ mrp_event_string(event),
+ mrp_state_string(mrp_state));
+ }
+#endif
attrib->mrp_state = mrp_state;
attrib->notify = notify;
return 0;
******************************************************************************/
-#define LOG_MRP 1
-#define LOG_MVRP 1
-#define LOG_MMRP 1
-#define LOG_MSRP 1
-
+/* control debug output on stdout */
+#define LOG_MRP 0
+#define LOG_MVRP 0
+#define LOG_MMRP 0
+#define LOG_MSRP 0
+#define LOG_TIMERS 0
+#define LOG_TXNOW 0
+#define LOG_CLIENT_RECV 0
+#define LOG_CLIENT_SEND 0
#define MRP_ENCODE_YES 0 /* must send */
#define MRP_ENCODE_OPTIONAL 1 /* send if smaller */
#define MRP_VP_STATE 1 /* Very Anxious Passive */
#define MRP_VN_STATE 2 /* Very Anxious New */
#define MRP_AN_STATE 3 /* Anxious New */
-#define MRP_AA_STATE 4 /* Anxious New */
+#define MRP_AA_STATE 4 /* Anxious Active */
#define MRP_QA_STATE 5 /* Quiet Active */
#define MRP_LA_STATE 6 /* Leaving Active */
#define MRP_AO_STATE 7 /* Anxious Observer State */
memset(msgbuf,0,1500);
sprintf(msgbuf,"V++:I=0002");
rc = send_control_msg(msgbuf, 1500 );
-
+
+#ifdef YYYY
memset(msgbuf,0,1500);
sprintf(msgbuf,"S+L:L=0050c24edb0a0001,D=2");
rc = send_control_msg(msgbuf, 1500);
-
+#endif
+
do {
memset(msgbuf,0,1500);
sprintf(msgbuf,"M??");
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
+#include <stdarg.h>
#include <string.h>
#include <syslog.h>
#include <signal.h>
#include "msrp.h"
#include "mmrp.h"
+static void mrpd_log_timer_event(char *src, int event);
+
/* global mgmt parameters */
int daemonize;
int mmrp_enable;
if (-1 == control_socket)
return 0;
+#if LOG_CLIENT_SEND
if (logging_enable) {
- printf("[%02d] CTL MSG:%s to CLNT %d\n",
- gc_ctl_msg_count, notify_data, client_addr->sin_port);
+ mrpd_log_printf("[%02d] CLT MSG %05d:%s",
+ gc_ctl_msg_count, client_addr->sin_port, notify_data);
gc_ctl_msg_count = (gc_ctl_msg_count + 1) % 100;
- }
-
+ }
+#endif
rc = sendto(control_socket, notify_data, notify_len,
0, (struct sockaddr *)client_addr, sizeof(struct sockaddr));
return rc;
memset(respbuf, 0, sizeof(respbuf));
+#if LOG_CLIENT_RECV
if (logging_enable)
- printf("CMD:%s from CLNT %d\n", buf, client->sin_port);
+ mrpd_log_printf("CMD:%s from CLNT %d\n", buf, client->sin_port);
+#endif
if (buflen < 3) {
printf("buflen = %d!\b", buflen);
(mmrp_socket, &sel_fds) mmrp_recv_msg();
if FD_ISSET
(MMRP_db->mrp_db.lva_timer, &sel_fds) {
+ mrpd_log_timer_event("MMRP",
+ MRP_EVENT_LVATIMER);
mmrp_event(MRP_EVENT_LVATIMER, NULL);
}
if FD_ISSET
(MMRP_db->mrp_db.lv_timer, &sel_fds) {
+ mrpd_log_timer_event("MMRP",
+ MRP_EVENT_LVTIMER);
mmrp_event(MRP_EVENT_LVTIMER, NULL);
}
if FD_ISSET
(MMRP_db->mrp_db.join_timer, &sel_fds) {
+ mrpd_log_timer_event("MMRP",
+ MRP_EVENT_TX);
mmrp_event(MRP_EVENT_TX, NULL);
}
}
(mvrp_socket, &sel_fds) mvrp_recv_msg();
if FD_ISSET
(MVRP_db->mrp_db.lva_timer, &sel_fds) {
+ mrpd_log_timer_event("MVRP",
+ MRP_EVENT_LVATIMER);
mvrp_event(MRP_EVENT_LVATIMER, NULL);
}
if FD_ISSET
(MVRP_db->mrp_db.lv_timer, &sel_fds) {
+ mrpd_log_timer_event("MVRP",
+ MRP_EVENT_LVTIMER);
mvrp_event(MRP_EVENT_LVTIMER, NULL);
}
if FD_ISSET
(MVRP_db->mrp_db.join_timer, &sel_fds) {
+ mrpd_log_timer_event("MVRP",
+ MRP_EVENT_TX);
mvrp_event(MRP_EVENT_TX, NULL);
}
}
(msrp_socket, &sel_fds) msrp_recv_msg();
if FD_ISSET
(MSRP_db->mrp_db.lva_timer, &sel_fds) {
+ mrpd_log_timer_event("MSRP",
+ MRP_EVENT_LVATIMER);
msrp_event(MRP_EVENT_LVATIMER, NULL);
}
if FD_ISSET
(MSRP_db->mrp_db.lv_timer, &sel_fds) {
+ mrpd_log_timer_event("MSRP",
+ MRP_EVENT_LVTIMER);
msrp_event(MRP_EVENT_LVTIMER, NULL);
}
if FD_ISSET
(MSRP_db->mrp_db.join_timer, &sel_fds) {
+ mrpd_log_timer_event("MSRP",
+ MRP_EVENT_TX);
msrp_event(MRP_EVENT_TX, NULL);
}
}
if (FD_ISSET(txnowevt_fd, &sel_fds)) {
uint64_t count;
read(txnowevt_fd, &count, sizeof(count));
- if (mmrp_enable && MMRP_db->mrp_db.schedule_tx_flag) {
+ if (mmrp_enable
+ && MMRP_db->mrp_db.schedule_tx_flag) {
MMRP_db->mrp_db.schedule_tx_flag = 0;
+#if LOG_TXNOW
+ mrpd_log_printf("MMRP txnow event\n");
+#endif
mmrp_event(MRP_EVENT_TX, NULL);
}
- if (mvrp_enable && MVRP_db->mrp_db.schedule_tx_flag) {
+ if (mvrp_enable
+ && MVRP_db->mrp_db.schedule_tx_flag) {
MVRP_db->mrp_db.schedule_tx_flag = 0;
+#if LOG_TXNOW
+ mrpd_log_printf("MVRP txnow event\n");
+#endif
mvrp_event(MRP_EVENT_TX, NULL);
}
- if (msrp_enable && MSRP_db->mrp_db.schedule_tx_flag) {
+ if (msrp_enable
+ && MSRP_db->mrp_db.schedule_tx_flag) {
MSRP_db->mrp_db.schedule_tx_flag = 0;
+#if LOG_TXNOW
+ mrpd_log_printf("MSRP txnow event\n");
+#endif
msrp_event(MRP_EVENT_TX, NULL);
}
}
return rc;
}
+
+static void mrpd_log_timer_event(char *src, int event)
+{
+#if LOG_TIMERS
+ if (event == MRP_EVENT_LVATIMER) {
+ mrpd_log_printf("%s leaveAll timer expires ->\n", src);
+ } else if (event == MRP_EVENT_LVTIMER) {
+ mrpd_log_printf("%s leave timer expires ->\n", src);
+ } else if (event == MRP_EVENT_TX) {
+ mrpd_log_printf("%s join timer expires ->\n", src);
+ }
+#endif
+}
+
+void mrpd_log_printf(const char *fmt, ...)
+{
+ struct timeval tv;
+ char sz[512];
+
+ if (logging_enable) {
+ gettimeofday(&tv, NULL);
+ va_list arglist;
+ va_start(arglist, fmt);
+ vsnprintf(sz, 512, fmt, arglist);
+ printf("MRPD %03d.%06d %s",
+ (int)(tv.tv_sec % 1000),
+ (int)tv.tv_usec,
+ sz);
+ va_end(arglist);
+ }
+}
unsigned char *multicast_addr);
int mrpd_close_socket(SOCKET sock);
int mrpd_recvmsgbuf(SOCKET sock, char **buf);
+
+void mrpd_log_printf(const char *fmt, ...);
void mrp_schedule_tx_event(void)
{
if (!SetEvent(pkt_events[tx_request_event]))
- printf("SetEvent tx_request_event failed (%d)\n", GetLastError());
+ printf("SetEvent tx_request_event failed (%d)\n",
+ GetLastError());
}
-
HANDLE kill_packet_capture;
void process_events(void)
while (NULL != attrib) {
#if LOG_MSRP
- printf("MSRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MSRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MSRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_TXLA);
mrp_registrar_fsm(&(attrib->registrar),
while (NULL != attrib) {
#if LOG_MSRP
- printf("MSRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MSRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MSRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_RLA);
mrp_registrar_fsm(&(attrib->registrar),
while (NULL != attrib) {
#if LOG_MSRP
- printf("MSRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MSRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MSRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_TX);
attrib = attrib->next;
while (NULL != attrib) {
#if LOG_MSRP
- printf("MSRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MSRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MSRP_db->mrp_db), &(attrib->applicant),
MRP_EVENT_PERIODIC);
listen_declare_end = listen_declare_idx;
- printf("######listen_declare_end %d\n", listen_declare_end);
-
for (listen_declare_idx = 0;
listen_declare_idx < ((listen_declare_end / 4) * 4);
listen_declare_idx += 4) {
msgbuf_len = mrpdu_msg_ptr - msgbuf;
bytes = mrpd_send(msrp_socket, msgbuf, msgbuf_len, 0);
+#if LOG_MSRP
+ mrpd_log_printf("MSRP send PDU\n");
+#endif
if (bytes <= 0)
goto out;
int msrp_recv_cmd(char *buf, int buflen, struct sockaddr_in *client)
{
int rc;
- char respbuf[8];
+ char respbuf[12];
int mrp_event;
unsigned int substate;
struct msrpdu_domain domain_param;
int err_index;
if (NULL == MSRP_db) {
- snprintf(respbuf, sizeof(respbuf) - 1, "ERC %s", buf);
+ snprintf(respbuf, sizeof(respbuf) - 1, "ERC %s\n", buf);
mrpd_send_ctl_msg(client, respbuf, sizeof(respbuf));
goto out;
}
while (NULL != attrib) {
#if LOG_MVRP
- printf("MVRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MVRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MVRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_TXLA);
mrp_registrar_fsm(&(attrib->registrar),
while (NULL != attrib) {
#if LOG_MVRP
- printf("MVRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MVRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MVRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_RLA);
mrp_registrar_fsm(&(attrib->registrar),
while (NULL != attrib) {
#if LOG_MVRP
- printf("MVRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MVRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MVRP_db->mrp_db), &(attrib->applicant), MRP_EVENT_TX);
attrib = attrib->next;
while (NULL != attrib) {
#if LOG_MVRP
- printf("MVRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MVRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MVRP_db->mrp_db), &(attrib->applicant),
MRP_EVENT_PERIODIC);
}
#if LOG_MVRP
- printf("MVRP -> mrp_applicant_fsm\n");
+ mrpd_log_printf("MVRP -> mrp_applicant_fsm\n");
#endif
mrp_applicant_fsm(&(MVRP_db->mrp_db), &(attrib->applicant), event);
/* remap local requests into registrar events */
msgbuf_len = mrpdu_msg_ptr - msgbuf;
bytes = mrpd_send(mvrp_socket, msgbuf, msgbuf_len, 0);
+#if LOG_MVRP
+ mrpd_log_printf("MVRP send PDU\n");
+#endif
if (bytes <= 0)
goto out;
{
int rc;
int mrp_event;
- char respbuf[8];
+ char respbuf[12];
uint16_t vid_param;
int err_index;
if (NULL == MVRP_db) {
- snprintf(respbuf, sizeof(respbuf) - 1, "ERC %s", buf);
+ snprintf(respbuf, sizeof(respbuf) - 1, "ERC %s\n", buf);
mrpd_send_ctl_msg(client, respbuf, sizeof(respbuf));
goto out;
}