Revert "ovn-controller: race between binding-run and patch-run for localnet ports"
[cascardo/ovs.git] / lib / smap.c
index 8865a88..07dd23a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014 Nicira, Inc.
+/* Copyright (c) 2012, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
 
 #include "hash.h"
 #include "json.h"
+#include "packets.h"
+#include "uuid.h"
 
 static struct smap_node *smap_add__(struct smap *, char *, void *,
                                     size_t hash);
@@ -94,6 +96,16 @@ smap_add_format(struct smap *smap, const char *key, const char *format, ...)
                hash_bytes(key, key_len, 0));
 }
 
+/* Adds 'key' paired with a string representation of 'addr'. It is the
+ * caller's responsibility to avoid duplicate keys if desirable. */
+void
+smap_add_ipv6(struct smap *smap, const char *key, struct in6_addr *addr)
+{
+    char buf[INET6_ADDRSTRLEN];
+    ipv6_string_mapped(buf, addr);
+    smap_add(smap, key, buf);
+}
+
 /* Searches for 'key' in 'smap'.  If it does not already exists, adds it.
  * Otherwise, changes its value to 'value'. */
 void
@@ -215,6 +227,16 @@ smap_get_int(const struct smap *smap, const char *key, int def)
     return value ? atoi(value) : def;
 }
 
+/* Gets the value associated with 'key' in 'smap' and converts it to a UUID
+ * using uuid_from_string().  Returns true if successful, false if 'key' is not
+ * in 'smap' or if 'key' does not have the correct syntax for a UUID. */
+bool
+smap_get_uuid(const struct smap *smap, const char *key, struct uuid *uuid)
+{
+    const char *value = smap_get(smap, key);
+    return value && uuid_from_string(uuid, value);
+}
+
 /* Returns true of there are no elements in 'smap'. */
 bool
 smap_is_empty(const struct smap *smap)