Skip to content

Commit

Permalink
enabling set_timeout and show_mgmtIds commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Himanshu Singh committed Aug 8, 2012
1 parent 30512eb commit 83b4bd6
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 35 deletions.
1 change: 1 addition & 0 deletions tools/ptpmanager/constants.h
Expand Up @@ -8,6 +8,7 @@
#define MANAGEMENT 13
#define TLV_LENGTH 6
#define USER_DESCRIPTION_MAX 128
#define DEFAULT_TIMEOUT 10

#define flip16(x) htons(x)
#define flip32(x) htonl(x)
Expand Down
33 changes: 30 additions & 3 deletions tools/ptpmanager/network.c
Expand Up @@ -89,25 +89,52 @@ netSendGeneral(Octet * buf, UInteger16 length, char *ip)
return (ret);
}

/*Function to set timeout as provided by user */
void
set_timeout()
{
printf("Timeout value in seconds? ");
scanf("%d",&timeout);
}

/* Function to receive the management response/ack/error message */
ssize_t
netRecv(Octet *message, char *src)
netRecv(Octet *message, char *dest)
{
ssize_t ret = 0;
char srcIp[16];
int try;
int ret_select;
fd_set socks;
struct sockaddr_in client_addr;
socklen_t len = sizeof(client_addr);
struct timeval timeout_val;

FD_ZERO(&socks);
FD_SET(netPath->generalSock, &socks);

timeout_val.tv_sec = timeout;
timeout_val.tv_usec = 0;

for (try = 0;try < 3; try++){
if ((ret_select = select(netPath->generalSock + 1, &socks, NULL, NULL,
&timeout_val)) != 0) {
ret = recvfrom(netPath->generalSock, message, PACKET_SIZE , 0 ,
(struct sockaddr *)&client_addr, &len);
if (ret == 0 || (strcmp(inet_ntop(AF_INET, &(client_addr.sin_addr), srcIp,
sizeof(srcIp)), src) == 0))
sizeof(srcIp)), dest) == 0))
return (ret);
else
printf("false\n");
}
else if (ret_select < 0){
printf("Network error (select)\n");
return 0;
}
else {
printf("Timed out. Please check that server is reachable and try again."
" You can use 'send_previous'\n");
return 0;
}
}

/*shutdown the network layer*/
Expand Down
2 changes: 1 addition & 1 deletion tools/ptpmanager/packOutgoingMsg.c
Expand Up @@ -61,7 +61,7 @@ packOutgoingMsg(Octet *buf)
scanf("%d", &tlvtype);

if (tlvtype==TLV_MANAGEMENT){
printf(">managementId (see Table 40) (Eg: '2010' for ClockAccuracy)?");
printf(">managementId (use command 'show_mgmtIds' to find managementId)?");
scanf("%x", &managementId);

switch(managementId){
Expand Down
32 changes: 11 additions & 21 deletions tools/ptpmanager/ptpmanager.c
Expand Up @@ -27,9 +27,9 @@ getCommandId(char *command)
return (6);
else if (strcmp(command, "show_tlv")==0)
return (7);
else if (strcmp(command, "show_clock_description")==0)
else if (strcmp(command, "show_mgmtIds") == 0)
return (8);
else if (strcmp(command, "show_default_data_set")==0)
else if (strcmp(command, "set_timeout") == 0)
return (9);

return (0); /* for wrong command */
Expand All @@ -45,22 +45,11 @@ sendMessage(Octet* outmessage, char *dest)
printf("Message sent, waiting for response...\n");

receivedFlag = FALSE;
// for (;;){

/*
* TODO wait for some time to receive a response
* or ack, if not received till timeout send the
* management message again, Use receivedFlag for this.
*
* Currently, 'receive' is 'blocking' and therefore program hangs if
* packet delivery fails. TODO: Use non-blocking call.
*/
memset(inmessage, 0, PACKET_SIZE);
if (netRecv(inmessage, dest)) {
handleIncomingMsg(inmessage);
in_sequence++;
}
//}
memset(inmessage, 0, PACKET_SIZE);
if (netRecv(inmessage, dest)) {
handleIncomingMsg(inmessage);
in_sequence++;
}
}
}

Expand All @@ -81,6 +70,7 @@ main(int argc, char *argv[ ])
out_sequence = 0;
in_sequence = 0;
out_length = 0;
timeout = DEFAULT_TIMEOUT;
netPath = (NetPath*)malloc(sizeof(NetPath));

if (outmessage == NULL || inmessage == NULL || netPath == NULL){
Expand Down Expand Up @@ -156,11 +146,11 @@ main(int argc, char *argv[ ])
break;

case 8:
show_clock_description();
show_mgmtIds();
break;

case 9:
show_default_data_set();
set_timeout();
break;

default:
Expand Down
2 changes: 2 additions & 0 deletions tools/ptpmanager/ptpmanager.h
Expand Up @@ -52,6 +52,8 @@ UInteger16 in_sequence;
Boolean receivedFlag;
Octet *outmessage;
Octet *inmessage;
UInteger32 timeout;

/**
* \brief Struct used to store network datas
*/
Expand Down
68 changes: 58 additions & 10 deletions tools/ptpmanager/show.c
Expand Up @@ -17,8 +17,7 @@ show_help()
show_commonheader - to see header (Table 18 of spec)\n\
show_managementheader - to see management header (Table 37)\n\
show_tlv - to see management TLV fields (Table 35)\n\
show_clock_description - to see dataField of clock_description TLV (Table 41)\n\
show_default_data_set - to see fields of default data set (Table 50)\n\
show_mgmtIds - to see all available management TLVs\n\
quit - to close the program\n\
..etc\n\n");
}
Expand All @@ -42,13 +41,62 @@ show_tlv()
}

