PUD: add downlink port to clusterleader message
authorFerry Huberts <f.huberts@mindef.nl>
Thu, 22 Sep 2011 16:26:56 +0000 (18:26 +0200)
committerFerry Huberts <f.huberts@mindef.nl>
Tue, 18 Oct 2011 10:08:27 +0000 (12:08 +0200)
Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/doc/olsrd.conf.default.pud
lib/pud/src/configuration.c
lib/pud/src/configuration.h
lib/pud/src/pudOlsrdPlugin.h
lib/pud/src/receiver.c
lib/pud/wireformat-java/src/main/c/org_olsr_plugin_pud_ClusterLeader.c
lib/pud/wireformat-java/src/main/java/org/olsr/plugin/pud/ClusterLeader.java
lib/pud/wireformat/include/OlsrdPudWireFormat/wireFormat.h

index 84a09c9..01b7d83 100644 (file)
@@ -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
index ae98669..e6cf8e3 100644 (file)
@@ -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;
 }
 
index f03b6e6..d859fdf 100644 (file)
@@ -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
  */
index 0df6e81..59c03bd 100644 (file)
@@ -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},
index 45581b8..fcc8c41 100644 (file)
@@ -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);
index c3ebe73..ed449bf 100644 (file)
@@ -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
index f2b1ae5..14c42b9 100644 (file)
@@ -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
index 783b2a5..2e0108e 100644 (file)
@@ -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