From 86a10dff1668a5267f16b75c8e0050ed6f65e598 Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Thu, 22 Sep 2011 18:26:56 +0200 Subject: [PATCH] PUD: add downlink port to clusterleader message Signed-off-by: Ferry Huberts --- lib/pud/doc/olsrd.conf.default.pud | 9 ++- lib/pud/src/configuration.c | 66 +++++++++++++++++++ lib/pud/src/configuration.h | 14 ++++ lib/pud/src/pudOlsrdPlugin.h | 1 + lib/pud/src/receiver.c | 12 ++-- .../c/org_olsr_plugin_pud_ClusterLeader.c | 20 ++++++ .../org/olsr/plugin/pud/ClusterLeader.java | 7 +- .../include/OlsrdPudWireFormat/wireFormat.h | 27 ++++++++ 8 files changed, 148 insertions(+), 8 deletions(-) diff --git a/lib/pud/doc/olsrd.conf.default.pud b/lib/pud/doc/olsrd.conf.default.pud index 84a09c96..01b7d835 100644 --- a/lib/pud/doc/olsrd.conf.default.pud +++ b/lib/pud/doc/olsrd.conf.default.pud @@ -571,12 +571,19 @@ LoadPlugin "./lib/pud/olsrd_pud.so.1.0.0" PlParam "uplinkAddr" "127.0.0.2" # uplinkPort is the UDP port to which the plugin will transmit GPS position - # updates. + # updates. Can't be the same as the downlink port. # # Default: 2241 # #PlParam "uplinkPort" "2241" + # downlinkPort is the UDP port on which the plugin will receive GPS position + # updates. Can't be the same as the uplink port. + # + # Default: 2242 + # + #PlParam "downlinkPort" "2242" + # # OLSR Parameters diff --git a/lib/pud/src/configuration.c b/lib/pud/src/configuration.c index ae986693..e6cf8e39 100644 --- a/lib/pud/src/configuration.c +++ b/lib/pud/src/configuration.c @@ -1074,6 +1074,67 @@ int setUplinkPort(const char *value, void *data __attribute__ ((unused)), set_pl return false; } + +/* + * downlinkPort + */ + +/** the downlink port */ +unsigned short downlinkPort = 0; + +/** true when the downlinkPort is set */ +bool downlinkPortSet = false; + +/** + @return + The downlink port (in network byte order) + */ +unsigned short getDownlinkPort(void) { + if (!downlinkPortSet) { + downlinkPort = htons(PUD_DOWNLINK_PORT_DEFAULT); + downlinkPortSet = true; + } + + return downlinkPort; +} + +/** + Set the downlink port + + @param value + The downlink port (a number in string representation) + @param data + Unused + @param addon + Unused + + @return + - true when an error is detected + - false otherwise + */ +int setDownlinkPort(const char *value, void *data __attribute__ ((unused)), + set_plugin_parameter_addon addon __attribute__ ((unused))) { + static const char * valueName = PUD_DOWNLINK_PORT_NAME; + unsigned long long downlinkPortNew; + + assert(value != NULL); + + if (!readULL(valueName, value, &downlinkPortNew)) { + return true; + } + + if ((downlinkPortNew < 1) || (downlinkPortNew > 65535)) { + pudError(false, "Configured %s (%llu) is outside of" + " valid range 1-65535", valueName, downlinkPortNew); + return true; + } + + downlinkPort = htons(downlinkPortNew); + downlinkPortSet = true; + + return false; +} + /* * txTtl */ @@ -2019,6 +2080,11 @@ unsigned int checkConfig(void) { retval = false; } + if (getUplinkPort() == getDownlinkPort()) { + pudError(false, "The uplink port and the downlink port must not be the same"); + retval = false; + } + return retval; } diff --git a/lib/pud/src/configuration.h b/lib/pud/src/configuration.h index f03b6e69..d859fdf1 100644 --- a/lib/pud/src/configuration.h +++ b/lib/pud/src/configuration.h @@ -158,6 +158,20 @@ unsigned short getUplinkPort(void); int setUplinkPort(const char *value, void *data, set_plugin_parameter_addon addon); +/* + * Downlink Parameters + */ + +/** The name of the downlink port plugin parameter */ +#define PUD_DOWNLINK_PORT_NAME "downlinkPort" + +/** The default value of the downlink port plugin parameter */ +#define PUD_DOWNLINK_PORT_DEFAULT 2242 + +unsigned short getDownlinkPort(void); +int +setDownlinkPort(const char *value, void *data, set_plugin_parameter_addon addon); + /* * OLSR Parameters */ diff --git a/lib/pud/src/pudOlsrdPlugin.h b/lib/pud/src/pudOlsrdPlugin.h index 0df6e81a..59c03bd9 100644 --- a/lib/pud/src/pudOlsrdPlugin.h +++ b/lib/pud/src/pudOlsrdPlugin.h @@ -32,6 +32,7 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = { { .name = PUD_TX_NMEAMESSAGEPREFIX_NAME, .set_plugin_parameter = &setTxNmeaMessagePrefix, .data = NULL}, { .name = PUD_UPLINK_ADDR_NAME, .set_plugin_parameter = &setUplinkAddr, .data = NULL}, { .name = PUD_UPLINK_PORT_NAME, .set_plugin_parameter = &setUplinkPort, .data = NULL}, + { .name = PUD_DOWNLINK_PORT_NAME, .set_plugin_parameter = &setDownlinkPort, .data = NULL}, { .name = PUD_OLSR_TTL_NAME, .set_plugin_parameter = &setOlsrTtl, .data = NULL}, { .name = PUD_UPDATE_INTERVAL_STATIONARY_NAME, .set_plugin_parameter = &setUpdateIntervalStationary, .data = NULL}, { .name = PUD_UPDATE_INTERVAL_MOVING_NAME, .set_plugin_parameter = &setUpdateIntervalMoving, .data = NULL}, diff --git a/lib/pud/src/receiver.c b/lib/pud/src/receiver.c index 45581b80..fcc8c413 100644 --- a/lib/pud/src/receiver.c +++ b/lib/pud/src/receiver.c @@ -297,14 +297,12 @@ static void txToAllOlsrInterfaces(TimedTxInterface interfaces) { clusterLeaderMessage); clClusterLeader = getClusterLeaderClusterLeader( olsr_cnf->ip_version, clusterLeaderMessage); + message2Size = sizeof(UplinkClusterLeader) + - sizeof(clusterLeaderMessage->leader); if (olsr_cnf->ip_version == AF_INET) { - message2Size = sizeof(clusterLeaderMessage->version) - + sizeof(clusterLeaderMessage->validityTime) - + sizeof(clusterLeaderMessage->leader.v4); + message2Size += sizeof(clusterLeaderMessage->leader.v4); } else { - message2Size = sizeof(clusterLeaderMessage->version) - + sizeof(clusterLeaderMessage->validityTime) - + sizeof(clusterLeaderMessage->leader.v6); + message2Size = sizeof(clusterLeaderMessage->leader.v6); } /* set header fields */ @@ -321,6 +319,8 @@ static void txToAllOlsrInterfaces(TimedTxInterface interfaces) { (state.externalState == MOVING) ? getUplinkUpdateIntervalMoving() : getUplinkUpdateIntervalStationary()); + setClusterLeaderDownlinkPort(clusterLeaderMessage, + getDownlinkPort()); memcpy(clOriginator, &olsr_cnf->main_addr, olsr_cnf->ipsize); memcpy(clClusterLeader, gwAddr, olsr_cnf->ipsize); diff --git a/lib/pud/wireformat-java/src/main/c/org_olsr_plugin_pud_ClusterLeader.c b/lib/pud/wireformat-java/src/main/c/org_olsr_plugin_pud_ClusterLeader.c index c3ebe738..ed449bf1 100644 --- a/lib/pud/wireformat-java/src/main/c/org_olsr_plugin_pud_ClusterLeader.c +++ b/lib/pud/wireformat-java/src/main/c/org_olsr_plugin_pud_ClusterLeader.c @@ -41,6 +41,26 @@ JNIEXPORT jlong JNICALL Java_org_olsr_plugin_pud_ClusterLeader_getClusterLeaderV return (jlong) validityTime; } +/* + * Class: org_olsr_plugin_pud_ClusterLeader + * Method: getClusterLeaderDownlinkPort + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_olsr_plugin_pud_ClusterLeader_getClusterLeaderDownlinkPort + (JNIEnv * env, jobject this) { + jobject dataObject; + jboolean isCopy; + UplinkMessage * uplinkMessage = getUplinkMessage(env, this, &dataObject, + &isCopy); + + unsigned short downlinkPort = getClusterLeaderDownlinkPort( + getClusterLeaderMessage(uplinkMessage)); + + releaseUplinkMessage(env, uplinkMessage, dataObject, isCopy, JNI_ABORT); + + return (jint) downlinkPort; +} + /* * Class: org_olsr_plugin_pud_ClusterLeader * Method: getClusterLeaderOriginator diff --git a/lib/pud/wireformat-java/src/main/java/org/olsr/plugin/pud/ClusterLeader.java b/lib/pud/wireformat-java/src/main/java/org/olsr/plugin/pud/ClusterLeader.java index f2b1ae53..14c42b9b 100644 --- a/lib/pud/wireformat-java/src/main/java/org/olsr/plugin/pud/ClusterLeader.java +++ b/lib/pud/wireformat-java/src/main/java/org/olsr/plugin/pud/ClusterLeader.java @@ -37,10 +37,15 @@ public class ClusterLeader extends UplinkMessage { public native int getClusterLeaderVersion(); /** - * @return the validity time (in seconds) the cluster leader message + * @return the validity time (in seconds) of the cluster leader message */ public native long getClusterLeaderValidityTime(); + /** + * @return the downlink UDP port of the cluster leader message + */ + public native int getClusterLeaderDownlinkPort(); + /** * @return the (OLSR main) IP address of the OLSR node that sent the cluster * leader message diff --git a/lib/pud/wireformat/include/OlsrdPudWireFormat/wireFormat.h b/lib/pud/wireformat/include/OlsrdPudWireFormat/wireFormat.h index 783b2a54..2e0108e3 100644 --- a/lib/pud/wireformat/include/OlsrdPudWireFormat/wireFormat.h +++ b/lib/pud/wireformat/include/OlsrdPudWireFormat/wireFormat.h @@ -234,6 +234,7 @@ typedef enum _UplinkMessageType { typedef struct _UplinkClusterLeader { uint8_t version; /**< the version of the message */ uint8_t validityTime; /**< the validity time of the sentence */ + uint16_t downlinkPort; /**< the UDP port on which downlink messages are expected */ union _leader { struct _v4 { struct in_addr originator; @@ -872,6 +873,32 @@ static inline void setClusterLeaderVersion( clusterLeaderMessage->version = version; } +/** + Get the downlink port of the cluster leader message + + @param clusterLeaderMessage + A pointer to the cluster leader message + @return + The downlink port of the cluster leader message + */ +static inline uint16_t getClusterLeaderDownlinkPort( + UplinkClusterLeader * clusterLeaderMessage) { + return clusterLeaderMessage->downlinkPort; +} + +/** + Set the downlink port of the cluster leader message + + @param clusterLeaderMessage + A pointer to the cluster leader message + @param port + The downlink port of the cluster leader message + */ +static inline void setClusterLeaderDownlinkPort( + UplinkClusterLeader * clusterLeaderMessage, uint16_t port) { + clusterLeaderMessage->downlinkPort = port; +} + /** Get the originator of a cluster leader message -- 2.20.1