void
show_clock_description()
show_mgmtIds()
{
printf("Not implemented yet\n");
}

void
show_default_data_set()
{
printf("Not implemented yet\n");
printf("managementId name \tmanagementId value (hex) \tAllowed actions \tApplies to\n"
"\n"
"===Applicable to all node types===================================================================================\n"
"NULL_MANAGEMENT \t0000 \tGET, SET, COMMAND \tport\n"
"CLOCK_DESCRIPTION \t0001 \tGET \tport\n"
"USER_DESCRIPTION \t0002 \tGET, SET \tclock\n"
"SAVE_IN_NON_VOLATILE_STORAGE \t0003 \tCOMMAND \tclock\n"
"RESET_NON_VOLATILE_STORAGE \t0004 \tCOMMAND \tclock\n"
"INITIALIZE \t0005 \tCOMMAND \tclock\n"
"FAULT_LOG \t0006 \tGET \tclock\n"
"FAULT_LOG_RESET \t0007 \tCOMMAND \tclock\n"
"\n"
"===Applicable to ordinary and boundary clocks=====================================================================\n"
"DEFAULT_DATA_SET \t2000 \tGET \tclock\n"
"CURRENT_DATA_SET \t2001 \tGET \tclock\n"
"PARENT_DATA_SET \t2002 \tGET \tclock\n"
"TIME_PROPERTIES_DATA_SET \t2003 \tGET \tclock\n"
"PORT_DATA_SET \t2004 \tGET \tport\n"
"PRIORITY1 \t2005 \tGET, SET \tclock\n"
"PRIORITY2 \t2006 \tGET, SET \tclock\n"
"DOMAIN \t2007 \tGET, SET \tclock\n"
"SLAVE_ONLY \t2008 \tGET, SET \tclock\n"
"LOG_ ANNOUNCE_INTERVAL \t2009 \tGET, SET \tport\n"
"ANNOUNCE_RECEIPT_TIMEOUT \t200A \tGET, SET \tport\n"
"LOG_ SYNC_INTERVAL \t200B \tGET, SET \tport\n"
"VERSION_NUMBER \t200C \tGET, SET \tport\n"
"ENABLE_PORT \t200D \tCOMMAND \tport\n"
"DISABLE_PORT \t200E \tCOMMAND \tport\n"
"TIME \t200F \tGET, SET \tclock\n"
"CLOCK_ACCURACY \t2010 \tGET, SET \tclock\n"
"UTC_PROPERTIES \t2011 \tGET, SET \tclock\n"
"TRACEABILITY_PROPERTIES \t2012 \tGET, SET \tclock\n"
"TIMESCALE_PROPERTIES \t2013 \tGET, SET \tclock\n"
"UNICAST_NEGOTIATION_ENABLE \t2014 \tGET, SET \tport\n"
"PATH_TRACE_LIST \t2015 \tGET \tclock\n"
"PATH_TRACE_ENABLE \t2016 \tGET, SET \tclock\n"
"GRANDMASTER_CLUSTER_TABLE \t2017 \tGET, SET \tclock\n"
"UNICAST_MASTER_TABLE \t2018 \tGET, SET \tport\n"
"UNICAST_MASTER_MAX_TABLE_SIZE \t2019 \tGET \tport\n"
"ACCEPTABLE_MASTER_TABLE \t201A \tGET, SET \tclock\n"
"ACCEPTABLE_MASTER_TABLE_ENABLED \t201B \tGET, SET \tport\n"
"ACCEPTABLE_MASTER_MAX_TABLE_SIZE \t201C \tGET \tclock\n"
"ALTERNATE_MASTER \t201D \tGET, SET \tport\n"
"ALTERNATE_TIME_OFFSET_ENABLE \t201E \tGET, SET \tclock\n"
"ALTERNATE_TIME_OFFSET_NAME \t201F \tGET, SET \tclock\n"
"ALTERNATE_TIME_OFFSET_MAX_KEY \t2020 \tGET \tclock\n"
"ALTERNATE_TIME_OFFSET_PROPERTIES \t2021 \tGET, SET \tclock\n"
"\n"
"===Applicable to transparent clocks==============================================================================\n"
"TRANSPARENT_CLOCK_DEFAULT_DATA_SET \t4000 \tGET \tclock\n"
"TRANSPARENT_CLOCK_PORT_DATA_SET \t4001 \tGET \tport\n"
"PRIMARY_DOMAIN \t4002 \tGET, SET \tclock\n"
"\n"
"===Applicable to ordinary, boundary, and transparent clocks======================================================\n"
"DELAY_MECHANISM \t6000 \tGET, SET \tport\n"
"LOG_MIN_ PDELAY_REQ_INTERVAL \t6001 \tGET, SET \tport\n");
}

0 comments on commit 83b4bd6

Please sign in to comment.