static char **find_key_ge(const char *key);
static char *find_key(const char *);
static bool parse_mac(const char *, uint8_t mac[6]);
+static bool parse_dpid(const char *, uint64_t *);
static bool is_key(const char *);
static bool is_int(const char *);
static bool is_bool(const char *);
return eth_addr_to_uint64(mac);
}
+/* Returns the value numbered 'idx' of 'key', parsed as an datapath ID.
+ * Returns 0 if 'idx' is greater than or equal to cfg_count(key) or if the
+ * value 'idx' of 'key' is not a valid datapath ID consisting of exactly 12
+ * hexadecimal digits. */
+uint64_t
+cfg_get_dpid(int idx, const char *key_, ...)
+{
+ uint64_t dpid;
+ const char *value;
+ char *key;
+
+ FORMAT_KEY(key_, key);
+ value = get_nth_value(idx, key);
+ if (!value || !parse_dpid(value, &dpid)) {
+ dpid = 0;
+ }
+ free(key);
+ return dpid;
+}
+
/* Returns the value numbered 'idx' of 'key', converted to an integer. Returns
* -1 if 'idx' is greater than or equal to cfg_count(key) or if the value 'idx'
* of 'key' is not a valid integer between 0 and 4095. */
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6;
}
+static bool
+parse_dpid(const char *s, uint64_t *dpid)
+{
+ if (strlen(s) == 12 && strspn(s, "0123456789abcdefABCDEF") == 12) {
+ *dpid = strtoll(s, NULL, 16);
+ return true;
+ } else {
+ return false;
+ }
+}
+
static bool
is_key(const char *s)
{
{
uint8_t mac[ETH_ADDR_LEN];
struct in_addr addr;
+ uint64_t dpid;
return (flags & CFG_STRING
|| (flags & CFG_KEY && is_key(s))
|| (flags & CFG_INT && is_int(s))
|| (flags & CFG_BOOL && is_bool(s))
|| (flags & CFG_IP && inet_aton(s, &addr))
- || (flags & CFG_MAC && parse_mac(s, mac)));
+ || (flags & CFG_MAC && parse_mac(s, mac))
+ || (flags & CFG_DPID && parse_dpid(s, &dpid)));
}
CFG_IP = 1 << 4, /* IPv4 address. */
CFG_MAC = 1 << 5, /* MAC address. */
CFG_VLAN = 1 << 6, /* Integer in range 0...4095. */
+ CFG_DPID = 1 << 7, /* 12 hexadecimal digits. */
/* Number allowed. */
- CFG_REQUIRED = 1 << 7, /* At least one value allowed. */
- CFG_MULTIPLE = 1 << 8 /* More than one value allowed. */
+ CFG_REQUIRED = 1 << 8, /* At least one value allowed. */
+ CFG_MULTIPLE = 1 << 9 /* More than one value allowed. */
};
void cfg_register(const char *key_spec, enum cfg_flags);
uint32_t cfg_get_ip(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
uint64_t cfg_get_mac(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
int cfg_get_vlan(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
+uint64_t cfg_get_dpid(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
void cfg_get_all_strings(struct svec *, const char *key, ...)
PRINTF_FORMAT(2, 3);