pud: add UUID nodeId type
authorFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 4 Oct 2013 08:18:11 +0000 (10:18 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 4 Oct 2013 08:46:53 +0000 (10:46 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/olsrd.conf.sample
lib/pud/src/configuration.c
lib/pud/wireformat-java/resources/WireFormatConstants.java.h
lib/pud/wireformat/include/OlsrdPudWireFormat/wireFormat.h
lib/pud/wireformat/src/nodeIdConversion.c
lib/pud/wireformat/src/wireFormat.c

index ebf59fb..0a6db30 100644 (file)
@@ -19,6 +19,7 @@ LoadPlugin "<olsrd plugin library path>/olsrd_pud.so.1.1.0"
     #                used)
     #           4 : IPv4 address (OLSR main address) of the sending node
     #               (identification is not relevant)
+    #           5 : an UUID number with 32 hexadecimal digits
     #           6 : IPv6 address (OLSR main address) of the sending node
     #               (identification is not relevant)
     #           7 : an AIS MMSI number with 9 digits
index 21f7ee9..8b38f41 100644 (file)
@@ -402,6 +402,16 @@ static bool setupNodeIdBinaryAndValidate(NodeIdType nodeIdTypeNumber) {
                case PUD_NODEIDTYPE_IPV6: /* IPv6 address */
                        return intSetupNodeIdBinaryIp();
 
+               case PUD_NODEIDTYPE_UUID: /* a UUID number */
+                       return intSetupNodeIdBinaryDoubleLongLong(
+                           &nodeIdBinary.buffer.uuid[0],
+                           PUD_NODEIDTYPE_UUID_CHARS1,
+                           PUD_NODEIDTYPE_UUID_MIN1, PUD_NODEIDTYPE_UUID_MAX1,
+                           PUD_NODEIDTYPE_UUID_BYTES1,
+                           PUD_NODEIDTYPE_UUID_MIN2, PUD_NODEIDTYPE_UUID_MAX2,
+                           PUD_NODEIDTYPE_UUID_BYTES - PUD_NODEIDTYPE_UUID_BYTES1,
+                           16);
+
                case PUD_NODEIDTYPE_MMSI: /* an AIS MMSI number */
                        return intSetupNodeIdBinaryLongLong(PUD_NODEIDTYPE_MMSI_MIN,
                                PUD_NODEIDTYPE_MMSI_MAX, PUD_NODEIDTYPE_MMSI_BYTES);
index 5ea8525..3525381 100644 (file)
@@ -48,6 +48,12 @@ public class WireFormatConstants {
        public static final int NODEIDTYPE_MAC_BYTES = PUD_NODEIDTYPE_MAC_BYTES;
        public static final int NODEIDTYPE_MSISDN_BYTES = PUD_NODEIDTYPE_MSISDN_BYTES;
        public static final int NODEIDTYPE_TETRA_BYTES = PUD_NODEIDTYPE_TETRA_BYTES;
+       public static final int NODEIDTYPE_UUID_BYTES  = PUD_NODEIDTYPE_UUID_BYTES;
+       public static final int NODEIDTYPE_UUID_BYTES1 = PUD_NODEIDTYPE_UUID_BYTES1;
+       public static final int NODEIDTYPE_UUID_BYTES2 = PUD_NODEIDTYPE_UUID_BYTES2;
+       public static final int NODEIDTYPE_UUID_CHARS  = PUD_NODEIDTYPE_UUID_CHARS;
+       public static final int NODEIDTYPE_UUID_CHARS1 = PUD_NODEIDTYPE_UUID_CHARS1;
+       public static final int NODEIDTYPE_UUID_CHARS2 = PUD_NODEIDTYPE_UUID_CHARS2;
        public static final int NODEIDTYPE_MMSI_BYTES = PUD_NODEIDTYPE_MMSI_BYTES;
        public static final int NODEIDTYPE_URN_BYTES = PUD_NODEIDTYPE_URN_BYTES;
        public static final int NODEIDTYPE_MIP_BYTES  = PUD_NODEIDTYPE_MIP_BYTES;
index 378e51a..efe96dd 100644 (file)
@@ -148,8 +148,8 @@ typedef enum _NodeIdType {
        /** IPv4 address, 32 bits, 4 bytes */
        PUD_NODEIDTYPE_IPV4 = 4,
 
-       /** gap 1 */
-       PUD_NODEIDTYPE_GAP1 = 5,
+       /** UUID, 32 hexadecimal digits, 128 bits, 16 bytes */
+       PUD_NODEIDTYPE_UUID = 5,
 
        /** IPv6 address, 128 bits, 16 bytes */
        PUD_NODEIDTYPE_IPV6 = 6,
@@ -195,6 +195,18 @@ typedef enum _NodeIdType {
 #define PUD_NODEIDTYPE_TETRA_MIN               0LLU
 #define PUD_NODEIDTYPE_TETRA_MAX               99999999999999999LLU
 
+/** the number of nodeId bytes for PUD_NODEIDTYPE_UUID */
+#define PUD_NODEIDTYPE_UUID_BYTES   16
+#define PUD_NODEIDTYPE_UUID_BYTES1  8
+#define PUD_NODEIDTYPE_UUID_BYTES2  (PUD_NODEIDTYPE_UUID_BYTES - PUD_NODEIDTYPE_UUID_BYTES1)
+#define PUD_NODEIDTYPE_UUID_CHARS   32
+#define PUD_NODEIDTYPE_UUID_CHARS1  16
+#define PUD_NODEIDTYPE_UUID_CHARS2  (PUD_NODEIDTYPE_UUID_CHARS - PUD_NODEIDTYPE_UUID_CHARS1)
+#define PUD_NODEIDTYPE_UUID_MIN1    0LLU
+#define PUD_NODEIDTYPE_UUID_MAX1    0xFFFFFFFFFFFFFFFFLLU
+#define PUD_NODEIDTYPE_UUID_MIN2    0LLU
+#define PUD_NODEIDTYPE_UUID_MAX2    0xFFFFFFFFFFFFFFFFLLU
+
 /** the number of nodeId bytes for PUD_NODEIDTYPE_MMSI */
 #define PUD_NODEIDTYPE_MMSI_BYTES              4
 #define PUD_NODEIDTYPE_MMSI_MIN                        0LLU
@@ -260,6 +272,7 @@ typedef struct _nodeIdBinaryType {
                                union olsr_ip_addr ip;
                                unsigned long long longValue;
                                unsigned char stringValue[PUD_TX_NODEID_BUFFERSIZE];
+                               unsigned char uuid[PUD_NODEIDTYPE_UUID_BYTES];
                                unsigned char mip[PUD_NODEIDTYPE_MIP_BYTES];
                } buffer;
 } nodeIdBinaryType;
index 6a17c92..2878046 100644 (file)
@@ -70,6 +70,37 @@ static char *getNodeIdNumberFromOlsr(unsigned char * buffer,
 }
 
 /**
+ Get a nodeId hexadecimal number (in string representation), using a certain
+ number of bytes, from the message of an OLSR message.
+
+ @param buffer
+ A pointer to the buffer that holds the nodeId
+ @param bufferSize
+ The number of bytes used by the number in the buffer
+ @param nodeIdBuffer
+ The buffer in which to place the nodeId number in string representation
+ @param nodeIdBufferSize
+ The size of the nodeIdbuffer
+
+ @return
+ A pointer to the nodeId string representation (&nodeIdBuffer[0])
+ */
+static char *getNodeIdHexNumberFromOlsr(unsigned char * buffer,
+               unsigned int bufferSize, char *nodeIdBuffer, socklen_t nodeIdBufferSize) {
+       unsigned long long val = 0;
+       unsigned int i = 0;
+
+       while (i < bufferSize) {
+               val <<= 8;
+               val += buffer[i];
+               i++;
+       }
+
+       snprintf(nodeIdBuffer, nodeIdBufferSize, "%llx", val);
+       return &nodeIdBuffer[0];
+}
+
+/**
  Convert the nodeId of an OLSR message into a string.
 
  @param ipVersion
@@ -140,6 +171,19 @@ void getNodeIdStringFromOlsr(int ipVersion, union olsr_message *olsrMessage,
                                nodeIdStrBuffer, nodeIdStrBufferSize);
                break;
 
+       case PUD_NODEIDTYPE_UUID: /* a UUID number */
+         *nodeIdStr = getNodeIdHexNumberFromOlsr(
+             &nodeId[0],
+             PUD_NODEIDTYPE_UUID_BYTES1,
+             &nodeIdStrBuffer[0],
+             PUD_NODEIDTYPE_UUID_CHARS1 + 1);
+         getNodeIdHexNumberFromOlsr(
+             &nodeId[PUD_NODEIDTYPE_UUID_BYTES1],
+             nodeIdSize - PUD_NODEIDTYPE_UUID_BYTES1,
+             &nodeIdStrBuffer[PUD_NODEIDTYPE_UUID_CHARS1],
+             nodeIdStrBufferSize - PUD_NODEIDTYPE_UUID_CHARS1);
+               break;
+
        case PUD_NODEIDTYPE_MIP: /* a MIP OID number */
          *nodeIdStr = getNodeIdNumberFromOlsr(
              &nodeId[0],
index 96cc534..62b595b 100644 (file)
@@ -13,10 +13,6 @@ bool isValidNodeIdType(unsigned long long nodeIdType) {
                        (/* (nodeIdType >= PUD_NODEIDTYPE_GLOBAL_FIRST) && */ (nodeIdType <= PUD_NODEIDTYPE_GLOBAL_LAST)) ||
                        (   (nodeIdType >= PUD_NODEIDTYPE_LOCAL_FIRST ) &&    (nodeIdType <= PUD_NODEIDTYPE_LOCAL_LAST ))
                )
-               &&
-               (
-                       (nodeIdType != PUD_NODEIDTYPE_GAP1)
-               )
        );
 }
 
@@ -727,6 +723,10 @@ void getPositionUpdateNodeId(int ipVersion, union olsr_message * olsrMessage,
          }
                break;
 
+       case PUD_NODEIDTYPE_UUID: /* a UUID number */
+               *nodeIdSize = PUD_NODEIDTYPE_UUID_BYTES;
+               break;
+
        case PUD_NODEIDTYPE_MMSI: /* an AIS MMSI number */
                *nodeIdSize = PUD_NODEIDTYPE_MMSI_BYTES;
                break;
@@ -820,6 +820,7 @@ size_t setPositionUpdateNodeInfo(int ipVersion,
        case PUD_NODEIDTYPE_MAC: /* hardware address */
        case PUD_NODEIDTYPE_MSISDN: /* an MSISDN number */
        case PUD_NODEIDTYPE_TETRA: /* a Tetra number */
+       case PUD_NODEIDTYPE_UUID: /* a UUID number */
        case PUD_NODEIDTYPE_MMSI: /* an AIS MMSI number */
        case PUD_NODEIDTYPE_URN: /* a URN number */
        case PUD_NODEIDTYPE_MIP: /* a MIP OID number */